Browse files

Refactored CommentParser to have the node parsers injected.

Adding support for a new node no longer requires changes to CommentParser.
Just create a new class that implements ICommentNodeParser and it will be automatically injected by the container.

Signed-off-by: James Gregory <james@jagregory.com>
  • Loading branch information...
1 parent e5569e4 commit 41bf6458ed4297a355400b0ea2c465a1511122b0 @joshuaflanagan joshuaflanagan committed with May 18, 2009
Showing with 196 additions and 172 deletions.
  1. +2 −3 src/Docu.Console/Console/ConsoleApplication.cs
  2. +3 −3 src/Docu.Console/ContainerBootstrapper.cs
  3. +2 −0 src/Docu.Console/DefaultRegistry.cs
  4. +1 −1 src/Docu.Console/Docu.csproj
  5. +4 −4 src/Docu.Console/Documentation/Generators/BaseGenerator.cs
  6. +20 −0 src/Docu.Console/Extensions.cs
  7. +19 −44 src/Docu.Console/Parsing/Comments/CommentParser.cs
  8. +0 −26 src/Docu.Console/Parsing/Comments/CommentParserBase.cs
  9. +11 −0 src/Docu.Console/Parsing/Comments/ICommentNodeParser.cs
  10. +2 −1 src/Docu.Console/Parsing/Comments/ICommentParser.cs
  11. +8 −3 src/Docu.Console/Parsing/Comments/InlineCodeCommentParser.cs
  12. +8 −11 src/Docu.Console/Parsing/Comments/InlineListCommentParser.cs
  13. +8 −3 src/Docu.Console/Parsing/Comments/InlineTextCommentParser.cs
  14. +8 −3 src/Docu.Console/Parsing/Comments/MultilineCodeCommentParser.cs
  15. +5 −7 src/Docu.Console/Parsing/Comments/ParagraphCommentParser.cs
  16. +8 −3 src/Docu.Console/Parsing/Comments/ParameterReferenceParser.cs
  17. +9 −4 src/Docu.Console/Parsing/Comments/SeeCodeCommentParser.cs
  18. +4 −0 src/Docu.Tests/Docu.Tests.csproj
  19. +10 −0 src/Docu.Tests/Documentation/DocumentModelGeneratorTests/BaseDocumentModelGeneratorFixture.cs
  20. +3 −3 src/Docu.Tests/Documentation/DocumentModelGeneratorTests/General.cs
  21. +9 −9 src/Docu.Tests/Documentation/DocumentModelGeneratorTests/Remarks.cs
  22. +3 −3 src/Docu.Tests/Documentation/DocumentModelGeneratorTests/Returns.cs
  23. +13 −13 src/Docu.Tests/Documentation/DocumentModelGeneratorTests/Summaries.cs
  24. +4 −4 src/Docu.Tests/Documentation/DocumentModelGeneratorTests/UnrecognisedDocumentationTypes.cs
  25. +2 −2 src/Docu.Tests/Documentation/DocumentModelGeneratorTests/Values.cs
  26. +30 −22 src/Docu.Tests/Parsing/CommentParserTests.cs
