コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: TestTreeWizard.cs プロジェクト: ymf1/webgrease
        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);
        }
コード例 #3
0
        public void TestInvalidListTree() /*throws Exception*/
        {
            TreeWizard wiz = new TreeWizard(adaptor, tokens);
            CommonTree t   = (CommonTree)wiz.Create("A B C");

            Assert.IsNull(t);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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
        }
コード例 #7
0
ファイル: TestTreeWizard.cs プロジェクト: ymf1/webgrease
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
ファイル: TestTreeWizard.cs プロジェクト: ymf1/webgrease
        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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        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);
        }
コード例 #15
0
ファイル: TestTreeWizard.cs プロジェクト: ymf1/webgrease
        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);
        }
コード例 #16
0
        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());
        }
コード例 #17
0
        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);
        }
コード例 #18
0
        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);
        }
コード例 #19
0
        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());
        }
コード例 #20
0
ファイル: TestTreeWizard.cs プロジェクト: ymf1/webgrease
        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());
        }
コード例 #21
0
        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);
        }
コード例 #22
0
        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());
        }
コード例 #23
0
        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);
        }
コード例 #24
0
        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);
        }
コード例 #25
0
        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);
        }
コード例 #26
0
ファイル: TestTreeWizard.cs プロジェクト: ymf1/webgrease
        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);
        }
コード例 #27
0
        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());
        }