~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.Tests/Documentation/CSharpDocumentationTests.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
Import upstream version 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
 
2
// 
 
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:
 
8
// 
 
9
// The above copyright notice and this permission notice shall be included in all copies or
 
10
// substantial portions of the Software.
 
11
// 
 
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.
 
18
 
 
19
using System;
 
20
using System.IO;
 
21
using System.Linq;
 
22
using ICSharpCode.NRefactory.CSharp;
 
23
using ICSharpCode.NRefactory.TypeSystem;
 
24
using ICSharpCode.NRefactory.Xml;
 
25
using NUnit.Framework;
 
26
 
 
27
namespace ICSharpCode.NRefactory.Documentation
 
28
{
 
29
        [TestFixture]
 
30
        public class CSharpDocumentationTests
 
31
        {
 
32
                ICompilation compilation;
 
33
                ITypeDefinition typeDefinition;
 
34
                
 
35
                void Init(string program)
 
36
                {
 
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();
 
41
                }
 
42
                
 
43
                [Test]
 
44
                public void TypeDocumentationLookup()
 
45
                {
 
46
                        Init(@"using System;
 
47
/// <summary/>
 
48
class Test { }");
 
49
                        Assert.AreEqual("<summary/>", typeDefinition.Documentation.ToString());
 
50
                }
 
51
                
 
52
                [Test]
 
53
                public void TypeDocumentationLookup2()
 
54
                {
 
55
                        Init(@"using System;
 
56
/// <summary>
 
57
/// Documentation
 
58
/// </summary>
 
59
class Test { }");
 
60
                        Assert.AreEqual("<summary>" + Environment.NewLine + "Documentation" + Environment.NewLine + "</summary>", typeDefinition.Documentation.ToString());
 
61
                }
 
62
                
 
63
                [Test]
 
64
                public void TypeDocumentationLookupWithIndentation()
 
65
                {
 
66
                        Init(@"using System;
 
67
/// <summary>
 
68
///   Documentation
 
69
/// </summary>
 
70
class Test { }");
 
71
                        Assert.AreEqual("<summary>" + Environment.NewLine + "  Documentation" + Environment.NewLine + "</summary>", typeDefinition.Documentation.ToString());
 
72
                }
 
73
                
 
74
                [Test]
 
75
                public void MultilineDocumentation()
 
76
                {
 
77
                        Init(@"using System;
 
78
/** <summary>Documentation</summary> */
 
79
class Test { }");
 
80
                        Assert.AreEqual("<summary>Documentation</summary> ", typeDefinition.Documentation.ToString());
 
81
                }
 
82
                
 
83
                [Test]
 
84
                public void MultilineDocumentation2()
 
85
                {
 
86
                        Init(@"using System;
 
87
/**
 
88
<summary>
 
89
  Documentation
 
90
</summary>
 
91
*/
 
92
class Test { }");
 
93
                        Assert.AreEqual("<summary>" + Environment.NewLine + "  Documentation" + Environment.NewLine + "</summary>", typeDefinition.Documentation.ToString());
 
94
                }
 
95
                
 
96
                [Test]
 
97
                public void MultilineDocumentationCommonPattern()
 
98
                {
 
99
                        Init(@"using System;
 
100
/**
 
101
 * <summary>
 
102
 *   Documentation
 
103
 * </summary>*/
 
104
class Test { }");
 
105
                        Assert.AreEqual("<summary>" + Environment.NewLine + "  Documentation" + Environment.NewLine + "</summary>", typeDefinition.Documentation.ToString());
 
106
                }
 
107
                
 
108
                [Test]
 
109
                public void MultilineDocumentationNoCommonPattern()
 
110
                {
 
111
                        Init(@"using System;
 
112
/**
 
113
   <summary>
 
114
 *   Documentation
 
115
 */
 
116
class Test { }");
 
117
                        Assert.AreEqual("   <summary>" + Environment.NewLine + " *   Documentation", typeDefinition.Documentation.ToString());
 
118
                }
 
119
                
 
120
                [Test]
 
121
                public void InheritedDocumentation()
 
122
                {
 
123
                        Init(@"using System;
 
124
class Derived : Base {
 
125
        /// <summary>Overridden summary</summary><inheritdoc/>
 
126
        public override void Method();
 
127
}
 
128
class Base {
 
129
        /// <summary>Base summary</summary><remarks>Base remarks</remarks>
 
130
        public virtual void Method();
 
131
}
 
132
");
 
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);
 
139
                }
 
140
                
 
141
                [Test]
 
142
                public void DocumentationAboveAttribute()
 
143
                {
 
144
                        Init(@"using System;
 
145
/// <summary/>
 
146
[SomeAttribute]
 
147
class Test { }");
 
148
                        Assert.AreEqual("<summary/>", typeDefinition.Documentation.ToString());
 
149
                }
 
150
                
 
151
                [Test]
 
152
                public void DocumentationAboveAttribute2()
 
153
                {
 
154
                        Init(@"using System;
 
155
/// <summary/>
 
156
[SomeAttribute] // a comment on the attribute
 
157
class Test { }");
 
158
                        Assert.AreEqual("<summary/>", typeDefinition.Documentation.ToString());
 
159
                }
 
160
                
 
161
                [Test]
 
162
                public void DocumentationAboveAttributeInRegion()
 
163
                {
 
164
                        Init(@"using System;
 
165
/// <summary/>
 
166
#region R
 
167
[SomeAttribute]
 
168
#endregion
 
169
class Test { }");
 
170
                        Assert.AreEqual("<summary/>", typeDefinition.Documentation.ToString());
 
171
                }
 
172
        }
 
173
}