| 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_constructor; | 5 library test.services.refactoring.rename_constructor; |
| 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:analyzer/src/generated/ast.dart'; | 9 import 'package:analyzer/src/generated/ast.dart'; |
| 10 import 'package:analyzer/src/generated/element.dart'; | 10 import 'package:analyzer/src/generated/element.dart'; |
| 11 import 'package:unittest/unittest.dart'; | 11 import 'package:unittest/unittest.dart'; |
| 12 | 12 |
| 13 import 'abstract_rename.dart'; | 13 import 'abstract_rename.dart'; |
| 14 | 14 |
| 15 | 15 |
| 16 main() { | 16 main() { |
| 17 groupSep = ' | '; | 17 groupSep = ' | '; |
| 18 runReflectiveTests(RenameConstructorTest); | 18 runReflectiveTests(RenameConstructorTest); |
| 19 } | 19 } |
| 20 | 20 |
| 21 | 21 |
| 22 @ReflectiveTestCase() | 22 @ReflectiveTestCase() |
| 23 class RenameConstructorTest extends RenameRefactoringTest { | 23 class RenameConstructorTest extends RenameRefactoringTest { |
| 24 test_checkFinalConditions_hasMember_constructor() { | 24 test_checkFinalConditions_hasMember_constructor() { |
| 25 indexTestUnit(''' | 25 indexTestUnit(''' |
| 26 class A { | 26 class A { |
| 27 A.test() {} | 27 A.test() {} |
| 28 A.newName() {} // existing | 28 A.newName() {} // existing |
| 29 } | 29 } |
| 30 '''); | 30 '''); |
| 31 _createConstructorDeclarationRefactoring('test() {}'); | 31 _createConstructorDeclarationRefactoring('test() {}'); |
| 32 // check status | 32 // check status |
| 33 refactoring.newName = 'newName'; | 33 refactoring.newName = 'newName'; |
| 34 return refactoring.checkFinalConditions().then((status) { | 34 return refactoring.checkFinalConditions().then((status) { |
| 35 assertRefactoringStatus( | 35 assertRefactoringStatus( |
| 36 status, | 36 status, |
| 37 RefactoringStatusSeverity.ERROR, | 37 RefactoringProblemSeverity.ERROR, |
| 38 expectedMessage: "Class 'A' already declares constructor with name 'ne
wName'.", | 38 expectedMessage: "Class 'A' already declares constructor with name 'ne
wName'.", |
| 39 expectedContextSearch: 'newName() {} // existing'); | 39 expectedContextSearch: 'newName() {} // existing'); |
| 40 }); | 40 }); |
| 41 } | 41 } |
| 42 | 42 |
| 43 test_checkFinalConditions_hasMember_method() { | 43 test_checkFinalConditions_hasMember_method() { |
| 44 indexTestUnit(''' | 44 indexTestUnit(''' |
| 45 class A { | 45 class A { |
| 46 A.test() {} | 46 A.test() {} |
| 47 newName() {} // existing | 47 newName() {} // existing |
| 48 } | 48 } |
| 49 '''); | 49 '''); |
| 50 _createConstructorDeclarationRefactoring('test() {}'); | 50 _createConstructorDeclarationRefactoring('test() {}'); |
| 51 // check status | 51 // check status |
| 52 refactoring.newName = 'newName'; | 52 refactoring.newName = 'newName'; |
| 53 return refactoring.checkFinalConditions().then((status) { | 53 return refactoring.checkFinalConditions().then((status) { |
| 54 assertRefactoringStatus( | 54 assertRefactoringStatus( |
| 55 status, | 55 status, |
| 56 RefactoringStatusSeverity.ERROR, | 56 RefactoringProblemSeverity.ERROR, |
| 57 expectedMessage: "Class 'A' already declares method with name 'newName
'.", | 57 expectedMessage: "Class 'A' already declares method with name 'newName
'.", |
| 58 expectedContextSearch: 'newName() {} // existing'); | 58 expectedContextSearch: 'newName() {} // existing'); |
| 59 }); | 59 }); |
| 60 } | 60 } |
| 61 | 61 |
| 62 test_checkNewName() { | 62 test_checkNewName() { |
| 63 indexTestUnit(''' | 63 indexTestUnit(''' |
| 64 class A { | 64 class A { |
| 65 A.test() {} | 65 A.test() {} |
| 66 } | 66 } |
| 67 '''); | 67 '''); |
| 68 createRenameRefactoringAtString('test() {}'); | 68 createRenameRefactoringAtString('test() {}'); |
| 69 expect(refactoring.oldName, 'test'); | 69 expect(refactoring.oldName, 'test'); |
| 70 // null | 70 // null |
| 71 refactoring.newName = null; | 71 refactoring.newName = null; |
| 72 assertRefactoringStatus( | 72 assertRefactoringStatus( |
| 73 refactoring.checkNewName(), | 73 refactoring.checkNewName(), |
| 74 RefactoringStatusSeverity.ERROR, | 74 RefactoringProblemSeverity.ERROR, |
| 75 expectedMessage: "Constructor name must not be null."); | 75 expectedMessage: "Constructor name must not be null."); |
| 76 // same | 76 // same |
| 77 refactoring.newName = 'test'; | 77 refactoring.newName = 'test'; |
| 78 assertRefactoringStatus( | 78 assertRefactoringStatus( |
| 79 refactoring.checkNewName(), | 79 refactoring.checkNewName(), |
| 80 RefactoringStatusSeverity.FATAL, | 80 RefactoringProblemSeverity.FATAL, |
| 81 expectedMessage: "The new name must be different than the current name."
); | 81 expectedMessage: "The new name must be different than the current name."
); |
| 82 // empty | 82 // empty |
| 83 refactoring.newName = ''; | 83 refactoring.newName = ''; |
| 84 assertRefactoringStatusOK(refactoring.checkNewName()); | 84 assertRefactoringStatusOK(refactoring.checkNewName()); |
| 85 // OK | 85 // OK |
| 86 refactoring.newName = 'newName'; | 86 refactoring.newName = 'newName'; |
| 87 assertRefactoringStatusOK(refactoring.checkNewName()); | 87 assertRefactoringStatusOK(refactoring.checkNewName()); |
| 88 } | 88 } |
| 89 | 89 |
| 90 test_createChange_add() { | 90 test_createChange_add() { |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 } | 185 } |
| 186 '''); | 186 '''); |
| 187 } | 187 } |
| 188 | 188 |
| 189 void _createConstructorDeclarationRefactoring(String search) { | 189 void _createConstructorDeclarationRefactoring(String search) { |
| 190 ConstructorElement element = | 190 ConstructorElement element = |
| 191 findNodeElementAtString(search, (node) => node is ConstructorDeclaration
); | 191 findNodeElementAtString(search, (node) => node is ConstructorDeclaration
); |
| 192 createRenameRefactoringForElement(element); | 192 createRenameRefactoringForElement(element); |
| 193 } | 193 } |
| 194 } | 194 } |
| OLD | NEW |