Пример #1
0
        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;
                Assert.AreSame(first, a.Parent);
            }
            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);
            }
        }
Пример #2
0
        public PathTreeNode AddNode(string path, object id, out bool isModified)
        {
            if (TryFind(path, out var result, out var parent, out var previousNode, out var lastIndex))
            {
                isModified = !result.IsLive;
                result.RegisterId(id);
                return(result);
            }

            // At this point, we need to create a new node.
            isModified       = true;
            var(first, leaf) = PathTreeNode.CreateSubTree(path, lastIndex);
            leaf.RegisterId(id);

            InsertNode(first, parent, previousNode);

            return(leaf);
        }
Пример #3
0
        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);
        }
Пример #4
0
 [TestCase(1)]          // Should not crash
 public void EmptySubTrie(int startIndex)
 {
     var(node, leaf) = PathTreeNode.CreateSubTree(string.Empty, startIndex);
     Assert.IsNull(node);
     Assert.IsNull(leaf);
 }
Пример #5
0
 public void JustSlash()
 {
     var(node, leaf) = PathTreeNode.CreateSubTree(Path.DirectorySeparatorChar.ToString(), 0);
     Assert.IsNull(node);
     Assert.IsNull(leaf);
 }