// Copyright (c) 2002, 2003 Cunningham & Cunningham, Inc.
// Released under the terms of the GNU General Public License version 2 or later.
using System;
using NUnit.Framework;
using System.Reflection;
using System.IO;
namespace fit {
public class FrameworkTest : TestCase {
public FrameworkTest(string name) : base(name) {
}
public void TestParsing() {
Parse p = new Parse("leader
trailer", new string[] {"table"});
AssertEquals("leader", p.leader);
AssertEquals("", p.tag);
AssertEquals("body", p.body);
AssertEquals("trailer", p.trailer);
}
public void testRecursing() {
Parse p = new Parse("leadertrailer");
AssertEquals(null, p.body);
AssertEquals(null, p.parts.body);
AssertEquals("body", p.parts.parts.body);
}
public void testIterating() {
Parse p = new Parse("leadertrailer");
AssertEquals("one", p.parts.parts.body);
AssertEquals("two", p.parts.parts.more.body);
AssertEquals("three", p.parts.parts.more.more.body);
}
public void testIndexing() {
Parse p = new Parse("leadertrailer");
AssertEquals("one", p.at(0,0,0).body);
AssertEquals("two", p.at(0,0,1).body);
AssertEquals("three", p.at(0,0,2).body);
AssertEquals("three", p.at(0,0,3).body);
AssertEquals("three", p.at(0,0,4).body);
AssertEquals("four", p.at(0,1,0).body);
AssertEquals("four", p.at(0,1,1).body);
AssertEquals("four", p.at(0,2,0).body);
AssertEquals(1, p.size());
AssertEquals(2, p.parts.size());
AssertEquals(3, p.parts.parts.size());
AssertEquals("one", p.leaf().body);
AssertEquals("four", p.parts.last().leaf().body);
}
public void testParseException() {
try {
Parse p = new Parse("leadertrailer");
}
catch (ApplicationException e) {
// AssertEquals(17, e.getErrorOffset());
AssertEquals("Can't find tag: td", e.Message);
return;
}
Fail("exptected exception not thrown");
}
public void testText() {
string[] tags ={"td"};
Parse p = new Parse("a<b | ", tags);
AssertEquals("a<b", p.body);
AssertEquals("a\ta>b & b>c && ", tags);
AssertEquals("a>b & b>c &&", p.text());
p = new Parse("\ta>b & b>c & | ", tags);
AssertEquals("a>b & b>c &", p.text());
p = new Parse("GroupTestFixture | ", tags);
AssertEquals("GroupTestFixture",p.text());
}
public void testUnescape () {
AssertEquals("ab & b>c &&", Parse.unescape("a>b & b>c &&"));
AssertEquals("&&", Parse.unescape("&&"));
AssertEquals("a>b & b>c &&", Parse.unescape("a>b & b>c &&"));
}
public void testUnformat () {
AssertEquals("ab",Parse.unformat("ab"));
AssertEquals("ab",Parse.unformat("ab"));
AssertEquals("a") >= 0) {
tables = new Parse(input, new String[]{"wiki", "table", "tr", "td"});
fixture.doTables(tables.parts);
} else {
tables = new Parse(input, new String[]{"table", "tr", "td"});
fixture.doTables(tables);
}
StringWriter output = new StringWriter();
tables.print(output);
output.Close();
AssertEquals(file+" right", right, fixture.counts.right);
AssertEquals(file+" wrong", wrong, fixture.counts.wrong);
AssertEquals(file+" ignores", ignores, fixture.counts.ignores);
AssertEquals(file+" exceptions", exceptions, fixture.counts.exceptions);
}
protected String read(string filename) {
StreamReader input = new StreamReader(filename);
string result = input.ReadToEnd();
input.Close();
return result;
}
}
}