public void TestEqualsWithMismatchedText() /*throws Exception*/ { TreeWizard wiz = new TreeWizard(adaptor, tokens); CommonTree t1 = (CommonTree)wiz.Create("(A B[foo] C)"); CommonTree t2 = (CommonTree)wiz.Create("(A B C)"); bool same = TreeWizard.Equals(t1, t2, adaptor); Assert.IsTrue(!same); }
public void TestEquals() /*throws Exception*/ { TreeWizard wiz = new TreeWizard(adaptor, tokens); CommonTree t1 = (CommonTree)wiz.Create("(A B C)"); CommonTree t2 = (CommonTree)wiz.Create("(A B C)"); bool same = TreeWizard.Equals(t1, t2, adaptor); assertTrue(same); }
public void TestInvalidListTree() /*throws Exception*/ { TreeWizard wiz = new TreeWizard(adaptor, tokens); CommonTree t = (CommonTree)wiz.Create("A B C"); Assert.IsNull(t); }
public void TestFlatAB() { ITreeAdaptor adaptor = new CommonTreeAdaptor(); TreeWizard wiz = new TreeWizard(adaptor, tokens); CommonTree t = (CommonTree)wiz.Create("(nil A B)"); TreeIterator it = new TreeIterator(t); StringBuilder buf = new StringBuilder(); bool first = true; while (it.MoveNext()) { CommonTree n = (CommonTree)it.Current; if (!first) { buf.Append(" "); } first = false; buf.Append(n); } string expecting = "nil DOWN A B UP EOF"; string found = buf.ToString(); Assert.AreEqual(expecting, found); }
public void TestWildcard() /*throws Exception*/ { TreeWizard wiz = new TreeWizard(adaptor, tokens); CommonTree t = (CommonTree)wiz.Create("(A B C)"); bool valid = wiz.Parse(t, "(A . .)"); Assert.IsTrue(valid); }
public void TestParseWithTextFails() /*throws Exception*/ { TreeWizard wiz = new TreeWizard(adaptor, tokens); CommonTree t = (CommonTree)wiz.Create("(A B C)"); bool valid = wiz.Parse(t, "(A[foo] B C)"); Assert.IsTrue(!valid); // fails }
public void TestParseFlatTree() /*throws Exception*/ { TreeWizard wiz = new TreeWizard(adaptor, tokens); CommonTree t = (CommonTree)wiz.Create("(nil A B C)"); bool valid = wiz.Parse(t, "(nil A B C)"); assertTrue(valid); }
public void TestParseSingleNode() /*throws Exception*/ { TreeWizard wiz = new TreeWizard(adaptor, tokens); CommonTree t = (CommonTree)wiz.Create("A"); bool valid = wiz.Parse(t, "A"); Assert.IsTrue(valid); }
public void TestSingleNodeWithArg() /*throws Exception*/ { TreeWizard wiz = new TreeWizard(adaptor, tokens); CommonTree t = (CommonTree)wiz.Create("ID[foo]"); string found = t.ToStringTree(); string expecting = "foo"; Assert.AreEqual(expecting, found); }
public void TestDoubleLevelTree() /*throws Exception*/ { TreeWizard wiz = new TreeWizard(adaptor, tokens); CommonTree t = (CommonTree)wiz.Create("(A (B C) (B D) E)"); string found = t.ToStringTree(); string expecting = "(A (B C) (B D) E)"; Assert.AreEqual(expecting, found); }
public void TestSingleLevelTree() /*throws Exception*/ { TreeWizard wiz = new TreeWizard(adaptor, tokens); CommonTree t = (CommonTree)wiz.Create("(A B C D)"); string found = t.ToStringTree(); string expecting = "(A B C D)"; assertEquals(expecting, found); }
public void TestListTree() /*throws Exception*/ { TreeWizard wiz = new TreeWizard(adaptor, tokens); CommonTree t = (CommonTree)wiz.Create("(nil A B C)"); string found = t.ToStringTree(); string expecting = "A B C"; Assert.AreEqual(expecting, found); }
public void TestRepeatsIndex() /*throws Exception*/ { TreeWizard wiz = new TreeWizard(adaptor, tokens); CommonTree t = (CommonTree)wiz.Create("(A B (A C B) B D D)"); var m = wiz.Index(t); string found = sortMapToString(m); string expecting = "{5=[A, A], 6=[B, B, B], 7=[C], 8=[D, D]}"; Assert.AreEqual(expecting, found); }
public void TestSingleNodeIndex() /*throws Exception*/ { TreeWizard wiz = new TreeWizard(adaptor, tokens); CommonTree t = (CommonTree)wiz.Create("ID"); var m = wiz.Index(t); string found = m.ToElementString(); string expecting = "{10=[ID]}"; Assert.AreEqual(expecting, found); }
public void TestNoRepeatsIndex() /*throws Exception*/ { TreeWizard wiz = new TreeWizard(adaptor, tokens); CommonTree t = (CommonTree)wiz.Create("(A B C D)"); var m = wiz.Index(t); string found = sortMapToString(m); string expecting = "{5=[A], 6=[B], 7=[C], 8=[D]}"; assertEquals(expecting, found); }
public void TestParseWithText2() { TreeWizard wiz = new TreeWizard(adaptor, tokens); CommonTree t = (CommonTree)wiz.Create("(A B[T__32] (C (D E[a])))"); // C pattern has no text arg so despite [bar] in t, no need // to match text--check structure only. bool valid = wiz.Parse(t, "(A B[foo] C)"); Assert.AreEqual("(A T__32 (C (D a)))", t.ToStringTree()); }
public void TestParseWithText() /*throws Exception*/ { TreeWizard wiz = new TreeWizard(adaptor, tokens); CommonTree t = (CommonTree)wiz.Create("(A B[foo] C[bar])"); // C pattern has no text arg so despite [bar] in t, no need // to match text--check structure only. bool valid = wiz.Parse(t, "(A B[foo] C)"); Assert.IsTrue(valid); }
public void TestFindPattern() /*throws Exception*/ { TreeWizard wiz = new TreeWizard(adaptor, tokens); CommonTree t = (CommonTree)wiz.Create("(A B C (A[foo] B[bar]) (D (A[big] B[dog])))"); IList subtrees = wiz.Find(t, "(A B)"); IList elements = subtrees; string found = elements.ToElementString(); string expecting = "[foo, big]"; Assert.AreEqual(expecting, found); }
public void TestParseWithWildcardLabels() /*throws Exception*/ { TreeWizard wiz = new TreeWizard(adaptor, tokens); CommonTree t = (CommonTree)wiz.Create("(A B C)"); var labels = new Dictionary <string, object>(); bool valid = wiz.Parse(t, "(A %b:. %c:.)", labels); Assert.IsTrue(valid); Assert.AreEqual("B", labels.get("b").ToString()); Assert.AreEqual("C", labels.get("c").ToString()); }
public void TestParseLabels() /*throws Exception*/ { TreeWizard wiz = new TreeWizard(adaptor, tokens); CommonTree t = (CommonTree)wiz.Create("(A B C)"); IDictionary <string, object> labels = new Dictionary <string, object>(); bool valid = wiz.Parse(t, "(%a:A %b:B %c:C)", labels); assertTrue(valid); assertEquals("A", labels.get("a").ToString()); assertEquals("B", labels.get("b").ToString()); assertEquals("C", labels.get("c").ToString()); }
public void TestNoRepeatsVisit() /*throws Exception*/ { TreeWizard wiz = new TreeWizard(adaptor, tokens); CommonTree t = (CommonTree)wiz.Create("(A B C D)"); IList elements = new List <object>(); wiz.Visit(t, wiz.GetTokenType("B"), new testNoRepeatsVisit_TreeWizard_Visitor(elements)); string found = elements.ToElementString(); string expecting = "[B]"; Assert.AreEqual(expecting, found); }
public void TestParseLabelsAndTestText() /*throws Exception*/ { TreeWizard wiz = new TreeWizard(adaptor, tokens); CommonTree t = (CommonTree)wiz.Create("(A B[foo] C)"); var labels = new Dictionary <string, object>(); bool valid = wiz.Parse(t, "(%a:A %b:B[foo] %c:C)", labels); Assert.IsTrue(valid); Assert.AreEqual("A", labels.get("a").ToString()); Assert.AreEqual("foo", labels.get("b").ToString()); Assert.AreEqual("C", labels.get("c").ToString()); }
public void TestVisitPatternMultipleWithLabels() /*throws Exception*/ { TreeWizard wiz = new TreeWizard(adaptor, tokens); CommonTree t = (CommonTree)wiz.Create("(A B C (A[foo] B[bar]) (D (A[big] B[dog])))"); IList elements = new List <object>(); wiz.Visit(t, "(%a:A %b:B)", new testVisitPatternMultipleWithLabels_TreeWizard_Visitor(elements)); string found = elements.ToElementString(); string expecting = "[foo@A[2]foo&bar, big@D[0]big&dog]"; Assert.AreEqual(expecting, found); }
public void TestRepeatsVisitWithNullParentAndContext() /*throws Exception*/ { TreeWizard wiz = new TreeWizard(adaptor, tokens); CommonTree t = (CommonTree)wiz.Create("(A B (A C B) B D D)"); IList elements = new List <object>(); wiz.Visit(t, wiz.GetTokenType("A"), new testRepeatsVisitWithContext_TreeWizard_Visitor(elements)); string found = elements.ToElementString(); string expecting = "[A@nil[0], A@A[1]]"; Assert.AreEqual(expecting, found); }
public void TestVisitPatternMultiple() /*throws Exception*/ { TreeWizard wiz = new TreeWizard(adaptor, tokens); CommonTree t = (CommonTree)wiz.Create("(A B C (A B) (D (A B)))"); IList elements = new List <object>(); wiz.Visit(t, "(A B)", new testRepeatsVisitWithContext_TreeWizard_Visitor(elements)); string found = elements.ToElementString(); string expecting = "[A@A[2], A@D[0]]"; // shouldn't match overall root, just (A B) Assert.AreEqual(expecting, found); }
public void TestVisitPattern() /*throws Exception*/ { TreeWizard wiz = new TreeWizard(adaptor, tokens); CommonTree t = (CommonTree)wiz.Create("(A B C (A B) D)"); IList elements = new List <object>(); wiz.Visit(t, "(A B)", new testNoRepeatsVisit_TreeWizard_Visitor(elements)); string found = elements.ToElementString(); string expecting = "[A]"; // shouldn't match overall root, just (A B) assertEquals(expecting, found); }
public void TestParseLabelsInNestedTree() /*throws Exception*/ { TreeWizard wiz = new TreeWizard(adaptor, tokens); CommonTree t = (CommonTree)wiz.Create("(A (B C) (D E))"); var labels = new Dictionary <string, object>(); bool valid = wiz.Parse(t, "(%a:A (%b:B %c:C) (%d:D %e:E) )", labels); Assert.IsTrue(valid); Assert.AreEqual("A", labels.get("a").ToString()); Assert.AreEqual("B", labels.get("b").ToString()); Assert.AreEqual("C", labels.get("c").ToString()); Assert.AreEqual("D", labels.get("d").ToString()); Assert.AreEqual("E", labels.get("e").ToString()); }