public void testEqualsWithMismatchedText()
        {
            ITreeAdaptor adaptor = new CommonTreeAdaptor();
            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 testInvalidListTree()
        {
            ITreeAdaptor adaptor = new CommonTreeAdaptor();
            TreeWizard   wiz     = new TreeWizard(adaptor, tokens);
            CommonTree   t       = (CommonTree)wiz.Create("A B C");

            Assert.IsTrue(t == null);
        }
        public void testParseSingleNode()
        {
            ITreeAdaptor adaptor = new CommonTreeAdaptor();
            TreeWizard   wiz     = new TreeWizard(adaptor, tokens);
            CommonTree   t       = (CommonTree)wiz.Create("A");
            bool         valid   = wiz.Parse(t, "A");

            Assert.IsTrue(valid);
        }
        public void testWildcard()
        {
            ITreeAdaptor adaptor = new CommonTreeAdaptor();
            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()
        {
            ITreeAdaptor adaptor = new CommonTreeAdaptor();
            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 testDoubleLevelTree()
 {
     ITreeAdaptor adaptor = new CommonTreeAdaptor();
     TreeWizard wiz = new TreeWizard(adaptor, tokens);
     CommonTree t = (CommonTree)wiz.Create("(A (B C) (B D) E)");
     string actual = t.ToStringTree();
     string expected = "(A (B C) (B D) E)";
     Assert.AreEqual(expected, actual);
 }
        public void testListTree()
        {
            ITreeAdaptor adaptor  = new CommonTreeAdaptor();
            TreeWizard   wiz      = new TreeWizard(adaptor, tokens);
            CommonTree   t        = (CommonTree)wiz.Create("(nil A B C)");
            string       actual   = t.ToStringTree();
            string       expected = "A B C";

            Assert.AreEqual(expected, actual);
        }
        public void testDoubleLevelTree()
        {
            ITreeAdaptor adaptor  = new CommonTreeAdaptor();
            TreeWizard   wiz      = new TreeWizard(adaptor, tokens);
            CommonTree   t        = (CommonTree)wiz.Create("(A (B C) (B D) E)");
            string       actual   = t.ToStringTree();
            string       expected = "(A (B C) (B D) E)";

            Assert.AreEqual(expected, actual);
        }
        public void testSingleNodeWithArg()
        {
            ITreeAdaptor adaptor  = new CommonTreeAdaptor();
            TreeWizard   wiz      = new TreeWizard(adaptor, tokens);
            CommonTree   t        = (CommonTree)wiz.Create("ID[foo]");
            string       actual   = t.ToStringTree();
            string       expected = "foo";

            Assert.AreEqual(expected, actual);
        }
Example #10
0
        public void testSingleNodeIndex()
        {
            ITreeAdaptor adaptor  = new CommonTreeAdaptor();
            TreeWizard   wiz      = new TreeWizard(adaptor, tokens);
            CommonTree   t        = (CommonTree)wiz.Create("ID");
            IDictionary  m        = wiz.Index(t);
            string       actual   = CollectionUtils.DictionaryToString(m);
            string       expected = "{10=[ID]}";

            Assert.AreEqual(expected, actual);
        }
Example #11
0
        public void testParseWithText()
        {
            ITreeAdaptor adaptor = new CommonTreeAdaptor();
            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);
        }
Example #12
0
        public void testFindPattern()
        {
            ITreeAdaptor adaptor  = new CommonTreeAdaptor();
            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       actual   = CollectionUtils.ListToString(elements);
            string       expected = "[foo, big]";

            Assert.AreEqual(expected, actual);
        }
Example #13
0
        public void testParseWithWildcardLabels()
        {
            ITreeAdaptor adaptor = new CommonTreeAdaptor();
            TreeWizard   wiz     = new TreeWizard(adaptor, tokens);
            CommonTree   t       = (CommonTree)wiz.Create("(A B C)");
            IDictionary  labels  = new Hashtable();
            bool         valid   = wiz.Parse(t, "(A %b:. %c:.)", labels);

            Assert.IsTrue(valid);
            Assert.AreEqual("B", labels["b"].ToString());
            Assert.AreEqual("C", labels["c"].ToString());
        }
Example #14
0
        public void testRepeatsIndex()
        {
            ITreeAdaptor adaptor = new CommonTreeAdaptor();
            TreeWizard   wiz     = new TreeWizard(adaptor, tokens);
            CommonTree   t       = (CommonTree)wiz.Create("(A B (A C B) B D D)");
            IDictionary  m       = wiz.Index(t);
            string       actual  = CollectionUtils.DictionaryToString(m);
            //string expected = "{8=[D, D], 6=[B, B, B], 7=[C], 5=[A, A]}";
            string expected = "{8=[D, D], 7=[C], 6=[B, B, B], 5=[A, A]}";

            Assert.AreEqual(expected, actual);
        }
Example #15
0
        public void testRepeatsVisit2()
        {
            ITreeAdaptor adaptor  = new CommonTreeAdaptor();
            TreeWizard   wiz      = new TreeWizard(adaptor, tokens);
            CommonTree   t        = (CommonTree)wiz.Create("(A B (A C B) B D D)");
            IList        elements = new ArrayList();

            wiz.Visit(t, wiz.GetTokenType("A"), new RecordAllElementsVisitor(elements));
            string actual   = CollectionUtils.ListToString(elements);
            string expected = "[A, A]";

            Assert.AreEqual(expected, actual);
        }
Example #16
0
        public void testVisitPattern()
        {
            ITreeAdaptor adaptor  = new CommonTreeAdaptor();
            TreeWizard   wiz      = new TreeWizard(adaptor, tokens);
            CommonTree   t        = (CommonTree)wiz.Create("(A B C (A B) D)");
            IList        elements = new ArrayList();

            wiz.Visit(t, "(A B)", new RecordAllElementsVisitor(elements));
            string actual   = CollectionUtils.ListToString(elements);
            string expected = "[A]";             // shouldn't match overall root, just (A B)

            Assert.AreEqual(expected, actual);
        }
Example #17
0
        public void testVisitPatternMultiple()
        {
            ITreeAdaptor adaptor  = new CommonTreeAdaptor();
            TreeWizard   wiz      = new TreeWizard(adaptor, tokens);
            CommonTree   t        = (CommonTree)wiz.Create("(A B C (A B) (D (A B)))");
            IList        elements = new ArrayList();

            wiz.Visit(t, "(A B)", new Test1ContextVisitor(adaptor, elements));
            string actual   = CollectionUtils.ListToString(elements);
            string expected = "[A@A[2], A@D[0]]";             // shouldn't match overall root, just (A B)

            Assert.AreEqual(expected, actual);
        }
Example #18
0
        public void testVisitPatternMultipleWithLabels()
        {
            ITreeAdaptor adaptor  = new CommonTreeAdaptor();
            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 ArrayList();

            wiz.Visit(t, "(%a:A %b:B)", new Test2ContextVisitor(adaptor, elements));
            string actual   = CollectionUtils.ListToString(elements);
            string expected = "[foo@A[2]foo&bar, big@D[0]big&dog]";

            Assert.AreEqual(expected, actual);
        }
Example #19
0
        public void testRepeatsVisitWithNullParentAndContext()
        {
            ITreeAdaptor adaptor  = new CommonTreeAdaptor();
            TreeWizard   wiz      = new TreeWizard(adaptor, tokens);
            CommonTree   t        = (CommonTree)wiz.Create("(A B (A C B) B D D)");
            IList        elements = new ArrayList();

            wiz.Visit(t, wiz.GetTokenType("A"), new Test1ContextVisitor(adaptor, elements));
            string actual   = CollectionUtils.ListToString(elements);
            string expected = "[A@nil[0], A@A[1]]";

            Assert.AreEqual(expected, actual);
        }
Example #20
0
        public void testParseLabelsAndTestText()
        {
            ITreeAdaptor adaptor = new CommonTreeAdaptor();
            TreeWizard   wiz     = new TreeWizard(adaptor, tokens);
            CommonTree   t       = (CommonTree)wiz.Create("(A B[foo] C)");
            IDictionary  labels  = new Hashtable();
            bool         valid   = wiz.Parse(t, "(%a:A %b:B[foo] %c:C)", labels);

            Assert.IsTrue(valid);
            Assert.AreEqual("A", labels["a"].ToString());
            Assert.AreEqual("foo", labels["b"].ToString());
            Assert.AreEqual("C", labels["c"].ToString());
        }
Example #21
0
        public void testParseLabelsInNestedTree()
        {
            ITreeAdaptor adaptor = new CommonTreeAdaptor();
            TreeWizard   wiz     = new TreeWizard(adaptor, tokens);
            CommonTree   t       = (CommonTree)wiz.Create("(A (B C) (D E))");
            IDictionary  labels  = new Hashtable();
            bool         valid   = wiz.Parse(t, "(%a:A (%b:B %c:C) (%d:D %e:E) )", labels);

            Assert.IsTrue(valid);
            Assert.AreEqual("A", labels["a"].ToString());
            Assert.AreEqual("B", labels["b"].ToString());
            Assert.AreEqual("C", labels["c"].ToString());
            Assert.AreEqual("D", labels["d"].ToString());
            Assert.AreEqual("E", labels["e"].ToString());
        }
Example #22
0
 public void testVisitPatternMultipleWithLabels()
 {
     ITreeAdaptor adaptor = new CommonTreeAdaptor();
     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 ArrayList();
     wiz.Visit(t, "(%a:A %b:B)", new Test2ContextVisitor(adaptor, elements));
     string actual = CollectionUtils.ListToString(elements);
     string expected = "[foo@A[2]foo&bar, big@D[0]big&dog]";
     Assert.AreEqual(expected, actual);
 }
Example #23
0
 public void testParseLabelsAndTestText()
 {
     ITreeAdaptor adaptor = new CommonTreeAdaptor();
     TreeWizard wiz = new TreeWizard(adaptor, tokens);
     CommonTree t = (CommonTree)wiz.Create("(A B[foo] C)");
     IDictionary labels = new Hashtable();
     bool valid = wiz.Parse(t, "(%a:A %b:B[foo] %c:C)", labels);
     Assert.IsTrue(valid);
     Assert.AreEqual("A", labels["a"].ToString());
     Assert.AreEqual("foo", labels["b"].ToString());
     Assert.AreEqual("C", labels["c"].ToString());
 }
Example #24
0
 public void testParseSingleNode()
 {
     ITreeAdaptor adaptor = new CommonTreeAdaptor();
     TreeWizard wiz = new TreeWizard(adaptor, tokens);
     CommonTree t = (CommonTree)wiz.Create("A");
     bool valid = wiz.Parse(t, "A");
     Assert.IsTrue(valid);
 }
Example #25
0
 public void testRepeatsIndex()
 {
     ITreeAdaptor adaptor = new CommonTreeAdaptor();
     TreeWizard wiz = new TreeWizard(adaptor, tokens);
     CommonTree t = (CommonTree)wiz.Create("(A B (A C B) B D D)");
     IDictionary m = wiz.Index(t);
     string actual = CollectionUtils.DictionaryToString(m);
     //string expected = "{8=[D, D], 6=[B, B, B], 7=[C], 5=[A, A]}";
     string expected = "{8=[D, D], 7=[C], 6=[B, B, B], 5=[A, A]}";
     Assert.AreEqual(expected, actual);
 }
Example #26
0
 public void testRepeatsVisit2()
 {
     ITreeAdaptor adaptor = new CommonTreeAdaptor();
     TreeWizard wiz = new TreeWizard(adaptor, tokens);
     CommonTree t = (CommonTree)wiz.Create("(A B (A C B) B D D)");
     IList elements = new ArrayList();
     wiz.Visit(t, wiz.GetTokenType("A"), new RecordAllElementsVisitor(elements));
     string actual = CollectionUtils.ListToString(elements);
     string expected = "[A, A]";
     Assert.AreEqual(expected, actual);
 }
Example #27
0
 public void testInvalidListTree()
 {
     ITreeAdaptor adaptor = new CommonTreeAdaptor();
     TreeWizard wiz = new TreeWizard(adaptor, tokens);
     CommonTree t = (CommonTree)wiz.Create("A B C");
     Assert.IsTrue(t == null);
 }
Example #28
0
 public void testEquals()
 {
     ITreeAdaptor adaptor = new CommonTreeAdaptor();
     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);
     Assert.IsTrue(same);
 }
Example #29
0
 public void testRepeatsVisitWithNullParentAndContext()
 {
     ITreeAdaptor adaptor = new CommonTreeAdaptor();
     TreeWizard wiz = new TreeWizard(adaptor, tokens);
     CommonTree t = (CommonTree)wiz.Create("(A B (A C B) B D D)");
     IList elements = new ArrayList();
     wiz.Visit(t, wiz.GetTokenType("A"), new Test1ContextVisitor(adaptor, elements));
     string actual = CollectionUtils.ListToString(elements);
     string expected = "[A@nil[0], A@A[1]]";
     Assert.AreEqual(expected, actual);
 }
Example #30
0
 public void testWildcard()
 {
     ITreeAdaptor adaptor = new CommonTreeAdaptor();
     TreeWizard wiz = new TreeWizard(adaptor, tokens);
     CommonTree t = (CommonTree)wiz.Create("(A B C)");
     bool valid = wiz.Parse(t, "(A . .)");
     Assert.IsTrue(valid);
 }
Example #31
0
 public void testParseWithText()
 {
     ITreeAdaptor adaptor = new CommonTreeAdaptor();
     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);
 }
