| 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_local; | 5 library test.services.refactoring.rename_local; |
| 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:unittest/unittest.dart'; | 9 import 'package:unittest/unittest.dart'; |
| 9 | 10 |
| 10 import '../../reflective_tests.dart'; | 11 import '../../reflective_tests.dart'; |
| 11 import 'abstract_rename.dart'; | 12 import 'abstract_rename.dart'; |
| 12 import 'package:analysis_server/src/services/correction/status.dart'; | |
| 13 | |
| 14 | 13 |
| 15 main() { | 14 main() { |
| 16 groupSep = ' | '; | 15 groupSep = ' | '; |
| 17 runReflectiveTests(RenameLocalTest); | 16 runReflectiveTests(RenameLocalTest); |
| 18 } | 17 } |
| 19 | 18 |
| 20 | |
| 21 @reflectiveTest | 19 @reflectiveTest |
| 22 class RenameLocalTest extends RenameRefactoringTest { | 20 class RenameLocalTest extends RenameRefactoringTest { |
| 23 test_checkFinalConditions_hasLocalFunction_after() async { | 21 test_checkFinalConditions_hasLocalFunction_after() async { |
| 24 indexTestUnit(''' | 22 indexTestUnit(''' |
| 25 main() { | 23 main() { |
| 26 int test = 0; | 24 int test = 0; |
| 27 newName() => 1; | 25 newName() => 1; |
| 28 } | 26 } |
| 29 '''); | 27 '''); |
| 30 createRenameRefactoringAtString('test = 0'); | 28 createRenameRefactoringAtString('test = 0'); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 refactoring.newName = 'newName'; | 138 refactoring.newName = 'newName'; |
| 141 RefactoringStatus status = await refactoring.checkFinalConditions(); | 139 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 142 assertRefactoringStatus( | 140 assertRefactoringStatus( |
| 143 status, | 141 status, |
| 144 RefactoringProblemSeverity.ERROR, | 142 RefactoringProblemSeverity.ERROR, |
| 145 expectedMessage: 'Usage of field "A.newName" declared in "test.dart" ' | 143 expectedMessage: 'Usage of field "A.newName" declared in "test.dart" ' |
| 146 'will be shadowed by renamed local variable.', | 144 'will be shadowed by renamed local variable.', |
| 147 expectedContextSearch: 'newName);'); | 145 expectedContextSearch: 'newName);'); |
| 148 } | 146 } |
| 149 | 147 |
| 148 test_checkFinalConditions_shadows_classMember_namedParameter() async { |
| 149 indexTestUnit(''' |
| 150 class A { |
| 151 foo({test: 1}) { |
| 152 } |
| 153 } |
| 154 class B extends A { |
| 155 var newName = 1; |
| 156 foo({test: 2}) { |
| 157 print(newName); |
| 158 } |
| 159 } |
| 160 '''); |
| 161 createRenameRefactoringAtString('test: 1}'); |
| 162 // check status |
| 163 refactoring.newName = 'newName'; |
| 164 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 165 assertRefactoringStatus( |
| 166 status, |
| 167 RefactoringProblemSeverity.ERROR, |
| 168 expectedMessage: 'Usage of field "B.newName" declared in "test.dart" ' |
| 169 'will be shadowed by renamed parameter.', |
| 170 expectedContextSearch: 'newName);'); |
| 171 } |
| 172 |
| 150 test_checkFinalConditions_shadows_classMemberOK_qualifiedReference() { | 173 test_checkFinalConditions_shadows_classMemberOK_qualifiedReference() { |
| 151 indexTestUnit(''' | 174 indexTestUnit(''' |
| 152 class A { | 175 class A { |
| 153 var newName = 1; | 176 var newName = 1; |
| 154 main() { | 177 main() { |
| 155 var test = 0; | 178 var test = 0; |
| 156 print(this.newName); | 179 print(this.newName); |
| 157 } | 180 } |
| 158 } | 181 } |
| 159 '''); | 182 '''); |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 newName = 1; | 427 newName = 1; |
| 405 newName += 2; | 428 newName += 2; |
| 406 print(newName); | 429 print(newName); |
| 407 } | 430 } |
| 408 main() { | 431 main() { |
| 409 myFunction(newName: 2); | 432 myFunction(newName: 2); |
| 410 } | 433 } |
| 411 '''); | 434 '''); |
| 412 } | 435 } |
| 413 | 436 |
| 414 test_createChange_parameter_namedInOtherFile() async { | 437 test_createChange_parameter_named_inOtherFile() async { |
| 415 indexTestUnit(''' | 438 indexTestUnit(''' |
| 416 class A { | 439 class A { |
| 417 A({test}); | 440 A({test}); |
| 418 } | 441 } |
| 419 '''); | 442 '''); |
| 420 indexUnit('/test2.dart', ''' | 443 indexUnit('/test2.dart', ''' |
| 421 import 'test.dart'; | 444 import 'test.dart'; |
| 422 main() { | 445 main() { |
| 423 new A(test: 2); | 446 new A(test: 2); |
| 424 } | 447 } |
| 425 '''); | 448 '''); |
| 426 // configure refactoring | 449 // configure refactoring |
| 427 createRenameRefactoringAtString('test});'); | 450 createRenameRefactoringAtString('test});'); |
| 428 expect(refactoring.refactoringName, 'Rename Parameter'); | 451 expect(refactoring.refactoringName, 'Rename Parameter'); |
| 429 refactoring.newName = 'newName'; | 452 refactoring.newName = 'newName'; |
| 430 // validate change | 453 // validate change |
| 431 await assertSuccessfulRefactoring(''' | 454 await assertSuccessfulRefactoring(''' |
| 432 class A { | 455 class A { |
| 433 A({newName}); | 456 A({newName}); |
| 434 } | 457 } |
| 435 '''); | 458 '''); |
| 436 assertFileChangeResult('/test2.dart', ''' | 459 assertFileChangeResult('/test2.dart', ''' |
| 437 import 'test.dart'; | 460 import 'test.dart'; |
| 438 main() { | 461 main() { |
| 439 new A(newName: 2); | 462 new A(newName: 2); |
| 440 } | 463 } |
| 441 '''); | 464 '''); |
| 442 } | 465 } |
| 443 | 466 |
| 467 test_createChange_parameter_named_updateHierarchy() async { |
| 468 indexUnit('/test2.dart', ''' |
| 469 library test2; |
| 470 class A { |
| 471 void foo({int test: 1}) { |
| 472 print(test); |
| 473 } |
| 474 } |
| 475 class B extends A { |
| 476 void foo({int test: 2}) { |
| 477 print(test); |
| 478 } |
| 479 } |
| 480 '''); |
| 481 indexTestUnit(''' |
| 482 import 'test2.dart'; |
| 483 main() { |
| 484 new A().foo(test: 10); |
| 485 new B().foo(test: 20); |
| 486 new C().foo(test: 30); |
| 487 } |
| 488 class C extends A { |
| 489 void foo({int test: 3}) { |
| 490 print(test); |
| 491 } |
| 492 } |
| 493 '''); |
| 494 // configure refactoring |
| 495 createRenameRefactoringAtString('test: 20'); |
| 496 expect(refactoring.refactoringName, 'Rename Parameter'); |
| 497 refactoring.newName = 'newName'; |
| 498 // validate change |
| 499 await assertSuccessfulRefactoring(''' |
| 500 import 'test2.dart'; |
| 501 main() { |
| 502 new A().foo(newName: 10); |
| 503 new B().foo(newName: 20); |
| 504 new C().foo(newName: 30); |
| 505 } |
| 506 class C extends A { |
| 507 void foo({int newName: 3}) { |
| 508 print(newName); |
| 509 } |
| 510 } |
| 511 '''); |
| 512 assertFileChangeResult('/test2.dart', ''' |
| 513 library test2; |
| 514 class A { |
| 515 void foo({int newName: 1}) { |
| 516 print(newName); |
| 517 } |
| 518 } |
| 519 class B extends A { |
| 520 void foo({int newName: 2}) { |
| 521 print(newName); |
| 522 } |
| 523 } |
| 524 '''); |
| 525 } |
| 526 |
| 444 test_oldName() { | 527 test_oldName() { |
| 445 indexTestUnit(''' | 528 indexTestUnit(''' |
| 446 main() { | 529 main() { |
| 447 int test = 0; | 530 int test = 0; |
| 448 } | 531 } |
| 449 '''); | 532 '''); |
| 450 // configure refactoring | 533 // configure refactoring |
| 451 createRenameRefactoringAtString('test = 0'); | 534 createRenameRefactoringAtString('test = 0'); |
| 452 // old name | 535 // old name |
| 453 expect(refactoring.oldName, 'test'); | 536 expect(refactoring.oldName, 'test'); |
| 454 } | 537 } |
| 455 } | 538 } |
| OLD | NEW |