| 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_import; | 5 library test.services.refactoring.rename_import; |
| 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:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
| 11 | 11 |
| 12 import 'abstract_rename.dart'; | 12 import 'abstract_rename.dart'; |
| 13 | 13 |
| 14 | 14 |
| 15 main() { | 15 main() { |
| 16 groupSep = ' | '; | 16 groupSep = ' | '; |
| 17 runReflectiveTests(RenameImportTest); | 17 runReflectiveTests(RenameImportTest); |
| 18 } | 18 } |
| 19 | 19 |
| 20 | 20 |
| 21 @ReflectiveTestCase() | 21 @ReflectiveTestCase() |
| 22 class RenameImportTest extends RenameRefactoringTest { | 22 class RenameImportTest extends RenameRefactoringTest { |
| 23 test_checkNewName() { | 23 test_checkNewName() { |
| 24 indexTestUnit("import 'dart:async' as test;"); | 24 indexTestUnit("import 'dart:async' as test;"); |
| 25 _createRefactoring("import 'dart:"); | 25 _createRefactoring("import 'dart:"); |
| 26 expect(refactoring.oldName, 'test'); | 26 expect(refactoring.oldName, 'test'); |
| 27 // null | 27 // null |
| 28 refactoring.newName = null; | 28 refactoring.newName = null; |
| 29 assertRefactoringStatus( | 29 assertRefactoringStatus( |
| 30 refactoring.checkNewName(), | 30 refactoring.checkNewName(), |
| 31 RefactoringStatusSeverity.ERROR, | 31 RefactoringProblemSeverity.ERROR, |
| 32 expectedMessage: "Import prefix name must not be null."); | 32 expectedMessage: "Import prefix name must not be null."); |
| 33 // same | 33 // same |
| 34 refactoring.newName = 'test'; | 34 refactoring.newName = 'test'; |
| 35 assertRefactoringStatus( | 35 assertRefactoringStatus( |
| 36 refactoring.checkNewName(), | 36 refactoring.checkNewName(), |
| 37 RefactoringStatusSeverity.FATAL, | 37 RefactoringProblemSeverity.FATAL, |
| 38 expectedMessage: "The new name must be different than the current name."
); | 38 expectedMessage: "The new name must be different than the current name."
); |
| 39 // empty | 39 // empty |
| 40 refactoring.newName = ''; | 40 refactoring.newName = ''; |
| 41 assertRefactoringStatusOK(refactoring.checkNewName()); | 41 assertRefactoringStatusOK(refactoring.checkNewName()); |
| 42 // OK | 42 // OK |
| 43 refactoring.newName = 'newName'; | 43 refactoring.newName = 'newName'; |
| 44 assertRefactoringStatusOK(refactoring.checkNewName()); | 44 assertRefactoringStatusOK(refactoring.checkNewName()); |
| 45 } | 45 } |
| 46 | 46 |
| 47 test_createChange_add() { | 47 test_createChange_add() { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 // validate change | 86 // validate change |
| 87 return assertSuccessfulRename(''' | 87 return assertSuccessfulRename(''' |
| 88 import 'dart:math' as test; | 88 import 'dart:math' as test; |
| 89 import 'dart:async' as newName; | 89 import 'dart:async' as newName; |
| 90 main() { | 90 main() { |
| 91 newName.Future f; | 91 newName.Future f; |
| 92 } | 92 } |
| 93 '''); | 93 '''); |
| 94 } | 94 } |
| 95 | 95 |
| 96 test_createChange_change_function() { |
| 97 indexTestUnit(''' |
| 98 import 'dart:math' as test; |
| 99 import 'dart:async' as test; |
| 100 main() { |
| 101 test.max(1, 2); |
| 102 test.Future f; |
| 103 } |
| 104 '''); |
| 105 // configure refactoring |
| 106 _createRefactoring("import 'dart:math"); |
| 107 expect(refactoring.refactoringName, 'Rename Import Prefix'); |
| 108 expect(refactoring.oldName, 'test'); |
| 109 refactoring.newName = 'newName'; |
| 110 // validate change |
| 111 return assertSuccessfulRename(''' |
| 112 import 'dart:math' as newName; |
| 113 import 'dart:async' as test; |
| 114 main() { |
| 115 newName.max(1, 2); |
| 116 test.Future f; |
| 117 } |
| 118 '''); |
| 119 } |
| 120 |
| 96 test_createChange_change_onPrefixElement() { | 121 test_createChange_change_onPrefixElement() { |
| 97 indexTestUnit(''' | 122 indexTestUnit(''' |
| 98 import 'dart:async' as test; | 123 import 'dart:async' as test; |
| 99 import 'dart:math' as test; | 124 import 'dart:math' as test; |
| 100 main() { | 125 main() { |
| 101 test.Future f; | 126 test.Future f; |
| 102 test.PI; | 127 test.PI; |
| 103 test.E; | 128 test.E; |
| 104 } | 129 } |
| 105 '''); | 130 '''); |
| 106 // configure refactoring | 131 // configure refactoring |
| 107 createRenameRefactoringAtString('test.PI'); | 132 createRenameRefactoringAtString('test.PI'); |
| 108 expect(refactoring.refactoringName, 'Rename Import Prefix'); | 133 expect(refactoring.refactoringName, 'Rename Import Prefix'); |
| 109 expect(refactoring.oldName, 'test'); | 134 expect(refactoring.oldName, 'test'); |
| 110 refactoring.newName = 'newName'; | 135 refactoring.newName = 'newName'; |
| 111 // validate change | 136 // validate change |
| 112 return assertSuccessfulRename(''' | 137 return assertSuccessfulRename(''' |
| 113 import 'dart:async' as test; | 138 import 'dart:async' as test; |
| 114 import 'dart:math' as newName; | 139 import 'dart:math' as newName; |
| 115 main() { | 140 main() { |
| 116 test.Future f; | 141 test.Future f; |
| 117 newName.PI; | 142 newName.PI; |
| 118 newName.E; | 143 newName.E; |
| 119 } | 144 } |
| 120 '''); | 145 '''); |
| 121 } | 146 } |
| 122 | |
| 123 test_createChange_change_function() { | |
| 124 indexTestUnit(''' | |
| 125 import 'dart:math' as test; | |
| 126 import 'dart:async' as test; | |
| 127 main() { | |
| 128 test.max(1, 2); | |
| 129 test.Future f; | |
| 130 } | |
| 131 '''); | |
| 132 // configure refactoring | |
| 133 _createRefactoring("import 'dart:math"); | |
| 134 expect(refactoring.refactoringName, 'Rename Import Prefix'); | |
| 135 expect(refactoring.oldName, 'test'); | |
| 136 refactoring.newName = 'newName'; | |
| 137 // validate change | |
| 138 return assertSuccessfulRename(''' | |
| 139 import 'dart:math' as newName; | |
| 140 import 'dart:async' as test; | |
| 141 main() { | |
| 142 newName.max(1, 2); | |
| 143 test.Future f; | |
| 144 } | |
| 145 '''); | |
| 146 } | |
| 147 | 147 |
| 148 test_createChange_remove() { | 148 test_createChange_remove() { |
| 149 indexTestUnit(''' | 149 indexTestUnit(''' |
| 150 import 'dart:math' as test; | 150 import 'dart:math' as test; |
| 151 import 'dart:async' as test; | 151 import 'dart:async' as test; |
| 152 main() { | 152 main() { |
| 153 test.Future f; | 153 test.Future f; |
| 154 } | 154 } |
| 155 '''); | 155 '''); |
| 156 // configure refactoring | 156 // configure refactoring |
| (...skipping 10 matching lines...) Expand all Loading... |
| 167 } | 167 } |
| 168 '''); | 168 '''); |
| 169 } | 169 } |
| 170 | 170 |
| 171 void _createRefactoring(String search) { | 171 void _createRefactoring(String search) { |
| 172 ImportDirective directive = | 172 ImportDirective directive = |
| 173 findNodeAtString(search, (node) => node is ImportDirective); | 173 findNodeAtString(search, (node) => node is ImportDirective); |
| 174 createRenameRefactoringForElement(directive.element); | 174 createRenameRefactoringForElement(directive.element); |
| 175 } | 175 } |
| 176 } | 176 } |
| OLD | NEW |