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

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.Tests/CSharp/CodeIssues/AssignmentMadeToSameVariableIssueTests.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
// AssignmentMadeToSameVariableIssueTests.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 AssignmentMadeToSameVariableIssueTests : InspectionActionTestBase
 
34
        {
 
35
                [Test]
 
36
                public void TestVariable ()
 
37
                {
 
38
                        var input = @"
 
39
class TestClass
 
40
{
 
41
        void TestMethod ()
 
42
        {
 
43
                int a = 0;
 
44
                a = a;
 
45
        }
 
46
}";
 
47
                        var output = @"
 
48
class TestClass
 
49
{
 
50
        void TestMethod ()
 
51
        {
 
52
                int a = 0;
 
53
        }
 
54
}";
 
55
                        Test<AssignmentMadeToSameVariableIssue> (input, 1, output);
 
56
                }
 
57
 
 
58
                [Test]
 
59
                public void TestParameter ()
 
60
                {
 
61
                        var input = @"
 
62
class TestClass
 
63
{
 
64
        void TestMethod (int a)
 
65
        {
 
66
                a = a;
 
67
        }
 
68
}";
 
69
                        var output = @"
 
70
class TestClass
 
71
{
 
72
        void TestMethod (int a)
 
73
        {
 
74
        }
 
75
}";
 
76
                        Test<AssignmentMadeToSameVariableIssue> (input, 1, output);
 
77
                }
 
78
 
 
79
                [Test]
 
80
                public void TestField ()
 
81
                {
 
82
                        var input = @"
 
83
class TestClass
 
84
{
 
85
        int a;
 
86
        void TestMethod ()
 
87
        {
 
88
                a = a;
 
89
                this.a = this.a;
 
90
                this.a = a;
 
91
        }
 
92
}";
 
93
                        var output = @"
 
94
class TestClass
 
95
{
 
96
        int a;
 
97
        void TestMethod ()
 
98
        {
 
99
        }
 
100
}";
 
101
                        Test<AssignmentMadeToSameVariableIssue> (input, 3, output);
 
102
                }
 
103
 
 
104
                [Test]
 
105
                public void TestFix ()
 
106
                {
 
107
                        var input = @"
 
108
class TestClass
 
109
{
 
110
        void Test (int i) { }
 
111
        void TestMethod ()
 
112
        {
 
113
                int a = 0;
 
114
                a = a;
 
115
                Test (a = a);
 
116
        }
 
117
}";
 
118
                        var output = @"
 
119
class TestClass
 
120
{
 
121
        void Test (int i) { }
 
122
        void TestMethod ()
 
123
        {
 
124
                int a = 0;
 
125
                Test (a);
 
126
        }
 
127
}";
 
128
                        Test<AssignmentMadeToSameVariableIssue> (input, 2, output);
 
129
                }
 
130
                
 
131
                [Test]
 
132
                public void TestNoIssue ()
 
133
                {
 
134
                        var input = @"
 
135
class TestClass
 
136
{
 
137
        int a;
 
138
        int b;
 
139
 
 
140
        public int Prop { get; set; }
 
141
 
 
142
        void TestMethod (int a)
 
143
        {
 
144
                a = b;
 
145
                this.a = b;
 
146
                this.a = a;
 
147
                Prop = Prop;
 
148
        }
 
149
}";
 
150
                        Test<AssignmentMadeToSameVariableIssue> (input, 0);
 
151
                }
 
152
                
 
153
                [Test]
 
154
                public void IgnoresAssignmentWithDifferentRootObjects ()
 
155
                {
 
156
                        var input = @"
 
157
class TestClass
 
158
{
 
159
        int a;
 
160
 
 
161
        void TestMethod (TestClass tc)
 
162
        {
 
163
                a = tc.a;
 
164
        }
 
165
}";
 
166
                        Test<AssignmentMadeToSameVariableIssue> (input, 0);
 
167
                }
 
168
                
 
169
                [Test]
 
170
                public void NestedFieldAccess ()
 
171
                {
 
172
                        var input = @"
 
173
class TestClass
 
174
{
 
175
        int a;
 
176
 
 
177
        TestClass nested;
 
178
 
 
179
        void TestMethod ()
 
180
        {
 
181
                nested.nested.a = nested.nested.a;
 
182
        }
 
183
}";
 
184
                        var output = @"
 
185
class TestClass
 
186
{
 
187
        int a;
 
188
 
 
189
        TestClass nested;
 
190
 
 
191
        void TestMethod ()
 
192
        {
 
193
        }
 
194
}";
 
195
                        Test<AssignmentMadeToSameVariableIssue> (input, 1, output);
 
196
                }
 
197
                
 
198
                [Test]
 
199
                public void NestedPropertyAccess ()
 
200
                {
 
201
                        var input = @"
 
202
class TestClass
 
203
{
 
204
        int a;
 
205
 
 
206
        TestClass nested { get; set; }
 
207
 
 
208
        void TestMethod ()
 
209
        {
 
210
                nested.nested.a = nested.nested.a;
 
211
        }
 
212
}";
 
213
                        Test<AssignmentMadeToSameVariableIssue> (input, 0);
 
214
                }
 
215
                
 
216
                [Test]
 
217
                public void TestNoIssueWithCompoundOperator ()
 
218
                {
 
219
                        var input = @"
 
220
class TestClass
 
221
{
 
222
        void TestMethod (int a)
 
223
        {
 
224
                a += a;
 
225
        }
 
226
}";
 
227
                        Test<AssignmentMadeToSameVariableIssue> (input, 0);
 
228
                }
 
229
        }
 
230
}