2
// RedundantAssignmentIssueTests.cs
5
// Mansheng Yang <lightyang0@gmail.com>
7
// Copyright (c) 2012 Mansheng Yang <lightyang0@gmail.com>
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:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
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
27
using ICSharpCode.NRefactory.CSharp.Refactoring;
28
using NUnit.Framework;
30
namespace ICSharpCode.NRefactory.CSharp.CodeIssues
33
public class RedundantAssignmentIssueTests : InspectionActionTestBase
36
public void TestVariableInitializerNotUsed()
53
Test<RedundantAssignmentIssue>(input, 1, output);
57
public void TestVariableInitializerNotUsedVar()
74
Test<RedundantAssignmentIssue>(input, 1, output);
78
public void TestVariableAssignmentNotUsed()
101
Test<RedundantAssignmentIssue>(input, 1, output);
105
public void TestParameterAssignmentNotUsed()
110
int TestMethod (int i)
120
int TestMethod (int i)
126
Test<RedundantAssignmentIssue>(input, 1, output);
130
public void TestAssignmentInExpression()
135
int TestMethod (int i)
144
int TestMethod (int i)
150
Test<RedundantAssignmentIssue>(input, 1, output);
154
public void TestOutArgument()
159
void Test (out int i)
173
void Test (out int i)
184
Test<RedundantAssignmentIssue>(input, 1, output);
188
public void TestOutArgument2()
193
void Test (out int i)
205
Test<RedundantAssignmentIssue>(input, 0);
209
public void TestRefArgument()
214
void Test (ref int i)
219
Test<RedundantAssignmentIssue>(input, 0);
223
public void TestAssignmentOperator()
235
Test<RedundantAssignmentIssue>(input, 0);
244
int TestMethod (int j)
254
Test<RedundantAssignmentIssue>(input, 0);
258
public void TestConditionalExpression()
263
int TestMethod (int j)
266
return j > 0 ? i : 0;
269
Test<RedundantAssignmentIssue>(input, 0);
273
public void TestLoop()
281
for (int i = 0; i < 10; i++) {
291
Test<RedundantAssignmentIssue>(input, 0);
295
public void TestForeach()
300
void TestMethod (int[] array)
302
foreach (int j in array) {
304
foreach (int k in array)
305
foreach (int i in array)
311
Test<RedundantAssignmentIssue>(input, 0);
315
public void TestAssignmentInTryCatch()
317
var input = @"using System;
322
var a = new TestClass ();
325
} catch (Exception) {
332
Test<RedundantAssignmentIssue>(input, 0);
336
public void TestAssignmentInTryCatchFinally()
343
var a = new TestClass ();
353
Test<RedundantAssignmentIssue>(input, 0);
357
public void TestAssignmentInCatch()
359
var input = @"using System;
362
void Test(TestClass a) { }
366
var a = new TestClass ();
368
} catch (Exception) {
374
Test<RedundantAssignmentIssue>(input, 0);
378
public void TestAssignmentBeforeTry()
380
var input = @"using System;
383
void Test(TestClass a) { }
389
a = new TestClass ();
390
} catch (Exception) {
395
Test<RedundantAssignmentIssue>(input, 0);
399
public void TestAssignmentInUsing()
401
var input = @"using System;
406
using (var tc = new TestClass ()) {
411
Test<RedundantAssignmentIssue>(input, 0);
415
public void TestAssignmentWithFunction()
417
var input = @"using System;
420
TestClass Func () { return null; }
426
var output = @"using System;
429
TestClass Func () { return null; }
435
Test<RedundantAssignmentIssue>(input, output);
439
public void TestAssignmentWithFunctionUsedLater()
441
var input = @"using System;
444
TestClass Func () { return null; }
451
var output = @"using System;
454
TestClass Func () { return null; }
462
Test<RedundantAssignmentIssue>(input, 2, output, 0);
b'\\ No newline at end of file'