| 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_unit_member; | 5 library test.services.refactoring.rename_unit_member; |
| 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(RenameUnitMemberTest); | 16 runReflectiveTests(RenameUnitMemberTest); |
| 17 } | 17 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 43 indexTestUnit(''' | 43 indexTestUnit(''' |
| 44 class Test {} | 44 class Test {} |
| 45 class NewName {} // existing | 45 class NewName {} // existing |
| 46 '''); | 46 '''); |
| 47 createRenameRefactoringAtString('Test {}'); | 47 createRenameRefactoringAtString('Test {}'); |
| 48 // check status | 48 // check status |
| 49 refactoring.newName = 'NewName'; | 49 refactoring.newName = 'NewName'; |
| 50 return refactoring.checkFinalConditions().then((status) { | 50 return refactoring.checkFinalConditions().then((status) { |
| 51 assertRefactoringStatus( | 51 assertRefactoringStatus( |
| 52 status, | 52 status, |
| 53 RefactoringStatusSeverity.ERROR, | 53 RefactoringProblemSeverity.ERROR, |
| 54 expectedMessage: "Library already declares class with name 'NewName'."
, | 54 expectedMessage: "Library already declares class with name 'NewName'."
, |
| 55 expectedContextSearch: 'NewName {} // existing'); | 55 expectedContextSearch: 'NewName {} // existing'); |
| 56 }); | 56 }); |
| 57 } | 57 } |
| 58 | 58 |
| 59 test_checkFinalConditions_hasTopLevel_FunctionTypeAliasElement() { | 59 test_checkFinalConditions_hasTopLevel_FunctionTypeAliasElement() { |
| 60 indexTestUnit(''' | 60 indexTestUnit(''' |
| 61 class Test {} | 61 class Test {} |
| 62 typedef NewName(); // existing | 62 typedef NewName(); // existing |
| 63 '''); | 63 '''); |
| 64 createRenameRefactoringAtString('Test {}'); | 64 createRenameRefactoringAtString('Test {}'); |
| 65 // check status | 65 // check status |
| 66 refactoring.newName = 'NewName'; | 66 refactoring.newName = 'NewName'; |
| 67 return refactoring.checkFinalConditions().then((status) { | 67 return refactoring.checkFinalConditions().then((status) { |
| 68 assertRefactoringStatus( | 68 assertRefactoringStatus( |
| 69 status, | 69 status, |
| 70 RefactoringStatusSeverity.ERROR, | 70 RefactoringProblemSeverity.ERROR, |
| 71 expectedMessage: | 71 expectedMessage: |
| 72 "Library already declares function type alias with name 'NewName'.
", | 72 "Library already declares function type alias with name 'NewName'.
", |
| 73 expectedContextSearch: 'NewName(); // existing'); | 73 expectedContextSearch: 'NewName(); // existing'); |
| 74 }); | 74 }); |
| 75 } | 75 } |
| 76 | 76 |
| 77 test_checkFinalConditions_shadowedBy_MethodElement() { | 77 test_checkFinalConditions_shadowedBy_MethodElement() { |
| 78 indexTestUnit(''' | 78 indexTestUnit(''' |
| 79 class Test {} | 79 class Test {} |
| 80 class A { | 80 class A { |
| 81 void NewName() {} | 81 void NewName() {} |
| 82 main() { | 82 main() { |
| 83 new Test(); | 83 new Test(); |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 '''); | 86 '''); |
| 87 createRenameRefactoringAtString('Test {}'); | 87 createRenameRefactoringAtString('Test {}'); |
| 88 // check status | 88 // check status |
| 89 refactoring.newName = 'NewName'; | 89 refactoring.newName = 'NewName'; |
| 90 return refactoring.checkFinalConditions().then((status) { | 90 return refactoring.checkFinalConditions().then((status) { |
| 91 assertRefactoringStatus( | 91 assertRefactoringStatus( |
| 92 status, | 92 status, |
| 93 RefactoringStatusSeverity.ERROR, | 93 RefactoringProblemSeverity.ERROR, |
| 94 expectedMessage: | 94 expectedMessage: |
| 95 "Reference to renamed class will be shadowed by method 'A.NewName'
.", | 95 "Reference to renamed class will be shadowed by method 'A.NewName'
.", |
| 96 expectedContextSearch: 'NewName() {}'); | 96 expectedContextSearch: 'NewName() {}'); |
| 97 }); | 97 }); |
| 98 } | 98 } |
| 99 | 99 |
| 100 test_checkFinalConditions_shadowsInSubClass_MethodElement() { | 100 test_checkFinalConditions_shadowsInSubClass_MethodElement() { |
| 101 indexTestUnit(''' | 101 indexTestUnit(''' |
| 102 class Test {} | 102 class Test {} |
| 103 class A { | 103 class A { |
| 104 NewName() {} | 104 NewName() {} |
| 105 } | 105 } |
| 106 class B extends A { | 106 class B extends A { |
| 107 main() { | 107 main() { |
| 108 NewName(); // super-ref | 108 NewName(); // super-ref |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 '''); | 111 '''); |
| 112 createRenameRefactoringAtString('Test {}'); | 112 createRenameRefactoringAtString('Test {}'); |
| 113 // check status | 113 // check status |
| 114 refactoring.newName = 'NewName'; | 114 refactoring.newName = 'NewName'; |
| 115 return refactoring.checkFinalConditions().then((status) { | 115 return refactoring.checkFinalConditions().then((status) { |
| 116 assertRefactoringStatus( | 116 assertRefactoringStatus( |
| 117 status, | 117 status, |
| 118 RefactoringStatusSeverity.ERROR, | 118 RefactoringProblemSeverity.ERROR, |
| 119 expectedMessage: "Renamed class will shadow method 'A.NewName'.", | 119 expectedMessage: "Renamed class will shadow method 'A.NewName'.", |
| 120 expectedContextSearch: 'NewName(); // super-ref'); | 120 expectedContextSearch: 'NewName(); // super-ref'); |
| 121 }); | 121 }); |
| 122 } | 122 } |
| 123 | 123 |
| 124 test_checkFinalConditions_shadowsInSubClass_importedLib() { | 124 test_checkFinalConditions_shadowsInSubClass_importedLib() { |
| 125 indexTestUnit(''' | 125 indexTestUnit(''' |
| 126 class Test {} | 126 class Test {} |
| 127 '''); | 127 '''); |
| 128 indexUnit('/lib.dart', ''' | 128 indexUnit('/lib.dart', ''' |
| 129 library my.lib; | 129 library my.lib; |
| 130 import 'test.dart'; | 130 import 'test.dart'; |
| 131 class A { | 131 class A { |
| 132 NewName() {} | 132 NewName() {} |
| 133 } | 133 } |
| 134 class B extends A { | 134 class B extends A { |
| 135 main() { | 135 main() { |
| 136 NewName(); // super-ref | 136 NewName(); // super-ref |
| 137 }", | 137 }", |
| 138 } | 138 } |
| 139 '''); | 139 '''); |
| 140 createRenameRefactoringAtString('Test {}'); | 140 createRenameRefactoringAtString('Test {}'); |
| 141 // check status | 141 // check status |
| 142 refactoring.newName = 'NewName'; | 142 refactoring.newName = 'NewName'; |
| 143 return refactoring.checkFinalConditions().then((status) { | 143 return refactoring.checkFinalConditions().then((status) { |
| 144 assertRefactoringStatus( | 144 assertRefactoringStatus( |
| 145 status, | 145 status, |
| 146 RefactoringStatusSeverity.ERROR, | 146 RefactoringProblemSeverity.ERROR, |
| 147 expectedMessage: "Renamed class will shadow method 'A.NewName'."); | 147 expectedMessage: "Renamed class will shadow method 'A.NewName'."); |
| 148 }); | 148 }); |
| 149 } | 149 } |
| 150 | 150 |
| 151 test_checkFinalConditions_shadowsInSubClass_importedLib_hideCombinator() { | 151 test_checkFinalConditions_shadowsInSubClass_importedLib_hideCombinator() { |
| 152 indexTestUnit(''' | 152 indexTestUnit(''' |
| 153 class Test {} | 153 class Test {} |
| 154 '''); | 154 '''); |
| 155 indexUnit('/lib.dart', ''' | 155 indexUnit('/lib.dart', ''' |
| 156 library my.lib; | 156 library my.lib; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 217 |
| 218 test_checkNewName_ClassElement() { | 218 test_checkNewName_ClassElement() { |
| 219 indexTestUnit(''' | 219 indexTestUnit(''' |
| 220 class Test {} | 220 class Test {} |
| 221 '''); | 221 '''); |
| 222 createRenameRefactoringAtString('Test {}'); | 222 createRenameRefactoringAtString('Test {}'); |
| 223 // null | 223 // null |
| 224 refactoring.newName = null; | 224 refactoring.newName = null; |
| 225 assertRefactoringStatus( | 225 assertRefactoringStatus( |
| 226 refactoring.checkNewName(), | 226 refactoring.checkNewName(), |
| 227 RefactoringStatusSeverity.ERROR, | 227 RefactoringProblemSeverity.ERROR, |
| 228 expectedMessage: "Class name must not be null."); | 228 expectedMessage: "Class name must not be null."); |
| 229 // empty | 229 // empty |
| 230 refactoring.newName = ''; | 230 refactoring.newName = ''; |
| 231 assertRefactoringStatus( | 231 assertRefactoringStatus( |
| 232 refactoring.checkNewName(), | 232 refactoring.checkNewName(), |
| 233 RefactoringStatusSeverity.ERROR, | 233 RefactoringProblemSeverity.ERROR, |
| 234 expectedMessage: "Class name must not be empty."); | 234 expectedMessage: "Class name must not be empty."); |
| 235 // same | 235 // same |
| 236 refactoring.newName = 'Test'; | 236 refactoring.newName = 'Test'; |
| 237 assertRefactoringStatus( | 237 assertRefactoringStatus( |
| 238 refactoring.checkNewName(), | 238 refactoring.checkNewName(), |
| 239 RefactoringStatusSeverity.FATAL, | 239 RefactoringProblemSeverity.FATAL, |
| 240 expectedMessage: "The new name must be different than the current name."
); | 240 expectedMessage: "The new name must be different than the current name."
); |
| 241 // OK | 241 // OK |
| 242 refactoring.newName = 'NewName'; | 242 refactoring.newName = 'NewName'; |
| 243 assertRefactoringStatusOK(refactoring.checkNewName()); | 243 assertRefactoringStatusOK(refactoring.checkNewName()); |
| 244 } | 244 } |
| 245 | 245 |
| 246 test_checkNewName_FunctionElement() { | 246 test_checkNewName_FunctionElement() { |
| 247 indexTestUnit(''' | 247 indexTestUnit(''' |
| 248 test() {} | 248 test() {} |
| 249 '''); | 249 '''); |
| 250 createRenameRefactoringAtString('test() {}'); | 250 createRenameRefactoringAtString('test() {}'); |
| 251 // null | 251 // null |
| 252 refactoring.newName = null; | 252 refactoring.newName = null; |
| 253 assertRefactoringStatus( | 253 assertRefactoringStatus( |
| 254 refactoring.checkNewName(), | 254 refactoring.checkNewName(), |
| 255 RefactoringStatusSeverity.ERROR, | 255 RefactoringProblemSeverity.ERROR, |
| 256 expectedMessage: "Function name must not be null."); | 256 expectedMessage: "Function name must not be null."); |
| 257 // empty | 257 // empty |
| 258 refactoring.newName = ''; | 258 refactoring.newName = ''; |
| 259 assertRefactoringStatus( | 259 assertRefactoringStatus( |
| 260 refactoring.checkNewName(), | 260 refactoring.checkNewName(), |
| 261 RefactoringStatusSeverity.ERROR, | 261 RefactoringProblemSeverity.ERROR, |
| 262 expectedMessage: "Function name must not be empty."); | 262 expectedMessage: "Function name must not be empty."); |
| 263 // OK | 263 // OK |
| 264 refactoring.newName = 'newName'; | 264 refactoring.newName = 'newName'; |
| 265 assertRefactoringStatusOK(refactoring.checkNewName()); | 265 assertRefactoringStatusOK(refactoring.checkNewName()); |
| 266 } | 266 } |
| 267 | 267 |
| 268 test_checkNewName_FunctionTypeAliasElement() { | 268 test_checkNewName_FunctionTypeAliasElement() { |
| 269 indexTestUnit(''' | 269 indexTestUnit(''' |
| 270 typedef Test(); | 270 typedef Test(); |
| 271 '''); | 271 '''); |
| 272 createRenameRefactoringAtString('Test();'); | 272 createRenameRefactoringAtString('Test();'); |
| 273 // null | 273 // null |
| 274 refactoring.newName = null; | 274 refactoring.newName = null; |
| 275 assertRefactoringStatus( | 275 assertRefactoringStatus( |
| 276 refactoring.checkNewName(), | 276 refactoring.checkNewName(), |
| 277 RefactoringStatusSeverity.ERROR, | 277 RefactoringProblemSeverity.ERROR, |
| 278 expectedMessage: "Function type alias name must not be null."); | 278 expectedMessage: "Function type alias name must not be null."); |
| 279 // OK | 279 // OK |
| 280 refactoring.newName = 'NewName'; | 280 refactoring.newName = 'NewName'; |
| 281 assertRefactoringStatusOK(refactoring.checkNewName()); | 281 assertRefactoringStatusOK(refactoring.checkNewName()); |
| 282 } | 282 } |
| 283 | 283 |
| 284 test_checkNewName_TopLevelVariableElement() { | 284 test_checkNewName_TopLevelVariableElement() { |
| 285 indexTestUnit(''' | 285 indexTestUnit(''' |
| 286 var test; | 286 var test; |
| 287 '''); | 287 '''); |
| 288 createRenameRefactoringAtString('test;'); | 288 createRenameRefactoringAtString('test;'); |
| 289 // null | 289 // null |
| 290 refactoring.newName = null; | 290 refactoring.newName = null; |
| 291 assertRefactoringStatus( | 291 assertRefactoringStatus( |
| 292 refactoring.checkNewName(), | 292 refactoring.checkNewName(), |
| 293 RefactoringStatusSeverity.ERROR, | 293 RefactoringProblemSeverity.ERROR, |
| 294 expectedMessage: "Variable name must not be null."); | 294 expectedMessage: "Variable name must not be null."); |
| 295 // empty | 295 // empty |
| 296 refactoring.newName = ''; | 296 refactoring.newName = ''; |
| 297 assertRefactoringStatus( | 297 assertRefactoringStatus( |
| 298 refactoring.checkNewName(), | 298 refactoring.checkNewName(), |
| 299 RefactoringStatusSeverity.ERROR, | 299 RefactoringProblemSeverity.ERROR, |
| 300 expectedMessage: "Variable name must not be empty."); | 300 expectedMessage: "Variable name must not be empty."); |
| 301 // OK | 301 // OK |
| 302 refactoring.newName = 'newName'; | 302 refactoring.newName = 'newName'; |
| 303 assertRefactoringStatusOK(refactoring.checkNewName()); | 303 assertRefactoringStatusOK(refactoring.checkNewName()); |
| 304 } | 304 } |
| 305 | 305 |
| 306 test_checkNewName_TopLevelVariableElement_const() { | 306 test_checkNewName_TopLevelVariableElement_const() { |
| 307 indexTestUnit(''' | 307 indexTestUnit(''' |
| 308 const TEST = 0; | 308 const TEST = 0; |
| 309 '''); | 309 '''); |
| 310 createRenameRefactoringAtString('TEST ='); | 310 createRenameRefactoringAtString('TEST ='); |
| 311 // null | 311 // null |
| 312 refactoring.newName = null; | 312 refactoring.newName = null; |
| 313 assertRefactoringStatus( | 313 assertRefactoringStatus( |
| 314 refactoring.checkNewName(), | 314 refactoring.checkNewName(), |
| 315 RefactoringStatusSeverity.ERROR, | 315 RefactoringProblemSeverity.ERROR, |
| 316 expectedMessage: "Constant name must not be null."); | 316 expectedMessage: "Constant name must not be null."); |
| 317 // empty | 317 // empty |
| 318 refactoring.newName = ''; | 318 refactoring.newName = ''; |
| 319 assertRefactoringStatus( | 319 assertRefactoringStatus( |
| 320 refactoring.checkNewName(), | 320 refactoring.checkNewName(), |
| 321 RefactoringStatusSeverity.ERROR, | 321 RefactoringProblemSeverity.ERROR, |
| 322 expectedMessage: "Constant name must not be empty."); | 322 expectedMessage: "Constant name must not be empty."); |
| 323 // OK | 323 // OK |
| 324 refactoring.newName = 'NEW_NAME'; | 324 refactoring.newName = 'NEW_NAME'; |
| 325 assertRefactoringStatusOK(refactoring.checkNewName()); | 325 assertRefactoringStatusOK(refactoring.checkNewName()); |
| 326 } | 326 } |
| 327 | 327 |
| 328 test_createChange_ClassElement() { | 328 test_createChange_ClassElement() { |
| 329 indexTestUnit(''' | 329 indexTestUnit(''' |
| 330 class Test implements Other { | 330 class Test implements Other { |
| 331 Test() {} | 331 Test() {} |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 return assertSuccessfulRename(''' | 512 return assertSuccessfulRename(''' |
| 513 int newName = 0; | 513 int newName = 0; |
| 514 main() { | 514 main() { |
| 515 print(newName); | 515 print(newName); |
| 516 newName = 1; | 516 newName = 1; |
| 517 newName += 2; | 517 newName += 2; |
| 518 } | 518 } |
| 519 '''); | 519 '''); |
| 520 } | 520 } |
| 521 } | 521 } |
| OLD | NEW |