Example #32
0
 public void testParseWithWildcardLabels()
 {
     ITreeAdaptor adaptor = new CommonTreeAdaptor();
     TreeWizard wiz = new TreeWizard(adaptor, tokens);
     CommonTree t = (CommonTree)wiz.Create("(A B C)");
     IDictionary labels = new Hashtable();
     bool valid = wiz.Parse(t, "(A %b:. %c:.)", labels);
     Assert.IsTrue(valid);
     Assert.AreEqual("B", labels["b"].ToString());
     Assert.AreEqual("C", labels["c"].ToString());
 }
Example #33
0
 public void testParseLabelsInNestedTree()
 {
     ITreeAdaptor adaptor = new CommonTreeAdaptor();
     TreeWizard wiz = new TreeWizard(adaptor, tokens);
     CommonTree t = (CommonTree)wiz.Create("(A (B C) (D E))");
     IDictionary labels = new Hashtable();
     bool valid = wiz.Parse(t, "(%a:A (%b:B %c:C) (%d:D %e:E) )", labels);
     Assert.IsTrue(valid);
     Assert.AreEqual("A", labels["a"].ToString());
     Assert.AreEqual("B", labels["b"].ToString());
     Assert.AreEqual("C", labels["c"].ToString());
     Assert.AreEqual("D", labels["d"].ToString());
     Assert.AreEqual("E", labels["e"].ToString());
 }
