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

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/ExpressionIsNeverOfProvidedTypeIssueTests.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
// ExpressionIsNeverOfProvidedTypeIssueTests.cs
 
3
// 
 
4
// Author:
 
5
//      Mansheng Yang <lightyang0@gmail.com>
 
6
// 
 
7
// Copyright (c) 2012 Mansheng Yang <lightyang0@gmail.com>
 
8
// 
 
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
10
// of this software and associated documentation files (the "Software"), to deal
 
11
// in the Software without restriction, including without limitation the rights
 
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
13
// copies of the Software, and to permit persons to whom the Software is
 
14
// furnished to do so, subject to the following conditions:
 
15
// 
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
// 
 
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
25
// THE SOFTWARE.
 
26
 
 
27
using ICSharpCode.NRefactory.CSharp.Refactoring;
 
28
using NUnit.Framework;
 
29
 
 
30
namespace ICSharpCode.NRefactory.CSharp.CodeIssues
 
31
{
 
32
        [TestFixture]
 
33
        public class ExpressionIsNeverOfProvidedTypeIssueTests : InspectionActionTestBase
 
34
        {
 
35
                [Test]
 
36
                public void TestClass ()
 
37
                {
 
38
                        var input = @"
 
39
class AnotherClass { }
 
40
class TestClass
 
41
{
 
42
        void TestMethod (AnotherClass x)
 
43
        {
 
44
                if (x is TestClass) ;
 
45
        }
 
46
}";
 
47
                        Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 1);
 
48
                }
 
49
 
 
50
                [Test]
 
51
                public void TestClassNoIssue ()
 
52
                {
 
53
                        var input = @"
 
54
interface ITest { }
 
55
class TestClass
 
56
{
 
57
        void TestMethod (object x)
 
58
        {
 
59
                if (x is ITest) ;
 
60
                if (x is TestClass) ;
 
61
        }
 
62
}";
 
63
                        Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 0);
 
64
                }
 
65
 
 
66
                [Test]
 
67
                public void TestSealedClass ()
 
68
                {
 
69
                        var input = @"
 
70
interface ITest { }
 
71
sealed class TestClass
 
72
{
 
73
        void TestMethod (TestClass x)
 
74
        {
 
75
                if (x is ITest) ;
 
76
        }
 
77
}";
 
78
                        Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 1);
 
79
                }
 
80
 
 
81
                [Test]
 
82
                public void TestNull ()
 
83
                {
 
84
                        var input = @"
 
85
class TestClass
 
86
{
 
87
        void TestMethod ()
 
88
        {
 
89
                if (null is object) ;
 
90
        }
 
91
}";
 
92
                        Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 1);
 
93
                }
 
94
 
 
95
                [Test]
 
96
                public void TestObjectToInt ()
 
97
                {
 
98
                        var input = @"
 
99
sealed class TestClass
 
100
{
 
101
        void TestMethod (object x)
 
102
        {
 
103
                if (x is int) ;
 
104
        }
 
105
}";
 
106
                        Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 0);
 
107
                }
 
108
 
 
109
                [Test]
 
110
                public void TestClassIsTypeParameter ()
 
111
                {
 
112
                        var input = @"
 
113
class TestClass2 { }
 
114
class TestClass
 
115
{
 
116
        void TestMethod<T, T2> (TestClass x) where T : TestClass2 where T2 : struct
 
117
        {
 
118
                if (x is T) ;
 
119
                if (x is T2) ;
 
120
        }
 
121
}";
 
122
                        Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 2);
 
123
                }
 
124
 
 
125
                [Test]
 
126
                public void TestClassIsTypeParameter2 ()
 
127
                {
 
128
                        var input = @"
 
129
interface ITest { }
 
130
class TestBase { }
 
131
class TestClass2 : TestClass { }
 
132
class TestClass : TestBase
 
133
{
 
134
        void TestMethod<T, T2, T3> (TestClass x) where T : TestBase where T2 : ITest where T3 : TestClass2
 
135
        {
 
136
                if (x is T3) ;
 
137
        }
 
138
}";
 
139
                        Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 0);
 
140
                }
 
141
 
 
142
                [Test]
 
143
                public void TestStructIsTypeParameter ()
 
144
                {
 
145
                        var input = @"
 
146
interface ITest { }
 
147
struct TestStruct : ITest { }
 
148
class TestClass
 
149
{
 
150
        void TestMethod<T> (TestStruct x) where T : ITest
 
151
        {
 
152
                if (x is T) ;
 
153
        }
 
154
}";
 
155
                        Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 0);
 
