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

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/UnreachableCodeIssueTests.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
// UnreachableCodeIssueTests.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 UnreachableCodeIssueTests : InspectionActionTestBase
 
34
        {
 
35
                [Test]
 
36
                public void TestReturn ()
 
37
                {
 
38
                        var input = @"
 
39
class TestClass
 
40
{
 
41
        void TestMethod ()
 
42
        {
 
43
                return;
 
44
                int a = 1;
 
45
        }
 
46
}";
 
47
                        Test<UnreachableCodeIssue> (input, 1);
 
48
                }
 
49
 
 
50
                [Test]
 
51
                public void TestBreak ()
 
52
                {
 
53
                        var input = @"
 
54
class TestClass
 
55
{
 
56
        void TestMethod ()
 
57
        {
 
58
                while (true) {
 
59
                        break;
 
60
                        int a = 1;
 
61
                }
 
62
        }
 
63
}";
 
64
                        Test<UnreachableCodeIssue> (input, 1);
 
65
                }
 
66
 
 
67
                [Test]
 
68
                public void TestContinue ()
 
69
                {
 
70
                        var input = @"
 
71
class TestClass
 
72
{
 
73
        void TestMethod ()
 
74
        {
 
75
                while (true) {
 
76
                        continue;
 
77
                        break;
 
78
                }
 
79
        }
 
80
}";
 
81
                        Test<UnreachableCodeIssue> (input, 1);
 
82
                }
 
83
 
 
84
                [Test]
 
85
                public void TestFor ()
 
86
                {
 
87
                        var input = @"
 
88
class TestClass
 
89
{
 
90
        void TestMethod ()
 
91
        {
 
92
                for (int i = 0; i < 10; i++) {
 
93
                        break;
 
94
                }
 
95
        }
 
96
}";
 
97
                        Test<UnreachableCodeIssue> (input, 1);
 
98
                }
 
99
 
 
100
                [Test]
 
101
                public void TestConstantCondition ()
 
102
                {
 
103
                        var input = @"
 
104
class TestClass
 
105
{
 
106
        void TestMethod ()
 
107
        {
 
108
                if (true) {
 
109
                        return;
 
110
                }
 
111
                int a = 1;
 
112
        }
 
113
}";
 
114
                        Test<UnreachableCodeIssue> (input, 1);
 
115
                }
 
116
 
 
117
                [Test]
 
118
                public void TestConditionalExpression ()
 
119
                {
 
120
                        var input = @"
 
121
class TestClass
 
122
{
 
123
        void TestMethod ()
 
124
        {
 
125
                int a = true ? 1 : 0;
 
126
        }
 
127
}";
 
128
                        var output = @"
 
129
class TestClass
 
130
{
 
131
        void TestMethod ()
 
132
        {
 
133
                int a = 1;
 
134
        }
 
135
}";
 
136
                        Test<UnreachableCodeIssue> (input, 1, output);
 
137
                }
 
138
 
 
139
                [Test]
 
140
                public void TestInsideLambda ()
 
141
                {
 
142
                        var input = @"
 
143
class TestClass
 
144
{
 
145
        void TestMethod ()
 
146
        {
 
147
                System.Action action = () => {
 
148
                        return;
 
149
                        int a = 1;
 
150
                };
 
151
        }
 
152
}";
 
153
                        Test<UnreachableCodeIssue> (input, 1);
 
154
                }
 
155
 
 
156
                [Test]
 
157
                public void TestInsideAnonymousMethod ()
 
158
                {
 
159
                        var input = @"
 
160
class TestClass
 
161
{
 
162
        void TestMethod ()
 
163
        {
 
164
                System.Action action = delegate () {
 
165
                        return;
 
166
                        int a = 1;
 
167
                };
 
168
        }
 
169
}";
 
170
                        Test<UnreachableCodeIssue> (input, 1);
 
171
                }
 
172
 
 
173
                [Test]
 
174
                public void TestIgnoreLambdaBody ()
 
175
                {
 
176
                        var input = @"
 
177
class TestClass
 
178
{
 
179
        void TestMethod ()
 
180
        {
 
181
                return;
 
182
                System.Action action = () => {
 
183
                        return;
 
184
                        int a = 1;
 
185
                };
 
186
        }
 
187
}";
 
188
                        Test<UnreachableCodeIssue> (input, 1);
 
189
                }
 
190
 
 
191
                [Test]
 
192
                public void TestIgnoreAnonymousMethodBody ()
 
193
                {
 
194
                        var input = @"
 
195
class TestClass
 
196
{
 
197
        void TestMethod ()
 
198
        {
 
199
                return;
 
200
                System.Action action = delegate() {
 
201
                        return;
 
202
                        int a = 1;
 
203
                };
 
204
        }
 
205
}";
 
206
                        Test<UnreachableCodeIssue> (input, 1);
 
207
                }
 
208
 
 
209
                [Test]
 
210
                public void TestGroupMultipleStatements ()
 
211
                {
 
212
                        var input = @"
 
213
class TestClass
 
214
{
 
215
        void TestMethod ()
 
216
        {
 
217
                return;
 
218
                int a = 1;
 
219
                a++;
 
220
        }
 
221
}";
 
222
                        Test<UnreachableCodeIssue> (input, 1);
 
223
                }
 
224
 
 
225
                [Test]
 
226
                public void TestRemoveCode ()
 
227
                {
 
228
                        var input = @"
 
229
class TestClass
 
230
{
 
231
        void TestMethod ()
 
232
        {
 
233
                return;
 
234
                int a = 1;
 
235
                a++;
 
236
        }
 
237
}";
 
238
                        var output = @"
 
239
class TestClass
 
240
{
 
241
        void TestMethod ()
 
242
        {
 
243
                return;
 
244
        }
 
245
}";
 
246
                        Test<UnreachableCodeIssue> (input, output, 0);
 
247
                }
 
248
 
 
249
        //      [Ignore("Got broken due ast new line nodes")]
 
250
                [Test]
 
251
                public void TestCommentCode ()
 
252
                {
 
253
                        var input = @"
 
254
class TestClass
 
255
{
 
256
        void TestMethod ()
 
257
        {
 
258
                return;
 
259
                int a = 1;
 
260
                a++;
 
261
        }
 
262
}";
 
263
                        var output = @"
 
264
class TestClass
 
265
{
 
266
        void TestMethod ()
 
267
        {
 
268
                return;
 
269
/*
 
270
                int a = 1;
 
271
                a++;
 
272
*/
 
273
        }
 
274
}";
 
275
                        Test<UnreachableCodeIssue> (input, output, 1);
 
276
                }
 
277
 
 
278
                [Test]
 
279
                public void TestDefaultParameter ()
 
280
                {
 
281
                        var input = @"
 
282
using System;
 
283
 
 
284
namespace TestProjectForBug
 
285
{
 
286
        class MainClass
 
287
        {
 
288
                public static void CondMethod (bool cond = false)
 
289
                {
 
290
                        Console.WriteLine (cond ? ""true"" : ""false"");
 
291
                }
 
292
        }
 
293
}";
 
294
                        Test<UnreachableCodeIssue> (input, 0);
 
295
                }
 
296
        }
 
297
}