Example #34
0
 public void testParseWithTextFails()
 {
     ITreeAdaptor adaptor = new CommonTreeAdaptor();
     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
 }
Example #35
0
 public void testVisitPattern()
 {
     ITreeAdaptor adaptor = new CommonTreeAdaptor();
     TreeWizard wiz = new TreeWizard(adaptor, tokens);
     CommonTree t = (CommonTree)wiz.Create("(A B C (A B) D)");
     IList elements = new ArrayList();
     wiz.Visit(t, "(A B)", new RecordAllElementsVisitor(elements));
     string actual = CollectionUtils.ListToString(elements);
     string expected = "[A]"; // shouldn't match overall root, just (A B)
     Assert.AreEqual(expected, actual);
 }
Example #36
0
 public void testListTree()
 {
     ITreeAdaptor adaptor = new CommonTreeAdaptor();
     TreeWizard wiz = new TreeWizard(adaptor, tokens);
     CommonTree t = (CommonTree)wiz.Create("(nil A B C)");
     string actual = t.ToStringTree();
     string expected = "A B C";
     Assert.AreEqual(expected, actual);
 }
Example #37
0
 public void testSingleNodeWithArg()
 {
     ITreeAdaptor adaptor = new CommonTreeAdaptor();
     TreeWizard wiz = new TreeWizard(adaptor, tokens);
     CommonTree t = (CommonTree)wiz.Create("ID[foo]");
     string actual = t.ToStringTree();
     string expected = "foo";
     Assert.AreEqual(expected, actual);
 }
