| 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_local; | 5 library test.services.refactoring.rename_local; |
| 6 | 6 |
| 7 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 7 import 'package:analysis_server/plugin/protocol/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:test/test.dart'; | 9 import 'package:test/test.dart'; |
| 10 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 10 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 11 | 11 |
| 12 import 'abstract_rename.dart'; | 12 import 'abstract_rename.dart'; |
| 13 | 13 |
| 14 main() { | 14 main() { |
| 15 defineReflectiveSuite(() { | 15 defineReflectiveSuite(() { |
| 16 defineReflectiveTests(RenameLocalTest); | 16 defineReflectiveTests(RenameLocalTest); |
| 17 }); | 17 }); |
| 18 } | 18 } |
| 19 | 19 |
| 20 @reflectiveTest | 20 @reflectiveTest |
| 21 class RenameLocalTest extends RenameRefactoringTest { | 21 class RenameLocalTest extends RenameRefactoringTest { |
| 22 test_checkFinalConditions_hasLocalFunction_after() async { | 22 test_checkFinalConditions_hasLocalFunction_after() async { |
| 23 indexTestUnit(''' | 23 await indexTestUnit(''' |
| 24 main() { | 24 main() { |
| 25 int test = 0; | 25 int test = 0; |
| 26 newName() => 1; | 26 newName() => 1; |
| 27 } | 27 } |
| 28 '''); | 28 '''); |
| 29 createRenameRefactoringAtString('test = 0'); | 29 createRenameRefactoringAtString('test = 0'); |
| 30 // check status | 30 // check status |
| 31 refactoring.newName = 'newName'; | 31 refactoring.newName = 'newName'; |
| 32 RefactoringStatus status = await refactoring.checkFinalConditions(); | 32 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 33 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 33 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
| 34 expectedMessage: "Duplicate function 'newName'.", | 34 expectedMessage: "Duplicate function 'newName'.", |
| 35 expectedContextSearch: 'newName() => 1'); | 35 expectedContextSearch: 'newName() => 1'); |
| 36 } | 36 } |
| 37 | 37 |
| 38 test_checkFinalConditions_hasLocalFunction_before() async { | 38 test_checkFinalConditions_hasLocalFunction_before() async { |
| 39 indexTestUnit(''' | 39 await indexTestUnit(''' |
| 40 main() { | 40 main() { |
| 41 newName() => 1; | 41 newName() => 1; |
| 42 int test = 0; | 42 int test = 0; |
| 43 } | 43 } |
| 44 '''); | 44 '''); |
| 45 createRenameRefactoringAtString('test = 0'); | 45 createRenameRefactoringAtString('test = 0'); |
| 46 // check status | 46 // check status |
| 47 refactoring.newName = 'newName'; | 47 refactoring.newName = 'newName'; |
| 48 RefactoringStatus status = await refactoring.checkFinalConditions(); | 48 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 49 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 49 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
| 50 expectedMessage: "Duplicate function 'newName'."); | 50 expectedMessage: "Duplicate function 'newName'."); |
| 51 } | 51 } |
| 52 | 52 |
| 53 test_checkFinalConditions_hasLocalVariable_after() async { | 53 test_checkFinalConditions_hasLocalVariable_after() async { |
| 54 indexTestUnit(''' | 54 await indexTestUnit(''' |
| 55 main() { | 55 main() { |
| 56 int test = 0; | 56 int test = 0; |
| 57 var newName = 1; | 57 var newName = 1; |
| 58 print(newName); | 58 print(newName); |
| 59 } | 59 } |
| 60 '''); | 60 '''); |
| 61 createRenameRefactoringAtString('test = 0'); | 61 createRenameRefactoringAtString('test = 0'); |
| 62 // check status | 62 // check status |
| 63 refactoring.newName = 'newName'; | 63 refactoring.newName = 'newName'; |
| 64 RefactoringStatus status = await refactoring.checkFinalConditions(); | 64 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 65 expect(status.problems, hasLength(1)); | 65 expect(status.problems, hasLength(1)); |
| 66 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 66 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
| 67 expectedMessage: "Duplicate local variable 'newName'.", | 67 expectedMessage: "Duplicate local variable 'newName'.", |
| 68 expectedContextSearch: 'newName = 1;'); | 68 expectedContextSearch: 'newName = 1;'); |
| 69 } | 69 } |
| 70 | 70 |
| 71 test_checkFinalConditions_hasLocalVariable_before() async { | 71 test_checkFinalConditions_hasLocalVariable_before() async { |
| 72 indexTestUnit(''' | 72 await indexTestUnit(''' |
| 73 main() { | 73 main() { |
| 74 var newName = 1; | 74 var newName = 1; |
| 75 int test = 0; | 75 int test = 0; |
| 76 } | 76 } |
| 77 '''); | 77 '''); |
| 78 createRenameRefactoringAtString('test = 0'); | 78 createRenameRefactoringAtString('test = 0'); |
| 79 // check status | 79 // check status |
| 80 refactoring.newName = 'newName'; | 80 refactoring.newName = 'newName'; |
| 81 RefactoringStatus status = await refactoring.checkFinalConditions(); | 81 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 82 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 82 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
| 83 expectedMessage: "Duplicate local variable 'newName'.", | 83 expectedMessage: "Duplicate local variable 'newName'.", |
| 84 expectedContextSearch: 'newName = 1;'); | 84 expectedContextSearch: 'newName = 1;'); |
| 85 } | 85 } |
| 86 | 86 |
| 87 test_checkFinalConditions_hasLocalVariable_otherBlock() { | 87 test_checkFinalConditions_hasLocalVariable_otherBlock() async { |
| 88 indexTestUnit(''' | 88 await indexTestUnit(''' |
| 89 main() { | 89 main() { |
| 90 { | 90 { |
| 91 var newName = 1; | 91 var newName = 1; |
| 92 } | 92 } |
| 93 { | 93 { |
| 94 int test = 0; | 94 int test = 0; |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 '''); | 97 '''); |
| 98 createRenameRefactoringAtString('test = 0'); | 98 createRenameRefactoringAtString('test = 0'); |
| 99 // check status | 99 // check status |
| 100 refactoring.newName = 'newName'; | 100 refactoring.newName = 'newName'; |
| 101 return assertRefactoringConditionsOK(); | 101 return assertRefactoringConditionsOK(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 test_checkFinalConditions_hasLocalVariable_otherForEachLoop() { | 104 test_checkFinalConditions_hasLocalVariable_otherForEachLoop() async { |
| 105 indexTestUnit(''' | 105 await indexTestUnit(''' |
| 106 main() { | 106 main() { |
| 107 for (int newName in []) {} | 107 for (int newName in []) {} |
| 108 for (int test in []) {} | 108 for (int test in []) {} |
| 109 } | 109 } |
| 110 '''); | 110 '''); |
| 111 createRenameRefactoringAtString('test in'); | 111 createRenameRefactoringAtString('test in'); |
| 112 // check status | 112 // check status |
| 113 refactoring.newName = 'newName'; | 113 refactoring.newName = 'newName'; |
| 114 return assertRefactoringConditionsOK(); | 114 return assertRefactoringConditionsOK(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 test_checkFinalConditions_hasLocalVariable_otherForLoop() { | 117 test_checkFinalConditions_hasLocalVariable_otherForLoop() async { |
| 118 indexTestUnit(''' | 118 await indexTestUnit(''' |
| 119 main() { | 119 main() { |
| 120 for (int newName = 0; newName < 10; newName++) {} | 120 for (int newName = 0; newName < 10; newName++) {} |
| 121 for (int test = 0; test < 10; test++) {} | 121 for (int test = 0; test < 10; test++) {} |
| 122 } | 122 } |
| 123 '''); | 123 '''); |
| 124 createRenameRefactoringAtString('test = 0'); | 124 createRenameRefactoringAtString('test = 0'); |
| 125 // check status | 125 // check status |
| 126 refactoring.newName = 'newName'; | 126 refactoring.newName = 'newName'; |
| 127 return assertRefactoringConditionsOK(); | 127 return assertRefactoringConditionsOK(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 test_checkFinalConditions_hasLocalVariable_otherFunction() { | 130 test_checkFinalConditions_hasLocalVariable_otherFunction() async { |
| 131 indexTestUnit(''' | 131 await indexTestUnit(''' |
| 132 main() { | 132 main() { |
| 133 int test = 0; | 133 int test = 0; |
| 134 } | 134 } |
| 135 main2() { | 135 main2() { |
| 136 var newName = 1; | 136 var newName = 1; |
| 137 } | 137 } |
| 138 '''); | 138 '''); |
| 139 createRenameRefactoringAtString('test = 0'); | 139 createRenameRefactoringAtString('test = 0'); |
| 140 // check status | 140 // check status |
| 141 refactoring.newName = 'newName'; | 141 refactoring.newName = 'newName'; |
| 142 return assertRefactoringConditionsOK(); | 142 return assertRefactoringConditionsOK(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 test_checkFinalConditions_shadows_classMember() async { | 145 test_checkFinalConditions_shadows_classMember() async { |
| 146 indexTestUnit(''' | 146 await indexTestUnit(''' |
| 147 class A { | 147 class A { |
| 148 var newName = 1; | 148 var newName = 1; |
| 149 main() { | 149 main() { |
| 150 var test = 0; | 150 var test = 0; |
| 151 print(newName); | 151 print(newName); |
| 152 } | 152 } |
| 153 } | 153 } |
| 154 '''); | 154 '''); |
| 155 createRenameRefactoringAtString('test = 0'); | 155 createRenameRefactoringAtString('test = 0'); |
| 156 // check status | 156 // check status |
| 157 refactoring.newName = 'newName'; | 157 refactoring.newName = 'newName'; |
| 158 RefactoringStatus status = await refactoring.checkFinalConditions(); | 158 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 159 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 159 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
| 160 expectedMessage: 'Usage of field "A.newName" declared in "test.dart" ' | 160 expectedMessage: 'Usage of field "A.newName" declared in "test.dart" ' |
| 161 'will be shadowed by renamed local variable.', | 161 'will be shadowed by renamed local variable.', |
| 162 expectedContextSearch: 'newName);'); | 162 expectedContextSearch: 'newName);'); |
| 163 } | 163 } |
| 164 | 164 |
| 165 test_checkFinalConditions_shadows_classMember_namedParameter() async { | 165 test_checkFinalConditions_shadows_classMember_namedParameter() async { |
| 166 indexTestUnit(''' | 166 await indexTestUnit(''' |
| 167 class A { | 167 class A { |
| 168 foo({test: 1}) { | 168 foo({test: 1}) { |
| 169 } | 169 } |
| 170 } | 170 } |
| 171 class B extends A { | 171 class B extends A { |
| 172 var newName = 1; | 172 var newName = 1; |
| 173 foo({test: 2}) { | 173 foo({test: 2}) { |
| 174 print(newName); | 174 print(newName); |
| 175 } | 175 } |
| 176 } | 176 } |
| 177 '''); | 177 '''); |
| 178 createRenameRefactoringAtString('test: 1}'); | 178 createRenameRefactoringAtString('test: 1}'); |
| 179 // check status | 179 // check status |
| 180 refactoring.newName = 'newName'; | 180 refactoring.newName = 'newName'; |
| 181 RefactoringStatus status = await refactoring.checkFinalConditions(); | 181 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 182 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 182 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
| 183 expectedMessage: 'Usage of field "B.newName" declared in "test.dart" ' | 183 expectedMessage: 'Usage of field "B.newName" declared in "test.dart" ' |
| 184 'will be shadowed by renamed parameter.', | 184 'will be shadowed by renamed parameter.', |
| 185 expectedContextSearch: 'newName);'); | 185 expectedContextSearch: 'newName);'); |
| 186 } | 186 } |
| 187 | 187 |
| 188 test_checkFinalConditions_shadows_classMemberOK_qualifiedReference() { | 188 test_checkFinalConditions_shadows_classMemberOK_qualifiedReference() async { |
| 189 indexTestUnit(''' | 189 await indexTestUnit(''' |
| 190 class A { | 190 class A { |
| 191 var newName = 1; | 191 var newName = 1; |
| 192 main() { | 192 main() { |
| 193 var test = 0; | 193 var test = 0; |
| 194 print(this.newName); | 194 print(this.newName); |
| 195 } | 195 } |
| 196 } | 196 } |
| 197 '''); | 197 '''); |
| 198 createRenameRefactoringAtString('test = 0'); | 198 createRenameRefactoringAtString('test = 0'); |
| 199 // check status | 199 // check status |
| 200 refactoring.newName = 'newName'; | 200 refactoring.newName = 'newName'; |
| 201 return assertRefactoringConditionsOK(); | 201 return assertRefactoringConditionsOK(); |
| 202 } | 202 } |
| 203 | 203 |
| 204 test_checkFinalConditions_shadows_OK_namedParameterReference() { | 204 test_checkFinalConditions_shadows_OK_namedParameterReference() async { |
| 205 indexTestUnit(''' | 205 await indexTestUnit(''' |
| 206 void f({newName}) {} | 206 void f({newName}) {} |
| 207 main() { | 207 main() { |
| 208 var test = 0; | 208 var test = 0; |
| 209 f(newName: test); | 209 f(newName: test); |
| 210 } | 210 } |
| 211 '''); | 211 '''); |
| 212 createRenameRefactoringAtString('test = 0'); | 212 createRenameRefactoringAtString('test = 0'); |
| 213 // check status | 213 // check status |
| 214 refactoring.newName = 'newName'; | 214 refactoring.newName = 'newName'; |
| 215 return assertRefactoringFinalConditionsOK(); | 215 return assertRefactoringFinalConditionsOK(); |
| 216 } | 216 } |
| 217 | 217 |
| 218 test_checkFinalConditions_shadows_topLevelFunction() async { | 218 test_checkFinalConditions_shadows_topLevelFunction() async { |
| 219 indexTestUnit(''' | 219 await indexTestUnit(''' |
| 220 newName() {} | 220 newName() {} |
| 221 main() { | 221 main() { |
| 222 var test = 0; | 222 var test = 0; |
| 223 newName(); // ref | 223 newName(); // ref |
| 224 } | 224 } |
| 225 '''); | 225 '''); |
| 226 createRenameRefactoringAtString('test = 0'); | 226 createRenameRefactoringAtString('test = 0'); |
| 227 // check status | 227 // check status |
| 228 refactoring.newName = 'newName'; | 228 refactoring.newName = 'newName'; |
| 229 RefactoringStatus status = await refactoring.checkFinalConditions(); | 229 RefactoringStatus status = await refactoring.checkFinalConditions(); |
| 230 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 230 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
| 231 expectedContextSearch: 'newName(); // ref'); | 231 expectedContextSearch: 'newName(); // ref'); |
| 232 } | 232 } |
| 233 | 233 |
| 234 test_checkNewName_FunctionElement() { | 234 test_checkNewName_FunctionElement() async { |
| 235 indexTestUnit(''' | 235 await indexTestUnit(''' |
| 236 main() { | 236 main() { |
| 237 int test() {} | 237 int test() {} |
| 238 } | 238 } |
| 239 '''); | 239 '''); |
| 240 createRenameRefactoringAtString('test() {}'); | 240 createRenameRefactoringAtString('test() {}'); |
| 241 // null | 241 // null |
| 242 refactoring.newName = null; | 242 refactoring.newName = null; |
| 243 assertRefactoringStatus( | 243 assertRefactoringStatus( |
| 244 refactoring.checkNewName(), RefactoringProblemSeverity.FATAL, | 244 refactoring.checkNewName(), RefactoringProblemSeverity.FATAL, |
| 245 expectedMessage: "Function name must not be null."); | 245 expectedMessage: "Function name must not be null."); |
| 246 // OK | 246 // OK |
| 247 refactoring.newName = 'newName'; | 247 refactoring.newName = 'newName'; |
| 248 assertRefactoringStatusOK(refactoring.checkNewName()); | 248 assertRefactoringStatusOK(refactoring.checkNewName()); |
| 249 } | 249 } |
| 250 | 250 |
| 251 test_checkNewName_LocalVariableElement() { | 251 test_checkNewName_LocalVariableElement() async { |
| 252 indexTestUnit(''' | 252 await indexTestUnit(''' |
| 253 main() { | 253 main() { |
| 254 int test = 0; | 254 int test = 0; |
| 255 } | 255 } |
| 256 '''); | 256 '''); |
| 257 createRenameRefactoringAtString('test = 0;'); | 257 createRenameRefactoringAtString('test = 0;'); |
| 258 // null | 258 // null |
| 259 refactoring.newName = null; | 259 refactoring.newName = null; |
| 260 assertRefactoringStatus( | 260 assertRefactoringStatus( |
| 261 refactoring.checkNewName(), RefactoringProblemSeverity.FATAL, | 261 refactoring.checkNewName(), RefactoringProblemSeverity.FATAL, |
| 262 expectedMessage: "Variable name must not be null."); | 262 expectedMessage: "Variable name must not be null."); |
| 263 // empty | 263 // empty |
| 264 refactoring.newName = ''; | 264 refactoring.newName = ''; |
| 265 assertRefactoringStatus( | 265 assertRefactoringStatus( |
| 266 refactoring.checkNewName(), RefactoringProblemSeverity.FATAL, | 266 refactoring.checkNewName(), RefactoringProblemSeverity.FATAL, |
| 267 expectedMessage: "Variable name must not be empty."); | 267 expectedMessage: "Variable name must not be empty."); |
| 268 // OK | 268 // OK |
| 269 refactoring.newName = 'newName'; | 269 refactoring.newName = 'newName'; |
| 270 assertRefactoringStatusOK(refactoring.checkNewName()); | 270 assertRefactoringStatusOK(refactoring.checkNewName()); |
| 271 } | 271 } |
| 272 | 272 |
| 273 test_checkNewName_ParameterElement() { | 273 test_checkNewName_ParameterElement() async { |
| 274 indexTestUnit(''' | 274 await indexTestUnit(''' |
| 275 main(test) { | 275 main(test) { |
| 276 } | 276 } |
| 277 '''); | 277 '''); |
| 278 createRenameRefactoringAtString('test) {'); | 278 createRenameRefactoringAtString('test) {'); |
| 279 // null | 279 // null |
| 280 refactoring.newName = null; | 280 refactoring.newName = null; |
| 281 assertRefactoringStatus( | 281 assertRefactoringStatus( |
| 282 refactoring.checkNewName(), RefactoringProblemSeverity.FATAL, | 282 refactoring.checkNewName(), RefactoringProblemSeverity.FATAL, |
| 283 expectedMessage: "Parameter name must not be null."); | 283 expectedMessage: "Parameter name must not be null."); |
| 284 // OK | 284 // OK |
| 285 refactoring.newName = 'newName'; | 285 refactoring.newName = 'newName'; |
| 286 assertRefactoringStatusOK(refactoring.checkNewName()); | 286 assertRefactoringStatusOK(refactoring.checkNewName()); |
| 287 } | 287 } |
| 288 | 288 |
| 289 test_createChange_localFunction() { | 289 test_createChange_localFunction() async { |
| 290 indexTestUnit(''' | 290 await indexTestUnit(''' |
| 291 main() { | 291 main() { |
| 292 int test() => 0; | 292 int test() => 0; |
| 293 print(test); | 293 print(test); |
| 294 print(test()); | 294 print(test()); |
| 295 } | 295 } |
| 296 '''); | 296 '''); |
| 297 // configure refactoring | 297 // configure refactoring |
| 298 createRenameRefactoringAtString('test() => 0'); | 298 createRenameRefactoringAtString('test() => 0'); |
| 299 expect(refactoring.refactoringName, 'Rename Local Function'); | 299 expect(refactoring.refactoringName, 'Rename Local Function'); |
| 300 expect(refactoring.elementKindName, 'function'); | 300 expect(refactoring.elementKindName, 'function'); |
| 301 refactoring.newName = 'newName'; | 301 refactoring.newName = 'newName'; |
| 302 // validate change | 302 // validate change |
| 303 return assertSuccessfulRefactoring(''' | 303 return assertSuccessfulRefactoring(''' |
| 304 main() { | 304 main() { |
| 305 int newName() => 0; | 305 int newName() => 0; |
| 306 print(newName); | 306 print(newName); |
| 307 print(newName()); | 307 print(newName()); |
| 308 } | 308 } |
| 309 '''); | 309 '''); |
| 310 } | 310 } |
| 311 | 311 |
| 312 test_createChange_localFunction_sameNameDifferenceScopes() { | 312 test_createChange_localFunction_sameNameDifferenceScopes() async { |
| 313 indexTestUnit(''' | 313 await indexTestUnit(''' |
| 314 main() { | 314 main() { |
| 315 { | 315 { |
| 316 int test() => 0; | 316 int test() => 0; |
| 317 print(test); | 317 print(test); |
| 318 } | 318 } |
| 319 { | 319 { |
| 320 int test() => 1; | 320 int test() => 1; |
| 321 print(test); | 321 print(test); |
| 322 } | 322 } |
| 323 { | 323 { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 342 print(newName); | 342 print(newName); |
| 343 } | 343 } |
| 344 { | 344 { |
| 345 int test() => 2; | 345 int test() => 2; |
| 346 print(test); | 346 print(test); |
| 347 } | 347 } |
| 348 } | 348 } |
| 349 '''); | 349 '''); |
| 350 } | 350 } |
| 351 | 351 |
| 352 test_createChange_localVariable() { | 352 test_createChange_localVariable() async { |
| 353 indexTestUnit(''' | 353 await indexTestUnit(''' |
| 354 main() { | 354 main() { |
| 355 int test = 0; | 355 int test = 0; |
| 356 test = 1; | 356 test = 1; |
| 357 test += 2; | 357 test += 2; |
| 358 print(test); | 358 print(test); |
| 359 } | 359 } |
| 360 '''); | 360 '''); |
| 361 // configure refactoring | 361 // configure refactoring |
| 362 createRenameRefactoringAtString('test = 0'); | 362 createRenameRefactoringAtString('test = 0'); |
| 363 expect(refactoring.refactoringName, 'Rename Local Variable'); | 363 expect(refactoring.refactoringName, 'Rename Local Variable'); |
| 364 expect(refactoring.elementKindName, 'local variable'); | 364 expect(refactoring.elementKindName, 'local variable'); |
| 365 refactoring.newName = 'newName'; | 365 refactoring.newName = 'newName'; |
| 366 // validate change | 366 // validate change |
| 367 return assertSuccessfulRefactoring(''' | 367 return assertSuccessfulRefactoring(''' |
| 368 main() { | 368 main() { |
| 369 int newName = 0; | 369 int newName = 0; |
| 370 newName = 1; | 370 newName = 1; |
| 371 newName += 2; | 371 newName += 2; |
| 372 print(newName); | 372 print(newName); |
| 373 } | 373 } |
| 374 '''); | 374 '''); |
| 375 } | 375 } |
| 376 | 376 |
| 377 test_createChange_localVariable_sameNameDifferenceScopes() { | 377 test_createChange_localVariable_sameNameDifferenceScopes() async { |
| 378 indexTestUnit(''' | 378 await indexTestUnit(''' |
| 379 main() { | 379 main() { |
| 380 { | 380 { |
| 381 int test = 0; | 381 int test = 0; |
| 382 print(test); | 382 print(test); |
| 383 } | 383 } |
| 384 { | 384 { |
| 385 int test = 1; | 385 int test = 1; |
| 386 print(test); | 386 print(test); |
| 387 } | 387 } |
| 388 { | 388 { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 407 print(newName); | 407 print(newName); |
| 408 } | 408 } |
| 409 { | 409 { |
| 410 int test = 2; | 410 int test = 2; |
| 411 print(test); | 411 print(test); |
| 412 } | 412 } |
| 413 } | 413 } |
| 414 '''); | 414 '''); |
| 415 } | 415 } |
| 416 | 416 |
| 417 test_createChange_parameter() { | 417 test_createChange_parameter() async { |
| 418 indexTestUnit(''' | 418 await indexTestUnit(''' |
| 419 myFunction({int test}) { | 419 myFunction({int test}) { |
| 420 test = 1; | 420 test = 1; |
| 421 test += 2; | 421 test += 2; |
| 422 print(test); | 422 print(test); |
| 423 } | 423 } |
| 424 main() { | 424 main() { |
| 425 myFunction(test: 2); | 425 myFunction(test: 2); |
| 426 } | 426 } |
| 427 '''); | 427 '''); |
| 428 // configure refactoring | 428 // configure refactoring |
| 429 createRenameRefactoringAtString('test}) {'); | 429 createRenameRefactoringAtString('test}) {'); |
| 430 expect(refactoring.refactoringName, 'Rename Parameter'); | 430 expect(refactoring.refactoringName, 'Rename Parameter'); |
| 431 expect(refactoring.elementKindName, 'parameter'); | 431 expect(refactoring.elementKindName, 'parameter'); |
| 432 refactoring.newName = 'newName'; | 432 refactoring.newName = 'newName'; |
| 433 // validate change | 433 // validate change |
| 434 return assertSuccessfulRefactoring(''' | 434 return assertSuccessfulRefactoring(''' |
| 435 myFunction({int newName}) { | 435 myFunction({int newName}) { |
| 436 newName = 1; | 436 newName = 1; |
| 437 newName += 2; | 437 newName += 2; |
| 438 print(newName); | 438 print(newName); |
| 439 } | 439 } |
| 440 main() { | 440 main() { |
| 441 myFunction(newName: 2); | 441 myFunction(newName: 2); |
| 442 } | 442 } |
| 443 '''); | 443 '''); |
| 444 } | 444 } |
| 445 | 445 |
| 446 test_createChange_parameter_named_inOtherFile() async { | 446 test_createChange_parameter_named_inOtherFile() async { |
| 447 indexTestUnit(''' | 447 await indexTestUnit(''' |
| 448 class A { | 448 class A { |
| 449 A({test}); | 449 A({test}); |
| 450 } | 450 } |
| 451 '''); | 451 '''); |
| 452 indexUnit( | 452 await indexUnit( |
| 453 '/test2.dart', | 453 '/test2.dart', |
| 454 ''' | 454 ''' |
| 455 import 'test.dart'; | 455 import 'test.dart'; |
| 456 main() { | 456 main() { |
| 457 new A(test: 2); | 457 new A(test: 2); |
| 458 } | 458 } |
| 459 '''); | 459 '''); |
| 460 // configure refactoring | 460 // configure refactoring |
| 461 createRenameRefactoringAtString('test});'); | 461 createRenameRefactoringAtString('test});'); |
| 462 expect(refactoring.refactoringName, 'Rename Parameter'); | 462 expect(refactoring.refactoringName, 'Rename Parameter'); |
| 463 refactoring.newName = 'newName'; | 463 refactoring.newName = 'newName'; |
| 464 // validate change | 464 // validate change |
| 465 await assertSuccessfulRefactoring(''' | 465 await assertSuccessfulRefactoring(''' |
| 466 class A { | 466 class A { |
| 467 A({newName}); | 467 A({newName}); |
| 468 } | 468 } |
| 469 '''); | 469 '''); |
| 470 assertFileChangeResult( | 470 assertFileChangeResult( |
| 471 '/test2.dart', | 471 '/test2.dart', |
| 472 ''' | 472 ''' |
| 473 import 'test.dart'; | 473 import 'test.dart'; |
| 474 main() { | 474 main() { |
| 475 new A(newName: 2); | 475 new A(newName: 2); |
| 476 } | 476 } |
| 477 '''); | 477 '''); |
| 478 } | 478 } |
| 479 | 479 |
| 480 test_createChange_parameter_named_updateHierarchy() async { | 480 test_createChange_parameter_named_updateHierarchy() async { |
| 481 indexUnit( | 481 await indexUnit( |
| 482 '/test2.dart', | 482 '/test2.dart', |
| 483 ''' | 483 ''' |
| 484 library test2; | 484 library test2; |
| 485 class A { | 485 class A { |
| 486 void foo({int test: 1}) { | 486 void foo({int test: 1}) { |
| 487 print(test); | 487 print(test); |
| 488 } | 488 } |
| 489 } | 489 } |
| 490 class B extends A { | 490 class B extends A { |
| 491 void foo({int test: 2}) { | 491 void foo({int test: 2}) { |
| 492 print(test); | 492 print(test); |
| 493 } | 493 } |
| 494 } | 494 } |
| 495 '''); | 495 '''); |
| 496 indexTestUnit(''' | 496 await indexTestUnit(''' |
| 497 import 'test2.dart'; | 497 import 'test2.dart'; |
| 498 main() { | 498 main() { |
| 499 new A().foo(test: 10); | 499 new A().foo(test: 10); |
| 500 new B().foo(test: 20); | 500 new B().foo(test: 20); |
| 501 new C().foo(test: 30); | 501 new C().foo(test: 30); |
| 502 } | 502 } |
| 503 class C extends A { | 503 class C extends A { |
| 504 void foo({int test: 3}) { | 504 void foo({int test: 3}) { |
| 505 print(test); | 505 print(test); |
| 506 } | 506 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 534 } | 534 } |
| 535 } | 535 } |
| 536 class B extends A { | 536 class B extends A { |
| 537 void foo({int newName: 2}) { | 537 void foo({int newName: 2}) { |
| 538 print(newName); | 538 print(newName); |
| 539 } | 539 } |
| 540 } | 540 } |
| 541 '''); | 541 '''); |
| 542 } | 542 } |
| 543 | 543 |
| 544 test_oldName() { | 544 test_oldName() async { |
| 545 indexTestUnit(''' | 545 await indexTestUnit(''' |
| 546 main() { | 546 main() { |
| 547 int test = 0; | 547 int test = 0; |
| 548 } | 548 } |
| 549 '''); | 549 '''); |
| 550 // configure refactoring | 550 // configure refactoring |
| 551 createRenameRefactoringAtString('test = 0'); | 551 createRenameRefactoringAtString('test = 0'); |
| 552 // old name | 552 // old name |
| 553 expect(refactoring.oldName, 'test'); | 553 expect(refactoring.oldName, 'test'); |
| 554 } | 554 } |
| 555 } | 555 } |
| OLD | NEW |