From: Jérémie Laval Date: Wed, 5 Jun 2013 23:04:04 +0000 (-0400) Subject: [monodoc] Fix ecma traversal with unattached tree. X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=ff817916b8b2527c885e574d48357fdcdeafdec6;p=mono.git [monodoc] Fix ecma traversal with unattached tree. 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. --- diff --git a/mcs/class/monodoc/Monodoc/providers/EcmaDoc.cs b/mcs/class/monodoc/Monodoc/providers/EcmaDoc.cs index 0fc4012de17..360889f6a73 100644 --- a/mcs/class/monodoc/Monodoc/providers/EcmaDoc.cs +++ b/mcs/class/monodoc/Monodoc/providers/EcmaDoc.cs @@ -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; } diff --git a/mcs/class/monodoc/Test/Monodoc/HelpSourceTests.cs b/mcs/class/monodoc/Test/Monodoc/HelpSourceTests.cs index f837c7ed38b..5816430c8d3 100644 --- a/mcs/class/monodoc/Test/Monodoc/HelpSourceTests.cs +++ b/mcs/class/monodoc/Test/Monodoc/HelpSourceTests.cs @@ -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 ()