Example #38
0
 public void testVisitPatternMultiple()
 {
     ITreeAdaptor adaptor = new CommonTreeAdaptor();
     TreeWizard wiz = new TreeWizard(adaptor, tokens);
     CommonTree t = (CommonTree)wiz.Create("(A B C (A B) (D (A B)))");
     IList elements = new ArrayList();
     wiz.Visit(t, "(A B)", new Test1ContextVisitor(adaptor, elements));
     string actual = CollectionUtils.ListToString(elements);
     string expected = "[A@A[2], A@D[0]]"; // shouldn't match overall root, just (A B)
     Assert.AreEqual(expected, actual);
 }
Example #39
0
 public void testFindPattern()
 {
     ITreeAdaptor adaptor = new CommonTreeAdaptor();
     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 actual = CollectionUtils.ListToString(elements);
     string expected = "[foo, big]";
     Assert.AreEqual(expected, actual);
 }
Example #40
0
 public void testSingleNodeIndex()
 {
     ITreeAdaptor adaptor = new CommonTreeAdaptor();
     TreeWizard wiz = new TreeWizard(adaptor, tokens);
     CommonTree t = (CommonTree)wiz.Create("ID");
     IDictionary m = wiz.Index(t);
     string actual = CollectionUtils.DictionaryToString(m);
     string expected = "{10=[ID]}";
     Assert.AreEqual(expected, actual);
 }