| 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'; |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_skipAssignments() async { | 429 test_coveringExpressions_namedExpression_value() async { |
| 430 indexTestUnit(''' |
| 431 main() { |
| 432 foo(ppp: 42); |
| 433 } |
| 434 int foo({int ppp: 0}) => ppp + 1; |
| 435 '''); |
| 436 _createRefactoring(testCode.indexOf('42'), 0); |
| 437 // check conditions |
| 438 await refactoring.checkInitialConditions(); |
| 439 List<String> subExpressions = _getCoveringExpressions(); |
| 440 expect(subExpressions, ['42', 'foo(ppp: 42)']); |
| 441 } |
| 442 |
| 443 test_coveringExpressions_skip_assignment() async { |
| 430 indexTestUnit(''' | 444 indexTestUnit(''' |
| 431 main() { | 445 main() { |
| 432 int v; | 446 int v; |
| 433 foo(v = 111 + 222); | 447 foo(v = 111 + 222); |
| 434 } | 448 } |
| 435 int foo(x) => 42; | 449 int foo(x) => 42; |
| 436 '''); | 450 '''); |
| 437 _createRefactoring(testCode.indexOf('11 +'), 0); | 451 _createRefactoring(testCode.indexOf('11 +'), 0); |
| 438 // check conditions | 452 // check conditions |
| 439 await refactoring.checkInitialConditions(); | 453 await refactoring.checkInitialConditions(); |
| 440 List<String> subExpressions = _getCoveringExpressions(); | 454 List<String> subExpressions = _getCoveringExpressions(); |
| 441 expect(subExpressions, ['111', '111 + 222', 'foo(v = 111 + 222)']); | 455 expect(subExpressions, ['111', '111 + 222', 'foo(v = 111 + 222)']); |
| 442 } | 456 } |
| 443 | 457 |
| 458 test_coveringExpressions_skip_constructorName() async { |
| 459 indexTestUnit(''' |
| 460 class AAA { |
| 461 AAA.name() {} |
| 462 } |
| 463 main() { |
| 464 int v = new AAA.name(); |
| 465 } |
| 466 '''); |
| 467 _createRefactoring(testCode.indexOf('AA.name();'), 5); |
| 468 // check conditions |
| 469 await refactoring.checkInitialConditions(); |
| 470 List<String> subExpressions = _getCoveringExpressions(); |
| 471 expect(subExpressions, ['new AAA.name()']); |
| 472 } |
| 473 |
| 474 test_coveringExpressions_skip_constructorName_name() async { |
| 475 indexTestUnit(''' |
| 476 class A { |
| 477 A.name() {} |
| 478 } |
| 479 main() { |
| 480 int v = new A.name(); |
| 481 } |
| 482 '''); |
| 483 _createRefactoring(testCode.indexOf('ame();'), 0); |
| 484 // check conditions |
| 485 await refactoring.checkInitialConditions(); |
| 486 List<String> subExpressions = _getCoveringExpressions(); |
| 487 expect(subExpressions, ['new A.name()']); |
| 488 } |
| 489 |
| 490 test_coveringExpressions_skip_constructorName_type() async { |
| 491 indexTestUnit(''' |
| 492 class A {} |
| 493 main() { |
| 494 int v = new A(); |
| 495 } |
| 496 '''); |
| 497 _createRefactoring(testCode.indexOf('A();'), 0); |
| 498 // check conditions |
| 499 await refactoring.checkInitialConditions(); |
| 500 List<String> subExpressions = _getCoveringExpressions(); |
| 501 expect(subExpressions, ['new A()']); |
| 502 } |
| 503 |
| 504 test_coveringExpressions_skip_constructorName_typeArgument() async { |
| 505 indexTestUnit(''' |
| 506 class A<T> {} |
| 507 main() { |
| 508 int v = new A<String>(); |
| 509 } |
| 510 '''); |
| 511 _createRefactoring(testCode.indexOf('ring>'), 0); |
| 512 // check conditions |
| 513 await refactoring.checkInitialConditions(); |
| 514 List<String> subExpressions = _getCoveringExpressions(); |
| 515 expect(subExpressions, ['new A<String>()']); |
| 516 } |
| 517 |
| 518 test_coveringExpressions_skip_namedExpression() async { |
| 519 indexTestUnit(''' |
| 520 main() { |
| 521 foo(ppp: 42); |
| 522 } |
| 523 int foo({int ppp: 0}) => ppp + 1; |
| 524 '''); |
| 525 _createRefactoring(testCode.indexOf('pp: 42'), 0); |
| 526 // check conditions |
| 527 await refactoring.checkInitialConditions(); |
| 528 List<String> subExpressions = _getCoveringExpressions(); |
| 529 expect(subExpressions, ['foo(ppp: 42)']); |
| 530 } |
| 531 |
| 444 test_fragmentExpression() { | 532 test_fragmentExpression() { |
| 445 indexTestUnit(''' | 533 indexTestUnit(''' |
| 446 main() { | 534 main() { |
| 447 int a = 1 + 2 + 3 + 4; | 535 int a = 1 + 2 + 3 + 4; |
| 448 } | 536 } |
| 449 '''); | 537 '''); |
| 450 _createRefactoringForString('2 + 3'); | 538 _createRefactoringForString('2 + 3'); |
| 451 // apply refactoring | 539 // apply refactoring |
| 452 return _assertSuccessfulRefactoring(''' | 540 return _assertSuccessfulRefactoring(''' |
| 453 main() { | 541 main() { |
| (...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1211 List<String> _getCoveringExpressions() { | 1299 List<String> _getCoveringExpressions() { |
| 1212 List<String> subExpressions = <String>[]; | 1300 List<String> subExpressions = <String>[]; |
| 1213 for (int i = 0; i < refactoring.coveringExpressionOffsets.length; i++) { | 1301 for (int i = 0; i < refactoring.coveringExpressionOffsets.length; i++) { |
| 1214 int offset = refactoring.coveringExpressionOffsets[i]; | 1302 int offset = refactoring.coveringExpressionOffsets[i]; |
| 1215 int length = refactoring.coveringExpressionLengths[i]; | 1303 int length = refactoring.coveringExpressionLengths[i]; |
| 1216 subExpressions.add(testCode.substring(offset, offset + length)); | 1304 subExpressions.add(testCode.substring(offset, offset + length)); |
| 1217 } | 1305 } |
| 1218 return subExpressions; | 1306 return subExpressions; |
| 1219 } | 1307 } |
| 1220 } | 1308 } |
| OLD | NEW |