View
5 src/Docu.Console/Console/ConsoleApplication.cs
@@ -3,7 +3,6 @@
using System.IO;
using System.Linq;
using Docu.Events;
-using StructureMap;
namespace Docu.Console
{
@@ -259,9 +258,9 @@ private IEnumerable<string> GetFiles(string path)
public static void Run(IEnumerable<string> args)
{
- ContainerBootstrapper.BootstrapStructureMap();
+ var container = ContainerBootstrapper.BootstrapStructureMap();
- var application = ObjectFactory.GetInstance<ConsoleApplication>();
+ var application = container.GetInstance<ConsoleApplication>();
application.SetArguments(args);
application.Run();
View
6 src/Docu.Console/ContainerBootstrapper.cs
@@ -2,11 +2,11 @@
namespace Docu
{
- internal static class ContainerBootstrapper
+ public static class ContainerBootstrapper
{
- public static void BootstrapStructureMap()
+ public static IContainer BootstrapStructureMap()
{
- ObjectFactory.Initialize(x => { x.AddRegistry(new DefaultRegistry()); });
+ return new Container(x => x.AddRegistry(new DefaultRegistry()));
}
}
}
View
2 src/Docu.Console/DefaultRegistry.cs
@@ -2,6 +2,7 @@
using Docu.Events;
using Docu.Output;
using Docu.IO;
+using Docu.Parsing.Comments;
using StructureMap.Configuration.DSL;
namespace Docu
@@ -14,6 +15,7 @@ public DefaultRegistry()
{
x.AssemblyContainingType<DocumentationGenerator>();
x.WithDefaultConventions();
+ x.AddAllTypesOf<ICommentNodeParser>();
});
ForRequestedType<IOutputGenerator>()
View
2 src/Docu.Console/Docu.csproj
@@ -121,7 +121,7 @@
<Compile Include="Output\IUntransformableResourceManager.cs" />
<Compile Include="IO\IAssemblyLoader.cs" />
<Compile Include="IO\IXmlLoader.cs" />
- <Compile Include="Parsing\Comments\CommentParserBase.cs" />
+ <Compile Include="Parsing\Comments\ICommentNodeParser.cs" />
<Compile Include="Parsing\Comments\InlineCodeCommentParser.cs" />
<Compile Include="Parsing\Comments\InlineListCommentParser.cs" />
<Compile Include="Parsing\Comments\InlineTextCommentParser.cs" />
View
8 src/Docu.Console/Documentation/Generators/BaseGenerator.cs
@@ -19,7 +19,7 @@ protected BaseGenerator(ICommentParser commentParser)
private void ParseSummary(XmlNode node, IDocumentationElement doc)
{
if (node != null)
- doc.Summary = new Summary(commentParser.Parse(node));
+ doc.Summary = new Summary(commentParser.ParseNode(node));
}
protected void ParseParamSummary(IDocumentationMember member, IDocumentationElement doc)
@@ -38,7 +38,7 @@ protected void ParseValue(IDocumentationMember member, IDocumentationElement doc
var node = member.Xml.SelectSingleNode("value");
if (node != null)
- doc.Value = new Value(commentParser.Parse(node));
+ doc.Value = new Value(commentParser.ParseNode(node));
}
protected void ParseSummary(IDocumentationMember member, IDocumentationElement doc)
@@ -57,7 +57,7 @@ protected void ParseRemarks(IDocumentationMember member, IDocumentationElement d
var node = member.Xml.SelectSingleNode("remarks");
if (node != null)
- doc.Remarks = new Remarks(commentParser.Parse(node));
+ doc.Remarks = new Remarks(commentParser.ParseNode(node));
}
protected void ParseReturns(IDocumentationMember member, Method doc)
@@ -67,7 +67,7 @@ protected void ParseReturns(IDocumentationMember member, Method doc)
var node = member.Xml.SelectSingleNode("returns");
if (node != null)
- doc.Returns = new Summary(commentParser.Parse(node));
+ doc.Returns = new Summary(commentParser.ParseNode(node));
}
protected Namespace FindNamespace(IDocumentationMember association, List<Namespace> namespaces)
View
20 src/Docu.Console/Extensions.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Text.RegularExpressions;
namespace Docu
{
@@ -22,5 +23,24 @@ public static IList<T> ToTail<T>(this IList<T> list)
return shortened;
}
+
+ public static string TrimComment(this string text, bool first, bool last)
+ {
+ var regexp = new Regex(@"[\s]{0,}\r\n[\s]{0,}");
+
+ string prepared = regexp.Replace(text, "\r\n");
+
+ if(first)
+ prepared = prepared.TrimStart(' ', '\t', '\r', '\n');
+ else
+ prepared = prepared.TrimStart('\t', '\r', '\n');
+
+ if(last)
+ prepared = prepared.TrimEnd(' ', '\t', '\r', '\n');
+ else
+ prepared = prepared.TrimEnd('\t', '\r', '\n');
+
+ return prepared;
+ }
}
}
View
63 src/Docu.Console/Parsing/Comments/CommentParser.cs
@@ -1,73 +1,48 @@
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.Xml;
using Docu.Documentation.Comments;
+using System.Linq;
namespace Docu.Parsing.Comments
{
public class CommentParser : ICommentParser
{
- private readonly IDictionary<Func<XmlNode, bool>, Func<XmlNode, bool, bool, IComment>> parsers =
- new Dictionary<Func<XmlNode, bool>, Func<XmlNode, bool, bool, IComment>>();
+ private readonly ICommentNodeParser[] _parsers;
- private readonly InlineTextCommentParser InlineText = new InlineTextCommentParser();
- private readonly InlineCodeCommentParser InlineCode = new InlineCodeCommentParser();
- private readonly MultilineCodeCommentParser MultilineCode = new MultilineCodeCommentParser();
- private readonly SeeCodeCommentParser See = new SeeCodeCommentParser();
- private readonly ParagraphCommentParser Paragraph;
- private readonly ParameterReferenceParser ParameterReference = new ParameterReferenceParser();
- private readonly InlineListCommentParser InlineList;
-
- public CommentParser()
+ public CommentParser(ICommentNodeParser[] parsers)
{
- Paragraph = new ParagraphCommentParser(this);
- InlineList = new InlineListCommentParser(this);
- parsers.Add(node => node is XmlText, InlineText.Parse);
- parsers.Add(node => node.Name == "c", InlineCode.Parse);
- parsers.Add(node => node.Name == "code", MultilineCode.Parse);
- parsers.Add(node => node.Name == "see", See.Parse);
- parsers.Add(node => node.Name == "para", Paragraph.Parse);
- parsers.Add(node => node.Name == "paramref", ParameterReference.Parse);
- parsers.Add(node => node.Name == "list", InlineList.Parse);
+ _parsers = parsers;
}
public IList<IComment> Parse(XmlNodeList nodes)
{
var blocks = new List<IComment>();
- int count = nodes.Count;
- for(int i = 0; i < count; i++)
+ var count = nodes.Count;
+ for(var i = 0; i < count; i++)
{
- XmlNode node = nodes[i];
- bool first = (i == 0);
- bool last = (i == (count - 1));
-
- foreach(var pair in parsers)
+ var node = nodes[i];
+ var first = (i == 0);
+ var last = (i == (count - 1));
+
+ var parser = _parsers.FirstOrDefault(p => p.CanParse(node));
+ if (parser == null) continue;
+
+ var block = parser.Parse(this, node, first, last);
+ if (block != null)
{
- var isValid = pair.Key;
- var parser = pair.Value;
-
- if(!isValid(node))
- continue;
-
- var block = parser(node, first, last);
-
- if(block != null)
- {
- blocks.Add(block);
- continue;
- }
+ blocks.Add(block);
}
}
return blocks;
}
- public IList<IComment> Parse(XmlNode content)
+ public IList<IComment> ParseNode(XmlNode node)
{
var blocks = new List<IComment>();
- blocks.AddRange(Parse(content.ChildNodes));
+ blocks.AddRange(Parse(node.ChildNodes));
return blocks.AsReadOnly();
}
View
26 src/Docu.Console/Parsing/Comments/CommentParserBase.cs
@@ -1,26 +0,0 @@
-using System.Text.RegularExpressions;
-
-namespace Docu.Parsing.Comments
-{
- internal abstract class CommentParserBase
- {
- protected string PrepareText(string text, bool first, bool last)
- {
- var regexp = new Regex(@"[\s]{0,}\r\n[\s]{0,}");
-
- string prepared = regexp.Replace(text, "\r\n");
-
- if(first)
- prepared = prepared.TrimStart(' ', '\t', '\r', '\n');
- else
- prepared = prepared.TrimStart('\t', '\r', '\n');
-
- if(last)
- prepared = prepared.TrimEnd(' ', '\t', '\r', '\n');
- else
- prepared = prepared.TrimEnd('\t', '\r', '\n');
-
- return prepared;
- }
- }
-}
View
11 src/Docu.Console/Parsing/Comments/ICommentNodeParser.cs
@@ -0,0 +1,11 @@
+using System.Xml;
+using Docu.Documentation.Comments;
+
+namespace Docu.Parsing.Comments
+{
+ public interface ICommentNodeParser
+ {
+ bool CanParse(XmlNode node);
+ IComment Parse(ICommentParser parser, XmlNode node, bool first, bool last);
+ }
+}
View
3 src/Docu.Console/Parsing/Comments/ICommentParser.cs
@@ -6,6 +6,7 @@ namespace Docu.Parsing.Comments
{
public interface ICommentParser
{
- IList<IComment> Parse(XmlNode content);
+ IList<IComment> Parse(XmlNodeList nodes);
+ IList<IComment> ParseNode(XmlNode node);
}
}
View
11 src/Docu.Console/Parsing/Comments/InlineCodeCommentParser.cs
@@ -3,11 +3,16 @@
namespace Docu.Parsing.Comments
{
- internal class InlineCodeCommentParser : CommentParserBase
+ public class InlineCodeCommentParser : ICommentNodeParser
{
- public IComment Parse(XmlNode content, bool first, bool last)
+ public bool CanParse(XmlNode node)
{
- return new InlineCode(PrepareText(content.InnerText, first, last));
+ return node.Name == "c";
+ }
+
+ public IComment Parse(ICommentParser parser, XmlNode node, bool first, bool last)
+ {
+ return new InlineCode(node.InnerText.TrimComment(first, last));
}
}
}
View
19 src/Docu.Console/Parsing/Comments/InlineListCommentParser.cs
@@ -1,36 +1,33 @@
-using System;
using System.Xml;
using Docu.Documentation.Comments;
namespace Docu.Parsing.Comments
{
- internal class InlineListCommentParser : CommentParserBase
+ public class InlineListCommentParser : ICommentNodeParser
{
- private readonly CommentParser _parser;
-
- public InlineListCommentParser(CommentParser parser)
+ public bool CanParse(XmlNode node)
{
- _parser = parser;
+ return node.Name == "list";
}
- public IComment Parse(XmlNode content, bool first, bool last)
+ public IComment Parse(ICommentParser parser, XmlNode node, bool first, bool last)
{
- var typeAttribute = content.Attributes["type"];
+ var typeAttribute = node.Attributes["type"];
var listTypeName = typeAttribute == null ? string.Empty : typeAttribute.Value;
var list = createListForType(listTypeName);
- foreach (XmlNode itemNode in content.SelectNodes("item"))
+ foreach (XmlNode itemNode in node.SelectNodes("item"))
{
Paragraph term = null;
Paragraph definition = null;
var termNode = itemNode.SelectSingleNode("term");
if (termNode != null)
{
- term = new Paragraph(_parser.Parse(termNode.ChildNodes));
+ term = new Paragraph(parser.Parse(termNode.ChildNodes));
}
var definitionNode = itemNode.SelectSingleNode("description");
if (definitionNode != null)
{
- definition = new Paragraph(_parser.Parse(definitionNode.ChildNodes));
+ definition = new Paragraph(parser.Parse(definitionNode.ChildNodes));
}
list.Items.Add(new InlineListItem(term, definition));
}
View
11 src/Docu.Console/Parsing/Comments/InlineTextCommentParser.cs
@@ -3,11 +3,16 @@
namespace Docu.Parsing.Comments
{
- internal class InlineTextCommentParser : CommentParserBase
+ public class InlineTextCommentParser : ICommentNodeParser
{
- public IComment Parse(XmlNode content, bool first, bool last)
+ public bool CanParse(XmlNode node)
{
- return new InlineText(PrepareText(content.InnerText, first, last));
+ return node is XmlText;
+ }
+
+ public IComment Parse(ICommentParser parser, XmlNode node, bool first, bool last)
+ {
+ return new InlineText(node.InnerText.TrimComment(first, last));
}
}
}
View
11 src/Docu.Console/Parsing/Comments/MultilineCodeCommentParser.cs
@@ -3,11 +3,16 @@
namespace Docu.Parsing.Comments
{
- internal class MultilineCodeCommentParser : CommentParserBase
+ public class MultilineCodeCommentParser : ICommentNodeParser
{
- public IComment Parse(XmlNode content, bool first, bool last)
+ public bool CanParse(XmlNode node)
{
- return new InlineCode(PrepareText(content.InnerText, true, true));
+ return node.Name == "code";
+ }
+
+ public IComment Parse(ICommentParser parser, XmlNode node, bool first, bool last)
+ {
+ return new InlineCode(node.InnerText.TrimComment(true, true));
}
}
}
View
12 src/Docu.Console/Parsing/Comments/ParagraphCommentParser.cs
@@ -3,18 +3,16 @@
namespace Docu.Parsing.Comments
{
- internal class ParagraphCommentParser : CommentParserBase
+ public class ParagraphCommentParser : ICommentNodeParser
{
- private readonly CommentParser parser;
-
- public ParagraphCommentParser(CommentParser parser)
+ public bool CanParse(XmlNode node)
{
- this.parser = parser;
+ return node.Name == "para";
}
- public IComment Parse(XmlNode content, bool first, bool last)
+ public IComment Parse(ICommentParser parser, XmlNode node, bool first, bool last)
{
- return new Paragraph(parser.Parse(content.ChildNodes));
+ return new Paragraph(parser.Parse(node.ChildNodes));
}
}
}
View
11 src/Docu.Console/Parsing/Comments/ParameterReferenceParser.cs
@@ -3,11 +3,16 @@
namespace Docu.Parsing.Comments
{
- internal class ParameterReferenceParser : CommentParserBase
+ public class ParameterReferenceParser : ICommentNodeParser
{
- public IComment Parse(XmlNode content, bool first, bool last)
+ public bool CanParse(XmlNode node)
{
- var attribute = content.Attributes["name"];
+ return node.Name == "paramref";
+ }
+
+ public IComment Parse(ICommentParser parser, XmlNode node, bool first, bool last)
+ {
+ var attribute = node.Attributes["name"];
var parameterName = attribute == null ? string.Empty : attribute.Value;
return new ParameterReference(parameterName);
}
View
13 src/Docu.Console/Parsing/Comments/SeeCodeCommentParser.cs
@@ -5,13 +5,18 @@
namespace Docu.Parsing.Comments
{
- internal class SeeCodeCommentParser : CommentParserBase
+ public class SeeCodeCommentParser : ICommentNodeParser
{
- public IComment Parse(XmlNode content, bool first, bool last)
+ public bool CanParse(XmlNode node)
+ {
+ return node.Name == "see";
+ }
+
+ public IComment Parse(ICommentParser parser, XmlNode node, bool first, bool last)
{
IReferencable reference = new NullReference();
- if (content.Attributes["cref"] == null) return new See(reference);
- var referenceTarget = Identifier.FromString(content.Attributes["cref"].Value);
+ if (node.Attributes["cref"] == null) return new See(reference);
+ var referenceTarget = Identifier.FromString(node.Attributes["cref"].Value);
if (referenceTarget is NamespaceIdentifier)
reference = Namespace.Unresolved((NamespaceIdentifier)referenceTarget);
View
4 src/Docu.Tests/Docu.Tests.csproj
@@ -39,6 +39,10 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\lib\rhino\Rhino.Mocks.dll</HintPath>
</Reference>
+ <Reference Include="StructureMap, Version=2.5.3.0, Culture=neutral, PublicKeyToken=e60ad81abae3c223, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\lib\structuremap\StructureMap.dll</HintPath>
+ </Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
View
10 ...Docu.Tests/Documentation/DocumentModelGeneratorTests/BaseDocumentModelGeneratorFixture.cs
@@ -8,13 +8,21 @@
using Docu.Parsing.Model;
using NUnit.Framework;
using Rhino.Mocks;
+using StructureMap;
namespace Docu.Tests.Documentation.DocumentModelGeneratorTests
{
public abstract class BaseDocumentModelGeneratorFixture : BaseFixture
{
protected ICommentParser StubParser;
public IEventAggregator StubEventAggregator;
+ private IContainer container;
+
+ [TestFixtureSetUp]
+ public void FixtureSetup()
+ {
+ container = ContainerBootstrapper.BootstrapStructureMap();
+ }
[SetUp]
public void CreateStubs()
@@ -26,6 +34,8 @@ public void CreateStubs()
.Return(new List<IComment>());
}
+ public ICommentParser RealParser { get { return container.GetInstance<ICommentParser>(); } }
+
protected DocumentedType Type<T>(string xml)
{
return new DocumentedType(Identifier.FromType(typeof(T)), xml.ToNode(), typeof(T));
View
6 src/Docu.Tests/Documentation/DocumentModelGeneratorTests/General.cs
@@ -49,7 +49,7 @@ public void ShouldHaveParentForTypes()
[Test]
public void should_have_summary_for_documented_types()
{
- var model = new DocumentModel(new CommentParser(), StubEventAggregator);
+ var model = new DocumentModel(RealParser, StubEventAggregator);
var members = new List<IDocumentationMember>(DocMembers(typeof(First)));
var indexOfType = members.FindIndex(m => m is UndocumentedType);
members[indexOfType] = Type<First>(@"<member name=""T:Example.First""><summary>The type description</summary></member>");
@@ -128,7 +128,7 @@ public void ShouldHavePrettyNamesForGenericTypes()
[Test]
public void ShouldntHaveAnyUnresolvedReferencesLeftIfAllValid()
{
- var model = new DocumentModel(new CommentParser(), StubEventAggregator);
+ var model = new DocumentModel(RealParser, StubEventAggregator);
var members = new[]
{
Type<First>(@"<member name=""T:Example.First"" />"),
@@ -144,7 +144,7 @@ public void ShouldntHaveAnyUnresolvedReferencesLeftIfAllValid()
[Test]
public void UnresolvedReferencesBecomeExternalReferencesIfStillExist()
{
- var model = new DocumentModel(new CommentParser(), StubEventAggregator);
+ var model = new DocumentModel(RealParser, StubEventAggregator);
var members = new[] { Type<Second>(@"<member name=""T:Example.Second""><summary><see cref=""T:Example.First"" /></summary></member>") };
var namespaces = model.Create(members);
var comment = new List<IComment>(namespaces[0].Types[0].Summary.Children);
View
18 src/Docu.Tests/Documentation/DocumentModelGeneratorTests/Remarks.cs
@@ -15,7 +15,7 @@ public class Remarks : BaseDocumentModelGeneratorFixture
[Test]
public void ShouldHaveRemarksForType()
{
- var model = new DocumentModel(new CommentParser(), StubEventAggregator);
+ var model = new DocumentModel(RealParser, StubEventAggregator);
var members = new[]
{
Type<First>(@"<member name=""T:Example.First""><remarks>First remark</remarks></member>"),
@@ -34,19 +34,19 @@ public void ShouldPassRemarksToContentParser()
var model = new DocumentModel(contentParser, StubEventAggregator);
var members = new[] { Type<First>(@"<member name=""T:Example.First""><remarks>First remark</remarks></member>") };
- contentParser.Stub(x => x.Parse(null))
+ contentParser.Stub(x => x.ParseNode(null))
.IgnoreArguments()
.Return(new List<IComment>());
model.Create(members);
- contentParser.AssertWasCalled(x => x.Parse(members[0].Xml.ChildNodes[0]));
+ contentParser.AssertWasCalled(x => x.ParseNode(members[0].Xml.ChildNodes[0]));
}
[Test]
public void ShouldHaveRemarksForMethods()
{
- var model = new DocumentModel(new CommentParser(), StubEventAggregator);
+ var model = new DocumentModel(RealParser, StubEventAggregator);
var members = new IDocumentationMember[]
{
Type<Second>(@"<member name=""T:Example.Second"" />"),
@@ -66,19 +66,19 @@ public void ShouldPassMethodRemarksToContentParser()
var model = new DocumentModel(contentParser, StubEventAggregator);
var members = new[] { Method<Second>(@"<member name=""M:Example.Second.SecondMethod""><remarks>First remark</remarks></member>", x => x.SecondMethod()) };
- contentParser.Stub(x => x.Parse(null))
+ contentParser.Stub(x => x.ParseNode(null))
.IgnoreArguments()
.Return(new List<IComment>());
model.Create(members);
- contentParser.AssertWasCalled(x => x.Parse(members[0].Xml.ChildNodes[0]));
+ contentParser.AssertWasCalled(x => x.ParseNode(members[0].Xml.ChildNodes[0]));
}
[Test]
public void ShouldHaveRemarksForProperties()
{
- var model = new DocumentModel(new CommentParser(), StubEventAggregator);
+ var model = new DocumentModel(RealParser, StubEventAggregator);
var members = new IDocumentationMember[]
{
Type<Second>(@"<member name=""T:Example.Second"" />"),
@@ -94,7 +94,7 @@ public void ShouldHaveRemarksForProperties()
[Test]
public void ShouldHaveRemarksForEvents()
{
- var model = new DocumentModel(new CommentParser(), StubEventAggregator);
+ var model = new DocumentModel(RealParser, StubEventAggregator);
var members = new IDocumentationMember[]
{
Type<Second>(@"<member name=""T:Example.Second"" />"),
@@ -110,7 +110,7 @@ public void ShouldHaveRemarksForEvents()
[Test]
public void ShouldHaveRemarksForFields()
{
- var model = new DocumentModel(new CommentParser(), StubEventAggregator);
+ var model = new DocumentModel(RealParser, StubEventAggregator);
var members = new IDocumentationMember[]
{
Type<Second>(@"<member name=""T:Example.Second"" />"),
View
6 src/Docu.Tests/Documentation/DocumentModelGeneratorTests/Returns.cs
@@ -16,7 +16,7 @@ public class Returns : BaseDocumentModelGeneratorFixture
[Test]
public void ShouldHaveReturnsForMethods()
{
- var model = new DocumentModel(new CommentParser(), StubEventAggregator);
+ var model = new DocumentModel(RealParser, StubEventAggregator);
var members = new IDocumentationMember[]
{
Type<Second>(@"<member name=""T:Example.Second"" />"),
@@ -35,13 +35,13 @@ public void ShouldPassMethodReturnsToContentParser()
var model = new DocumentModel(contentParser, StubEventAggregator);
var members = new[] { Method<Second>(@"<member name=""M:Example.Second.ReturnType""><returns>Method with return</returns></member>", x => x.ReturnType()), };
- contentParser.Stub(x => x.Parse(null))
+ contentParser.Stub(x => x.ParseNode(null))
.IgnoreArguments()
.Return(new List<IComment>());
model.Create(members);
- contentParser.AssertWasCalled(x => x.Parse(members[0].Xml.ChildNodes[0]));
+ contentParser.AssertWasCalled(x => x.ParseNode(members[0].Xml.ChildNodes[0]));
}
}
}
View
26 src/Docu.Tests/Documentation/DocumentModelGeneratorTests/Summaries.cs
@@ -15,7 +15,7 @@ public class Summaries : BaseDocumentModelGeneratorFixture
[Test]
public void ShouldHaveSummaryForType()
{
- var model = new DocumentModel(new CommentParser(), StubEventAggregator);
+ var model = new DocumentModel(RealParser, StubEventAggregator);
var members = new[]
{
Type<First>(@"<member name=""T:Example.First""><summary>First summary</summary></member>"),
@@ -34,19 +34,19 @@ public void ShouldPassSummaryToContentParser()
var model = new DocumentModel(contentParser, StubEventAggregator);
var members = new[] { Type<First>(@"<member name=""T:Example.First""><summary>First summary</summary></member>") };
- contentParser.Stub(x => x.Parse(null))
+ contentParser.Stub(x => x.ParseNode(null))
.IgnoreArguments()
.Return(new List<IComment>());
model.Create(members);
- contentParser.AssertWasCalled(x => x.Parse(members[0].Xml.ChildNodes[0]));
+ contentParser.AssertWasCalled(x => x.ParseNode(members[0].Xml.ChildNodes[0]));
}
[Test]
public void ShouldHaveSummaryForMethods()
{
- var model = new DocumentModel(new CommentParser(), StubEventAggregator);
+ var model = new DocumentModel(RealParser, StubEventAggregator);
var members = new IDocumentationMember[]
{
Type<Second>(@"<member name=""T:Example.Second"" />"),
@@ -66,19 +66,19 @@ public void ShouldPassMethodSummaryToContentParser()
var model = new DocumentModel(contentParser, StubEventAggregator);
var members = new[] { Method<Second>(@"<member name=""M:Example.Second.SecondMethod""><summary>First summary</summary></member>", x => x.SecondMethod()) };
- contentParser.Stub(x => x.Parse(null))
+ contentParser.Stub(x => x.ParseNode(null))
.IgnoreArguments()
.Return(new List<IComment>());
model.Create(members);
- contentParser.AssertWasCalled(x => x.Parse(members[0].Xml.ChildNodes[0]));
+ contentParser.AssertWasCalled(x => x.ParseNode(members[0].Xml.ChildNodes[0]));
}
[Test]
public void ShouldHaveSummaryForProperties()
{
- var model = new DocumentModel(new CommentParser(), StubEventAggregator);
+ var model = new DocumentModel(RealParser, StubEventAggregator);
var members = new IDocumentationMember[]
{
Type<Second>(@"<member name=""T:Example.Second"" />"),
@@ -94,7 +94,7 @@ public void ShouldHaveSummaryForProperties()
[Test]
public void ShouldHaveSummaryForEvents()
{
- var model = new DocumentModel(new CommentParser(), StubEventAggregator);
+ var model = new DocumentModel(RealParser, StubEventAggregator);
var members = new IDocumentationMember[]
{
Type<Second>(@"<member name=""T:Example.Second"" />"),
@@ -110,7 +110,7 @@ public void ShouldHaveSummaryForEvents()
[Test]
public void ShouldHaveSummaryForFields()
{
- var model = new DocumentModel(new CommentParser(), StubEventAggregator);
+ var model = new DocumentModel(RealParser, StubEventAggregator);
var members = new IDocumentationMember[]
{
Type<Second>(@"<member name=""T:Example.Second"" />"),
@@ -126,7 +126,7 @@ public void ShouldHaveSummaryForFields()
[Test]
public void ShouldHaveSummaryForMethodParameter()
{
- var model = new DocumentModel(new CommentParser(), StubEventAggregator);
+ var model = new DocumentModel(RealParser, StubEventAggregator);
var members = new IDocumentationMember[]
{
Type<Second>(@"<member name=""T:Example.Second"" />"),
@@ -160,14 +160,14 @@ public void ShouldPassMethodParameterSummaryToContentParser()
</member>", x => x.SecondMethod2(null, 0))
};
- contentParser.Stub(x => x.Parse(null))
+ contentParser.Stub(x => x.ParseNode(null))
.IgnoreArguments()
.Return(new List<IComment>());
model.Create(members);
- contentParser.AssertWasCalled(x => x.Parse(members[0].Xml.ChildNodes[0]));
- contentParser.AssertWasCalled(x => x.Parse(members[0].Xml.ChildNodes[1]));
+ contentParser.AssertWasCalled(x => x.ParseNode(members[0].Xml.ChildNodes[0]));
+ contentParser.AssertWasCalled(x => x.ParseNode(members[0].Xml.ChildNodes[1]));
}
}
}
View
8 src/Docu.Tests/Documentation/DocumentModelGeneratorTests/UnrecognisedDocumentationTypes.cs
@@ -15,7 +15,7 @@ public class UnrecognisedDocumentationTypes : BaseDocumentModelGeneratorFixture
public void ShouldRaiseWarningOnUnexpectedKindInReferenceInType()
{
var ev = MockRepository.GenerateMock<WarningEvent>();
- var model = new DocumentModel(new CommentParser(), StubEventAggregator);
+ var model = new DocumentModel(RealParser, StubEventAggregator);
var members = new IDocumentationMember[] { Type<Second>(@"<member name=""T:Example.Second""><summary><see cref=""G:Whats-a-g"" /></summary></member>") };
StubEventAggregator.Stub(x => x.GetEvent<WarningEvent>())
@@ -30,7 +30,7 @@ public void ShouldRaiseWarningOnUnexpectedKindInReferenceInType()
public void ShouldRaiseWarningOnUnexpectedKindInReferenceInMethod()
{
var ev = MockRepository.GenerateMock<WarningEvent>();
- var model = new DocumentModel(new CommentParser(), StubEventAggregator);
+ var model = new DocumentModel(RealParser, StubEventAggregator);
var members = new IDocumentationMember[] { Method<Second>(@"<member name=""M:Example.Second.SecondMethod""><summary><see cref=""G:Whats-a-g"" /></summary></member>", x => x.SecondMethod()) };
StubEventAggregator.Stub(x => x.GetEvent<WarningEvent>())
@@ -45,7 +45,7 @@ public void ShouldRaiseWarningOnUnexpectedKindInReferenceInMethod()
public void ShouldRaiseWarningOnUnexpectedKindInReferenceInProperty()
{
var ev = MockRepository.GenerateMock<WarningEvent>();
- var model = new DocumentModel(new CommentParser(), StubEventAggregator);
+ var model = new DocumentModel(RealParser, StubEventAggregator);
var members = new IDocumentationMember[] { Property<Second>(@"<member name=""P:Example.Second.SecondProperty""><summary><see cref=""G:Whats-a-g"" /></summary></member>", x => x.SecondProperty) };
StubEventAggregator.Stub(x => x.GetEvent<WarningEvent>())
@@ -60,7 +60,7 @@ public void ShouldRaiseWarningOnUnexpectedKindInReferenceInProperty()
public void ShouldRaiseWarningOnUnexpectedKindInReferenceInEvent()
{
var ev = MockRepository.GenerateMock<WarningEvent>();
- var model = new DocumentModel(new CommentParser(), StubEventAggregator);
+ var model = new DocumentModel(RealParser, StubEventAggregator);
var members = new IDocumentationMember[] { Event<Second>(@"<member name=""E:Example.Second.AnEvent""><summary><see cref=""G:Whats-a-g"" /></summary></member>", "AnEvent") };
StubEventAggregator.Stub(x => x.GetEvent<WarningEvent>())
View
4 src/Docu.Tests/Documentation/DocumentModelGeneratorTests/Values.cs
@@ -14,7 +14,7 @@ public class Values : BaseDocumentModelGeneratorFixture
[Test]
public void ShouldHaveValueForProperty()
{
- var model = new DocumentModel(new CommentParser(), StubEventAggregator);
+ var model = new DocumentModel(RealParser, StubEventAggregator);
var properties = new IDocumentationMember[]
{
Type<Second>(@"<member name=""T:Example.Second"" />"),
@@ -29,7 +29,7 @@ public void ShouldHaveValueForProperty()
[Test]
public void ShouldHaveValueForMethod()
{
- var model = new DocumentModel(new CommentParser(), StubEventAggregator);
+ var model = new DocumentModel(RealParser, StubEventAggregator);
var methods = new IDocumentationMember[]
{
Type<ReturnMethodClass>(@"<member name=""T:Example.ReturnMethodClass"" />"),
View
52 src/Docu.Tests/Parsing/CommentParserTests.cs
@@ -2,24 +2,32 @@
using Docu.Parsing.Comments;
using NUnit.Framework;
using System.Linq;
+using StructureMap;
namespace Docu.Tests.Parsing
{
[TestFixture]
public class CommentParserTests
{
private CommentParser parser;
+ private IContainer container;
+
+ [TestFixtureSetUp]
+ public void SetupContainer()
+ {
+ container = ContainerBootstrapper.BootstrapStructureMap();
+ }
[SetUp]
public void CreateParser()
{
- parser = new CommentParser();
+ parser = container.GetInstance<CommentParser>();
}
[Test]
public void ShouldParseSimple()
{
- var blocks = parser.Parse("<x>Hello world!</x>".ToNode());
+ var blocks = parser.ParseNode("<x>Hello world!</x>".ToNode());
blocks.Count.ShouldEqual(1);
blocks[0].ShouldBeOfType<InlineText>();
@@ -29,7 +37,7 @@ public void ShouldParseSimple()
[Test]
public void ShouldParseSimpleTrimLeadingWhitespace()
{
- var blocks = parser.Parse("<x> Hello world!</x>".ToNode());
+ var blocks = parser.ParseNode("<x> Hello world!</x>".ToNode());
blocks.Count.ShouldEqual(1);
blocks[0].ShouldBeOfType<InlineText>();
@@ -39,7 +47,7 @@ public void ShouldParseSimpleTrimLeadingWhitespace()
[Test]
public void ShouldParseSimpleTrimLeadingWhitespaceNewlines()
{
- var blocks = parser.Parse(@"
+ var blocks = parser.ParseNode(@"
<x>
Hello world!
</x>".ToNode());
@@ -52,7 +60,7 @@ public void ShouldParseSimpleTrimLeadingWhitespaceNewlines()
[Test]
public void ShouldParseCodeInline()
{
- var blocks = parser.Parse("<x><c>code</c></x>".ToNode());
+ var blocks = parser.ParseNode("<x><c>code</c></x>".ToNode());
blocks.Count.ShouldEqual(1);
blocks[0].ShouldBeOfType<InlineCode>();
@@ -62,7 +70,7 @@ public void ShouldParseCodeInline()
[Test]
public void ShouldParseCodeMultiline()
{
- var blocks = parser.Parse(@"
+ var blocks = parser.ParseNode(@"
<x>
<code>
Some multiline
@@ -78,7 +86,7 @@ Some multiline
[Test]
public void ShouldParseSeeForNamespace()
{
- var blocks = parser.Parse("<x><see cref=\"N:Example\" /></x>".ToNode());
+ var blocks = parser.ParseNode("<x><see cref=\"N:Example\" /></x>".ToNode());
blocks.Count.ShouldEqual(1);
blocks[0].ShouldBeOfType<See>();
@@ -89,7 +97,7 @@ public void ShouldParseSeeForNamespace()
[Test]
public void ShouldParseSeeForType()
{
- var blocks = parser.Parse("<x><see cref=\"T:Example.First\" /></x>".ToNode());
+ var blocks = parser.ParseNode("<x><see cref=\"T:Example.First\" /></x>".ToNode());
blocks.Count.ShouldEqual(1);
blocks[0].ShouldBeOfType<See>();
@@ -100,7 +108,7 @@ public void ShouldParseSeeForType()
[Test]
public void ShouldParseSeeForMethod()
{
- var blocks = parser.Parse("<x><see cref=\"M:Example.Second.SecondMethod\" /></x>".ToNode());
+ var blocks = parser.ParseNode("<x><see cref=\"M:Example.Second.SecondMethod\" /></x>".ToNode());
blocks.Count.ShouldEqual(1);
blocks[0].ShouldBeOfType<See>();
@@ -111,7 +119,7 @@ public void ShouldParseSeeForMethod()
[Test]
public void ShouldParseSeeForProperty()
{
- var blocks = parser.Parse("<x><see cref=\"P:Example.Second.SecondProperty\" /></x>".ToNode());
+ var blocks = parser.ParseNode("<x><see cref=\"P:Example.Second.SecondProperty\" /></x>".ToNode());
blocks.Count.ShouldEqual(1);
blocks[0].ShouldBeOfType<See>();
@@ -122,7 +130,7 @@ public void ShouldParseSeeForProperty()
[Test]
public void ShouldParseSeeForEvent()
{
- var blocks = parser.Parse("<x><see cref=\"E:Example.Second.AnEvent\" /></x>".ToNode());
+ var blocks = parser.ParseNode("<x><see cref=\"E:Example.Second.AnEvent\" /></x>".ToNode());
blocks.Count.ShouldEqual(1);
blocks[0].ShouldBeOfType<See>();
@@ -133,7 +141,7 @@ public void ShouldParseSeeForEvent()
[Test]
public void ShouldParseSeeForField()
{
- var blocks = parser.Parse("<x><see cref=\"F:Example.Second.aField\" /></x>".ToNode());
+ var blocks = parser.ParseNode("<x><see cref=\"F:Example.Second.aField\" /></x>".ToNode());
blocks.Count.ShouldEqual(1);
blocks[0].ShouldBeOfType<See>();
@@ -144,7 +152,7 @@ public void ShouldParseSeeForField()
[Test]
public void ShouldParseSeeNestedInPara()
{
- var blocks = parser.Parse("<x><para><see cref=\"N:Example\" /></para></x>".ToNode());
+ var blocks = parser.ParseNode("<x><para><see cref=\"N:Example\" /></para></x>".ToNode());
blocks.Count.ShouldEqual(1);
@@ -158,7 +166,7 @@ public void ShouldParseSeeNestedInPara()
[Test]
public void should_parse_single_para_as_paragraph()
{
- var blocks = parser.Parse("<x><para>some text</para></x>".ToNode());
+ var blocks = parser.ParseNode("<x><para>some text</para></x>".ToNode());
blocks.Count.ShouldEqual(1);
var para = blocks.First().ShouldBeOfType<Paragraph>();
@@ -168,7 +176,7 @@ public void should_parse_single_para_as_paragraph()
[Test]
public void should_parse_nested_para_as_paragraphs()
{
- var blocks = parser.Parse("<x><para>some text <para>some more text</para></para></x>".ToNode());
+ var blocks = parser.ParseNode("<x><para>some text <para>some more text</para></para></x>".ToNode());
blocks.Count.ShouldEqual(1);
var para = blocks.First().ShouldBeOfType<Paragraph>();
@@ -183,7 +191,7 @@ public void should_parse_nested_para_as_paragraphs()
[Test]
public void ShouldParseParamref()
{
- var blocks = parser.Parse("<x>Returns the <paramref name=\"inputString\" /></x>".ToNode());
+ var blocks = parser.ParseNode("<x>Returns the <paramref name=\"inputString\" /></x>".ToNode());
blocks.Count.ShouldEqual(2);
blocks[1].ShouldBeOfType<ParameterReference>();
var paramRef = (ParameterReference)blocks[1];
@@ -193,35 +201,35 @@ public void ShouldParseParamref()
[Test]
public void should_default_to_definition_list_if_no_type_specified()
{
- var blocks = parser.Parse("<x><list><item><term>IV</term><description>Four</description></item></list></x>".ToNode());
+ var blocks = parser.ParseNode("<x><list><item><term>IV</term><description>Four</description></item></list></x>".ToNode());
blocks.First().ShouldBeOfType<DefinitionList>();
}
[Test]
public void should_parse_bulleted_list_type()
{
- var blocks = parser.Parse("<x><list type=\"bullet\"><item><description>Four</description></item></list></x>".ToNode());
+ var blocks = parser.ParseNode("<x><list type=\"bullet\"><item><description>Four</description></item></list></x>".ToNode());
blocks.First().ShouldBeOfType<BulletList>();
}
[Test]
public void should_parse_numbered_list_type()
{
- var blocks = parser.Parse("<x><list type=\"number\"><item><description>Four</description></item></list></x>".ToNode());
+ var blocks = parser.ParseNode("<x><list type=\"number\"><item><description>Four</description></item></list></x>".ToNode());
blocks.First().ShouldBeOfType<NumberList>();
}
[Test]
public void should_parse_table_list_type()
{
- var blocks = parser.Parse("<x><list type=\"table\"><item><description>Four</description></item></list></x>".ToNode());
+ var blocks = parser.ParseNode("<x><list type=\"table\"><item><description>Four</description></item></list></x>".ToNode());
blocks.First().ShouldBeOfType<TableList>();
}
[Test]
public void should_parse_definition_list_with_multiple_items()
{
- var blocks = parser.Parse("<x>See <list type=\"definition\"><item><term>IV</term><description>Four</description></item><item><term>IX</term><description>Nine</description></item></list></x>".ToNode());
+ var blocks = parser.ParseNode("<x>See <list type=\"definition\"><item><term>IV</term><description>Four</description></item><item><term>IX</term><description>Nine</description></item></list></x>".ToNode());
blocks.Count.ShouldEqual(2);
blocks[1].ShouldBeOfType<DefinitionList>();
var list = (InlineList)blocks[1];
@@ -233,7 +241,7 @@ public void should_parse_definition_list_with_multiple_items()
[Test]
public void should_parse_definition_list_with_nested_comments()
{
- var blocks = parser.Parse("<x>See <list type=\"definition\"><item><term>IV</term><description>Four <see cref=\"N:Example\" /></description></item></list></x>".ToNode());
+ var blocks = parser.ParseNode("<x>See <list type=\"definition\"><item><term>IV</term><description>Four <see cref=\"N:Example\" /></description></item></list></x>".ToNode());
blocks.Count.ShouldEqual(2);
blocks[1].ShouldBeOfType<DefinitionList>();
var list = (InlineList)blocks[1];

0 comments on commit 41bf645

Please sign in to comment.