public void Test_NewNodesAreGeneratedAsTreeIsTraversed() { MockSyntaxTree tree = new MockSyntaxTree( new FullNameNode( new NameNode("Kallyn"), new NameNode("Gowdy") ) ); Assert.NotNull(tree); Assert.NotNull(tree.Root); FullNameNode root = tree.Root as FullNameNode; Assert.Null(root.Parent); Assert.NotNull(root.Tree); Assert.Same(tree, root.Tree); Assert.Equal(0, root.Position); Assert.Equal(11, root.Width); Assert.Equal("{Kallyn Gowdy}", root.ToString()); NameNode firstName = root.FirstName; Assert.NotNull(firstName.Parent); Assert.Same(root, firstName.Parent); Assert.Same(tree, firstName.Tree); Assert.Equal(0, firstName.Position); NameNode lastName = root.LastName; Assert.NotNull(lastName); Assert.Same(root, lastName.Parent); Assert.Same(tree, firstName.Tree); Assert.Equal(6, lastName.Position); }
public void Test_InsertNodeCreatesNewFacadeTree() { MockSyntaxTree tree = new MockSyntaxTree( new FullNameNode( new NameNode("Kallyn"), new NameNode("Gowdy") ) ); NameNode middleName = new NameNode("G."); FullNameNode fullName = (FullNameNode)tree.FullName.InsertNode(1, middleName); Assert.Equal(13, fullName.Width); Assert.Equal("{Kallyn G. Gowdy}", fullName.ToString()); Assert.NotSame(tree, fullName.Tree); Assert.Collection( fullName.Children, n => Assert.Equal(new NameNode("Kallyn"), n), n => Assert.Equal(new NameNode("G."), n), n => Assert.Equal(new NameNode("Gowdy"), n) ); Assert.Collection( tree.FullName.Children, n => Assert.Same(n.InternalNode, fullName.FirstName.InternalNode), n => Assert.Same(n.InternalNode, fullName.LastName.InternalNode) ); Assert.Collection( tree.FullName.Children, n => Assert.NotSame(n, fullName.FirstName), n => Assert.NotSame(n, fullName.LastName) ); Assert.Collection( fullName.Children, n => Assert.Same(n.InternalNode, fullName.FirstName.InternalNode), n => Assert.Same(n.InternalNode, middleName.InternalNode), n => Assert.Same(n.InternalNode, fullName.LastName.InternalNode) ); }
public void Test_RemoveNode() { MockSyntaxTree tree = new MockSyntaxTree( new FullNameNode( new NameNode("Kallyn"), new NameNode("G."), new NameNode("Gowdy"), new NameNode("Other") ) ); FullNameNode fullName = (FullNameNode)tree.FullName.RemoveNode(tree.FullName.Children[3]); Assert.Collection( fullName.Children, n => Assert.Equal(new NameNode("Kallyn"), n), n => Assert.Equal(new NameNode("G."), n), n => Assert.Equal(new NameNode("Gowdy"), n) ); Assert.Collection( tree.FullName.Children, n => Assert.Same(n.InternalNode, fullName.FirstName.InternalNode), n => Assert.Same(n.InternalNode, fullName.Children[1].InternalNode), n => Assert.Same(n.InternalNode, fullName.LastName.InternalNode), Assert.NotNull ); Assert.Collection( tree.FullName.Children, n => Assert.NotSame(n, fullName.FirstName), n => Assert.NotSame(n, fullName.Children[1]), n => Assert.NotSame(n, fullName.LastName), Assert.NotNull ); Assert.Equal(13, fullName.Width); Assert.Equal("{Kallyn G. Gowdy}", fullName.ToString()); }
public void Test_AddNodeCreatesNewFacadeTree() { MockSyntaxTree tree = new MockSyntaxTree( new FullNameNode( new NameNode("Kallyn"), new NameNode("Gowdy") ) ); Assert.Equal(2, tree.FullName.Children.Count); NameNode otherLastName = new NameNode("Other"); FullNameNode fullName = (FullNameNode)tree.FullName.AddNode(otherLastName); Assert.Collection( fullName.Children, n => Assert.Equal(new NameNode("Kallyn"), n), n => Assert.Equal(new NameNode("Gowdy"), n), n => Assert.Equal(new NameNode("Other"), n) ); Assert.Collection( tree.FullName.Children, n => Assert.Same(n.InternalNode, fullName.FirstName.InternalNode), n => Assert.Same(n.InternalNode, fullName.Children[1].InternalNode) // Last name gets changed by AddNode ); Assert.Collection( tree.FullName.Children, n => Assert.NotSame(n, fullName.FirstName), n => Assert.NotSame(n, fullName.Children[1]) ); Assert.Equal(16, fullName.Width); Assert.Equal("{Kallyn Gowdy Other}", fullName.ToString()); }