Esempio n. 1
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);
        }
Esempio n. 2
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
        }
Esempio n. 3
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);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
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());
        }
Esempio n. 6
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);
        }
Esempio n. 7
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());
        }
Esempio n. 8
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());
        }
Esempio n. 9
0
        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());
        }
Esempio n. 10
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());
        }