Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: pkg/analysis_server/test/services/refactoring/rename_local_test.dart

Issue 485083004: Make RefactoringStatus a collection of generated RefactoringProblems. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library test.services.refactoring.rename_local; 5 library test.services.refactoring.rename_local;
6 6
7 import 'package:analysis_server/src/services/correction/status.dart'; 7 import 'package:analysis_server/src/protocol2.dart';
8 import 'package:analysis_testing/reflective_tests.dart'; 8 import 'package:analysis_testing/reflective_tests.dart';
9 import 'package:unittest/unittest.dart'; 9 import 'package:unittest/unittest.dart';
10 10
11 import 'abstract_rename.dart'; 11 import 'abstract_rename.dart';
12 12
13 13
14 main() { 14 main() {
15 groupSep = ' | '; 15 groupSep = ' | ';
16 runReflectiveTests(RenameLocalTest); 16 runReflectiveTests(RenameLocalTest);
17 } 17 }
18 18
19 19
20 @ReflectiveTestCase() 20 @ReflectiveTestCase()
21 class RenameLocalTest extends RenameRefactoringTest { 21 class RenameLocalTest extends RenameRefactoringTest {
22 test_checkFinalConditions_hasLocalFunction_after() { 22 test_checkFinalConditions_hasLocalFunction_after() {
23 indexTestUnit(''' 23 indexTestUnit('''
24 main() { 24 main() {
25 int test = 0; 25 int test = 0;
26 newName() => 1; 26 newName() => 1;
27 } 27 }
28 '''); 28 ''');
29 createRenameRefactoringAtString('test = 0'); 29 createRenameRefactoringAtString('test = 0');
30 // check status 30 // check status
31 refactoring.newName = 'newName'; 31 refactoring.newName = 'newName';
32 return refactoring.checkFinalConditions().then((status) { 32 return refactoring.checkFinalConditions().then((status) {
33 assertRefactoringStatus( 33 assertRefactoringStatus(
34 status, 34 status,
35 RefactoringStatusSeverity.ERROR, 35 RefactoringProblemSeverity.ERROR,
36 expectedMessage: "Duplicate function 'newName'.", 36 expectedMessage: "Duplicate function 'newName'.",
37 expectedContextSearch: 'newName() => 1'); 37 expectedContextSearch: 'newName() => 1');
38 }); 38 });
39 } 39 }
40 40
41 test_checkFinalConditions_hasLocalFunction_before() { 41 test_checkFinalConditions_hasLocalFunction_before() {
42 indexTestUnit(''' 42 indexTestUnit('''
43 main() { 43 main() {
44 newName() => 1; 44 newName() => 1;
45 int test = 0; 45 int test = 0;
46 } 46 }
47 '''); 47 ''');
48 createRenameRefactoringAtString('test = 0'); 48 createRenameRefactoringAtString('test = 0');
49 // check status 49 // check status
50 refactoring.newName = 'newName'; 50 refactoring.newName = 'newName';
51 return refactoring.checkFinalConditions().then((status) { 51 return refactoring.checkFinalConditions().then((status) {
52 assertRefactoringStatus( 52 assertRefactoringStatus(
53 status, 53 status,
54 RefactoringStatusSeverity.ERROR, 54 RefactoringProblemSeverity.ERROR,
55 expectedMessage: "Duplicate function 'newName'."); 55 expectedMessage: "Duplicate function 'newName'.");
56 }); 56 });
57 } 57 }
58 58
59 test_checkFinalConditions_hasLocalVariable_after() { 59 test_checkFinalConditions_hasLocalVariable_after() {
60 indexTestUnit(''' 60 indexTestUnit('''
61 main() { 61 main() {
62 int test = 0; 62 int test = 0;
63 var newName = 1; 63 var newName = 1;
64 } 64 }
65 '''); 65 ''');
66 createRenameRefactoringAtString('test = 0'); 66 createRenameRefactoringAtString('test = 0');
67 // check status 67 // check status
68 refactoring.newName = 'newName'; 68 refactoring.newName = 'newName';
69 return refactoring.checkFinalConditions().then((status) { 69 return refactoring.checkFinalConditions().then((status) {
70 assertRefactoringStatus( 70 assertRefactoringStatus(
71 status, 71 status,
72 RefactoringStatusSeverity.ERROR, 72 RefactoringProblemSeverity.ERROR,
73 expectedMessage: "Duplicate local variable 'newName'.", 73 expectedMessage: "Duplicate local variable 'newName'.",
74 expectedContextSearch: 'newName = 1;'); 74 expectedContextSearch: 'newName = 1;');
75 }); 75 });
76 } 76 }
77 77
78 test_checkFinalConditions_hasLocalVariable_before() { 78 test_checkFinalConditions_hasLocalVariable_before() {
79 indexTestUnit(''' 79 indexTestUnit('''
80 main() { 80 main() {
81 var newName = 1; 81 var newName = 1;
82 int test = 0; 82 int test = 0;
83 } 83 }
84 '''); 84 ''');
85 createRenameRefactoringAtString('test = 0'); 85 createRenameRefactoringAtString('test = 0');
86 // check status 86 // check status
87 refactoring.newName = 'newName'; 87 refactoring.newName = 'newName';
88 return refactoring.checkFinalConditions().then((status) { 88 return refactoring.checkFinalConditions().then((status) {
89 assertRefactoringStatus( 89 assertRefactoringStatus(
90 status, 90 status,
91 RefactoringStatusSeverity.ERROR, 91 RefactoringProblemSeverity.ERROR,
92 expectedMessage: "Duplicate local variable 'newName'.", 92 expectedMessage: "Duplicate local variable 'newName'.",
93 expectedContextSearch: 'newName = 1;'); 93 expectedContextSearch: 'newName = 1;');
94 }); 94 });
95 } 95 }
96 96
97 test_checkFinalConditions_hasLocalVariable_otherBlock() { 97 test_checkFinalConditions_hasLocalVariable_otherBlock() {
98 indexTestUnit(''' 98 indexTestUnit('''
99 main() { 99 main() {
100 { 100 {
101 var newName = 1; 101 var newName = 1;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 print(newName); 135 print(newName);
136 } 136 }
137 } 137 }
138 '''); 138 ''');
139 createRenameRefactoringAtString('test = 0'); 139 createRenameRefactoringAtString('test = 0');
140 // check status 140 // check status
141 refactoring.newName = 'newName'; 141 refactoring.newName = 'newName';
142 return refactoring.checkFinalConditions().then((status) { 142 return refactoring.checkFinalConditions().then((status) {
143 assertRefactoringStatus( 143 assertRefactoringStatus(
144 status, 144 status,
145 RefactoringStatusSeverity.ERROR, 145 RefactoringProblemSeverity.ERROR,
146 expectedMessage: 'Usage of field "A.newName" declared in "test.dart" ' 146 expectedMessage: 'Usage of field "A.newName" declared in "test.dart" '
147 'will be shadowed by renamed local variable.', 147 'will be shadowed by renamed local variable.',
148 expectedContextSearch: 'newName);'); 148 expectedContextSearch: 'newName);');
149 }); 149 });
150 } 150 }
151 151
152 test_checkFinalConditions_shadows_classMemberOK_qualifiedReference() { 152 test_checkFinalConditions_shadows_classMemberOK_qualifiedReference() {
153 indexTestUnit(''' 153 indexTestUnit('''
154 class A { 154 class A {
155 var newName = 1; 155 var newName = 1;
(...skipping 16 matching lines...) Expand all
172 var test = 0; 172 var test = 0;
173 newName(); // ref 173 newName(); // ref
174 } 174 }
175 '''); 175 ''');
176 createRenameRefactoringAtString('test = 0'); 176 createRenameRefactoringAtString('test = 0');
177 // check status 177 // check status
178 refactoring.newName = 'newName'; 178 refactoring.newName = 'newName';
179 return refactoring.checkFinalConditions().then((status) { 179 return refactoring.checkFinalConditions().then((status) {
180 assertRefactoringStatus( 180 assertRefactoringStatus(
181 status, 181 status,
182 RefactoringStatusSeverity.ERROR, 182 RefactoringProblemSeverity.ERROR,
183 expectedContextSearch: 'newName(); // ref'); 183 expectedContextSearch: 'newName(); // ref');
184 }); 184 });
185 } 185 }
186 186
187 test_checkNewName_FunctionElement() { 187 test_checkNewName_FunctionElement() {
188 indexTestUnit(''' 188 indexTestUnit('''
189 main() { 189 main() {
190 int test() {} 190 int test() {}
191 } 191 }
192 '''); 192 ''');
193 createRenameRefactoringAtString('test() {}'); 193 createRenameRefactoringAtString('test() {}');
194 // null 194 // null
195 refactoring.newName = null; 195 refactoring.newName = null;
196 assertRefactoringStatus( 196 assertRefactoringStatus(
197 refactoring.checkNewName(), 197 refactoring.checkNewName(),
198 RefactoringStatusSeverity.ERROR, 198 RefactoringProblemSeverity.ERROR,
199 expectedMessage: "Function name must not be null."); 199 expectedMessage: "Function name must not be null.");
200 // OK 200 // OK
201 refactoring.newName = 'newName'; 201 refactoring.newName = 'newName';
202 assertRefactoringStatusOK(refactoring.checkNewName()); 202 assertRefactoringStatusOK(refactoring.checkNewName());
203 } 203 }
204 204
205 test_checkNewName_LocalVariableElement() { 205 test_checkNewName_LocalVariableElement() {
206 indexTestUnit(''' 206 indexTestUnit('''
207 main() { 207 main() {
208 int test = 0; 208 int test = 0;
209 } 209 }
210 '''); 210 ''');
211 createRenameRefactoringAtString('test = 0;'); 211 createRenameRefactoringAtString('test = 0;');
212 // null 212 // null
213 refactoring.newName = null; 213 refactoring.newName = null;
214 assertRefactoringStatus( 214 assertRefactoringStatus(
215 refactoring.checkNewName(), 215 refactoring.checkNewName(),
216 RefactoringStatusSeverity.ERROR, 216 RefactoringProblemSeverity.ERROR,
217 expectedMessage: "Variable name must not be null."); 217 expectedMessage: "Variable name must not be null.");
218 // empty 218 // empty
219 refactoring.newName = ''; 219 refactoring.newName = '';
220 assertRefactoringStatus( 220 assertRefactoringStatus(
221 refactoring.checkNewName(), 221 refactoring.checkNewName(),
222 RefactoringStatusSeverity.ERROR, 222 RefactoringProblemSeverity.ERROR,
223 expectedMessage: "Variable name must not be empty."); 223 expectedMessage: "Variable name must not be empty.");
224 // OK 224 // OK
225 refactoring.newName = 'newName'; 225 refactoring.newName = 'newName';
226 assertRefactoringStatusOK(refactoring.checkNewName()); 226 assertRefactoringStatusOK(refactoring.checkNewName());
227 } 227 }
228 228
229 test_checkNewName_LocalVariableElement_const() { 229 test_checkNewName_LocalVariableElement_const() {
230 indexTestUnit(''' 230 indexTestUnit('''
231 main() { 231 main() {
232 const int TEST = 0; 232 const int TEST = 0;
233 } 233 }
234 '''); 234 ''');
235 createRenameRefactoringAtString('TEST = 0;'); 235 createRenameRefactoringAtString('TEST = 0;');
236 // null 236 // null
237 refactoring.newName = null; 237 refactoring.newName = null;
238 assertRefactoringStatus( 238 assertRefactoringStatus(
239 refactoring.checkNewName(), 239 refactoring.checkNewName(),
240 RefactoringStatusSeverity.ERROR, 240 RefactoringProblemSeverity.ERROR,
241 expectedMessage: "Constant name must not be null."); 241 expectedMessage: "Constant name must not be null.");
242 // empty 242 // empty
243 refactoring.newName = ''; 243 refactoring.newName = '';
244 assertRefactoringStatus( 244 assertRefactoringStatus(
245 refactoring.checkNewName(), 245 refactoring.checkNewName(),
246 RefactoringStatusSeverity.ERROR, 246 RefactoringProblemSeverity.ERROR,
247 expectedMessage: "Constant name must not be empty."); 247 expectedMessage: "Constant name must not be empty.");
248 // same 248 // same
249 refactoring.newName = 'TEST'; 249 refactoring.newName = 'TEST';
250 assertRefactoringStatus( 250 assertRefactoringStatus(
251 refactoring.checkNewName(), 251 refactoring.checkNewName(),
252 RefactoringStatusSeverity.FATAL, 252 RefactoringProblemSeverity.FATAL,
253 expectedMessage: "The new name must be different than the current name." ); 253 expectedMessage: "The new name must be different than the current name." );
254 // OK 254 // OK
255 refactoring.newName = 'NEW_NAME'; 255 refactoring.newName = 'NEW_NAME';
256 assertRefactoringStatusOK(refactoring.checkNewName()); 256 assertRefactoringStatusOK(refactoring.checkNewName());
257 } 257 }
258 258
259 test_checkNewName_ParameterElement() { 259 test_checkNewName_ParameterElement() {
260 indexTestUnit(''' 260 indexTestUnit('''
261 main(test) { 261 main(test) {
262 } 262 }
263 '''); 263 ''');
264 createRenameRefactoringAtString('test) {'); 264 createRenameRefactoringAtString('test) {');
265 // null 265 // null
266 refactoring.newName = null; 266 refactoring.newName = null;
267 assertRefactoringStatus( 267 assertRefactoringStatus(
268 refactoring.checkNewName(), 268 refactoring.checkNewName(),
269 RefactoringStatusSeverity.ERROR, 269 RefactoringProblemSeverity.ERROR,
270 expectedMessage: "Parameter name must not be null."); 270 expectedMessage: "Parameter name must not be null.");
271 // OK 271 // OK
272 refactoring.newName = 'newName'; 272 refactoring.newName = 'newName';
273 assertRefactoringStatusOK(refactoring.checkNewName()); 273 assertRefactoringStatusOK(refactoring.checkNewName());
274 } 274 }
275 275
276 test_createChange_localFunction() { 276 test_createChange_localFunction() {
277 indexTestUnit(''' 277 indexTestUnit('''
278 main() { 278 main() {
279 int test() => 0; 279 int test() => 0;
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 main() { 463 main() {
464 int test = 0; 464 int test = 0;
465 } 465 }
466 '''); 466 ''');
467 // configure refactoring 467 // configure refactoring
468 createRenameRefactoringAtString('test = 0'); 468 createRenameRefactoringAtString('test = 0');
469 // old name 469 // old name
470 expect(refactoring.oldName, 'test'); 470 expect(refactoring.oldName, 'test');
471 } 471 }
472 } 472 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698