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 | 8 |
9 import 'package:analysis_server/plugin/protocol/protocol.dart'; | 9 import 'package:analysis_server/plugin/protocol/protocol.dart'; |
10 import 'package:analysis_server/src/services/correction/status.dart'; | 10 import 'package:analysis_server/src/services/correction/status.dart'; |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 indexTestUnit(''' | 325 indexTestUnit(''' |
326 main() { | 326 main() { |
327 int aaa = 1; | 327 int aaa = 1; |
328 int bbb = 2; | 328 int bbb = 2; |
329 var c = aaa + bbb * 2 + 3; | 329 var c = aaa + bbb * 2 + 3; |
330 } | 330 } |
331 '''); | 331 '''); |
332 _createRefactoring(testCode.indexOf('bb * 2'), 0); | 332 _createRefactoring(testCode.indexOf('bb * 2'), 0); |
333 // check conditions | 333 // check conditions |
334 await refactoring.checkInitialConditions(); | 334 await refactoring.checkInitialConditions(); |
335 List<String> subExpressions = <String>[]; | 335 List<String> subExpressions = _getCoveringExpressions(); |
336 for (int i = 0; i < refactoring.coveringExpressionOffsets.length; i++) { | |
337 int offset = refactoring.coveringExpressionOffsets[i]; | |
338 int length = refactoring.coveringExpressionLengths[i]; | |
339 subExpressions.add(testCode.substring(offset, offset + length)); | |
340 } | |
341 expect(subExpressions, | 336 expect(subExpressions, |
342 ['bbb', 'bbb * 2', 'aaa + bbb * 2', 'aaa + bbb * 2 + 3']); | 337 ['bbb', 'bbb * 2', 'aaa + bbb * 2', 'aaa + bbb * 2 + 3']); |
343 } | 338 } |
344 | 339 |
| 340 test_coveringExpressions_inArgumentList() async { |
| 341 indexTestUnit(''' |
| 342 main() { |
| 343 foo(111 + 222); |
| 344 } |
| 345 int foo(int x) => x; |
| 346 '''); |
| 347 _createRefactoring(testCode.indexOf('11 +'), 0); |
| 348 // check conditions |
| 349 await refactoring.checkInitialConditions(); |
| 350 List<String> subExpressions = _getCoveringExpressions(); |
| 351 expect(subExpressions, ['111', '111 + 222', 'foo(111 + 222)']); |
| 352 } |
| 353 |
| 354 test_coveringExpressions_skipAssignments() async { |
| 355 indexTestUnit(''' |
| 356 main() { |
| 357 int v; |
| 358 foo(v = 111 + 222); |
| 359 } |
| 360 int foo(x) => 42; |
| 361 '''); |
| 362 _createRefactoring(testCode.indexOf('11 +'), 0); |
| 363 // check conditions |
| 364 await refactoring.checkInitialConditions(); |
| 365 List<String> subExpressions = _getCoveringExpressions(); |
| 366 expect(subExpressions, ['111', '111 + 222', 'foo(v = 111 + 222)']); |
| 367 } |
| 368 |
345 test_fragmentExpression() { | 369 test_fragmentExpression() { |
346 indexTestUnit(''' | 370 indexTestUnit(''' |
347 main() { | 371 main() { |
348 int a = 1 + 2 + 3 + 4; | 372 int a = 1 + 2 + 3 + 4; |
349 } | 373 } |
350 '''); | 374 '''); |
351 _createRefactoringForString('2 + 3'); | 375 _createRefactoringForString('2 + 3'); |
352 // apply refactoring | 376 // apply refactoring |
353 return _assertSuccessfulRefactoring(''' | 377 return _assertSuccessfulRefactoring(''' |
354 main() { | 378 main() { |
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1046 int offset = findOffset(search); | 1070 int offset = findOffset(search); |
1047 int length = search.length; | 1071 int length = search.length; |
1048 _createRefactoring(offset, length); | 1072 _createRefactoring(offset, length); |
1049 } | 1073 } |
1050 | 1074 |
1051 void _createRefactoringWithSuffix(String selectionSearch, String suffix) { | 1075 void _createRefactoringWithSuffix(String selectionSearch, String suffix) { |
1052 int offset = findOffset(selectionSearch + suffix); | 1076 int offset = findOffset(selectionSearch + suffix); |
1053 int length = selectionSearch.length; | 1077 int length = selectionSearch.length; |
1054 _createRefactoring(offset, length); | 1078 _createRefactoring(offset, length); |
1055 } | 1079 } |
| 1080 |
| 1081 List<String> _getCoveringExpressions() { |
| 1082 List<String> subExpressions = <String>[]; |
| 1083 for (int i = 0; i < refactoring.coveringExpressionOffsets.length; i++) { |
| 1084 int offset = refactoring.coveringExpressionOffsets[i]; |
| 1085 int length = refactoring.coveringExpressionLengths[i]; |
| 1086 subExpressions.add(testCode.substring(offset, offset + length)); |
| 1087 } |
| 1088 return subExpressions; |
| 1089 } |
1056 } | 1090 } |
OLD | NEW |