Example #1
0
        public void TestReplaceWithNoChildren() /*throws Exception*/
        {
            CommonTree t        = new CommonTree(new CommonToken(101));
            CommonTree newChild = new CommonTree(new CommonToken(5));

            t.ReplaceChildren(0, 0, newChild);
        }
Example #2
0
 private void Replace(CommonTree parent, CommonTree newNode, int index)
 {
     if (newNode != null)
     {
         parent.ReplaceChildren(index, index, newNode);
     }
 }
Example #3
0
        public void TestReplaceAllWithOne() /*throws Exception*/
        {
            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 expecting = "(a x)";

            Assert.AreEqual(expecting, t.ToStringTree());
            t.SanityCheckParentAndChildIndexes();
        }
Example #4
0
        public void TestReplaceWithOneChildren() /*throws Exception*/
        {
            // 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 expecting = "(a c)";

            Assert.AreEqual(expecting, t.ToStringTree());
            t.SanityCheckParentAndChildIndexes();
        }
Example #5
0
        public void TestReplaceTwoWithOneAtRight() /*throws Exception*/
        {
            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 expecting = "(a b x)";

            assertEquals(expecting, t.ToStringTree());
            t.SanityCheckParentAndChildIndexes();
        }
Example #6
0
        public void TestReplaceAtLeft() /*throws Exception*/
        {
            CommonTree t = new CommonTree(new CommonToken(99, "a"));

            t.AddChild(new CommonTree(new CommonToken(99, "b")));       // index 0
            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, 0, newChild);
            string expecting = "(a x c d)";

            assertEquals(expecting, t.ToStringTree());
            t.SanityCheckParentAndChildIndexes();
        }
Example #7
0
        public void TestReplaceWithNoChildren() /*throws Exception*/
        {
            CommonTree t        = new CommonTree(new CommonToken(101));
            CommonTree newChild = new CommonTree(new CommonToken(5));
            bool       error    = false;

            try
            {
                t.ReplaceChildren(0, 0, newChild);
            }
            catch (ArgumentException /*iae*/)
            {
                error = true;
            }
            assertTrue(error);
        }
Example #8
0
        public void TestReplaceOneWithTwoInMiddle() /*throws Exception*/
        {
            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 expecting = "(a b x y d)";

            Assert.AreEqual(expecting, t.ToStringTree());
            t.SanityCheckParentAndChildIndexes();
        }
Example #9
0
        public void TestReplaceAllWithTwo() /*throws Exception*/
        {
            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 expecting = "(a x y)";

            assertEquals(expecting, t.ToStringTree());
            t.SanityCheckParentAndChildIndexes();
        }