156
                }
 
157
 
 
158
                [Test]
 
159
                public void TestStructIsTypeParameter2 ()
 
160
                {
 
161
                        var input = @"
 
162
struct TestStruct { }
 
163
class TestClass
 
164
{
 
165
        void TestMethod<T> (TestStruct x) where T : class
 
166
        {
 
167
                if (x is T) ;
 
168
        }
 
169
}";
 
170
                        // this is possible with T==object
 
171
                        Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 0);
 
172
                }
 
173
 
 
174
                [Test]
 
175
                public void TestTypeParameter ()
 
176
                {
 
177
                        var input = @"
 
178
class TestClass2 { }
 
179
class TestClass
 
180
{
 
181
        void TestMethod<T> (T x) where T : TestClass2
 
182
        {
 
183
                if (x is TestClass) ;
 
184
        }
 
185
}";
 
186
                        Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 1);
 
187
                }
 
188
 
 
189
                [Test]
 
190
                public void TestTypeParameter2 ()
 
191
                {
 
192
                        var input = @"
 
193
class TestClass
 
194
{
 
195
        void TestMethod<T> (T x) where T : struct
 
196
        {
 
197
                if (x is TestClass) ;
 
198
        }
 
199
}";
 
200
                        Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 1);
 
201
                }
 
202
 
 
203
                [Test]
 
204
                public void TestTypeParameter3 ()
 
205
                {
 
206
                        var input = @"
 
207
interface ITest { }
 
208
class TestClass
 
209
{
 
210
        void TestMethod<T> (T x) where T : ITest, new()
 
211
        {
 
212
                if (x is TestClass) ;
 
213
        }
 
214
}";
 
215
                        Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 0);
 
216
                }
 
217
 
 
218
                [Test]
 
219
                public void TestTypeParameter4 ()
 
220
                {
 
221
                        var input = @"
 
222
interface ITest { }
 
223
sealed class TestClass
 
224
{
 
225
        void TestMethod<T> (T x) where T : ITest
 
226
        {
 
227
                if (x is TestClass) ;
 
228
        }
 
229
}";
 
230
                        Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 1);
 
231
                }
 
232
 
 
233
                [Test]
 
234
                public void TestTypeParameterIsTypeParameter ()
 
235
                {
 
236
                        var input = @"
 
237
class TestClass2 { }
 
238
class TestClass
 
239
{
 
240
        void TestMethod<T, T2> (T x) where T : TestClass where T2 : TestClass2
 
241
        {
 
242
                if (x is T2) ;
 
243
        }
 
244
}";
 
245
                        Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 1);
 
246
                }
 
247
 
 
248
                [Test]
 
249
                public void TestTypeParameterIsTypeParameter2 ()
 
250
                {
 
251
                        var input = @"
 
252
interface ITest { }
 
253
class TestClass
 
254
{
 
255
        void TestMethod<T, T2> (T x) where T : TestClass where T2 : ITest, new()
 
256
        {
 
257
                if (x is T2) ;
 
258
        }
 
259
}";
 
260
                        Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 0);
 
261
                }
 
262
                
 
263
                [Test]
 
264
                public void TestObjectArrayToStringArray ()
 
265
                {
 
266
                        var input = @"
 
267
sealed class TestClass
 
268
{
 
269
        void TestMethod (object[] x)
 
270
        {
 
271
                if (x is string[]) ;
 
272
        }
 
273
}";
 
274
                        Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 0);
 
275
                }
 
276
                
 
277
                [Test]
 
278
                public void UnknownExpression()
 
279
                {
 
280
                        var input = @"
 
281
sealed class TestClass
 
282
{
 
283
        void TestMethod ()
 
284
        {
 
285
                if (unknown is string) ;
 
286
        }
 
287
}";
 
288
                        Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 0);
 
289
                }
 
290
                
 
291
                [Test]
 
292
                public void UnknownType()
 
293
                {
 
294
                        var input = @"
 
295
sealed class TestClass
 
296
{
 
297
        void TestMethod (int x)
 
298
        {
 
299
                if (x is unknown) ;
 
300
        }
 
301
}";
 
302
                        Test<ExpressionIsNeverOfProvidedTypeIssue> (input, 0);
 
303
                }
 
304
        }
 
305
}