Beispiel #1
0
        public void testBecomeRoot6()
        {
            // emulates construction of ^(5 6)
            ITreeAdaptor adaptor = new CommonTreeAdaptor();
            CommonTree   root_0  = (CommonTree)adaptor.GetNilNode();
            CommonTree   root_1  = (CommonTree)adaptor.GetNilNode();

            root_1 = (CommonTree)adaptor.BecomeRoot(new CommonTree(new CommonToken(5)), root_1);

            adaptor.AddChild(root_1, new CommonTree(new CommonToken(6)));

            adaptor.AddChild(root_0, root_1);

            root_0.SanityCheckParentAndChildIndexes();
        }
Beispiel #2
0
        public void testBecomeRoot2()
        {
            // 5 becomes new root of ^(101 102 103)
            CommonTree newRoot = new CommonTree(new CommonToken(5));

            CommonTree oldRoot = new CommonTree(new CommonToken(101));

            oldRoot.AddChild(new CommonTree(new CommonToken(102)));
            oldRoot.AddChild(new CommonTree(new CommonToken(103)));

            ITreeAdaptor adaptor = new CommonTreeAdaptor();

            adaptor.BecomeRoot(newRoot, oldRoot);
            newRoot.SanityCheckParentAndChildIndexes();
        }
Beispiel #3
0
        public void testReplaceAllWithOne()
        {
            CommonTree t = new CommonTree(new CommonToken(99, "a"));

            t.AddChild(new CommonTree(new CommonToken(99, "b")));
            t.AddChild(new CommonTree(new CommonToken(99, "c")));
            t.AddChild(new CommonTree(new CommonToken(99, "d")));

            CommonTree newChild = new CommonTree(new CommonToken(99, "x"));

            t.ReplaceChildren(0, 2, newChild);
            String expected = "(a x)";

            Assert.AreEqual(expected, t.ToStringTree());
            t.SanityCheckParentAndChildIndexes();
        }
Beispiel #4
0
        public void testReplaceInMiddle()
        {
            CommonTree t = new CommonTree(new CommonToken(99, "a"));

            t.AddChild(new CommonTree(new CommonToken(99, "b")));
            t.AddChild(new CommonTree(new CommonToken(99, "c")));             // index 1
            t.AddChild(new CommonTree(new CommonToken(99, "d")));

            CommonTree newChild = new CommonTree(new CommonToken(99, "x"));

            t.ReplaceChildren(1, 1, newChild);
            String expected = "(a b x d)";

            Assert.AreEqual(expected, t.ToStringTree());
            t.SanityCheckParentAndChildIndexes();
        }
Beispiel #5
0
        public void testReplaceWithOneChildren()
        {
            // assume token type 99 and use text
            CommonTree t  = new CommonTree(new CommonToken(99, "a"));
            CommonTree c0 = new CommonTree(new CommonToken(99, "b"));

            t.AddChild(c0);

            CommonTree newChild = new CommonTree(new CommonToken(99, "c"));

            t.ReplaceChildren(0, 0, newChild);
            String expected = "(a c)";

            Assert.AreEqual(expected, t.ToStringTree());
            t.SanityCheckParentAndChildIndexes();
        }
Beispiel #6
0
        public void testReplaceAllWithTwo()
        {
            ITreeAdaptor adaptor = new CommonTreeAdaptor();
            CommonTree   t       = new CommonTree(new CommonToken(99, "a"));

            t.AddChild(new CommonTree(new CommonToken(99, "b")));
            t.AddChild(new CommonTree(new CommonToken(99, "c")));
            t.AddChild(new CommonTree(new CommonToken(99, "d")));

            CommonTree newChildren = (CommonTree)adaptor.GetNilNode();

            newChildren.AddChild(new CommonTree(new CommonToken(99, "x")));
            newChildren.AddChild(new CommonTree(new CommonToken(99, "y")));

            t.ReplaceChildren(0, 2, newChildren);
            String expected = "(a x y)";

            Assert.AreEqual(expected, t.ToStringTree());
            t.SanityCheckParentAndChildIndexes();
        }
Beispiel #7
0
        public void testReplaceOneWithTwoInMiddle()
        {
            ITreeAdaptor adaptor = new CommonTreeAdaptor();
            CommonTree   t       = new CommonTree(new CommonToken(99, "a"));

            t.AddChild(new CommonTree(new CommonToken(99, "b")));
            t.AddChild(new CommonTree(new CommonToken(99, "c")));
            t.AddChild(new CommonTree(new CommonToken(99, "d")));

            CommonTree newChildren = (CommonTree)adaptor.Nil();

            newChildren.AddChild(new CommonTree(new CommonToken(99, "x")));
            newChildren.AddChild(new CommonTree(new CommonToken(99, "y")));

            t.ReplaceChildren(1, 1, newChildren);
            String expected = "(a b x y d)";

            Assert.AreEqual(expected, t.ToStringTree());
            t.SanityCheckParentAndChildIndexes();
        }
