public void CreateSubTree(string sep) { var path = MakePath("a", "b", "c") + sep; var(first, leaf) = PathTreeNode.CreateSubTree(path, 0); PathTreeNode a; if (Platform.IsWindows) { AssertPathTreeSubtree(first, "C:"); Assert.AreEqual(1, first.ChildrenCount); a = first.FirstChild; } else { a = first; } AssertPathTreeSubtree(a, "a"); Assert.AreEqual(1, a.ChildrenCount); var b = a.FirstChild; Assert.AreSame(a, b.Parent); AssertPathTreeSubtree(b, "b"); Assert.AreEqual(1, b.ChildrenCount); var c = b.FirstChild; Assert.AreSame(b, c.Parent); AssertPathTreeSubtree(c, "c"); Assert.AreEqual(0, c.ChildrenCount); Assert.AreSame(c, leaf); Assert.IsNull(c.FirstChild); void AssertPathTreeSubtree(PathTreeNode node, string segment) { Assert.AreEqual(segment, node.Segment); Assert.IsNull(node.Next); Assert.AreSame(node.FirstChild, node.LastChild); } }
public PathTreeNode AddNode(string path, object id) { if (TryFind(path, out var result, out var parent, out var previousNode, out var lastIndex)) { result.RegisterId(id); return(result); } // At this point, we need to create a new node. var(first, leaf) = PathTreeNode.CreateSubTree(path, lastIndex); if (id != null) { leaf.RegisterId(id); } InsertNode(first, parent, previousNode); return(leaf); }
public void JustSlash() { var(node, leaf) = PathTreeNode.CreateSubTree(Path.DirectorySeparatorChar.ToString(), 0); Assert.IsNull(node); Assert.IsNull(leaf); }
[TestCase(1)] // Should not crash public void EmptySubTrie(int startIndex) { var(node, leaf) = PathTreeNode.CreateSubTree(string.Empty, startIndex); Assert.IsNull(node); Assert.IsNull(leaf); }