OLD | NEW |
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_class_member; | 5 library test.services.refactoring.rename_class_member; |
6 | 6 |
7 import 'package:analysis_server/src/protocol.dart'; | 7 import 'package:analysis_server/src/protocol.dart'; |
8 import 'package:analysis_server/src/services/correction/status.dart'; | 8 import 'package:analysis_server/src/services/correction/status.dart'; |
9 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 9 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
11 | 11 |
| 12 import '../../utils.dart'; |
12 import 'abstract_rename.dart'; | 13 import 'abstract_rename.dart'; |
13 | 14 |
14 main() { | 15 main() { |
15 groupSep = ' | '; | 16 initializeTestEnvironment(); |
16 defineReflectiveTests(RenameClassMemberTest); | 17 defineReflectiveTests(RenameClassMemberTest); |
17 } | 18 } |
18 | 19 |
19 @reflectiveTest | 20 @reflectiveTest |
20 class RenameClassMemberTest extends RenameRefactoringTest { | 21 class RenameClassMemberTest extends RenameRefactoringTest { |
21 test_checkFinalConditions_hasMember_MethodElement() async { | 22 test_checkFinalConditions_hasMember_MethodElement() async { |
22 indexTestUnit(''' | 23 indexTestUnit(''' |
23 class A { | 24 class A { |
24 test() {} | 25 test() {} |
25 newName() {} // existing | 26 newName() {} // existing |
26 } | 27 } |
27 '''); | 28 '''); |
28 createRenameRefactoringAtString('test() {}'); | 29 createRenameRefactoringAtString('test() {}'); |
29 // check status | 30 // check status |
30 refactoring.newName = 'newName'; | 31 refactoring.newName = 'newName'; |
31 RefactoringStatus status = await refactoring.checkFinalConditions(); | 32 RefactoringStatus status = await refactoring.checkFinalConditions(); |
32 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 33 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
33 expectedMessage: "Class 'A' already declares method with name 'newName'.
", | 34 expectedMessage: |
| 35 "Class 'A' already declares method with name 'newName'.", |
34 expectedContextSearch: 'newName() {} // existing'); | 36 expectedContextSearch: 'newName() {} // existing'); |
35 } | 37 } |
36 | 38 |
37 test_checkFinalConditions_OK_noShadow() async { | 39 test_checkFinalConditions_OK_noShadow() async { |
38 indexTestUnit(''' | 40 indexTestUnit(''' |
39 class A { | 41 class A { |
40 int newName; | 42 int newName; |
41 } | 43 } |
42 class B { | 44 class B { |
43 test() {} | 45 test() {} |
(...skipping 10 matching lines...) Expand all Loading... |
54 RefactoringStatus status = await refactoring.checkFinalConditions(); | 56 RefactoringStatus status = await refactoring.checkFinalConditions(); |
55 assertRefactoringStatusOK(status); | 57 assertRefactoringStatusOK(status); |
56 } | 58 } |
57 | 59 |
58 test_checkFinalConditions_publicToPrivate_usedInOtherLibrary() async { | 60 test_checkFinalConditions_publicToPrivate_usedInOtherLibrary() async { |
59 indexTestUnit(''' | 61 indexTestUnit(''' |
60 class A { | 62 class A { |
61 test() {} | 63 test() {} |
62 } | 64 } |
63 '''); | 65 '''); |
64 indexUnit('/lib.dart', ''' | 66 indexUnit( |
| 67 '/lib.dart', |
| 68 ''' |
65 library my.lib; | 69 library my.lib; |
66 import 'test.dart'; | 70 import 'test.dart'; |
67 | 71 |
68 main(A a) { | 72 main(A a) { |
69 a.test(); | 73 a.test(); |
70 } | 74 } |
71 '''); | 75 '''); |
72 createRenameRefactoringAtString('test() {}'); | 76 createRenameRefactoringAtString('test() {}'); |
73 // check status | 77 // check status |
74 refactoring.newName = '_newName'; | 78 refactoring.newName = '_newName'; |
(...skipping 10 matching lines...) Expand all Loading... |
85 var newName; | 89 var newName; |
86 test(); // marker | 90 test(); // marker |
87 } | 91 } |
88 } | 92 } |
89 '''); | 93 '''); |
90 createRenameRefactoringAtString('test() {}'); | 94 createRenameRefactoringAtString('test() {}'); |
91 // check status | 95 // check status |
92 refactoring.newName = 'newName'; | 96 refactoring.newName = 'newName'; |
93 RefactoringStatus status = await refactoring.checkFinalConditions(); | 97 RefactoringStatus status = await refactoring.checkFinalConditions(); |
94 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 98 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
95 expectedMessage: "Usage of renamed method will be shadowed by local vari
able 'newName'.", | 99 expectedMessage: |
| 100 "Usage of renamed method will be shadowed by local variable 'newName
'.", |
96 expectedContextSearch: 'test(); // marker'); | 101 expectedContextSearch: 'test(); // marker'); |
97 } | 102 } |
98 | 103 |
99 test_checkFinalConditions_shadowed_byLocal_inSubClass() async { | 104 test_checkFinalConditions_shadowed_byLocal_inSubClass() async { |
100 indexTestUnit(''' | 105 indexTestUnit(''' |
101 class A { | 106 class A { |
102 test() {} | 107 test() {} |
103 } | 108 } |
104 class B extends A { | 109 class B extends A { |
105 main() { | 110 main() { |
106 var newName; | 111 var newName; |
107 test(); // marker | 112 test(); // marker |
108 } | 113 } |
109 } | 114 } |
110 '''); | 115 '''); |
111 createRenameRefactoringAtString('test() {}'); | 116 createRenameRefactoringAtString('test() {}'); |
112 // check status | 117 // check status |
113 refactoring.newName = 'newName'; | 118 refactoring.newName = 'newName'; |
114 RefactoringStatus status = await refactoring.checkFinalConditions(); | 119 RefactoringStatus status = await refactoring.checkFinalConditions(); |
115 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 120 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
116 expectedMessage: "Usage of renamed method will be shadowed by local vari
able 'newName'.", | 121 expectedMessage: |
| 122 "Usage of renamed method will be shadowed by local variable 'newName
'.", |
117 expectedContextSearch: 'test(); // marker'); | 123 expectedContextSearch: 'test(); // marker'); |
118 } | 124 } |
119 | 125 |
120 test_checkFinalConditions_shadowed_byLocal_OK_qualifiedReference() async { | 126 test_checkFinalConditions_shadowed_byLocal_OK_qualifiedReference() async { |
121 indexTestUnit(''' | 127 indexTestUnit(''' |
122 class A { | 128 class A { |
123 test() {} | 129 test() {} |
124 main() { | 130 main() { |
125 var newName; | 131 var newName; |
126 this.test(); // marker | 132 this.test(); // marker |
(...skipping 30 matching lines...) Expand all Loading... |
157 main(newName) { | 163 main(newName) { |
158 test(); // marker | 164 test(); // marker |
159 } | 165 } |
160 } | 166 } |
161 '''); | 167 '''); |
162 createRenameRefactoringAtString('test() {}'); | 168 createRenameRefactoringAtString('test() {}'); |
163 // check status | 169 // check status |
164 refactoring.newName = 'newName'; | 170 refactoring.newName = 'newName'; |
165 RefactoringStatus status = await refactoring.checkFinalConditions(); | 171 RefactoringStatus status = await refactoring.checkFinalConditions(); |
166 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 172 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
167 expectedMessage: "Usage of renamed method will be shadowed by parameter
'newName'.", | 173 expectedMessage: |
| 174 "Usage of renamed method will be shadowed by parameter 'newName'.", |
168 expectedContextSearch: 'test(); // marker'); | 175 expectedContextSearch: 'test(); // marker'); |
169 } | 176 } |
170 | 177 |
171 test_checkFinalConditions_shadowed_inSubClass() async { | 178 test_checkFinalConditions_shadowed_inSubClass() async { |
172 indexTestUnit(''' | 179 indexTestUnit(''' |
173 class A { | 180 class A { |
174 newName() {} // marker | 181 newName() {} // marker |
175 } | 182 } |
176 class B extends A { | 183 class B extends A { |
177 test() {} | 184 test() {} |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 main() { | 229 main() { |
223 test(); | 230 test(); |
224 } | 231 } |
225 } | 232 } |
226 '''); | 233 '''); |
227 createRenameRefactoringAtString('test() {}'); | 234 createRenameRefactoringAtString('test() {}'); |
228 // check status | 235 // check status |
229 refactoring.newName = 'newName'; | 236 refactoring.newName = 'newName'; |
230 RefactoringStatus status = await refactoring.checkFinalConditions(); | 237 RefactoringStatus status = await refactoring.checkFinalConditions(); |
231 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 238 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
232 expectedMessage: "Renamed method will be shadowed by method 'B.newName'.
", | 239 expectedMessage: |
| 240 "Renamed method will be shadowed by method 'B.newName'.", |
233 expectedContextSearch: 'newName() {} // marker'); | 241 expectedContextSearch: 'newName() {} // marker'); |
234 } | 242 } |
235 | 243 |
236 test_checkInitialConditions_operator() async { | 244 test_checkInitialConditions_operator() async { |
237 indexTestUnit(''' | 245 indexTestUnit(''' |
238 class A { | 246 class A { |
239 operator -(other) => this; | 247 operator -(other) => this; |
240 } | 248 } |
241 '''); | 249 '''); |
242 createRenameRefactoringAtString('-(other)'); | 250 createRenameRefactoringAtString('-(other)'); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 expectedMessage: "Method name must not be null."); | 285 expectedMessage: "Method name must not be null."); |
278 // empty | 286 // empty |
279 refactoring.newName = ''; | 287 refactoring.newName = ''; |
280 assertRefactoringStatus( | 288 assertRefactoringStatus( |
281 refactoring.checkNewName(), RefactoringProblemSeverity.FATAL, | 289 refactoring.checkNewName(), RefactoringProblemSeverity.FATAL, |
282 expectedMessage: "Method name must not be empty."); | 290 expectedMessage: "Method name must not be empty."); |
283 // same | 291 // same |
284 refactoring.newName = 'test'; | 292 refactoring.newName = 'test'; |
285 assertRefactoringStatus( | 293 assertRefactoringStatus( |
286 refactoring.checkNewName(), RefactoringProblemSeverity.FATAL, | 294 refactoring.checkNewName(), RefactoringProblemSeverity.FATAL, |
287 expectedMessage: "The new name must be different than the current name."
); | 295 expectedMessage: |
| 296 "The new name must be different than the current name."); |
288 // OK | 297 // OK |
289 refactoring.newName = 'newName'; | 298 refactoring.newName = 'newName'; |
290 assertRefactoringStatusOK(refactoring.checkNewName()); | 299 assertRefactoringStatusOK(refactoring.checkNewName()); |
291 } | 300 } |
292 | 301 |
293 test_createChange_FieldElement() { | 302 test_createChange_FieldElement() { |
294 indexTestUnit(''' | 303 indexTestUnit(''' |
295 class A { | 304 class A { |
296 int test; // marker | 305 int test; // marker |
297 main() { | 306 main() { |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 main(var a) { | 561 main(var a) { |
553 a.newName(); // 1 | 562 a.newName(); // 1 |
554 new A().newName(); | 563 new A().newName(); |
555 a.newName(); // 2 | 564 a.newName(); // 2 |
556 } | 565 } |
557 '''); | 566 '''); |
558 assertPotentialEdits(['test(); // 1', 'test(); // 2']); | 567 assertPotentialEdits(['test(); // 1', 'test(); // 2']); |
559 } | 568 } |
560 | 569 |
561 test_createChange_MethodElement_potential_private_otherLibrary() async { | 570 test_createChange_MethodElement_potential_private_otherLibrary() async { |
562 indexUnit('/lib.dart', ''' | 571 indexUnit( |
| 572 '/lib.dart', |
| 573 ''' |
563 library lib; | 574 library lib; |
564 main(p) { | 575 main(p) { |
565 p._test(); | 576 p._test(); |
566 } | 577 } |
567 '''); | 578 '''); |
568 indexTestUnit(''' | 579 indexTestUnit(''' |
569 class A { | 580 class A { |
570 _test() {} | 581 _test() {} |
571 } | 582 } |
572 main(var a) { | 583 main(var a) { |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
719 // validate change | 730 // validate change |
720 return assertSuccessfulRefactoring(''' | 731 return assertSuccessfulRefactoring(''' |
721 class A<NewName> { | 732 class A<NewName> { |
722 NewName field; | 733 NewName field; |
723 List<NewName> items; | 734 List<NewName> items; |
724 NewName method(NewName p) => null; | 735 NewName method(NewName p) => null; |
725 } | 736 } |
726 '''); | 737 '''); |
727 } | 738 } |
728 } | 739 } |
OLD | NEW |