From de670165f9230c758e283448af7c1aa2aa7275b5 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Sun, 25 Nov 2007 18:57:36 +0000 Subject: [PATCH] The CodeCoverageMethod.GetChildNamespaces method now correctly identifies the child namespaces when there are two that start the same and match up to just before the dot character. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2750 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- .../Project/Src/CodeCoverageMethod.cs | 3 +- .../Test/CodeCoverage.Tests.csproj | 1 + .../Test/SimilarRootNamespaceTestFixture.cs | 63 +++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 src/AddIns/Misc/CodeCoverage/Test/SimilarRootNamespaceTestFixture.cs diff --git a/src/AddIns/Misc/CodeCoverage/Project/Src/CodeCoverageMethod.cs b/src/AddIns/Misc/CodeCoverage/Project/Src/CodeCoverageMethod.cs index 86e65dd0bc..d625cdd8aa 100644 --- a/src/AddIns/Misc/CodeCoverage/Project/Src/CodeCoverageMethod.cs +++ b/src/AddIns/Misc/CodeCoverage/Project/Src/CodeCoverageMethod.cs @@ -166,7 +166,8 @@ namespace ICSharpCode.CodeCoverage List items = new List(); foreach (CodeCoverageMethod method in methods) { string classNamespace = method.ClassNamespace; - if (classNamespace.Length > parentNamespace.Length && classNamespace.StartsWith(parentNamespace)) { + string dottedParentNamespace = parentNamespace + "."; + if (classNamespace.Length > parentNamespace.Length && classNamespace.StartsWith(dottedParentNamespace)) { string ns = CodeCoverageMethod.GetChildNamespace(method.ClassNamespace, parentNamespace); if (!items.Contains(ns)) { items.Add(ns); diff --git a/src/AddIns/Misc/CodeCoverage/Test/CodeCoverage.Tests.csproj b/src/AddIns/Misc/CodeCoverage/Test/CodeCoverage.Tests.csproj index 1ce5e57f67..af22730ef1 100644 --- a/src/AddIns/Misc/CodeCoverage/Test/CodeCoverage.Tests.csproj +++ b/src/AddIns/Misc/CodeCoverage/Test/CodeCoverage.Tests.csproj @@ -71,6 +71,7 @@ + diff --git a/src/AddIns/Misc/CodeCoverage/Test/SimilarRootNamespaceTestFixture.cs b/src/AddIns/Misc/CodeCoverage/Test/SimilarRootNamespaceTestFixture.cs new file mode 100644 index 0000000000..e733fe5c6a --- /dev/null +++ b/src/AddIns/Misc/CodeCoverage/Test/SimilarRootNamespaceTestFixture.cs @@ -0,0 +1,63 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; +using ICSharpCode.CodeCoverage; +using NUnit.Framework; + +namespace ICSharpCode.CodeCoverage.Tests +{ + /// + /// If there are two namespaces that start the same and match up + /// to at least the start of the dot character then the + /// CodeCoverageMethod.GetChildNamespaces fails to correctly identify + /// child namespaces. + /// + /// For example: + /// + /// Root.Tests + /// RootBar + /// + /// If we look for child namespaces using the string "Root" the + /// code should only return "Tests", but it will also return + /// "Bar" due to a bug matching only the start of the class namespace + /// without taking into account the dot character. + /// + [TestFixture] + public class SimilarRootNamespaceTestFixture + { + List childNamespaces = new List(); + + [TestFixtureSetUp] + public void SetUpFixture() + { + CodeCoverageModule module = new CodeCoverageModule("Root.Tests"); + + // Add two methods in namespaces that start with the + // same initial characters. + CodeCoverageMethod rootTestsMethod = new CodeCoverageMethod("RunThis", "Root.Tests.MyTestFixture"); + module.Methods.Add(rootTestsMethod); + CodeCoverageMethod rootBarMethod = new CodeCoverageMethod("RunThis", "RootBar.MyTestFixture"); + module.Methods.Add(rootBarMethod); + + childNamespaces = CodeCoverageMethod.GetChildNamespaces(module.Methods, "Root"); + } + + [Test] + public void RootNamespaceHasOneChildNamespace() + { + Assert.AreEqual(1, childNamespaces.Count); + } + + [Test] + public void RootNamespaceChildNamespaceIsTests() + { + Assert.AreEqual("Tests", childNamespaces[0]); + } + } +}