Beispiel #8
0
        public void testDupTree()
        {
            // ^(101 ^(102 103 ^(106 107) ) 104 105)
            CommonTree r0 = new CommonTree(new CommonToken(101));
            CommonTree r1 = new CommonTree(new CommonToken(102));

            r0.AddChild(r1);
            r1.AddChild(new CommonTree(new CommonToken(103)));
            ITree r2 = new CommonTree(new CommonToken(106));

            r2.AddChild(new CommonTree(new CommonToken(107)));
            r1.AddChild(r2);
            r0.AddChild(new CommonTree(new CommonToken(104)));
            r0.AddChild(new CommonTree(new CommonToken(105)));

            CommonTree dup = (CommonTree)(new CommonTreeAdaptor()).DupTree(r0);

            Assert.IsNull(dup.parent);
            Assert.AreEqual(-1, dup.childIndex);
            dup.SanityCheckParentAndChildIndexes();
        }
Beispiel #9
0
        public void testReplaceWithOneChildren()
        {
            // assume token type 99 and use text
            CommonTree t = new CommonTree(new CommonToken(99, "a"));
            CommonTree c0 = new CommonTree(new CommonToken(99, "b"));
            t.AddChild(c0);

            CommonTree newChild = new CommonTree(new CommonToken(99, "c"));
            t.ReplaceChildren(0, 0, newChild);
            String expected = "(a c)";
            Assert.AreEqual(expected, t.ToStringTree());
            t.SanityCheckParentAndChildIndexes();
        }
Beispiel #10
0
        public void testReplaceTwoWithOneAtRight()
        {
            CommonTree t = new CommonTree(new CommonToken(99, "a"));
            t.AddChild(new CommonTree(new CommonToken(99, "b")));
            t.AddChild(new CommonTree(new CommonToken(99, "c")));
            t.AddChild(new CommonTree(new CommonToken(99, "d")));

            CommonTree newChild = new CommonTree(new CommonToken(99, "x"));

            t.ReplaceChildren(1, 2, newChild);
            String expected = "(a b x)";
            Assert.AreEqual(expected, t.ToStringTree());
            t.SanityCheckParentAndChildIndexes();
        }
Beispiel #11
0
        public void testReplaceOneWithTwoInMiddle()
        {
            ITreeAdaptor adaptor = new CommonTreeAdaptor();
            CommonTree t = new CommonTree(new CommonToken(99, "a"));
            t.AddChild(new CommonTree(new CommonToken(99, "b")));
            t.AddChild(new CommonTree(new CommonToken(99, "c")));
            t.AddChild(new CommonTree(new CommonToken(99, "d")));

            CommonTree newChildren = (CommonTree)adaptor.GetNilNode();
            newChildren.AddChild(new CommonTree(new CommonToken(99, "x")));
            newChildren.AddChild(new CommonTree(new CommonToken(99, "y")));

            t.ReplaceChildren(1, 1, newChildren);
            String expected = "(a b x y d)";
            Assert.AreEqual(expected, t.ToStringTree());
            t.SanityCheckParentAndChildIndexes();
        }
Beispiel #12
0
        public void testReplaceInMiddle()
        {
            CommonTree t = new CommonTree(new CommonToken(99, "a"));
            t.AddChild(new CommonTree(new CommonToken(99, "b")));
            t.AddChild(new CommonTree(new CommonToken(99, "c"))); // index 1
            t.AddChild(new CommonTree(new CommonToken(99, "d")));

            CommonTree newChild = new CommonTree(new CommonToken(99, "x"));
            t.ReplaceChildren(1, 1, newChild);
            String expected = "(a b x d)";
            Assert.AreEqual(expected, t.ToStringTree());
            t.SanityCheckParentAndChildIndexes();
        }
Beispiel #13
0
        public void testBecomeRoot5()
        {
            // ^(nil 5) becomes new root of ^(101 102 103)
            CommonTree newRoot = new CommonTree((IToken)null);
            newRoot.AddChild(new CommonTree(new CommonToken(5)));

            CommonTree oldRoot = new CommonTree(new CommonToken(101));
            oldRoot.AddChild(new CommonTree(new CommonToken(102)));
            oldRoot.AddChild(new CommonTree(new CommonToken(103)));

            ITreeAdaptor adaptor = new CommonTreeAdaptor();
            adaptor.BecomeRoot(newRoot, oldRoot);
            newRoot.SanityCheckParentAndChildIndexes();
        }
		public void testReplaceAllWithTwo()
		{
			ITreeAdaptor adaptor = new CommonTreeAdaptor();
			CommonTree t = new CommonTree(new CommonToken(99, "a"));
			t.AddChild(new CommonTree(new CommonToken(99, "b")));
			t.AddChild(new CommonTree(new CommonToken(99, "c")));
			t.AddChild(new CommonTree(new CommonToken(99, "d")));

			CommonTree newChildren = (CommonTree)adaptor.Nil();
			newChildren.AddChild(new CommonTree(new CommonToken(99, "x")));
			newChildren.AddChild(new CommonTree(new CommonToken(99, "y")));

			t.ReplaceChildren(0, 2, newChildren);
			String expected = "(a x y)";
			Assert.AreEqual(expected, t.ToStringTree());
			t.SanityCheckParentAndChildIndexes();
		}