1
// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
3
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4
// software and associated documentation files (the "Software"), to deal in the Software
5
// without restriction, including without limitation the rights to use, copy, modify, merge,
6
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7
// to whom the Software is furnished to do so, subject to the following conditions:
9
// The above copyright notice and this permission notice shall be included in all copies or
10
// substantial portions of the Software.
12
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17
// DEALINGS IN THE SOFTWARE.
22
using ICSharpCode.NRefactory.CSharp;
23
using ICSharpCode.NRefactory.TypeSystem;
24
using ICSharpCode.NRefactory.Xml;
25
using NUnit.Framework;
27
namespace ICSharpCode.NRefactory.Documentation
30
public class CSharpDocumentationTests
32
ICompilation compilation;
33
ITypeDefinition typeDefinition;
35
void Init(string program)
37
var pc = new CSharpProjectContent().AddAssemblyReferences(new[] { CecilLoaderTests.Mscorlib });
38
var syntaxTree = SyntaxTree.Parse(program, "program.cs");
39
compilation = pc.AddOrUpdateFiles(syntaxTree.ToTypeSystem()).CreateCompilation();
40
typeDefinition = compilation.MainAssembly.TopLevelTypeDefinitions.FirstOrDefault();
44
public void TypeDocumentationLookup()
49
Assert.AreEqual("<summary/>", typeDefinition.Documentation.ToString());
53
public void TypeDocumentationLookup2()
60
Assert.AreEqual("<summary>" + Environment.NewLine + "Documentation" + Environment.NewLine + "</summary>", typeDefinition.Documentation.ToString());
64
public void TypeDocumentationLookupWithIndentation()
71
Assert.AreEqual("<summary>" + Environment.NewLine + " Documentation" + Environment.NewLine + "</summary>", typeDefinition.Documentation.ToString());
75
public void MultilineDocumentation()
78
/** <summary>Documentation</summary> */
80
Assert.AreEqual("<summary>Documentation</summary> ", typeDefinition.Documentation.ToString());
84
public void MultilineDocumentation2()
93
Assert.AreEqual("<summary>" + Environment.NewLine + " Documentation" + Environment.NewLine + "</summary>", typeDefinition.Documentation.ToString());
97
public void MultilineDocumentationCommonPattern()
105
Assert.AreEqual("<summary>" + Environment.NewLine + " Documentation" + Environment.NewLine + "</summary>", typeDefinition.Documentation.ToString());
109
public void MultilineDocumentationNoCommonPattern()
117
Assert.AreEqual(" <summary>" + Environment.NewLine + " * Documentation", typeDefinition.Documentation.ToString());
121
public void InheritedDocumentation()
124
class Derived : Base {
125
/// <summary>Overridden summary</summary><inheritdoc/>
126
public override void Method();
129
/// <summary>Base summary</summary><remarks>Base remarks</remarks>
130
public virtual void Method();
133
var element = XmlDocumentationElement.Get(typeDefinition.Methods.Single(m => m.Name == "Method"));
134
Assert.AreEqual(2, element.Children.Count());
135
Assert.AreEqual("summary", element.Children[0].Name);
136
Assert.AreEqual("remarks", element.Children[1].Name);
137
Assert.AreEqual("Overridden summary", element.Children[0].TextContent);
138
Assert.AreEqual("Base remarks", element.Children[1].TextContent);
142
public void DocumentationAboveAttribute()
148
Assert.AreEqual("<summary/>", typeDefinition.Documentation.ToString());
152
public void DocumentationAboveAttribute2()
156
[SomeAttribute] // a comment on the attribute
158
Assert.AreEqual("<summary/>", typeDefinition.Documentation.ToString());
162
public void DocumentationAboveAttributeInRegion()
170
Assert.AreEqual("<summary/>", typeDefinition.Documentation.ToString());