| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library test.services.refactoring.rename_import; | |
| 6 | |
| 7 import 'package:analysis_services/correction/status.dart'; | |
| 8 import 'package:analysis_testing/reflective_tests.dart'; | |
| 9 import 'package:analyzer/src/generated/ast.dart'; | |
| 10 import 'package:unittest/unittest.dart'; | |
| 11 | |
| 12 import 'abstract_rename.dart'; | |
| 13 | |
| 14 | |
| 15 main() { | |
| 16 groupSep = ' | '; | |
| 17 runReflectiveTests(RenameImportTest); | |
| 18 } | |
| 19 | |
| 20 | |
| 21 @ReflectiveTestCase() | |
| 22 class RenameImportTest extends RenameRefactoringTest { | |
| 23 test_checkNewName() { | |
| 24 indexTestUnit("import 'dart:async' as test;"); | |
| 25 _createRefactoring("import 'dart:"); | |
| 26 expect(refactoring.oldName, 'test'); | |
| 27 // null | |
| 28 refactoring.newName = null; | |
| 29 assertRefactoringStatus( | |
| 30 refactoring.checkNewName(), | |
| 31 RefactoringStatusSeverity.ERROR, | |
| 32 expectedMessage: "Import prefix name must not be null."); | |
| 33 // same | |
| 34 refactoring.newName = 'test'; | |
| 35 assertRefactoringStatus( | |
| 36 refactoring.checkNewName(), | |
| 37 RefactoringStatusSeverity.FATAL, | |
| 38 expectedMessage: "The new name must be different than the current name."
); | |
| 39 // empty | |
| 40 refactoring.newName = ''; | |
| 41 assertRefactoringStatusOK(refactoring.checkNewName()); | |
| 42 // OK | |
| 43 refactoring.newName = 'newName'; | |
| 44 assertRefactoringStatusOK(refactoring.checkNewName()); | |
| 45 } | |
| 46 | |
| 47 test_createChange_add() { | |
| 48 indexTestUnit(''' | |
| 49 import 'dart:async'; | |
| 50 import 'dart:math' show Random, min hide max; | |
| 51 main() { | |
| 52 Future f; | |
| 53 Random r; | |
| 54 min(1, 2); | |
| 55 } | |
| 56 '''); | |
| 57 // configure refactoring | |
| 58 _createRefactoring("import 'dart:math"); | |
| 59 expect(refactoring.refactoringName, 'Rename Import Prefix'); | |
| 60 refactoring.newName = 'newName'; | |
| 61 // validate change | |
| 62 return assertSuccessfulRename(''' | |
| 63 import 'dart:async'; | |
| 64 import 'dart:math' as newName show Random, min hide max; | |
| 65 main() { | |
| 66 Future f; | |
| 67 newName.Random r; | |
| 68 newName.min(1, 2); | |
| 69 } | |
| 70 '''); | |
| 71 } | |
| 72 | |
| 73 test_createChange_change_className() { | |
| 74 indexTestUnit(''' | |
| 75 import 'dart:math' as test; | |
| 76 import 'dart:async' as test; | |
| 77 main() { | |
| 78 test.Future f; | |
| 79 } | |
| 80 '''); | |
| 81 // configure refactoring | |
| 82 _createRefactoring("import 'dart:async"); | |
| 83 expect(refactoring.refactoringName, 'Rename Import Prefix'); | |
| 84 expect(refactoring.oldName, 'test'); | |
| 85 refactoring.newName = 'newName'; | |
| 86 // validate change | |
| 87 return assertSuccessfulRename(''' | |
| 88 import 'dart:math' as test; | |
| 89 import 'dart:async' as newName; | |
| 90 main() { | |
| 91 newName.Future f; | |
| 92 } | |
| 93 '''); | |
| 94 } | |
| 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 | |
| 121 test_createChange_remove() { | |
| 122 indexTestUnit(''' | |
| 123 import 'dart:math' as test; | |
| 124 import 'dart:async' as test; | |
| 125 main() { | |
| 126 test.Future f; | |
| 127 } | |
| 128 '''); | |
| 129 // configure refactoring | |
| 130 _createRefactoring("import 'dart:async"); | |
| 131 expect(refactoring.refactoringName, 'Rename Import Prefix'); | |
| 132 expect(refactoring.oldName, 'test'); | |
| 133 refactoring.newName = ''; | |
| 134 // validate change | |
| 135 return assertSuccessfulRename(''' | |
| 136 import 'dart:math' as test; | |
| 137 import 'dart:async'; | |
| 138 main() { | |
| 139 Future f; | |
| 140 } | |
| 141 '''); | |
| 142 } | |
| 143 | |
| 144 void _createRefactoring(String search) { | |
| 145 ImportDirective directive = | |
| 146 findNodeAtString(search, (node) => node is ImportDirective); | |
| 147 createRenameRefactoringForElement(directive.element); | |
| 148 } | |
| 149 } | |
| OLD | NEW |