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

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.Tests/Documentation/CSharpCrefParserTests.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 ICSharpCode.NRefactory.CSharp;
 
21
using ICSharpCode.NRefactory.CSharp.Parser;
 
22
using ICSharpCode.NRefactory.TypeSystem;
 
23
using NUnit.Framework;
 
24
 
 
25
namespace ICSharpCode.NRefactory.Documentation
 
26
{
 
27
        [TestFixture]
 
28
        public class CSharpCrefParserTests
 
29
        {
 
30
                [Test]
 
31
                public void M()
 
32
                {
 
33
                        ParseUtilCSharp.AssertDocumentationReference(
 
34
                                "M",
 
35
                                new DocumentationReference {
 
36
                                        MemberName = "M"
 
37
                                });
 
38
                }
 
39
                
 
40
                [Test]
 
41
                [Ignore("mcs bug")]
 
42
                public void This()
 
43
                {
 
44
                        ParseUtilCSharp.AssertDocumentationReference(
 
45
                                "this",
 
46
                                new DocumentationReference {
 
47
                                        EntityType = EntityType.Indexer
 
48
                                });
 
49
                }
 
50
                
 
51
                [Test]
 
52
                [Ignore("mcs bug (Unexpected symbol `this', expecting `explicit', `implicit', `operator', or `type')")]
 
53
                public void ThisWithParameter()
 
54
                {
 
55
                        ParseUtilCSharp.AssertDocumentationReference(
 
56
                                "this[int]",
 
57
                                new DocumentationReference {
 
58
                                        EntityType = EntityType.Indexer,
 
59
                                        HasParameterList = true,
 
60
                                        Parameters = { new ParameterDeclaration { Type = new PrimitiveType("int") } }
 
61
                                });
 
62
                }
 
63
                
 
64
                [Test]
 
65
                public void ThisWithDeclaringType()
 
66
                {
 
67
                        ParseUtilCSharp.AssertDocumentationReference(
 
68
                                "List{T}.this",
 
69
                                new DocumentationReference {
 
70
                                        EntityType = EntityType.Indexer,
 
71
                                        DeclaringType = new SimpleType("List", new SimpleType("T"))
 
72
                                });
 
73
                }
 
74
                
 
75
                [Test]
 
76
                public void NestedTypeInGenericType()
 
77
                {
 
78
                        ParseUtilCSharp.AssertDocumentationReference(
 
79
                                "List{T}.Enumerator",
 
80
                                new DocumentationReference {
 
81
                                        DeclaringType = new SimpleType("List", new SimpleType("T")),
 
82
                                        MemberName = "Enumerator"
 
83
                                });
 
84
                }
 
85
                
 
86
                [Test]
 
87
                public void GenericTypeWithFullNamespace()
 
88
                {
 
89
                        ParseUtilCSharp.AssertDocumentationReference(
 
90
                                "System.Collections.Generic.List{T}",
 
91
                                new DocumentationReference {
 
92
                                        DeclaringType = new SimpleType("System").MemberType("Collections").MemberType("Generic"),
 
93
                                        MemberName = "List",
 
94
                                        TypeArguments = { new SimpleType("T") }
 
95
                                });
 
96
                }
 
97
                
 
98
                [Test]
 
99
                public void PrimitiveType()
 
100
                {
 
101
                        ParseUtilCSharp.AssertDocumentationReference(
 
102
                                "int",
 
103
                                new DocumentationReference {
 
104
                                        EntityType = EntityType.TypeDefinition,
 
105
                                        DeclaringType = new PrimitiveType("int")
 
106
                                });
 
107
                }
 
108
                
 
109
                [Test]
 
110
                public void VerbatimIdentifier()
 
111
                {
 
112
                        ParseUtilCSharp.AssertDocumentationReference(
 
113
                                "@int",
 
114
                                new DocumentationReference {
 
115
                                        MemberName = "int"
 
116
                                });
 
117
                }
 
118
                
 
119
                [Test]
 
120
                public void IntParse()
 
121
                {
 
122
                        ParseUtilCSharp.AssertDocumentationReference(
 
123
                                "int.Parse(string)",
 
124
                                new DocumentationReference {
 
125
                                        DeclaringType = new PrimitiveType("int"),
 
126
                                        MemberName = "Parse",
 
127
                                        HasParameterList = true,
 
128
                                        Parameters = {
 
129
                                                new ParameterDeclaration { Type = new PrimitiveType("string") }
 
130
                                        }
 
131
                                });
 
132
                }
 
133
                
 
134
                [Test]
 
135
                public void Generic()
 
136
                {
 
137
                        ParseUtilCSharp.AssertDocumentationReference(
 
138
                                "IGeneric{X, Y}",
 
139
                                new DocumentationReference {
 
140
                                        MemberName = "IGeneric",
 
141
                                        TypeArguments = { new SimpleType("X"), new SimpleType("Y") }
 
142
                                });
 
143
                }
 
144
                
 
145
                [Test]
 
146
                public void MixedGeneric()
 
147
                {
 
148
                        ParseUtilCSharp.AssertDocumentationReference(
 
149
                                "IGeneric<X, Y}",
 
150
                                new DocumentationReference {
 
151
                                        MemberName = "IGeneric",
 
152
                                        TypeArguments = { new SimpleType("X"), new SimpleType("Y") }
 
153
                                });
 
154
                }
 
155
                
 
156
                [Test]
 
157
                public void MethodInGeneric()
 
158
                {
 
159
                        ParseUtilCSharp.AssertDocumentationReference(
 
160
                                "IGeneric{X, Y}.Test",
 
161
                                new DocumentationReference {
 
162
                                        DeclaringType = new SimpleType("IGeneric", new SimpleType("X"), new SimpleType("Y")),
 
163
                                        MemberName = "Test"
 
164
                                });
 
165
                }
 
166
                
 
167
                [Test]
 
168
                public void GenericMethodInGeneric()
 
169
                {
 
170
                        ParseUtilCSharp.AssertDocumentationReference(
 
171
                                "IGeneric{X, Y}.Test{Z}",
 
172
                                new DocumentationReference {
 
173
                                        DeclaringType = new SimpleType("IGeneric", new SimpleType("X"), new SimpleType("Y")),
 
174
                                        MemberName = "Test",
 
175
                                        TypeArguments = { new SimpleType("Z") }
 
176
                                });
 
177
                }
 
178
                
 
179
                [Test]
 
180
                public void GenericMethodInGenericWithParameterList()
 
181
                {
 
182
                        ParseUtilCSharp.AssertDocumentationReference(
 
183
                                "IGeneric{X, Y}.Test{Z}(ref Z[,])",
 
184
                                new DocumentationReference {
 
185
                                        DeclaringType = new SimpleType("IGeneric", new SimpleType("X"), new SimpleType("Y")),
 
186
                                        MemberName = "Test",
 
187
                                        TypeArguments = { new SimpleType("Z") },
 
188
                                        HasParameterList = true,
 
189
                                        Parameters = {
 
190
                                                new ParameterDeclaration {
 
191
                                                        ParameterModifier = ParameterModifier.Ref,
 
192
                                                        Type = new SimpleType("Z").MakeArrayType(2)
 
193
                                                }
 
194
                                        }});
 
195
                }
 
196
                
 
197
                [Test]
 
198
                public void EmptyParameterList()
 
199
                {
 
200
                        ParseUtilCSharp.AssertDocumentationReference(
 
201
                                "Window1()",
 
202
                                new DocumentationReference {
 
203
                                        MemberName = "Window1",
 
204
                                        HasParameterList = true
 
205
                                });
 
206
                }
 
207
                
 
208
                [Test]
 
209
                public void OperatorPlus()
 
210
                {
 
211
                        ParseUtilCSharp.AssertDocumentationReference(
 
212
                                "operator +",
 
213
                                new DocumentationReference {
 
214
                                        EntityType = EntityType.Operator,
 
215
                                        OperatorType = OperatorType.Addition
 
216
                                });
 
217
                }
 
218
                
 
219
                [Test]
 
220
                [Ignore("mcs bug (Unexpected symbol `operator', expecting `identifier' or `this')")]
 
221
                public void OperatorPlusWithDeclaringType()
 
222
                {
 
223
                        ParseUtilCSharp.AssertDocumentationReference(
 
224
                                "Test.operator +",
 
225
                                new DocumentationReference {
 
226
                                        DeclaringType = new SimpleType("Test"),
 
227
                                        EntityType = EntityType.Operator,
 
228
                                        OperatorType = OperatorType.Addition
 
229
                                });
 
230
                }
 
231
                
 
232
                [Test]
 
233
                public void OperatorPlusWithParameterList()
 
234
                {
 
235
                        ParseUtilCSharp.AssertDocumentationReference(
 
236
                                "operator +(Test, int)",
 
237
                                new DocumentationReference {
 
238
                                        EntityType = EntityType.Operator,
 
239
                                        OperatorType = OperatorType.Addition,
 
240
                                        HasParameterList = true,
 
241
                                        Parameters = {
 
242
                                                new ParameterDeclaration { Type = new SimpleType("Test") },
 
243
                                                new ParameterDeclaration { Type = new PrimitiveType("int") }
 
244
                                        }});
 
245
                }
 
246
                
 
247
                [Test]
 
248
                public void ImplicitOperator()
 
249
                {
 
250
                        ParseUtilCSharp.AssertDocumentationReference(
 
251
                                "implicit operator int",
 
252
                                new DocumentationReference {
 
253
                                        EntityType = EntityType.Operator,
 
254
                                        OperatorType = OperatorType.Implicit,
 
255
                                        ConversionOperatorReturnType = new PrimitiveType("int")
 
256
                                });
 
257
                }
 
258
                
 
259
                [Test]
 
260
                public void ExplicitOperatorWithParameterList()
 
261
                {
 
262
                        ParseUtilCSharp.AssertDocumentationReference(
 
263
                                "explicit operator int(Test)",
 
264
                                new DocumentationReference {
 
265
                                        EntityType = EntityType.Operator,
 
266
                                        OperatorType = OperatorType.Explicit,
 
267
                                        ConversionOperatorReturnType = new PrimitiveType("int"),
 
268
                                        HasParameterList = true,
 
269
                                        Parameters = {
 
270
                                                new ParameterDeclaration { Type = new SimpleType("Test") },
 
271
                                        }
 
272
                                });
 
273
                }
 
274
                
 
275
                [Test]
 
276
                [Ignore("mcs bug (Unexpected symbol `explicit', expecting `identifier' or `this')")]
 
277
                public void ExplicitOperatorWithParameterListAndDeclaringType()
 
278
                {
 
279
                        ParseUtilCSharp.AssertDocumentationReference(
 
280
                                "Test.explicit operator int(Test)",
 
281
                                new DocumentationReference {
 
282
                                        EntityType = EntityType.Operator,
 
283
                                        OperatorType = OperatorType.Explicit,
 
284
                                        DeclaringType = new SimpleType("Test"),
 
285
                                        ConversionOperatorReturnType = new PrimitiveType("int"),
 
286
                                        HasParameterList = true,
 
287
                                        Parameters = {
 
288
                                                new ParameterDeclaration { Type = new SimpleType("Test") },
 
289
                                        }
 
290
                                });
 
291
                }
 
292
        }
 
293
}