Example #1
0
 public void TestEqualsWithMismatchedText()
 {
     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 );
 }
Example #2
0
 public void TestEquals()
 {
     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 );
 }
Example #3
0
 public void TestDoubleLevelTree()
 {
     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 );
 }
Example #4
0
        public void TestAB()
        {
            ITreeAdaptor adaptor = new CommonTreeAdaptor();
            TreeWizard wiz = new TreeWizard( adaptor, tokens );
            CommonTree t = (CommonTree)wiz.Create( "(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 = "A DOWN B UP EOF";
            string found = buf.ToString();
            Assert.AreEqual( expecting, found );
        }
Example #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());
 }
Example #6
0
 public void TestParseFlatTree()
 {
     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 );
 }
Example #7
0
 public void TestVisitPatternMultipleWithLabels()
 {
     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 );
 }
Example #8
0
 public void TestSingleNodeWithArg()
 {
     TreeWizard wiz = new TreeWizard( adaptor, tokens );
     CommonTree t = (CommonTree)wiz.Create( "ID[foo]" );
     string found = t.ToStringTree();
     string expecting = "foo";
     Assert.AreEqual( expecting, found );
 }
Example #9
0
 public void TestRepeatsVisitWithNullParentAndContext()
 {
     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 );
 }
Example #10
0
 public void TestRepeatsIndex()
 {
     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 );
 }
Example #11
0
 public void TestFindPattern()
 {
     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 );
 }
Example #12
0
 public void TestVisitPattern()
 {
     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 );
 }
Example #13
0
 public void TestSingleNodeTree()
 {
     TreeWizard wiz = new TreeWizard( adaptor, tokens );
     CommonTree t = (CommonTree)wiz.Create( "(A)" );
     string found = t.ToStringTree();
     string expecting = "A";
     assertEquals( expecting, found );
 }
Example #14
0
 public void TestRepeatsVisitWithContext()
 {
     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( "B" ),
        new testRepeatsVisitWithContext_TreeWizard_Visitor( elements ) );
     string found = elements.ToElementString();
     string expecting = "[B@A[0], B@A[1], B@A[2]]";
     assertEquals( expecting, found );
 }
Example #15
0
 public void TestParseLabels()
 {
     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() );
 }
Example #16
0
 public void TestParseWithTextFails()
 {
     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 #17
0
 public void TestParseWithWildcardLabels()
 {
     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() );
 }
Example #18
0
 public void TestInvalidListTree()
 {
     TreeWizard wiz = new TreeWizard( adaptor, tokens );
     CommonTree t = (CommonTree)wiz.Create( "A B C" );
     Assert.IsTrue( t == null );
 }
Example #19
0
 public void TestRepeatsVisit()
 {
     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( "B" ),
                    new testNoRepeatsVisit_TreeWizard_Visitor( elements ) );
     string found = elements.ToElementString();
     string expecting = "[B, B, B]";
     Assert.AreEqual( expecting, found );
 }
Example #20
0
 public void TestListTree()
 {
     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 );
 }
Example #21
0
 public void TestSingleNodeIndex()
 {
     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 );
 }
Example #22
0
 public void TestParseLabelsAndTestText()
 {
     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() );
 }
Example #23
0
 public void TestVisitPatternMultiple()
 {
     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 );
 }
Example #24
0
 public void TestParseLabelsInNestedTree()
 {
     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() );
 }
Example #25
0
 public void TestWildcard()
 {
     TreeWizard wiz = new TreeWizard( adaptor, tokens );
     CommonTree t = (CommonTree)wiz.Create( "(A B C)" );
     bool valid = wiz.Parse( t, "(A . .)" );
     Assert.IsTrue( valid );
 }
Example #26
0
 public void TestParseSingleNode()
 {
     TreeWizard wiz = new TreeWizard( adaptor, tokens );
     CommonTree t = (CommonTree)wiz.Create( "A" );
     bool valid = wiz.Parse( t, "A" );
     Assert.IsTrue( valid );
 }
Example #27
0
 public void TestParseWithText()
 {
     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 #28
0
 public void TestNoRepeatsIndex()
 {
     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 );
 }