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

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeCompletion/CodeCompletionCSharpTests.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
//
 
2
// CodeCompletionCSharpTests.cs
 
3
//
 
4
// Author:
 
5
//   Mike KrĆ¼ger <mkrueger@novell.com>
 
6
//
 
7
// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
 
8
//
 
9
// Permission is hereby granted, free of charge, to any person obtaining
 
10
// a copy of this software and associated documentation files (the
 
11
// "Software"), to deal in the Software without restriction, including
 
12
// without limitation the rights to use, copy, modify, merge, publish,
 
13
// distribute, sublicense, and/or sell copies of the Software, and to
 
14
// permit persons to whom the Software is furnished to do so, subject to
 
15
// the following conditions:
 
16
// 
 
17
// The above copyright notice and this permission notice shall be
 
18
// included in all copies or substantial portions of the Software.
 
19
// 
 
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
27
//
 
28
 
 
29
using System;
 
30
using NUnit.Framework;
 
31
 
 
32
namespace ICSharpCode.NRefactory.CSharp.CodeCompletion
 
33
{
 
34
        [TestFixture()]
 
35
        public class CodeCompletionCSharpTests : TestBase
 
36
        {
 
37
                [Test()]
 
38
                public void TestUsingDeclaration ()
 
39
                {
 
40
                        CompletionDataList provider = CodeCompletionBugTests.CreateProvider (
 
41
@"namespace Test {
 
42
        class Class
 
43
        {
 
44
        }
 
45
}
 
46
 
 
47
$using $
 
48
");
 
49
                        Assert.IsNotNull (provider, "provider == null");
 
50
                        Assert.IsNotNull (provider.Find ("Test"), "namespace 'Test' not found.");
 
51
                }
 
52
                
 
53
                [Test()]
 
54
                public void TestLocalVariableDeclaration ()
 
55
                {
 
56
                        CompletionDataList provider = CodeCompletionBugTests.CreateProvider (
 
57
@"class Test
 
58
{
 
59
        void Test ()
 
60
        {
 
61
                Test t;
 
62
                $t.$
 
63
        }
 
64
}");
 
65
                        Assert.IsNotNull (provider, "provider == null");
 
66
                        Assert.IsNotNull (provider.Find ("Test"), "method 'Test' not found.");
 
67
                }
 
68
                
 
69
                [Test()]
 
70
                public void TestObjectCreationExpression ()
 
71
                {
 
72
                        CompletionDataList provider = CodeCompletionBugTests.CreateProvider (
 
73
@"class Test
 
74
{
 
75
        void Test ()
 
76
        {
 
77
                $new Test ().$
 
78
        }
 
79
}");
 
80
                        Assert.IsNotNull (provider, "provider == null");
 
81
                        Assert.IsNotNull (provider.Find ("Test"), "method 'Test' not found.");
 
82
                }
 
83
                
 
84
                [Test()]
 
85
                public void TestCastExpression ()
 
86
                {
 
87
                        CompletionDataList provider = CodeCompletionBugTests.CreateProvider (
 
88
@"class Test
 
89
{
 
90
        void Test ()
 
91
        {
 
92
                object o;
 
93
                $((Test)o).$
 
94
        }
 
95
}");
 
96
                        Assert.IsNotNull (provider, "provider == null");
 
97
                        Assert.IsNotNull (provider.Find ("Test"), "method 'Test' not found.");
 
98
                }
 
99
                
 
100
                [Test()]
 
101
                public void TestThisReferenceExpression ()
 
102
                {
 
103
                        CompletionDataList provider = CodeCompletionBugTests.CreateProvider (
 
104
@"class Test
 
105
{
 
106
        void Test ()
 
107
        {
 
108
                $this.$
 
109
        }
 
110
}");
 
111
                        Assert.IsNotNull (provider, "provider == null");
 
112
                        Assert.IsNotNull (provider.Find ("Test"), "method 'Test' not found.");
 
113
                }
 
114
                
 
115
                [Test()]
 
116
                public void TestBaseReferenceExpression ()
 
117
                {
 
118
                        CompletionDataList provider = CodeCompletionBugTests.CreateProvider (
 
119
@"
 
120
class Test
 
121
{
 
122
        public void Test ()
 
123
        {
 
124
        }
 
125
}
 
126
 
 
127
class Test2 : Test
 
128
{
 
129
        void Test2 ()
 
130
        {
 
131
                $base.$
 
132
        }
 
133
}");
 
134
                        Assert.IsNotNull (provider, "provider == null");
 
135
                        Assert.IsNotNull (provider.Find ("Test"), "method 'Test' not found.");
 
136
                        Assert.IsNull (provider.Find ("Test2"), "method 'Test2' found but shouldn't.");
 
137
                }
 
138
                
 
139
                [Test()]
 
140
                public void TestConditionalExpression ()
 
141
                {
 
142
                        CompletionDataList provider = CodeCompletionBugTests.CreateProvider (
 
143
@"
 
144
class Test
 
145
{
 
146
        void Test ()
 
147
        {
 
148
                Test a, b;
 
149
                $(1 == 1 ? a : b).$
 
150
        }
 
151
}");
 
152
                        Assert.IsNotNull (provider, "provider == null");
 
153
                        Assert.IsNotNull (provider.Find ("Test"), "method 'Test' not found.");
 
154
                }
 
155
 
 
156
                [Test()]
 
157
                public void TestIndexerExpression ()
 
158
                {
 
159
                        CompletionDataList provider = CodeCompletionBugTests.CreateProvider (
 
160
@"
 
161
class Test
 
162
{
 
163
        void Test ()
 
164
        {
 
165
                Test[] a;
 
166
                $a[0].$
 
167
        }
 
168
}");
 
169
                        Assert.IsNotNull (provider, "provider == null");
 
170
                        Assert.IsNotNull (provider.Find ("Test"), "method 'Test' not found.");
 
171
                }
 
172
                
 
173
                [Test()]
 
174
                public void TestInvocationExpression ()
 
175
                {
 
176
                        CompletionDataList provider = CodeCompletionBugTests.CreateProvider (
 
177
@"
 
178
class Test
 
179
{
 
180
        static Test GetTest () {}
 
181
        
 
182
        void Test ()
 
183
        {
 
184
                $GetTest ().$
 
185
        }
 
186
}");
 
187
                        Assert.IsNotNull (provider, "provider == null");
 
188
                        Assert.IsNotNull (provider.Find ("Test"), "method 'Test' not found.");
 
189
                }
 
190
                
 
191
                [Test()]
 
192
                public void TestParenthesizedExpression ()
 
193
                {
 
194
                        CompletionDataList provider = CodeCompletionBugTests.CreateProvider (
 
195
@"
 
196
class Test
 
197
{
 
198
        void Test ()
 
199
        {
 
200
                $(this).$
 
201
        }
 
202
}");
 
203
                        Assert.IsNotNull (provider, "provider == null");
 
204
                        Assert.IsNotNull (provider.Find ("Test"), "method 'Test' not found.");
 
205
                }
 
206
                
 
207
                [Test()]
 
208
                public void TestForeachLoopVariable ()
 
209
                {
 
210
                        CompletionDataList provider = CodeCompletionBugTests.CreateProvider (
 
211
@"
 
212
class Test
 
213
{
 
214
        void Test ()
 
215
        {
 
216
                foreach (Test t in new string[] {""hello""})
 
217
                        $t.$;
 
218
        }
 
219
}");
 
220
                        Assert.IsNotNull (provider, "provider == null");
 
221
                        Assert.IsNotNull (provider.Find ("Test"), "method 'Test' not found.");
 
222
                }
 
223
                
 
224
                [Test()]
 
225
                public void TestMethodAccess ()
 
226
                {
 
227
                        CompletionDataList provider = CodeCompletionBugTests.CreateProvider (
 
228
@"
 
229
class AClass
 
230
{
 
231
        public AClass TestMethod ()
 
232
        {
 
233
        }
 
234
}
 
235
 
 
236
class Test
 
237
{
 
238
        void Test ()
 
239
        {
 
240
                AClass a;
 
241
                $a.TestMethod().$
 
242
        }
 
243
}");
 
244
                        Assert.IsNotNull (provider, "provider == null");
 
245
                        Assert.IsNotNull (provider.Find ("TestMethod"), "method 'TestMethod ' not found.");
 
246
                }
 
247
                
 
248
                [Test()]
 
249
                public void TestFieldAccess ()
 
250
                {
 
251
                        CompletionDataList provider = CodeCompletionBugTests.CreateProvider (
 
252
@"
 
253
class AClass
 
254
{
 
255
        public AClass TestField;
 
256
}
 
257
 
 
258
class Test
 
259
{
 
260
        void Test ()
 
261
        {
 
262
                AClass a;
 
263
                $a.TestField.$
 
264
        }
 
265
}");
 
266
                        Assert.IsNotNull (provider, "provider == null");
 
267
                        Assert.IsNotNull (provider.Find ("TestField"), "field 'TestField' not found.");
 
268
                }
 
269
                
 
270
                [Test()]
 
271
                public void TestPropertyAccess ()
 
272
                {
 
273
                        CompletionDataList provider = CodeCompletionBugTests.CreateProvider (
 
274
@"
 
275
class AClass
 
276
{
 
277
        public AClass TestProperty { get { return null; } }
 
278
}
 
279
 
 
280
class Test
 
281
{
 
282
        void Test ()
 
283
        {
 
284
                AClass a;
 
285
                $a.TestProperty.$
 
286
        }
 
287
}");
 
288
                        Assert.IsNotNull (provider, "provider == null");
 
289
                        Assert.IsNotNull (provider.Find ("TestProperty"), "property 'TestProperty' not found.");
 
290
                }
 
291
 
 
292
                [Test()]
 
293
                public void TestAsCompletionContext ()
 
294
                {
 
295
                        CompletionDataList provider = CodeCompletionBugTests.CreateProvider (
 
296
@"
 
297
class A
 
298
{
 
299
}
 
300
 
 
301
class B
 
302
{
 
303
}
 
304
 
 
305
class C : A
 
306
{
 
307
}
 
308
 
 
309
class Test
 
310
{
 
311
        public void TestMethod (object test)
 
312
        {
 
313
                $A a = test as $
 
314
        }
 
315
}
 
316
");
 
317
                        Assert.IsNotNull (provider, "provider == null");
 
318
                        Assert.IsNotNull (provider.Find ("A"), "class 'A' not found.");
 
319
                        Assert.IsNotNull (provider.Find ("C"), "class 'C' not found.");
 
320
                        Assert.IsNull (provider.Find ("B"), "class 'B' found, but shouldn't.");
 
321
                        Assert.IsNull (provider.Find ("Test"), "class 'Test' found, but shouldn't.");
 
322
                }
 
323
                
 
324
                
 
325
                        
 
326
                [Test()]
 
327
                public void TestLocalVariableNameContext ()
 
328
                {
 
329
                        CompletionDataList provider = CodeCompletionBugTests.CreateCtrlSpaceProvider (
 
330
@"
 
331
public class TestMyLongName
 
332
{
 
333
        public void Method ()
 
334
        {
 
335
                $TestMyLongName $
 
336
        }
 
337
}");
 
338
                        Assert.IsNotNull (provider, "provider == null");
 
339
                        Assert.IsNotNull (provider.Find ("testMyLongName"), "name 'testMyLongName' not found.");
 
340
                        Assert.IsNotNull (provider.Find ("myLongName"), "name 'myLongName' not found.");
 
341
                        Assert.IsNotNull (provider.Find ("longName"), "name 'longName' not found.");
 
342
                        Assert.IsNotNull (provider.Find ("name"), "name 'name' not found.");
 
343
                }
 
344
 
 
345
                
 
346
        }
 
347
}