| 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/protocol.dart'; | 7 import 'package:analysis_server/src/protocol.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'; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 Future f; | 52 Future f; |
| 53 Random r; | 53 Random r; |
| 54 min(1, 2); | 54 min(1, 2); |
| 55 } | 55 } |
| 56 '''); | 56 '''); |
| 57 // configure refactoring | 57 // configure refactoring |
| 58 _createRefactoring("import 'dart:math"); | 58 _createRefactoring("import 'dart:math"); |
| 59 expect(refactoring.refactoringName, 'Rename Import Prefix'); | 59 expect(refactoring.refactoringName, 'Rename Import Prefix'); |
| 60 refactoring.newName = 'newName'; | 60 refactoring.newName = 'newName'; |
| 61 // validate change | 61 // validate change |
| 62 return assertSuccessfulRename(''' | 62 return assertSuccessfulRefactoring(''' |
| 63 import 'dart:async'; | 63 import 'dart:async'; |
| 64 import 'dart:math' as newName show Random, min hide max; | 64 import 'dart:math' as newName show Random, min hide max; |
| 65 main() { | 65 main() { |
| 66 Future f; | 66 Future f; |
| 67 newName.Random r; | 67 newName.Random r; |
| 68 newName.min(1, 2); | 68 newName.min(1, 2); |
| 69 } | 69 } |
| 70 '''); | 70 '''); |
| 71 } | 71 } |
| 72 | 72 |
| 73 test_createChange_change_className() { | 73 test_createChange_change_className() { |
| 74 indexTestUnit(''' | 74 indexTestUnit(''' |
| 75 import 'dart:math' as test; | 75 import 'dart:math' as test; |
| 76 import 'dart:async' as test; | 76 import 'dart:async' as test; |
| 77 main() { | 77 main() { |
| 78 test.Future f; | 78 test.Future f; |
| 79 } | 79 } |
| 80 '''); | 80 '''); |
| 81 // configure refactoring | 81 // configure refactoring |
| 82 _createRefactoring("import 'dart:async"); | 82 _createRefactoring("import 'dart:async"); |
| 83 expect(refactoring.refactoringName, 'Rename Import Prefix'); | 83 expect(refactoring.refactoringName, 'Rename Import Prefix'); |
| 84 expect(refactoring.oldName, 'test'); | 84 expect(refactoring.oldName, 'test'); |
| 85 refactoring.newName = 'newName'; | 85 refactoring.newName = 'newName'; |
| 86 // validate change | 86 // validate change |
| 87 return assertSuccessfulRename(''' | 87 return assertSuccessfulRefactoring(''' |
| 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() { | 96 test_createChange_change_function() { |
| 97 indexTestUnit(''' | 97 indexTestUnit(''' |
| 98 import 'dart:math' as test; | 98 import 'dart:math' as test; |
| 99 import 'dart:async' as test; | 99 import 'dart:async' as test; |
| 100 main() { | 100 main() { |
| 101 test.max(1, 2); | 101 test.max(1, 2); |
| 102 test.Future f; | 102 test.Future f; |
| 103 } | 103 } |
| 104 '''); | 104 '''); |
| 105 // configure refactoring | 105 // configure refactoring |
| 106 _createRefactoring("import 'dart:math"); | 106 _createRefactoring("import 'dart:math"); |
| 107 expect(refactoring.refactoringName, 'Rename Import Prefix'); | 107 expect(refactoring.refactoringName, 'Rename Import Prefix'); |
| 108 expect(refactoring.oldName, 'test'); | 108 expect(refactoring.oldName, 'test'); |
| 109 refactoring.newName = 'newName'; | 109 refactoring.newName = 'newName'; |
| 110 // validate change | 110 // validate change |
| 111 return assertSuccessfulRename(''' | 111 return assertSuccessfulRefactoring(''' |
| 112 import 'dart:math' as newName; | 112 import 'dart:math' as newName; |
| 113 import 'dart:async' as test; | 113 import 'dart:async' as test; |
| 114 main() { | 114 main() { |
| 115 newName.max(1, 2); | 115 newName.max(1, 2); |
| 116 test.Future f; | 116 test.Future f; |
| 117 } | 117 } |
| 118 '''); | 118 '''); |
| 119 } | 119 } |
| 120 | 120 |
| 121 test_createChange_change_onPrefixElement() { | 121 test_createChange_change_onPrefixElement() { |
| 122 indexTestUnit(''' | 122 indexTestUnit(''' |
| 123 import 'dart:async' as test; | 123 import 'dart:async' as test; |
| 124 import 'dart:math' as test; | 124 import 'dart:math' as test; |
| 125 main() { | 125 main() { |
| 126 test.Future f; | 126 test.Future f; |
| 127 test.PI; | 127 test.PI; |
| 128 test.E; | 128 test.E; |
| 129 } | 129 } |
| 130 '''); | 130 '''); |
| 131 // configure refactoring | 131 // configure refactoring |
| 132 createRenameRefactoringAtString('test.PI'); | 132 createRenameRefactoringAtString('test.PI'); |
| 133 expect(refactoring.refactoringName, 'Rename Import Prefix'); | 133 expect(refactoring.refactoringName, 'Rename Import Prefix'); |
| 134 expect(refactoring.oldName, 'test'); | 134 expect(refactoring.oldName, 'test'); |
| 135 refactoring.newName = 'newName'; | 135 refactoring.newName = 'newName'; |
| 136 // validate change | 136 // validate change |
| 137 return assertSuccessfulRename(''' | 137 return assertSuccessfulRefactoring(''' |
| 138 import 'dart:async' as test; | 138 import 'dart:async' as test; |
| 139 import 'dart:math' as newName; | 139 import 'dart:math' as newName; |
| 140 main() { | 140 main() { |
| 141 test.Future f; | 141 test.Future f; |
| 142 newName.PI; | 142 newName.PI; |
| 143 newName.E; | 143 newName.E; |
| 144 } | 144 } |
| 145 '''); | 145 '''); |
| 146 } | 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 |
| 157 _createRefactoring("import 'dart:async"); | 157 _createRefactoring("import 'dart:async"); |
| 158 expect(refactoring.refactoringName, 'Rename Import Prefix'); | 158 expect(refactoring.refactoringName, 'Rename Import Prefix'); |
| 159 expect(refactoring.oldName, 'test'); | 159 expect(refactoring.oldName, 'test'); |
| 160 refactoring.newName = ''; | 160 refactoring.newName = ''; |
| 161 // validate change | 161 // validate change |
| 162 return assertSuccessfulRename(''' | 162 return assertSuccessfulRefactoring(''' |
| 163 import 'dart:math' as test; | 163 import 'dart:math' as test; |
| 164 import 'dart:async'; | 164 import 'dart:async'; |
| 165 main() { | 165 main() { |
| 166 Future f; | 166 Future f; |
| 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 |