[monodoc] Fix ecma traversal with unattached tree.
authorJérémie Laval <jeremie.laval@gmail.com>
Wed, 5 Jun 2013 23:04:04 +0000 (19:04 -0400)
committerJérémie Laval <jeremie.laval@gmail.com>
Wed, 5 Jun 2013 23:04:04 +0000 (19:04 -0400)
Previously the code expected to stop at upper level node using the fact that their element starts with `root:/'. This element is attributed by RootNode when loading a complete tree. However tool like mdoc also loads tree unattached which doesn't create a standard `root:/` top-level root node hence causing the issue.

mcs/class/monodoc/Monodoc/providers/EcmaDoc.cs
mcs/class/monodoc/Test/Monodoc/HelpSourceTests.cs

index 0fc4012de174ec62fc16f5071e761abc82b325ae..360889f6a732e84415f73ff1e1f07d8715cbc90b 100644 (file)
@@ -426,8 +426,11 @@ namespace Monodoc.Providers
                public static int GetNodeLevel (Node node)
                {
                        int i = 0;
-                       for (; !node.Element.StartsWith ("root:/", StringComparison.OrdinalIgnoreCase); i++)
+                       for (; !node.Element.StartsWith ("root:/", StringComparison.OrdinalIgnoreCase); i++) {
                                node = node.Parent;
+                               if (node == null)
+                                       return i - 1;
+                       }
                        return i - 1;
                }
 
index f837c7ed38bafc362bc0167bf11710dc18481716..5816430c8d3b7a061d2d6ce6dbabd02a79e0aa67 100644 (file)
@@ -7,6 +7,7 @@ using NUnit.Framework;
 
 using Monodoc;
 using Monodoc.Generators;
+using Monodoc.Providers;
 
 // Used by ReachabilityWithCrefsTest
 // using HtmlAgilityPack;
@@ -153,6 +154,19 @@ namespace MonoTests.Monodoc
                        Assert.IsTrue (rootTree.RenderUrl ("T:System.IComparable{T}", generator, out result), "#6");
                }
 
+               [Test]
+               public void PublicUrlOnUnattachedHelpSourceRoot ()
+               {
+                       // Unattached help source have no root:/ URL attributed
+                       var hs = new EcmaHelpSource (Path.Combine (BaseDir, "sources", "netdocs"), false);
+                       var rootTree = RootTree.LoadTree (Path.GetFullPath (BaseDir), false);
+                       hs.RootTree = rootTree;
+                       Assert.IsNull (hs.Tree.RootNode.PublicUrl);
+                       var nsChildUrl = hs.Tree.RootNode.ChildNodes.First ().PublicUrl;
+                       Assert.IsNotNull (nsChildUrl);
+                       StringAssert.StartsWith ("N:", nsChildUrl);
+               }
+
                /*
                [Test, Ignore ("Mono documentation is full of syntax errors so we can't use it reliably for this test")]
                public void ReachabilityWithCrefsTest ()