| 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.extract_local; | 5 library test.services.refactoring.extract_local; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 | 9 |
| 10 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 10 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
| 11 import 'package:analysis_server/src/services/correction/status.dart'; | 11 import 'package:analysis_server/src/services/correction/status.dart'; |
| 12 import 'package:analysis_server/src/services/refactoring/extract_local.dart'; | 12 import 'package:analysis_server/src/services/refactoring/extract_local.dart'; |
| 13 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | 13 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
| 14 import 'package:test/test.dart'; | 14 import 'package:test/test.dart'; |
| 15 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 15 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 16 | 16 |
| 17 import 'abstract_refactoring.dart'; | 17 import 'abstract_refactoring.dart'; |
| 18 | 18 |
| 19 main() { | 19 main() { |
| 20 defineReflectiveSuite(() { | 20 defineReflectiveSuite(() { |
| 21 defineReflectiveTests(ExtractLocalTest); | 21 defineReflectiveTests(ExtractLocalTest); |
| 22 }); | 22 }); |
| 23 } | 23 } |
| 24 | 24 |
| 25 @reflectiveTest | 25 @reflectiveTest |
| 26 class ExtractLocalTest extends RefactoringTest { | 26 class ExtractLocalTest extends RefactoringTest { |
| 27 ExtractLocalRefactoringImpl refactoring; | 27 ExtractLocalRefactoringImpl refactoring; |
| 28 | 28 |
| 29 test_checkFinalConditions_sameVariable_after() async { | 29 test_checkFinalConditions_sameVariable_after() async { |
| 30 indexTestUnit(''' | 30 await indexTestUnit(''' |
| 31 main() { | 31 main() { |
| 32 int a = 1 + 2; | 32 int a = 1 + 2; |
| 33 var res; | 33 var res; |
| 34 } | 34 } |
| 35 '''); | 35 '''); |
| 36 _createRefactoringForString('1 + 2'); | 36 _createRefactoringForString('1 + 2'); |
| 37 // conflicting name | 37 // conflicting name |
| 38 RefactoringStatus status = await refactoring.checkAllConditions(); | 38 RefactoringStatus status = await refactoring.checkAllConditions(); |
| 39 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 39 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
| 40 expectedMessage: "The name 'res' is already used in the scope."); | 40 expectedMessage: "The name 'res' is already used in the scope."); |
| 41 } | 41 } |
| 42 | 42 |
| 43 test_checkFinalConditions_sameVariable_before() async { | 43 test_checkFinalConditions_sameVariable_before() async { |
| 44 indexTestUnit(''' | 44 await indexTestUnit(''' |
| 45 main() { | 45 main() { |
| 46 var res; | 46 var res; |
| 47 int a = 1 + 2; | 47 int a = 1 + 2; |
| 48 } | 48 } |
| 49 '''); | 49 '''); |
| 50 _createRefactoringForString('1 + 2'); | 50 _createRefactoringForString('1 + 2'); |
| 51 // conflicting name | 51 // conflicting name |
| 52 RefactoringStatus status = await refactoring.checkAllConditions(); | 52 RefactoringStatus status = await refactoring.checkAllConditions(); |
| 53 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, | 53 assertRefactoringStatus(status, RefactoringProblemSeverity.ERROR, |
| 54 expectedMessage: "The name 'res' is already used in the scope."); | 54 expectedMessage: "The name 'res' is already used in the scope."); |
| 55 } | 55 } |
| 56 | 56 |
| 57 test_checkInitialConditions_assignmentLeftHandSize() async { | 57 test_checkInitialConditions_assignmentLeftHandSize() async { |
| 58 indexTestUnit(''' | 58 await indexTestUnit(''' |
| 59 main() { | 59 main() { |
| 60 var v = 0; | 60 var v = 0; |
| 61 v = 1; | 61 v = 1; |
| 62 } | 62 } |
| 63 '''); | 63 '''); |
| 64 _createRefactoringWithSuffix('v', ' = 1;'); | 64 _createRefactoringWithSuffix('v', ' = 1;'); |
| 65 // check conditions | 65 // check conditions |
| 66 RefactoringStatus status = await refactoring.checkAllConditions(); | 66 RefactoringStatus status = await refactoring.checkAllConditions(); |
| 67 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, | 67 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, |
| 68 expectedMessage: 'Cannot extract the left-hand side of an assignment.'); | 68 expectedMessage: 'Cannot extract the left-hand side of an assignment.'); |
| 69 } | 69 } |
| 70 | 70 |
| 71 test_checkInitialConditions_namePartOfDeclaration_function() async { | 71 test_checkInitialConditions_namePartOfDeclaration_function() async { |
| 72 indexTestUnit(''' | 72 await indexTestUnit(''' |
| 73 main() { | 73 main() { |
| 74 } | 74 } |
| 75 '''); | 75 '''); |
| 76 _createRefactoringWithSuffix('main', '()'); | 76 _createRefactoringWithSuffix('main', '()'); |
| 77 // check conditions | 77 // check conditions |
| 78 RefactoringStatus status = await refactoring.checkAllConditions(); | 78 RefactoringStatus status = await refactoring.checkAllConditions(); |
| 79 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, | 79 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, |
| 80 expectedMessage: 'Cannot extract the name part of a declaration.'); | 80 expectedMessage: 'Cannot extract the name part of a declaration.'); |
| 81 } | 81 } |
| 82 | 82 |
| 83 test_checkInitialConditions_namePartOfDeclaration_variable() async { | 83 test_checkInitialConditions_namePartOfDeclaration_variable() async { |
| 84 indexTestUnit(''' | 84 await indexTestUnit(''' |
| 85 main() { | 85 main() { |
| 86 int vvv = 0; | 86 int vvv = 0; |
| 87 } | 87 } |
| 88 '''); | 88 '''); |
| 89 _createRefactoringWithSuffix('vvv', ' = 0;'); | 89 _createRefactoringWithSuffix('vvv', ' = 0;'); |
| 90 // check conditions | 90 // check conditions |
| 91 RefactoringStatus status = await refactoring.checkAllConditions(); | 91 RefactoringStatus status = await refactoring.checkAllConditions(); |
| 92 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, | 92 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, |
| 93 expectedMessage: 'Cannot extract the name part of a declaration.'); | 93 expectedMessage: 'Cannot extract the name part of a declaration.'); |
| 94 } | 94 } |
| 95 | 95 |
| 96 test_checkInitialConditions_noExpression() async { | 96 test_checkInitialConditions_noExpression() async { |
| 97 indexTestUnit(''' | 97 await indexTestUnit(''' |
| 98 main() { | 98 main() { |
| 99 // abc | 99 // abc |
| 100 } | 100 } |
| 101 '''); | 101 '''); |
| 102 _createRefactoringForString('abc'); | 102 _createRefactoringForString('abc'); |
| 103 // check conditions | 103 // check conditions |
| 104 _assertInitialConditions_fatal_selection(); | 104 _assertInitialConditions_fatal_selection(); |
| 105 } | 105 } |
| 106 | 106 |
| 107 test_checkInitialConditions_notPartOfFunction() async { | 107 test_checkInitialConditions_notPartOfFunction() async { |
| 108 indexTestUnit(''' | 108 await indexTestUnit(''' |
| 109 int a = 1 + 2; | 109 int a = 1 + 2; |
| 110 '''); | 110 '''); |
| 111 _createRefactoringForString('1 + 2'); | 111 _createRefactoringForString('1 + 2'); |
| 112 // check conditions | 112 // check conditions |
| 113 RefactoringStatus status = await refactoring.checkAllConditions(); | 113 RefactoringStatus status = await refactoring.checkAllConditions(); |
| 114 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, | 114 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, |
| 115 expectedMessage: 'An expression inside a function must be selected ' | 115 expectedMessage: 'An expression inside a function must be selected ' |
| 116 'to activate this refactoring.'); | 116 'to activate this refactoring.'); |
| 117 } | 117 } |
| 118 | 118 |
| 119 test_checkInitialConditions_stringSelection_leadingQuote() async { | 119 test_checkInitialConditions_stringSelection_leadingQuote() async { |
| 120 indexTestUnit(''' | 120 await indexTestUnit(''' |
| 121 main() { | 121 main() { |
| 122 var vvv = 'abc'; | 122 var vvv = 'abc'; |
| 123 } | 123 } |
| 124 '''); | 124 '''); |
| 125 _createRefactoringForString("'a"); | 125 _createRefactoringForString("'a"); |
| 126 // apply refactoring | 126 // apply refactoring |
| 127 return _assertSuccessfulRefactoring(''' | 127 return _assertSuccessfulRefactoring(''' |
| 128 main() { | 128 main() { |
| 129 var res = 'abc'; | 129 var res = 'abc'; |
| 130 var vvv = res; | 130 var vvv = res; |
| 131 } | 131 } |
| 132 '''); | 132 '''); |
| 133 } | 133 } |
| 134 | 134 |
| 135 test_checkInitialConditions_stringSelection_trailingQuote() async { | 135 test_checkInitialConditions_stringSelection_trailingQuote() async { |
| 136 indexTestUnit(''' | 136 await indexTestUnit(''' |
| 137 main() { | 137 main() { |
| 138 var vvv = 'abc'; | 138 var vvv = 'abc'; |
| 139 } | 139 } |
| 140 '''); | 140 '''); |
| 141 _createRefactoringForString("c'"); | 141 _createRefactoringForString("c'"); |
| 142 // apply refactoring | 142 // apply refactoring |
| 143 return _assertSuccessfulRefactoring(''' | 143 return _assertSuccessfulRefactoring(''' |
| 144 main() { | 144 main() { |
| 145 var res = 'abc'; | 145 var res = 'abc'; |
| 146 var vvv = res; | 146 var vvv = res; |
| 147 } | 147 } |
| 148 '''); | 148 '''); |
| 149 } | 149 } |
| 150 | 150 |
| 151 test_checkInitialConditions_voidExpression() async { | 151 test_checkInitialConditions_voidExpression() async { |
| 152 indexTestUnit(''' | 152 await indexTestUnit(''' |
| 153 main() { | 153 main() { |
| 154 print(42); | 154 print(42); |
| 155 } | 155 } |
| 156 '''); | 156 '''); |
| 157 _createRefactoringForString('print'); | 157 _createRefactoringForString('print'); |
| 158 // check conditions | 158 // check conditions |
| 159 RefactoringStatus status = await refactoring.checkInitialConditions(); | 159 RefactoringStatus status = await refactoring.checkInitialConditions(); |
| 160 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, | 160 assertRefactoringStatus(status, RefactoringProblemSeverity.FATAL, |
| 161 expectedMessage: 'Cannot extract the void expression.'); | 161 expectedMessage: 'Cannot extract the void expression.'); |
| 162 } | 162 } |
| 163 | 163 |
| 164 test_checkName() { | 164 test_checkName() async { |
| 165 indexTestUnit(''' | 165 await indexTestUnit(''' |
| 166 main() { | 166 main() { |
| 167 int a = 1 + 2; | 167 int a = 1 + 2; |
| 168 } | 168 } |
| 169 '''); | 169 '''); |
| 170 _createRefactoringForString('1 + 2'); | 170 _createRefactoringForString('1 + 2'); |
| 171 expect(refactoring.refactoringName, 'Extract Local Variable'); | 171 expect(refactoring.refactoringName, 'Extract Local Variable'); |
| 172 // null | 172 // null |
| 173 refactoring.name = null; | 173 refactoring.name = null; |
| 174 assertRefactoringStatus( | 174 assertRefactoringStatus( |
| 175 refactoring.checkName(), RefactoringProblemSeverity.FATAL, | 175 refactoring.checkName(), RefactoringProblemSeverity.FATAL, |
| 176 expectedMessage: "Variable name must not be null."); | 176 expectedMessage: "Variable name must not be null."); |
| 177 // empty | 177 // empty |
| 178 refactoring.name = ''; | 178 refactoring.name = ''; |
| 179 assertRefactoringStatus( | 179 assertRefactoringStatus( |
| 180 refactoring.checkName(), RefactoringProblemSeverity.FATAL, | 180 refactoring.checkName(), RefactoringProblemSeverity.FATAL, |
| 181 expectedMessage: "Variable name must not be empty."); | 181 expectedMessage: "Variable name must not be empty."); |
| 182 // OK | 182 // OK |
| 183 refactoring.name = 'res'; | 183 refactoring.name = 'res'; |
| 184 assertRefactoringStatusOK(refactoring.checkName()); | 184 assertRefactoringStatusOK(refactoring.checkName()); |
| 185 } | 185 } |
| 186 | 186 |
| 187 test_checkName_conflict_withInvokedFunction() async { | 187 test_checkName_conflict_withInvokedFunction() async { |
| 188 indexTestUnit(''' | 188 await indexTestUnit(''' |
| 189 main() { | 189 main() { |
| 190 int a = 1 + 2; | 190 int a = 1 + 2; |
| 191 res(); | 191 res(); |
| 192 } | 192 } |
| 193 | 193 |
| 194 void res() {} | 194 void res() {} |
| 195 '''); | 195 '''); |
| 196 _createRefactoringForString('1 + 2'); | 196 _createRefactoringForString('1 + 2'); |
| 197 await refactoring.checkInitialConditions(); | 197 await refactoring.checkInitialConditions(); |
| 198 refactoring.name = 'res'; | 198 refactoring.name = 'res'; |
| 199 assertRefactoringStatus( | 199 assertRefactoringStatus( |
| 200 refactoring.checkName(), RefactoringProblemSeverity.ERROR, | 200 refactoring.checkName(), RefactoringProblemSeverity.ERROR, |
| 201 expectedMessage: "The name 'res' is already used in the scope."); | 201 expectedMessage: "The name 'res' is already used in the scope."); |
| 202 } | 202 } |
| 203 | 203 |
| 204 test_checkName_conflict_withOtherLocal() async { | 204 test_checkName_conflict_withOtherLocal() async { |
| 205 indexTestUnit(''' | 205 await indexTestUnit(''' |
| 206 main() { | 206 main() { |
| 207 var res; | 207 var res; |
| 208 int a = 1 + 2; | 208 int a = 1 + 2; |
| 209 } | 209 } |
| 210 '''); | 210 '''); |
| 211 _createRefactoringForString('1 + 2'); | 211 _createRefactoringForString('1 + 2'); |
| 212 await refactoring.checkInitialConditions(); | 212 await refactoring.checkInitialConditions(); |
| 213 refactoring.name = 'res'; | 213 refactoring.name = 'res'; |
| 214 assertRefactoringStatus( | 214 assertRefactoringStatus( |
| 215 refactoring.checkName(), RefactoringProblemSeverity.ERROR, | 215 refactoring.checkName(), RefactoringProblemSeverity.ERROR, |
| 216 expectedMessage: "The name 'res' is already used in the scope."); | 216 expectedMessage: "The name 'res' is already used in the scope."); |
| 217 } | 217 } |
| 218 | 218 |
| 219 test_checkName_conflict_withTypeName() async { | 219 test_checkName_conflict_withTypeName() async { |
| 220 indexTestUnit(''' | 220 await indexTestUnit(''' |
| 221 main() { | 221 main() { |
| 222 int a = 1 + 2; | 222 int a = 1 + 2; |
| 223 Res b = null; | 223 Res b = null; |
| 224 } | 224 } |
| 225 | 225 |
| 226 class Res {} | 226 class Res {} |
| 227 '''); | 227 '''); |
| 228 _createRefactoringForString('1 + 2'); | 228 _createRefactoringForString('1 + 2'); |
| 229 await refactoring.checkInitialConditions(); | 229 await refactoring.checkInitialConditions(); |
| 230 refactoring.name = 'Res'; | 230 refactoring.name = 'Res'; |
| 231 assertRefactoringStatus( | 231 assertRefactoringStatus( |
| 232 refactoring.checkName(), RefactoringProblemSeverity.ERROR, | 232 refactoring.checkName(), RefactoringProblemSeverity.ERROR, |
| 233 expectedMessage: "The name 'Res' is already used in the scope."); | 233 expectedMessage: "The name 'Res' is already used in the scope."); |
| 234 } | 234 } |
| 235 | 235 |
| 236 test_completeStatementExpression() { | 236 test_completeStatementExpression() async { |
| 237 indexTestUnit(''' | 237 await indexTestUnit(''' |
| 238 main(p) { | 238 main(p) { |
| 239 p.toString(); | 239 p.toString(); |
| 240 } | 240 } |
| 241 '''); | 241 '''); |
| 242 _createRefactoringForString('p.toString()'); | 242 _createRefactoringForString('p.toString()'); |
| 243 // apply refactoring | 243 // apply refactoring |
| 244 return _assertSuccessfulRefactoring(''' | 244 return _assertSuccessfulRefactoring(''' |
| 245 main(p) { | 245 main(p) { |
| 246 var res = p.toString(); | 246 var res = p.toString(); |
| 247 } | 247 } |
| 248 '''); | 248 '''); |
| 249 } | 249 } |
| 250 | 250 |
| 251 test_const_argument_inConstInstanceCreation() { | 251 test_const_argument_inConstInstanceCreation() async { |
| 252 indexTestUnit(''' | 252 await indexTestUnit(''' |
| 253 class A { | 253 class A { |
| 254 const A(int a, int b); | 254 const A(int a, int b); |
| 255 } | 255 } |
| 256 main() { | 256 main() { |
| 257 const A(1, 2); | 257 const A(1, 2); |
| 258 } | 258 } |
| 259 '''); | 259 '''); |
| 260 _createRefactoringForString('1'); | 260 _createRefactoringForString('1'); |
| 261 // apply refactoring | 261 // apply refactoring |
| 262 return _assertSuccessfulRefactoring(''' | 262 return _assertSuccessfulRefactoring(''' |
| 263 class A { | 263 class A { |
| 264 const A(int a, int b); | 264 const A(int a, int b); |
| 265 } | 265 } |
| 266 main() { | 266 main() { |
| 267 const res = 1; | 267 const res = 1; |
| 268 const A(res, 2); | 268 const A(res, 2); |
| 269 } | 269 } |
| 270 '''); | 270 '''); |
| 271 } | 271 } |
| 272 | 272 |
| 273 test_const_inList() { | 273 test_const_inList() async { |
| 274 indexTestUnit(''' | 274 await indexTestUnit(''' |
| 275 main() { | 275 main() { |
| 276 const [1, 2]; | 276 const [1, 2]; |
| 277 } | 277 } |
| 278 '''); | 278 '''); |
| 279 _createRefactoringForString('1'); | 279 _createRefactoringForString('1'); |
| 280 // apply refactoring | 280 // apply refactoring |
| 281 return _assertSuccessfulRefactoring(''' | 281 return _assertSuccessfulRefactoring(''' |
| 282 main() { | 282 main() { |
| 283 const res = 1; | 283 const res = 1; |
| 284 const [res, 2]; | 284 const [res, 2]; |
| 285 } | 285 } |
| 286 '''); | 286 '''); |
| 287 } | 287 } |
| 288 | 288 |
| 289 test_const_inList_inBinaryExpression() { | 289 test_const_inList_inBinaryExpression() async { |
| 290 indexTestUnit(''' | 290 await indexTestUnit(''' |
| 291 main() { | 291 main() { |
| 292 const [1 + 2, 3]; | 292 const [1 + 2, 3]; |
| 293 } | 293 } |
| 294 '''); | 294 '''); |
| 295 _createRefactoringForString('1'); | 295 _createRefactoringForString('1'); |
| 296 // apply refactoring | 296 // apply refactoring |
| 297 return _assertSuccessfulRefactoring(''' | 297 return _assertSuccessfulRefactoring(''' |
| 298 main() { | 298 main() { |
| 299 const res = 1; | 299 const res = 1; |
| 300 const [res + 2, 3]; | 300 const [res + 2, 3]; |
| 301 } | 301 } |
| 302 '''); | 302 '''); |
| 303 } | 303 } |
| 304 | 304 |
| 305 test_const_inList_inConditionalExpression() { | 305 test_const_inList_inConditionalExpression() async { |
| 306 indexTestUnit(''' | 306 await indexTestUnit(''' |
| 307 main() { | 307 main() { |
| 308 const [true ? 1 : 2, 3]; | 308 const [true ? 1 : 2, 3]; |
| 309 } | 309 } |
| 310 '''); | 310 '''); |
| 311 _createRefactoringForString('1'); | 311 _createRefactoringForString('1'); |
| 312 // apply refactoring | 312 // apply refactoring |
| 313 return _assertSuccessfulRefactoring(''' | 313 return _assertSuccessfulRefactoring(''' |
| 314 main() { | 314 main() { |
| 315 const res = 1; | 315 const res = 1; |
| 316 const [true ? res : 2, 3]; | 316 const [true ? res : 2, 3]; |
| 317 } | 317 } |
| 318 '''); | 318 '''); |
| 319 } | 319 } |
| 320 | 320 |
| 321 test_const_inList_inParenthesis() { | 321 test_const_inList_inParenthesis() async { |
| 322 indexTestUnit(''' | 322 await indexTestUnit(''' |
| 323 main() { | 323 main() { |
| 324 const [(1), 2]; | 324 const [(1), 2]; |
| 325 } | 325 } |
| 326 '''); | 326 '''); |
| 327 _createRefactoringForString('1'); | 327 _createRefactoringForString('1'); |
| 328 // apply refactoring | 328 // apply refactoring |
| 329 return _assertSuccessfulRefactoring(''' | 329 return _assertSuccessfulRefactoring(''' |
| 330 main() { | 330 main() { |
| 331 const res = 1; | 331 const res = 1; |
| 332 const [(res), 2]; | 332 const [(res), 2]; |
| 333 } | 333 } |
| 334 '''); | 334 '''); |
| 335 } | 335 } |
| 336 | 336 |
| 337 test_const_inList_inPrefixExpression() { | 337 test_const_inList_inPrefixExpression() async { |
| 338 indexTestUnit(''' | 338 await indexTestUnit(''' |
| 339 main() { | 339 main() { |
| 340 const [!true, 2]; | 340 const [!true, 2]; |
| 341 } | 341 } |
| 342 '''); | 342 '''); |
| 343 _createRefactoringForString('true'); | 343 _createRefactoringForString('true'); |
| 344 // apply refactoring | 344 // apply refactoring |
| 345 return _assertSuccessfulRefactoring(''' | 345 return _assertSuccessfulRefactoring(''' |
| 346 main() { | 346 main() { |
| 347 const res = true; | 347 const res = true; |
| 348 const [!res, 2]; | 348 const [!res, 2]; |
| 349 } | 349 } |
| 350 '''); | 350 '''); |
| 351 } | 351 } |
| 352 | 352 |
| 353 test_const_inMap_key() { | 353 test_const_inMap_key() async { |
| 354 indexTestUnit(''' | 354 await indexTestUnit(''' |
| 355 main() { | 355 main() { |
| 356 const {1: 2}; | 356 const {1: 2}; |
| 357 } | 357 } |
| 358 '''); | 358 '''); |
| 359 _createRefactoringForString('1'); | 359 _createRefactoringForString('1'); |
| 360 // apply refactoring | 360 // apply refactoring |
| 361 return _assertSuccessfulRefactoring(''' | 361 return _assertSuccessfulRefactoring(''' |
| 362 main() { | 362 main() { |
| 363 const res = 1; | 363 const res = 1; |
| 364 const {res: 2}; | 364 const {res: 2}; |
| 365 } | 365 } |
| 366 '''); | 366 '''); |
| 367 } | 367 } |
| 368 | 368 |
| 369 test_const_inMap_value() { | 369 test_const_inMap_value() async { |
| 370 indexTestUnit(''' | 370 await indexTestUnit(''' |
| 371 main() { | 371 main() { |
| 372 const {1: 2}; | 372 const {1: 2}; |
| 373 } | 373 } |
| 374 '''); | 374 '''); |
| 375 _createRefactoringForString('2'); | 375 _createRefactoringForString('2'); |
| 376 // apply refactoring | 376 // apply refactoring |
| 377 return _assertSuccessfulRefactoring(''' | 377 return _assertSuccessfulRefactoring(''' |
| 378 main() { | 378 main() { |
| 379 const res = 2; | 379 const res = 2; |
| 380 const {1: res}; | 380 const {1: res}; |
| 381 } | 381 } |
| 382 '''); | 382 '''); |
| 383 } | 383 } |
| 384 | 384 |
| 385 test_coveringExpressions() async { | 385 test_coveringExpressions() async { |
| 386 indexTestUnit(''' | 386 await indexTestUnit(''' |
| 387 main() { | 387 main() { |
| 388 int aaa = 1; | 388 int aaa = 1; |
| 389 int bbb = 2; | 389 int bbb = 2; |
| 390 var c = aaa + bbb * 2 + 3; | 390 var c = aaa + bbb * 2 + 3; |
| 391 } | 391 } |
| 392 '''); | 392 '''); |
| 393 _createRefactoring(testCode.indexOf('bb * 2'), 0); | 393 _createRefactoring(testCode.indexOf('bb * 2'), 0); |
| 394 // check conditions | 394 // check conditions |
| 395 await refactoring.checkInitialConditions(); | 395 await refactoring.checkInitialConditions(); |
| 396 List<String> subExpressions = _getCoveringExpressions(); | 396 List<String> subExpressions = _getCoveringExpressions(); |
| 397 expect(subExpressions, | 397 expect(subExpressions, |
| 398 ['bbb', 'bbb * 2', 'aaa + bbb * 2', 'aaa + bbb * 2 + 3']); | 398 ['bbb', 'bbb * 2', 'aaa + bbb * 2', 'aaa + bbb * 2 + 3']); |
| 399 } | 399 } |
| 400 | 400 |
| 401 test_coveringExpressions_inArgumentList() async { | 401 test_coveringExpressions_inArgumentList() async { |
| 402 indexTestUnit(''' | 402 await indexTestUnit(''' |
| 403 main() { | 403 main() { |
| 404 foo(111 + 222); | 404 foo(111 + 222); |
| 405 } | 405 } |
| 406 int foo(int x) => x; | 406 int foo(int x) => x; |
| 407 '''); | 407 '''); |
| 408 _createRefactoring(testCode.indexOf('11 +'), 0); | 408 _createRefactoring(testCode.indexOf('11 +'), 0); |
| 409 // check conditions | 409 // check conditions |
| 410 await refactoring.checkInitialConditions(); | 410 await refactoring.checkInitialConditions(); |
| 411 List<String> subExpressions = _getCoveringExpressions(); | 411 List<String> subExpressions = _getCoveringExpressions(); |
| 412 expect(subExpressions, ['111', '111 + 222', 'foo(111 + 222)']); | 412 expect(subExpressions, ['111', '111 + 222', 'foo(111 + 222)']); |
| 413 } | 413 } |
| 414 | 414 |
| 415 test_coveringExpressions_inInvocationOfVoidFunction() async { | 415 test_coveringExpressions_inInvocationOfVoidFunction() async { |
| 416 indexTestUnit(''' | 416 await indexTestUnit(''' |
| 417 main() { | 417 main() { |
| 418 foo(111 + 222); | 418 foo(111 + 222); |
| 419 } | 419 } |
| 420 void foo(int x) {} | 420 void foo(int x) {} |
| 421 '''); | 421 '''); |
| 422 _createRefactoring(testCode.indexOf('11 +'), 0); | 422 _createRefactoring(testCode.indexOf('11 +'), 0); |
| 423 // check conditions | 423 // check conditions |
| 424 await refactoring.checkInitialConditions(); | 424 await refactoring.checkInitialConditions(); |
| 425 List<String> subExpressions = _getCoveringExpressions(); | 425 List<String> subExpressions = _getCoveringExpressions(); |
| 426 expect(subExpressions, ['111', '111 + 222']); | 426 expect(subExpressions, ['111', '111 + 222']); |
| 427 } | 427 } |
| 428 | 428 |
| 429 test_coveringExpressions_namedExpression_value() async { | 429 test_coveringExpressions_namedExpression_value() async { |
| 430 indexTestUnit(''' | 430 await indexTestUnit(''' |
| 431 main() { | 431 main() { |
| 432 foo(ppp: 42); | 432 foo(ppp: 42); |
| 433 } | 433 } |
| 434 int foo({int ppp: 0}) => ppp + 1; | 434 int foo({int ppp: 0}) => ppp + 1; |
| 435 '''); | 435 '''); |
| 436 _createRefactoring(testCode.indexOf('42'), 0); | 436 _createRefactoring(testCode.indexOf('42'), 0); |
| 437 // check conditions | 437 // check conditions |
| 438 await refactoring.checkInitialConditions(); | 438 await refactoring.checkInitialConditions(); |
| 439 List<String> subExpressions = _getCoveringExpressions(); | 439 List<String> subExpressions = _getCoveringExpressions(); |
| 440 expect(subExpressions, ['42', 'foo(ppp: 42)']); | 440 expect(subExpressions, ['42', 'foo(ppp: 42)']); |
| 441 } | 441 } |
| 442 | 442 |
| 443 test_coveringExpressions_skip_assignment() async { | 443 test_coveringExpressions_skip_assignment() async { |
| 444 indexTestUnit(''' | 444 await indexTestUnit(''' |
| 445 main() { | 445 main() { |
| 446 int v; | 446 int v; |
| 447 foo(v = 111 + 222); | 447 foo(v = 111 + 222); |
| 448 } | 448 } |
| 449 int foo(x) => 42; | 449 int foo(x) => 42; |
| 450 '''); | 450 '''); |
| 451 _createRefactoring(testCode.indexOf('11 +'), 0); | 451 _createRefactoring(testCode.indexOf('11 +'), 0); |
| 452 // check conditions | 452 // check conditions |
| 453 await refactoring.checkInitialConditions(); | 453 await refactoring.checkInitialConditions(); |
| 454 List<String> subExpressions = _getCoveringExpressions(); | 454 List<String> subExpressions = _getCoveringExpressions(); |
| 455 expect(subExpressions, ['111', '111 + 222', 'foo(v = 111 + 222)']); | 455 expect(subExpressions, ['111', '111 + 222', 'foo(v = 111 + 222)']); |
| 456 } | 456 } |
| 457 | 457 |
| 458 test_coveringExpressions_skip_constructorName() async { | 458 test_coveringExpressions_skip_constructorName() async { |
| 459 indexTestUnit(''' | 459 await indexTestUnit(''' |
| 460 class AAA { | 460 class AAA { |
| 461 AAA.name() {} | 461 AAA.name() {} |
| 462 } | 462 } |
| 463 main() { | 463 main() { |
| 464 int v = new AAA.name(); | 464 int v = new AAA.name(); |
| 465 } | 465 } |
| 466 '''); | 466 '''); |
| 467 _createRefactoring(testCode.indexOf('AA.name();'), 5); | 467 _createRefactoring(testCode.indexOf('AA.name();'), 5); |
| 468 // check conditions | 468 // check conditions |
| 469 await refactoring.checkInitialConditions(); | 469 await refactoring.checkInitialConditions(); |
| 470 List<String> subExpressions = _getCoveringExpressions(); | 470 List<String> subExpressions = _getCoveringExpressions(); |
| 471 expect(subExpressions, ['new AAA.name()']); | 471 expect(subExpressions, ['new AAA.name()']); |
| 472 } | 472 } |
| 473 | 473 |
| 474 test_coveringExpressions_skip_constructorName_name() async { | 474 test_coveringExpressions_skip_constructorName_name() async { |
| 475 indexTestUnit(''' | 475 await indexTestUnit(''' |
| 476 class A { | 476 class A { |
| 477 A.name() {} | 477 A.name() {} |
| 478 } | 478 } |
| 479 main() { | 479 main() { |
| 480 int v = new A.name(); | 480 int v = new A.name(); |
| 481 } | 481 } |
| 482 '''); | 482 '''); |
| 483 _createRefactoring(testCode.indexOf('ame();'), 0); | 483 _createRefactoring(testCode.indexOf('ame();'), 0); |
| 484 // check conditions | 484 // check conditions |
| 485 await refactoring.checkInitialConditions(); | 485 await refactoring.checkInitialConditions(); |
| 486 List<String> subExpressions = _getCoveringExpressions(); | 486 List<String> subExpressions = _getCoveringExpressions(); |
| 487 expect(subExpressions, ['new A.name()']); | 487 expect(subExpressions, ['new A.name()']); |
| 488 } | 488 } |
| 489 | 489 |
| 490 test_coveringExpressions_skip_constructorName_type() async { | 490 test_coveringExpressions_skip_constructorName_type() async { |
| 491 indexTestUnit(''' | 491 await indexTestUnit(''' |
| 492 class A {} | 492 class A {} |
| 493 main() { | 493 main() { |
| 494 int v = new A(); | 494 int v = new A(); |
| 495 } | 495 } |
| 496 '''); | 496 '''); |
| 497 _createRefactoring(testCode.indexOf('A();'), 0); | 497 _createRefactoring(testCode.indexOf('A();'), 0); |
| 498 // check conditions | 498 // check conditions |
| 499 await refactoring.checkInitialConditions(); | 499 await refactoring.checkInitialConditions(); |
| 500 List<String> subExpressions = _getCoveringExpressions(); | 500 List<String> subExpressions = _getCoveringExpressions(); |
| 501 expect(subExpressions, ['new A()']); | 501 expect(subExpressions, ['new A()']); |
| 502 } | 502 } |
| 503 | 503 |
| 504 test_coveringExpressions_skip_constructorName_typeArgument() async { | 504 test_coveringExpressions_skip_constructorName_typeArgument() async { |
| 505 indexTestUnit(''' | 505 await indexTestUnit(''' |
| 506 class A<T> {} | 506 class A<T> {} |
| 507 main() { | 507 main() { |
| 508 int v = new A<String>(); | 508 int v = new A<String>(); |
| 509 } | 509 } |
| 510 '''); | 510 '''); |
| 511 _createRefactoring(testCode.indexOf('ring>'), 0); | 511 _createRefactoring(testCode.indexOf('ring>'), 0); |
| 512 // check conditions | 512 // check conditions |
| 513 await refactoring.checkInitialConditions(); | 513 await refactoring.checkInitialConditions(); |
| 514 List<String> subExpressions = _getCoveringExpressions(); | 514 List<String> subExpressions = _getCoveringExpressions(); |
| 515 expect(subExpressions, ['new A<String>()']); | 515 expect(subExpressions, ['new A<String>()']); |
| 516 } | 516 } |
| 517 | 517 |
| 518 test_coveringExpressions_skip_namedExpression() async { | 518 test_coveringExpressions_skip_namedExpression() async { |
| 519 indexTestUnit(''' | 519 await indexTestUnit(''' |
| 520 main() { | 520 main() { |
| 521 foo(ppp: 42); | 521 foo(ppp: 42); |
| 522 } | 522 } |
| 523 int foo({int ppp: 0}) => ppp + 1; | 523 int foo({int ppp: 0}) => ppp + 1; |
| 524 '''); | 524 '''); |
| 525 _createRefactoring(testCode.indexOf('pp: 42'), 0); | 525 _createRefactoring(testCode.indexOf('pp: 42'), 0); |
| 526 // check conditions | 526 // check conditions |
| 527 await refactoring.checkInitialConditions(); | 527 await refactoring.checkInitialConditions(); |
| 528 List<String> subExpressions = _getCoveringExpressions(); | 528 List<String> subExpressions = _getCoveringExpressions(); |
| 529 expect(subExpressions, ['foo(ppp: 42)']); | 529 expect(subExpressions, ['foo(ppp: 42)']); |
| 530 } | 530 } |
| 531 | 531 |
| 532 test_fragmentExpression() { | 532 test_fragmentExpression() async { |
| 533 indexTestUnit(''' | 533 await indexTestUnit(''' |
| 534 main() { | 534 main() { |
| 535 int a = 1 + 2 + 3 + 4; | 535 int a = 1 + 2 + 3 + 4; |
| 536 } | 536 } |
| 537 '''); | 537 '''); |
| 538 _createRefactoringForString('2 + 3'); | 538 _createRefactoringForString('2 + 3'); |
| 539 // apply refactoring | 539 // apply refactoring |
| 540 return _assertSuccessfulRefactoring(''' | 540 return _assertSuccessfulRefactoring(''' |
| 541 main() { | 541 main() { |
| 542 var res = 1 + 2 + 3; | 542 var res = 1 + 2 + 3; |
| 543 int a = res + 4; | 543 int a = res + 4; |
| 544 } | 544 } |
| 545 '''); | 545 '''); |
| 546 } | 546 } |
| 547 | 547 |
| 548 test_fragmentExpression_leadingNotWhitespace() { | 548 test_fragmentExpression_leadingNotWhitespace() async { |
| 549 indexTestUnit(''' | 549 await indexTestUnit(''' |
| 550 main() { | 550 main() { |
| 551 int a = 1 + 2 + 3 + 4; | 551 int a = 1 + 2 + 3 + 4; |
| 552 } | 552 } |
| 553 '''); | 553 '''); |
| 554 _createRefactoringForString('+ 2'); | 554 _createRefactoringForString('+ 2'); |
| 555 // apply refactoring | 555 // apply refactoring |
| 556 return _assertSuccessfulRefactoring(''' | 556 return _assertSuccessfulRefactoring(''' |
| 557 main() { | 557 main() { |
| 558 var res = 1 + 2; | 558 var res = 1 + 2; |
| 559 int a = res + 3 + 4; | 559 int a = res + 3 + 4; |
| 560 } | 560 } |
| 561 '''); | 561 '''); |
| 562 } | 562 } |
| 563 | 563 |
| 564 test_fragmentExpression_leadingPartialSelection() { | 564 test_fragmentExpression_leadingPartialSelection() async { |
| 565 indexTestUnit(''' | 565 await indexTestUnit(''' |
| 566 main() { | 566 main() { |
| 567 int a = 111 + 2 + 3 + 4; | 567 int a = 111 + 2 + 3 + 4; |
| 568 } | 568 } |
| 569 '''); | 569 '''); |
| 570 _createRefactoringForString('11 + 2'); | 570 _createRefactoringForString('11 + 2'); |
| 571 // apply refactoring | 571 // apply refactoring |
| 572 return _assertSuccessfulRefactoring(''' | 572 return _assertSuccessfulRefactoring(''' |
| 573 main() { | 573 main() { |
| 574 var res = 111 + 2; | 574 var res = 111 + 2; |
| 575 int a = res + 3 + 4; | 575 int a = res + 3 + 4; |
| 576 } | 576 } |
| 577 '''); | 577 '''); |
| 578 } | 578 } |
| 579 | 579 |
| 580 test_fragmentExpression_leadingWhitespace() { | 580 test_fragmentExpression_leadingWhitespace() async { |
| 581 indexTestUnit(''' | 581 await indexTestUnit(''' |
| 582 main() { | 582 main() { |
| 583 int a = 1 + 2 + 3 + 4; | 583 int a = 1 + 2 + 3 + 4; |
| 584 } | 584 } |
| 585 '''); | 585 '''); |
| 586 _createRefactoringForString(' 2 + 3'); | 586 _createRefactoringForString(' 2 + 3'); |
| 587 // apply refactoring | 587 // apply refactoring |
| 588 return _assertSuccessfulRefactoring(''' | 588 return _assertSuccessfulRefactoring(''' |
| 589 main() { | 589 main() { |
| 590 var res = 1 + 2 + 3; | 590 var res = 1 + 2 + 3; |
| 591 int a = res + 4; | 591 int a = res + 4; |
| 592 } | 592 } |
| 593 '''); | 593 '''); |
| 594 } | 594 } |
| 595 | 595 |
| 596 test_fragmentExpression_notAssociativeOperator() { | 596 test_fragmentExpression_notAssociativeOperator() async { |
| 597 indexTestUnit(''' | 597 await indexTestUnit(''' |
| 598 main() { | 598 main() { |
| 599 int a = 1 - 2 - 3 - 4; | 599 int a = 1 - 2 - 3 - 4; |
| 600 } | 600 } |
| 601 '''); | 601 '''); |
| 602 _createRefactoringForString('2 - 3'); | 602 _createRefactoringForString('2 - 3'); |
| 603 // apply refactoring | 603 // apply refactoring |
| 604 return _assertSuccessfulRefactoring(''' | 604 return _assertSuccessfulRefactoring(''' |
| 605 main() { | 605 main() { |
| 606 var res = 1 - 2 - 3; | 606 var res = 1 - 2 - 3; |
| 607 int a = res - 4; | 607 int a = res - 4; |
| 608 } | 608 } |
| 609 '''); | 609 '''); |
| 610 } | 610 } |
| 611 | 611 |
| 612 test_fragmentExpression_trailingNotWhitespace() { | 612 test_fragmentExpression_trailingNotWhitespace() async { |
| 613 indexTestUnit(''' | 613 await indexTestUnit(''' |
| 614 main() { | 614 main() { |
| 615 int a = 1 + 2 + 3 + 4; | 615 int a = 1 + 2 + 3 + 4; |
| 616 } | 616 } |
| 617 '''); | 617 '''); |
| 618 _createRefactoringForString('1 + 2 +'); | 618 _createRefactoringForString('1 + 2 +'); |
| 619 // apply refactoring | 619 // apply refactoring |
| 620 return _assertSuccessfulRefactoring(''' | 620 return _assertSuccessfulRefactoring(''' |
| 621 main() { | 621 main() { |
| 622 var res = 1 + 2 + 3; | 622 var res = 1 + 2 + 3; |
| 623 int a = res + 4; | 623 int a = res + 4; |
| 624 } | 624 } |
| 625 '''); | 625 '''); |
| 626 } | 626 } |
| 627 | 627 |
| 628 test_fragmentExpression_trailingPartialSelection() { | 628 test_fragmentExpression_trailingPartialSelection() async { |
| 629 indexTestUnit(''' | 629 await indexTestUnit(''' |
| 630 main() { | 630 main() { |
| 631 int a = 1 + 2 + 333 + 4; | 631 int a = 1 + 2 + 333 + 4; |
| 632 } | 632 } |
| 633 '''); | 633 '''); |
| 634 _createRefactoringForString('2 + 33'); | 634 _createRefactoringForString('2 + 33'); |
| 635 // apply refactoring | 635 // apply refactoring |
| 636 return _assertSuccessfulRefactoring(''' | 636 return _assertSuccessfulRefactoring(''' |
| 637 main() { | 637 main() { |
| 638 var res = 1 + 2 + 333; | 638 var res = 1 + 2 + 333; |
| 639 int a = res + 4; | 639 int a = res + 4; |
| 640 } | 640 } |
| 641 '''); | 641 '''); |
| 642 } | 642 } |
| 643 | 643 |
| 644 test_fragmentExpression_trailingWhitespace() { | 644 test_fragmentExpression_trailingWhitespace() async { |
| 645 indexTestUnit(''' | 645 await indexTestUnit(''' |
| 646 main() { | 646 main() { |
| 647 int a = 1 + 2 + 3 + 4; | 647 int a = 1 + 2 + 3 + 4; |
| 648 } | 648 } |
| 649 '''); | 649 '''); |
| 650 _createRefactoringForString('2 + 3 '); | 650 _createRefactoringForString('2 + 3 '); |
| 651 // apply refactoring | 651 // apply refactoring |
| 652 return _assertSuccessfulRefactoring(''' | 652 return _assertSuccessfulRefactoring(''' |
| 653 main() { | 653 main() { |
| 654 var res = 1 + 2 + 3; | 654 var res = 1 + 2 + 3; |
| 655 int a = res + 4; | 655 int a = res + 4; |
| 656 } | 656 } |
| 657 '''); | 657 '''); |
| 658 } | 658 } |
| 659 | 659 |
| 660 test_guessNames_fragmentExpression() async { | 660 test_guessNames_fragmentExpression() async { |
| 661 indexTestUnit(''' | 661 await indexTestUnit(''' |
| 662 main() { | 662 main() { |
| 663 var a = 111 + 222 + 333 + 444; | 663 var a = 111 + 222 + 333 + 444; |
| 664 } | 664 } |
| 665 '''); | 665 '''); |
| 666 _createRefactoringForString('222 + 333'); | 666 _createRefactoringForString('222 + 333'); |
| 667 // check guesses | 667 // check guesses |
| 668 await refactoring.checkInitialConditions(); | 668 await refactoring.checkInitialConditions(); |
| 669 expect(refactoring.names, unorderedEquals(['i'])); | 669 expect(refactoring.names, unorderedEquals(['i'])); |
| 670 } | 670 } |
| 671 | 671 |
| 672 test_guessNames_singleExpression() async { | 672 test_guessNames_singleExpression() async { |
| 673 indexTestUnit(''' | 673 await indexTestUnit(''' |
| 674 class TreeItem {} | 674 class TreeItem {} |
| 675 TreeItem getSelectedItem() => null; | 675 TreeItem getSelectedItem() => null; |
| 676 process(my) {} | 676 process(my) {} |
| 677 main() { | 677 main() { |
| 678 process(getSelectedItem()); // marker | 678 process(getSelectedItem()); // marker |
| 679 } | 679 } |
| 680 '''); | 680 '''); |
| 681 _createRefactoringWithSuffix('getSelectedItem()', '); // marker'); | 681 _createRefactoringWithSuffix('getSelectedItem()', '); // marker'); |
| 682 // check guesses | 682 // check guesses |
| 683 await refactoring.checkInitialConditions(); | 683 await refactoring.checkInitialConditions(); |
| 684 expect(refactoring.names, | 684 expect(refactoring.names, |
| 685 unorderedEquals(['selectedItem', 'item', 'my', 'treeItem'])); | 685 unorderedEquals(['selectedItem', 'item', 'my', 'treeItem'])); |
| 686 } | 686 } |
| 687 | 687 |
| 688 test_guessNames_stringPart() async { | 688 test_guessNames_stringPart() async { |
| 689 indexTestUnit(''' | 689 await indexTestUnit(''' |
| 690 main() { | 690 main() { |
| 691 var s = 'Hello Bob... welcome to Dart!'; | 691 var s = 'Hello Bob... welcome to Dart!'; |
| 692 } | 692 } |
| 693 '''); | 693 '''); |
| 694 _createRefactoringForString('Hello Bob'); | 694 _createRefactoringForString('Hello Bob'); |
| 695 // check guesses | 695 // check guesses |
| 696 await refactoring.checkInitialConditions(); | 696 await refactoring.checkInitialConditions(); |
| 697 expect(refactoring.names, unorderedEquals(['helloBob', 'bob'])); | 697 expect(refactoring.names, unorderedEquals(['helloBob', 'bob'])); |
| 698 } | 698 } |
| 699 | 699 |
| 700 test_occurrences_differentVariable() async { | 700 test_occurrences_differentVariable() async { |
| 701 indexTestUnit(''' | 701 await indexTestUnit(''' |
| 702 main() { | 702 main() { |
| 703 { | 703 { |
| 704 int v = 1; | 704 int v = 1; |
| 705 print(v + 1); // marker | 705 print(v + 1); // marker |
| 706 print(v + 1); | 706 print(v + 1); |
| 707 } | 707 } |
| 708 { | 708 { |
| 709 int v = 2; | 709 int v = 2; |
| 710 print(v + 1); | 710 print(v + 1); |
| 711 } | 711 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 724 { | 724 { |
| 725 int v = 2; | 725 int v = 2; |
| 726 print(v + 1); | 726 print(v + 1); |
| 727 } | 727 } |
| 728 } | 728 } |
| 729 '''); | 729 '''); |
| 730 _assertSingleLinkedEditGroup( | 730 _assertSingleLinkedEditGroup( |
| 731 length: 3, offsets: [36, 59, 85], names: ['object', 'i']); | 731 length: 3, offsets: [36, 59, 85], names: ['object', 'i']); |
| 732 } | 732 } |
| 733 | 733 |
| 734 test_occurrences_disableOccurrences() { | 734 test_occurrences_disableOccurrences() async { |
| 735 indexTestUnit(''' | 735 await indexTestUnit(''' |
| 736 int foo() => 42; | 736 int foo() => 42; |
| 737 main() { | 737 main() { |
| 738 int a = 1 + foo(); | 738 int a = 1 + foo(); |
| 739 int b = 2 + foo(); // marker | 739 int b = 2 + foo(); // marker |
| 740 } | 740 } |
| 741 '''); | 741 '''); |
| 742 _createRefactoringWithSuffix('foo()', '; // marker'); | 742 _createRefactoringWithSuffix('foo()', '; // marker'); |
| 743 refactoring.extractAll = false; | 743 refactoring.extractAll = false; |
| 744 // apply refactoring | 744 // apply refactoring |
| 745 return _assertSuccessfulRefactoring(''' | 745 return _assertSuccessfulRefactoring(''' |
| 746 int foo() => 42; | 746 int foo() => 42; |
| 747 main() { | 747 main() { |
| 748 int a = 1 + foo(); | 748 int a = 1 + foo(); |
| 749 var res = foo(); | 749 var res = foo(); |
| 750 int b = 2 + res; // marker | 750 int b = 2 + res; // marker |
| 751 } | 751 } |
| 752 '''); | 752 '''); |
| 753 } | 753 } |
| 754 | 754 |
| 755 test_occurrences_ignore_assignmentLeftHandSize() { | 755 test_occurrences_ignore_assignmentLeftHandSize() async { |
| 756 indexTestUnit(''' | 756 await indexTestUnit(''' |
| 757 main() { | 757 main() { |
| 758 int v = 1; | 758 int v = 1; |
| 759 v = 2; | 759 v = 2; |
| 760 print(() {v = 2;}); | 760 print(() {v = 2;}); |
| 761 print(1 + (() {v = 2; return 3;})()); | 761 print(1 + (() {v = 2; return 3;})()); |
| 762 print(v); // marker | 762 print(v); // marker |
| 763 } | 763 } |
| 764 '''); | 764 '''); |
| 765 _createRefactoringWithSuffix('v', '); // marker'); | 765 _createRefactoringWithSuffix('v', '); // marker'); |
| 766 // apply refactoring | 766 // apply refactoring |
| 767 return _assertSuccessfulRefactoring(''' | 767 return _assertSuccessfulRefactoring(''' |
| 768 main() { | 768 main() { |
| 769 int v = 1; | 769 int v = 1; |
| 770 v = 2; | 770 v = 2; |
| 771 print(() {v = 2;}); | 771 print(() {v = 2;}); |
| 772 print(1 + (() {v = 2; return 3;})()); | 772 print(1 + (() {v = 2; return 3;})()); |
| 773 var res = v; | 773 var res = v; |
| 774 print(res); // marker | 774 print(res); // marker |
| 775 } | 775 } |
| 776 '''); | 776 '''); |
| 777 } | 777 } |
| 778 | 778 |
| 779 test_occurrences_ignore_nameOfVariableDeclaration() { | 779 test_occurrences_ignore_nameOfVariableDeclaration() async { |
| 780 indexTestUnit(''' | 780 await indexTestUnit(''' |
| 781 main() { | 781 main() { |
| 782 int v = 1; | 782 int v = 1; |
| 783 print(v); // marker | 783 print(v); // marker |
| 784 } | 784 } |
| 785 '''); | 785 '''); |
| 786 _createRefactoringWithSuffix('v', '); // marker'); | 786 _createRefactoringWithSuffix('v', '); // marker'); |
| 787 // apply refactoring | 787 // apply refactoring |
| 788 return _assertSuccessfulRefactoring(''' | 788 return _assertSuccessfulRefactoring(''' |
| 789 main() { | 789 main() { |
| 790 int v = 1; | 790 int v = 1; |
| 791 var res = v; | 791 var res = v; |
| 792 print(res); // marker | 792 print(res); // marker |
| 793 } | 793 } |
| 794 '''); | 794 '''); |
| 795 } | 795 } |
| 796 | 796 |
| 797 test_occurrences_singleExpression() { | 797 test_occurrences_singleExpression() async { |
| 798 indexTestUnit(''' | 798 await indexTestUnit(''' |
| 799 int foo() => 42; | 799 int foo() => 42; |
| 800 main() { | 800 main() { |
| 801 int a = 1 + foo(); | 801 int a = 1 + foo(); |
| 802 int b = 2 + foo(); // marker | 802 int b = 2 + foo(); // marker |
| 803 } | 803 } |
| 804 '''); | 804 '''); |
| 805 _createRefactoringWithSuffix('foo()', '; // marker'); | 805 _createRefactoringWithSuffix('foo()', '; // marker'); |
| 806 // apply refactoring | 806 // apply refactoring |
| 807 return _assertSuccessfulRefactoring(''' | 807 return _assertSuccessfulRefactoring(''' |
| 808 int foo() => 42; | 808 int foo() => 42; |
| 809 main() { | 809 main() { |
| 810 var res = foo(); | 810 var res = foo(); |
| 811 int a = 1 + res; | 811 int a = 1 + res; |
| 812 int b = 2 + res; // marker | 812 int b = 2 + res; // marker |
| 813 } | 813 } |
| 814 '''); | 814 '''); |
| 815 } | 815 } |
| 816 | 816 |
| 817 test_occurrences_useDominator() { | 817 test_occurrences_useDominator() async { |
| 818 indexTestUnit(''' | 818 await indexTestUnit(''' |
| 819 main() { | 819 main() { |
| 820 if (true) { | 820 if (true) { |
| 821 print(42); | 821 print(42); |
| 822 } else { | 822 } else { |
| 823 print(42); | 823 print(42); |
| 824 } | 824 } |
| 825 } | 825 } |
| 826 '''); | 826 '''); |
| 827 _createRefactoringForString('42'); | 827 _createRefactoringForString('42'); |
| 828 // apply refactoring | 828 // apply refactoring |
| 829 return _assertSuccessfulRefactoring(''' | 829 return _assertSuccessfulRefactoring(''' |
| 830 main() { | 830 main() { |
| 831 var res = 42; | 831 var res = 42; |
| 832 if (true) { | 832 if (true) { |
| 833 print(res); | 833 print(res); |
| 834 } else { | 834 } else { |
| 835 print(res); | 835 print(res); |
| 836 } | 836 } |
| 837 } | 837 } |
| 838 '''); | 838 '''); |
| 839 } | 839 } |
| 840 | 840 |
| 841 test_occurrences_whenComment() { | 841 test_occurrences_whenComment() async { |
| 842 indexTestUnit(''' | 842 await indexTestUnit(''' |
| 843 int foo() => 42; | 843 int foo() => 42; |
| 844 main() { | 844 main() { |
| 845 /*int a = 1 + foo();*/ | 845 /*int a = 1 + foo();*/ |
| 846 int b = 2 + foo(); // marker | 846 int b = 2 + foo(); // marker |
| 847 } | 847 } |
| 848 '''); | 848 '''); |
| 849 _createRefactoringWithSuffix('foo()', '; // marker'); | 849 _createRefactoringWithSuffix('foo()', '; // marker'); |
| 850 // apply refactoring | 850 // apply refactoring |
| 851 return _assertSuccessfulRefactoring(''' | 851 return _assertSuccessfulRefactoring(''' |
| 852 int foo() => 42; | 852 int foo() => 42; |
| 853 main() { | 853 main() { |
| 854 /*int a = 1 + foo();*/ | 854 /*int a = 1 + foo();*/ |
| 855 var res = foo(); | 855 var res = foo(); |
| 856 int b = 2 + res; // marker | 856 int b = 2 + res; // marker |
| 857 } | 857 } |
| 858 '''); | 858 '''); |
| 859 } | 859 } |
| 860 | 860 |
| 861 test_occurrences_withSpace() { | 861 test_occurrences_withSpace() async { |
| 862 indexTestUnit(''' | 862 await indexTestUnit(''' |
| 863 int foo(String s) => 42; | 863 int foo(String s) => 42; |
| 864 main() { | 864 main() { |
| 865 int a = 1 + foo('has space'); | 865 int a = 1 + foo('has space'); |
| 866 int b = 2 + foo('has space'); // marker | 866 int b = 2 + foo('has space'); // marker |
| 867 } | 867 } |
| 868 '''); | 868 '''); |
| 869 _createRefactoringWithSuffix("foo('has space')", '; // marker'); | 869 _createRefactoringWithSuffix("foo('has space')", '; // marker'); |
| 870 // apply refactoring | 870 // apply refactoring |
| 871 return _assertSuccessfulRefactoring(''' | 871 return _assertSuccessfulRefactoring(''' |
| 872 int foo(String s) => 42; | 872 int foo(String s) => 42; |
| 873 main() { | 873 main() { |
| 874 var res = foo('has space'); | 874 var res = foo('has space'); |
| 875 int a = 1 + res; | 875 int a = 1 + res; |
| 876 int b = 2 + res; // marker | 876 int b = 2 + res; // marker |
| 877 } | 877 } |
| 878 '''); | 878 '''); |
| 879 } | 879 } |
| 880 | 880 |
| 881 test_offsets_lengths() async { | 881 test_offsets_lengths() async { |
| 882 indexTestUnit(''' | 882 await indexTestUnit(''' |
| 883 int foo() => 42; | 883 int foo() => 42; |
| 884 main() { | 884 main() { |
| 885 int a = 1 + foo(); // marker | 885 int a = 1 + foo(); // marker |
| 886 int b = 2 + foo( ); | 886 int b = 2 + foo( ); |
| 887 } | 887 } |
| 888 '''); | 888 '''); |
| 889 _createRefactoringWithSuffix('foo()', '; // marker'); | 889 _createRefactoringWithSuffix('foo()', '; // marker'); |
| 890 // check offsets | 890 // check offsets |
| 891 await refactoring.checkInitialConditions(); | 891 await refactoring.checkInitialConditions(); |
| 892 expect(refactoring.offsets, | 892 expect(refactoring.offsets, |
| 893 unorderedEquals([findOffset('foo();'), findOffset('foo( );')])); | 893 unorderedEquals([findOffset('foo();'), findOffset('foo( );')])); |
| 894 expect(refactoring.lengths, unorderedEquals([5, 6])); | 894 expect(refactoring.lengths, unorderedEquals([5, 6])); |
| 895 } | 895 } |
| 896 | 896 |
| 897 test_singleExpression() { | 897 test_singleExpression() async { |
| 898 indexTestUnit(''' | 898 await indexTestUnit(''' |
| 899 main() { | 899 main() { |
| 900 int a = 1 + 2; | 900 int a = 1 + 2; |
| 901 } | 901 } |
| 902 '''); | 902 '''); |
| 903 _createRefactoringForString('1 + 2'); | 903 _createRefactoringForString('1 + 2'); |
| 904 // apply refactoring | 904 // apply refactoring |
| 905 return _assertSuccessfulRefactoring(''' | 905 return _assertSuccessfulRefactoring(''' |
| 906 main() { | 906 main() { |
| 907 var res = 1 + 2; | 907 var res = 1 + 2; |
| 908 int a = res; | 908 int a = res; |
| 909 } | 909 } |
| 910 '''); | 910 '''); |
| 911 } | 911 } |
| 912 | 912 |
| 913 test_singleExpression_getter() { | 913 test_singleExpression_getter() async { |
| 914 indexTestUnit(''' | 914 await indexTestUnit(''' |
| 915 class A { | 915 class A { |
| 916 int get foo => 42; | 916 int get foo => 42; |
| 917 } | 917 } |
| 918 main() { | 918 main() { |
| 919 A a = new A(); | 919 A a = new A(); |
| 920 int b = 1 + a.foo; // marker | 920 int b = 1 + a.foo; // marker |
| 921 } | 921 } |
| 922 '''); | 922 '''); |
| 923 _createRefactoringWithSuffix('a.foo', '; // marker'); | 923 _createRefactoringWithSuffix('a.foo', '; // marker'); |
| 924 // apply refactoring | 924 // apply refactoring |
| 925 return _assertSuccessfulRefactoring(''' | 925 return _assertSuccessfulRefactoring(''' |
| 926 class A { | 926 class A { |
| 927 int get foo => 42; | 927 int get foo => 42; |
| 928 } | 928 } |
| 929 main() { | 929 main() { |
| 930 A a = new A(); | 930 A a = new A(); |
| 931 var res = a.foo; | 931 var res = a.foo; |
| 932 int b = 1 + res; // marker | 932 int b = 1 + res; // marker |
| 933 } | 933 } |
| 934 '''); | 934 '''); |
| 935 } | 935 } |
| 936 | 936 |
| 937 test_singleExpression_hasParseError_expectedSemicolon() { | 937 test_singleExpression_hasParseError_expectedSemicolon() async { |
| 938 verifyNoTestUnitErrors = false; | 938 verifyNoTestUnitErrors = false; |
| 939 indexTestUnit(''' | 939 await indexTestUnit(''' |
| 940 main(p) { | 940 main(p) { |
| 941 foo | 941 foo |
| 942 p.bar.baz; | 942 p.bar.baz; |
| 943 } | 943 } |
| 944 '''); | 944 '''); |
| 945 _createRefactoringForString('p.bar'); | 945 _createRefactoringForString('p.bar'); |
| 946 // apply refactoring | 946 // apply refactoring |
| 947 return _assertSuccessfulRefactoring(''' | 947 return _assertSuccessfulRefactoring(''' |
| 948 main(p) { | 948 main(p) { |
| 949 foo | 949 foo |
| 950 var res = p.bar; | 950 var res = p.bar; |
| 951 res.baz; | 951 res.baz; |
| 952 } | 952 } |
| 953 '''); | 953 '''); |
| 954 } | 954 } |
| 955 | 955 |
| 956 test_singleExpression_inExpressionBody_ofClosure() async { | 956 test_singleExpression_inExpressionBody_ofClosure() async { |
| 957 indexTestUnit(''' | 957 await indexTestUnit(''' |
| 958 main() { | 958 main() { |
| 959 print((x) => x.y * x.y + 1); | 959 print((x) => x.y * x.y + 1); |
| 960 } | 960 } |
| 961 '''); | 961 '''); |
| 962 _createRefactoringForString('x.y'); | 962 _createRefactoringForString('x.y'); |
| 963 // apply refactoring | 963 // apply refactoring |
| 964 await _assertSuccessfulRefactoring(''' | 964 await _assertSuccessfulRefactoring(''' |
| 965 main() { | 965 main() { |
| 966 print((x) { | 966 print((x) { |
| 967 var res = x.y; | 967 var res = x.y; |
| 968 return res * res + 1; | 968 return res * res + 1; |
| 969 }); | 969 }); |
| 970 } | 970 } |
| 971 '''); | 971 '''); |
| 972 _assertSingleLinkedEditGroup( | 972 _assertSingleLinkedEditGroup( |
| 973 length: 3, offsets: [31, 53, 59], names: ['y']); | 973 length: 3, offsets: [31, 53, 59], names: ['y']); |
| 974 } | 974 } |
| 975 | 975 |
| 976 test_singleExpression_inExpressionBody_ofFunction() async { | 976 test_singleExpression_inExpressionBody_ofFunction() async { |
| 977 indexTestUnit(''' | 977 await indexTestUnit(''' |
| 978 foo(Point p) => p.x * p.x + p.y * p.y; | 978 foo(Point p) => p.x * p.x + p.y * p.y; |
| 979 class Point {int x; int y;} | 979 class Point {int x; int y;} |
| 980 '''); | 980 '''); |
| 981 _createRefactoringForString('p.x'); | 981 _createRefactoringForString('p.x'); |
| 982 // apply refactoring | 982 // apply refactoring |
| 983 await _assertSuccessfulRefactoring(''' | 983 await _assertSuccessfulRefactoring(''' |
| 984 foo(Point p) { | 984 foo(Point p) { |
| 985 var res = p.x; | 985 var res = p.x; |
| 986 return res * res + p.y * p.y; | 986 return res * res + p.y * p.y; |
| 987 } | 987 } |
| 988 class Point {int x; int y;} | 988 class Point {int x; int y;} |
| 989 '''); | 989 '''); |
| 990 _assertSingleLinkedEditGroup( | 990 _assertSingleLinkedEditGroup( |
| 991 length: 3, offsets: [21, 41, 47], names: ['x', 'i']); | 991 length: 3, offsets: [21, 41, 47], names: ['x', 'i']); |
| 992 } | 992 } |
| 993 | 993 |
| 994 test_singleExpression_inExpressionBody_ofMethod() async { | 994 test_singleExpression_inExpressionBody_ofMethod() async { |
| 995 indexTestUnit(''' | 995 await indexTestUnit(''' |
| 996 class A { | 996 class A { |
| 997 foo(Point p) => p.x * p.x + p.y * p.y; | 997 foo(Point p) => p.x * p.x + p.y * p.y; |
| 998 } | 998 } |
| 999 class Point {int x; int y;} | 999 class Point {int x; int y;} |
| 1000 '''); | 1000 '''); |
| 1001 _createRefactoringForString('p.x'); | 1001 _createRefactoringForString('p.x'); |
| 1002 // apply refactoring | 1002 // apply refactoring |
| 1003 await _assertSuccessfulRefactoring(''' | 1003 await _assertSuccessfulRefactoring(''' |
| 1004 class A { | 1004 class A { |
| 1005 foo(Point p) { | 1005 foo(Point p) { |
| 1006 var res = p.x; | 1006 var res = p.x; |
| 1007 return res * res + p.y * p.y; | 1007 return res * res + p.y * p.y; |
| 1008 } | 1008 } |
| 1009 } | 1009 } |
| 1010 class Point {int x; int y;} | 1010 class Point {int x; int y;} |
| 1011 '''); | 1011 '''); |
| 1012 _assertSingleLinkedEditGroup( | 1012 _assertSingleLinkedEditGroup( |
| 1013 length: 3, offsets: [35, 57, 63], names: ['x', 'i']); | 1013 length: 3, offsets: [35, 57, 63], names: ['x', 'i']); |
| 1014 } | 1014 } |
| 1015 | 1015 |
| 1016 test_singleExpression_inIfElseIf() { | 1016 test_singleExpression_inIfElseIf() async { |
| 1017 indexTestUnit(''' | 1017 await indexTestUnit(''' |
| 1018 main(int p) { | 1018 main(int p) { |
| 1019 if (p == 1) { | 1019 if (p == 1) { |
| 1020 print(1); | 1020 print(1); |
| 1021 } else if (p == 2) { | 1021 } else if (p == 2) { |
| 1022 print(2); | 1022 print(2); |
| 1023 } | 1023 } |
| 1024 } | 1024 } |
| 1025 '''); | 1025 '''); |
| 1026 _createRefactoringForString('2'); | 1026 _createRefactoringForString('2'); |
| 1027 // apply refactoring | 1027 // apply refactoring |
| 1028 return _assertSuccessfulRefactoring(''' | 1028 return _assertSuccessfulRefactoring(''' |
| 1029 main(int p) { | 1029 main(int p) { |
| 1030 var res = 2; | 1030 var res = 2; |
| 1031 if (p == 1) { | 1031 if (p == 1) { |
| 1032 print(1); | 1032 print(1); |
| 1033 } else if (p == res) { | 1033 } else if (p == res) { |
| 1034 print(res); | 1034 print(res); |
| 1035 } | 1035 } |
| 1036 } | 1036 } |
| 1037 '''); | 1037 '''); |
| 1038 } | 1038 } |
| 1039 | 1039 |
| 1040 test_singleExpression_inMethod() { | 1040 test_singleExpression_inMethod() async { |
| 1041 indexTestUnit(''' | 1041 await indexTestUnit(''' |
| 1042 class A { | 1042 class A { |
| 1043 main() { | 1043 main() { |
| 1044 print(1 + 2); | 1044 print(1 + 2); |
| 1045 } | 1045 } |
| 1046 } | 1046 } |
| 1047 '''); | 1047 '''); |
| 1048 _createRefactoringForString('1 + 2'); | 1048 _createRefactoringForString('1 + 2'); |
| 1049 // apply refactoring | 1049 // apply refactoring |
| 1050 return _assertSuccessfulRefactoring(''' | 1050 return _assertSuccessfulRefactoring(''' |
| 1051 class A { | 1051 class A { |
| 1052 main() { | 1052 main() { |
| 1053 var res = 1 + 2; | 1053 var res = 1 + 2; |
| 1054 print(res); | 1054 print(res); |
| 1055 } | 1055 } |
| 1056 } | 1056 } |
| 1057 '''); | 1057 '''); |
| 1058 } | 1058 } |
| 1059 | 1059 |
| 1060 test_singleExpression_leadingNotWhitespace() { | 1060 test_singleExpression_leadingNotWhitespace() async { |
| 1061 indexTestUnit(''' | 1061 await indexTestUnit(''' |
| 1062 main() { | 1062 main() { |
| 1063 int a = 12 + 345; | 1063 int a = 12 + 345; |
| 1064 } | 1064 } |
| 1065 '''); | 1065 '''); |
| 1066 _createRefactoringForString('+ 345'); | 1066 _createRefactoringForString('+ 345'); |
| 1067 // apply refactoring | 1067 // apply refactoring |
| 1068 return _assertSuccessfulRefactoring(''' | 1068 return _assertSuccessfulRefactoring(''' |
| 1069 main() { | 1069 main() { |
| 1070 var res = 12 + 345; | 1070 var res = 12 + 345; |
| 1071 int a = res; | 1071 int a = res; |
| 1072 } | 1072 } |
| 1073 '''); | 1073 '''); |
| 1074 } | 1074 } |
| 1075 | 1075 |
| 1076 test_singleExpression_leadingWhitespace() { | 1076 test_singleExpression_leadingWhitespace() async { |
| 1077 indexTestUnit(''' | 1077 await indexTestUnit(''' |
| 1078 main() { | 1078 main() { |
| 1079 int a = 1 /*abc*/ + 2 + 345; | 1079 int a = 1 /*abc*/ + 2 + 345; |
| 1080 } | 1080 } |
| 1081 '''); | 1081 '''); |
| 1082 _createRefactoringForString('1 /*abc*/'); | 1082 _createRefactoringForString('1 /*abc*/'); |
| 1083 // apply refactoring | 1083 // apply refactoring |
| 1084 return _assertSuccessfulRefactoring(''' | 1084 return _assertSuccessfulRefactoring(''' |
| 1085 main() { | 1085 main() { |
| 1086 var res = 1 /*abc*/ + 2; | 1086 var res = 1 /*abc*/ + 2; |
| 1087 int a = res + 345; | 1087 int a = res + 345; |
| 1088 } | 1088 } |
| 1089 '''); | 1089 '''); |
| 1090 } | 1090 } |
| 1091 | 1091 |
| 1092 test_singleExpression_methodName_reference() async { | 1092 test_singleExpression_methodName_reference() async { |
| 1093 indexTestUnit(''' | 1093 await indexTestUnit(''' |
| 1094 main() { | 1094 main() { |
| 1095 var v = foo().length; | 1095 var v = foo().length; |
| 1096 } | 1096 } |
| 1097 String foo() => ''; | 1097 String foo() => ''; |
| 1098 '''); | 1098 '''); |
| 1099 _createRefactoringWithSuffix('foo', '().'); | 1099 _createRefactoringWithSuffix('foo', '().'); |
| 1100 // apply refactoring | 1100 // apply refactoring |
| 1101 return _assertSuccessfulRefactoring(''' | 1101 return _assertSuccessfulRefactoring(''' |
| 1102 main() { | 1102 main() { |
| 1103 var res = foo(); | 1103 var res = foo(); |
| 1104 var v = res.length; | 1104 var v = res.length; |
| 1105 } | 1105 } |
| 1106 String foo() => ''; | 1106 String foo() => ''; |
| 1107 '''); | 1107 '''); |
| 1108 } | 1108 } |
| 1109 | 1109 |
| 1110 test_singleExpression_nameOfProperty_prefixedIdentifier() async { | 1110 test_singleExpression_nameOfProperty_prefixedIdentifier() async { |
| 1111 indexTestUnit(''' | 1111 await indexTestUnit(''' |
| 1112 main(p) { | 1112 main(p) { |
| 1113 var v = p.value; // marker | 1113 var v = p.value; // marker |
| 1114 } | 1114 } |
| 1115 '''); | 1115 '''); |
| 1116 _createRefactoringWithSuffix('value', '; // marker'); | 1116 _createRefactoringWithSuffix('value', '; // marker'); |
| 1117 // apply refactoring | 1117 // apply refactoring |
| 1118 return _assertSuccessfulRefactoring(''' | 1118 return _assertSuccessfulRefactoring(''' |
| 1119 main(p) { | 1119 main(p) { |
| 1120 var res = p.value; | 1120 var res = p.value; |
| 1121 var v = res; // marker | 1121 var v = res; // marker |
| 1122 } | 1122 } |
| 1123 '''); | 1123 '''); |
| 1124 } | 1124 } |
| 1125 | 1125 |
| 1126 test_singleExpression_nameOfProperty_propertyAccess() async { | 1126 test_singleExpression_nameOfProperty_propertyAccess() async { |
| 1127 indexTestUnit(''' | 1127 await indexTestUnit(''' |
| 1128 main() { | 1128 main() { |
| 1129 var v = foo().length; // marker | 1129 var v = foo().length; // marker |
| 1130 } | 1130 } |
| 1131 String foo() => ''; | 1131 String foo() => ''; |
| 1132 '''); | 1132 '''); |
| 1133 _createRefactoringWithSuffix('length', '; // marker'); | 1133 _createRefactoringWithSuffix('length', '; // marker'); |
| 1134 // apply refactoring | 1134 // apply refactoring |
| 1135 return _assertSuccessfulRefactoring(''' | 1135 return _assertSuccessfulRefactoring(''' |
| 1136 main() { | 1136 main() { |
| 1137 var res = foo().length; | 1137 var res = foo().length; |
| 1138 var v = res; // marker | 1138 var v = res; // marker |
| 1139 } | 1139 } |
| 1140 String foo() => ''; | 1140 String foo() => ''; |
| 1141 '''); | 1141 '''); |
| 1142 } | 1142 } |
| 1143 | 1143 |
| 1144 /** | 1144 /** |
| 1145 * Here we use knowledge how exactly `1 + 2 + 3 + 4` is parsed. We know that | 1145 * Here we use knowledge how exactly `1 + 2 + 3 + 4` is parsed. We know that |
| 1146 * `1 + 2` will be a separate and complete binary expression, so it can be | 1146 * `1 + 2` will be a separate and complete binary expression, so it can be |
| 1147 * handled as a single expression. | 1147 * handled as a single expression. |
| 1148 */ | 1148 */ |
| 1149 test_singleExpression_partOfBinaryExpression() { | 1149 test_singleExpression_partOfBinaryExpression() async { |
| 1150 indexTestUnit(''' | 1150 await indexTestUnit(''' |
| 1151 main() { | 1151 main() { |
| 1152 int a = 1 + 2 + 3 + 4; | 1152 int a = 1 + 2 + 3 + 4; |
| 1153 } | 1153 } |
| 1154 '''); | 1154 '''); |
| 1155 _createRefactoringForString('1 + 2'); | 1155 _createRefactoringForString('1 + 2'); |
| 1156 // apply refactoring | 1156 // apply refactoring |
| 1157 return _assertSuccessfulRefactoring(''' | 1157 return _assertSuccessfulRefactoring(''' |
| 1158 main() { | 1158 main() { |
| 1159 var res = 1 + 2; | 1159 var res = 1 + 2; |
| 1160 int a = res + 3 + 4; | 1160 int a = res + 3 + 4; |
| 1161 } | 1161 } |
| 1162 '''); | 1162 '''); |
| 1163 } | 1163 } |
| 1164 | 1164 |
| 1165 test_singleExpression_string() { | 1165 test_singleExpression_string() async { |
| 1166 indexTestUnit(''' | 1166 await indexTestUnit(''' |
| 1167 void main() { | 1167 void main() { |
| 1168 print("1234"); | 1168 print("1234"); |
| 1169 } | 1169 } |
| 1170 '''); | 1170 '''); |
| 1171 _createRefactoringAtString('34"'); | 1171 _createRefactoringAtString('34"'); |
| 1172 // apply refactoring | 1172 // apply refactoring |
| 1173 return _assertSuccessfulRefactoring(''' | 1173 return _assertSuccessfulRefactoring(''' |
| 1174 void main() { | 1174 void main() { |
| 1175 var res = "1234"; | 1175 var res = "1234"; |
| 1176 print(res); | 1176 print(res); |
| 1177 } | 1177 } |
| 1178 '''); | 1178 '''); |
| 1179 } | 1179 } |
| 1180 | 1180 |
| 1181 test_singleExpression_trailingNotWhitespace() { | 1181 test_singleExpression_trailingNotWhitespace() async { |
| 1182 indexTestUnit(''' | 1182 await indexTestUnit(''' |
| 1183 main() { | 1183 main() { |
| 1184 int a = 12 + 345; | 1184 int a = 12 + 345; |
| 1185 } | 1185 } |
| 1186 '''); | 1186 '''); |
| 1187 _createRefactoringForString('12 +'); | 1187 _createRefactoringForString('12 +'); |
| 1188 // apply refactoring | 1188 // apply refactoring |
| 1189 return _assertSuccessfulRefactoring(''' | 1189 return _assertSuccessfulRefactoring(''' |
| 1190 main() { | 1190 main() { |
| 1191 var res = 12 + 345; | 1191 var res = 12 + 345; |
| 1192 int a = res; | 1192 int a = res; |
| 1193 } | 1193 } |
| 1194 '''); | 1194 '''); |
| 1195 } | 1195 } |
| 1196 | 1196 |
| 1197 test_singleExpression_trailingWhitespace() { | 1197 test_singleExpression_trailingWhitespace() async { |
| 1198 indexTestUnit(''' | 1198 await indexTestUnit(''' |
| 1199 main() { | 1199 main() { |
| 1200 int a = 1 + 2 ; | 1200 int a = 1 + 2 ; |
| 1201 } | 1201 } |
| 1202 '''); | 1202 '''); |
| 1203 _createRefactoringForString('1 + 2 '); | 1203 _createRefactoringForString('1 + 2 '); |
| 1204 // apply refactoring | 1204 // apply refactoring |
| 1205 return _assertSuccessfulRefactoring(''' | 1205 return _assertSuccessfulRefactoring(''' |
| 1206 main() { | 1206 main() { |
| 1207 var res = 1 + 2; | 1207 var res = 1 + 2; |
| 1208 int a = res ; | 1208 int a = res ; |
| 1209 } | 1209 } |
| 1210 '''); | 1210 '''); |
| 1211 } | 1211 } |
| 1212 | 1212 |
| 1213 test_stringLiteral_part() async { | 1213 test_stringLiteral_part() async { |
| 1214 indexTestUnit(''' | 1214 await indexTestUnit(''' |
| 1215 main() { | 1215 main() { |
| 1216 print('abcdefgh'); | 1216 print('abcdefgh'); |
| 1217 } | 1217 } |
| 1218 '''); | 1218 '''); |
| 1219 _createRefactoringForString('cde'); | 1219 _createRefactoringForString('cde'); |
| 1220 // apply refactoring | 1220 // apply refactoring |
| 1221 await _assertSuccessfulRefactoring(r''' | 1221 await _assertSuccessfulRefactoring(r''' |
| 1222 main() { | 1222 main() { |
| 1223 var res = 'cde'; | 1223 var res = 'cde'; |
| 1224 print('ab${res}fgh'); | 1224 print('ab${res}fgh'); |
| 1225 } | 1225 } |
| 1226 '''); | 1226 '''); |
| 1227 _assertSingleLinkedEditGroup(length: 3, offsets: [15, 41], names: ['cde']); | 1227 _assertSingleLinkedEditGroup(length: 3, offsets: [15, 41], names: ['cde']); |
| 1228 } | 1228 } |
| 1229 | 1229 |
| 1230 test_stringLiteral_whole() async { | 1230 test_stringLiteral_whole() async { |
| 1231 indexTestUnit(''' | 1231 await indexTestUnit(''' |
| 1232 main() { | 1232 main() { |
| 1233 print('abc'); | 1233 print('abc'); |
| 1234 } | 1234 } |
| 1235 '''); | 1235 '''); |
| 1236 _createRefactoringForString("'abc'"); | 1236 _createRefactoringForString("'abc'"); |
| 1237 // apply refactoring | 1237 // apply refactoring |
| 1238 await _assertSuccessfulRefactoring(''' | 1238 await _assertSuccessfulRefactoring(''' |
| 1239 main() { | 1239 main() { |
| 1240 var res = 'abc'; | 1240 var res = 'abc'; |
| 1241 print(res); | 1241 print(res); |
| 1242 } | 1242 } |
| 1243 '''); | 1243 '''); |
| 1244 _assertSingleLinkedEditGroup( | 1244 _assertSingleLinkedEditGroup( |
| 1245 length: 3, offsets: [15, 36], names: ['object', 's']); | 1245 length: 3, offsets: [15, 36], names: ['object', 's']); |
| 1246 } | 1246 } |
| 1247 | 1247 |
| 1248 test_stringLiteralPart() async { | 1248 test_stringLiteralPart() async { |
| 1249 indexTestUnit(r''' | 1249 await indexTestUnit(r''' |
| 1250 main() { | 1250 main() { |
| 1251 int x = 1; | 1251 int x = 1; |
| 1252 int y = 2; | 1252 int y = 2; |
| 1253 print('$x+$y=${x+y}'); | 1253 print('$x+$y=${x+y}'); |
| 1254 } | 1254 } |
| 1255 '''); | 1255 '''); |
| 1256 _createRefactoringForString(r'$x+$y'); | 1256 _createRefactoringForString(r'$x+$y'); |
| 1257 // apply refactoring | 1257 // apply refactoring |
| 1258 await _assertSuccessfulRefactoring(r''' | 1258 await _assertSuccessfulRefactoring(r''' |
| 1259 main() { | 1259 main() { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1339 List<String> _getCoveringExpressions() { | 1339 List<String> _getCoveringExpressions() { |
| 1340 List<String> subExpressions = <String>[]; | 1340 List<String> subExpressions = <String>[]; |
| 1341 for (int i = 0; i < refactoring.coveringExpressionOffsets.length; i++) { | 1341 for (int i = 0; i < refactoring.coveringExpressionOffsets.length; i++) { |
| 1342 int offset = refactoring.coveringExpressionOffsets[i]; | 1342 int offset = refactoring.coveringExpressionOffsets[i]; |
| 1343 int length = refactoring.coveringExpressionLengths[i]; | 1343 int length = refactoring.coveringExpressionLengths[i]; |
| 1344 subExpressions.add(testCode.substring(offset, offset + length)); | 1344 subExpressions.add(testCode.substring(offset, offset + length)); |
| 1345 } | 1345 } |
| 1346 return subExpressions; | 1346 return subExpressions; |
| 1347 } | 1347 } |
| 1348 } | 1348 } |
| OLD | NEW |