Beispiel #1
0
        public void Test_SetRootCreatesNewImmutableTree()
        {
            MockSyntaxTree tree = new MockSyntaxTree(
                new FullNameNode(
                    new NameNode("Kallyn"),
                    new NameNode("Gowdy")
                    )
                );

            FullNameNode newFullName = new FullNameNode(
                new NameNode("K"),
                new NameNode("G")
                );

            SyntaxTree newTree = tree.SetRoot(newFullName);

            Assert.NotNull(newTree);
            Assert.IsType <MockSyntaxTree>(newTree);
            Assert.NotSame(tree, newTree);
        }
Beispiel #2
0
        public void Test_InternalNodeCanBeSharedBetweenDifferentTrees()
        {
            NameNode firstName = new NameNode("Kallyn");

            MockSyntaxTree tree = new MockSyntaxTree(
                new FullNameNode(
                    firstName,
                    new NameNode("Gowdy")
                    )
                );

            Assert.Equal("Kallyn", tree.FullName.FirstName.ToString());

            MockSyntaxTree newTree = tree.SetRoot(
                new FullNameNode(
                    firstName,
                    new NameNode("G")
                    )
                ) as MockSyntaxTree;

            Assert.NotNull(newTree);

            Assert.NotSame(tree, newTree);
            Assert.NotSame(tree.Root, newTree.Root);
            Assert.NotSame(tree.Root.FirstName, firstName);
            Assert.NotSame(newTree.Root.FirstName, firstName);
            Assert.NotSame(tree.Root.FirstName, newTree.Root.FirstName);

            Assert.NotEqual(tree, newTree);
            Assert.NotEqual(tree.Root, newTree.Root);

            Assert.Equal(tree.Root.FirstName, firstName);
            Assert.Equal(newTree.Root.FirstName, firstName);
            Assert.Equal(tree.Root.FirstName, newTree.Root.FirstName);

            Assert.Same(tree.Root.FirstName.InternalNode, firstName.InternalNode);
        }