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