Chromium Code Reviews| 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 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
| 6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
| 7 | 7 |
| 8 library test.services.correction.fix; | 8 library test.services.correction.fix; |
| 9 | 9 |
| 10 import 'package:analysis_services/correction/change.dart'; | 10 import 'package:analysis_services/correction/change.dart'; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 if (group.id == id) { | 52 if (group.id == id) { |
| 53 expect(group.positions, unorderedEquals(expectedPositions)); | 53 expect(group.positions, unorderedEquals(expectedPositions)); |
| 54 return; | 54 return; |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 fail('No PositionGroup with id=$id found in $linkedPositionGroups'); | 57 fail('No PositionGroup with id=$id found in $linkedPositionGroups'); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void assertNoFix(FixKind kind) { | 60 void assertNoFix(FixKind kind) { |
| 61 AnalysisError error = _findErrorToFix(); | 61 AnalysisError error = _findErrorToFix(); |
| 62 List<Fix> fixes = computeFixes(searchEngine, testFile, testUnit, error); | 62 List<Fix> fixes = computeFixes(searchEngine, testUnit, error); |
| 63 for (Fix fix in fixes) { | 63 for (Fix fix in fixes) { |
| 64 if (fix.kind == kind) { | 64 if (fix.kind == kind) { |
| 65 throw fail('Unexpected fix $kind in\n${fixes.join('\n')}'); | 65 throw fail('Unexpected fix $kind in\n${fixes.join('\n')}'); |
| 66 } | 66 } |
| 67 } | 67 } |
| 68 } | 68 } |
| 69 | 69 |
| 70 Position expectedPosition(String search) { | 70 Position expectedPosition(String search) { |
| 71 int offset = resultCode.indexOf(search); | 71 int offset = resultCode.indexOf(search); |
| 72 int length = getLeadingIdentifierLength(search); | 72 int length = getLeadingIdentifierLength(search); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 class A { | 235 class A { |
| 236 A._named(int p); | 236 A._named(int p); |
| 237 } | 237 } |
| 238 class B extends A { | 238 class B extends A { |
| 239 B() {} | 239 B() {} |
| 240 } | 240 } |
| 241 '''); | 241 '''); |
| 242 assertNoFix(FixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION); | 242 assertNoFix(FixKind.ADD_SUPER_CONSTRUCTOR_INVOCATION); |
| 243 } | 243 } |
| 244 | 244 |
| 245 void test_createConstructorSuperImplicit() { | |
| 246 _indexTestUnit(''' | |
| 247 class A { | |
| 248 A(p1, int p2, List<String> p3, [int p4]); | |
| 249 } | |
| 250 class B extends A { | |
| 251 int existingField; | |
| 252 | |
| 253 void existingMethod() {} | |
| 254 } | |
| 255 '''); | |
| 256 assertHasFix(FixKind.CREATE_CONSTRUCTOR_SUPER, ''' | |
| 257 class A { | |
| 258 A(p1, int p2, List<String> p3, [int p4]); | |
| 259 } | |
| 260 class B extends A { | |
| 261 int existingField; | |
| 262 | |
| 263 B(p1, int p2, List<String> p3) : super(p1, p2, p3); | |
| 264 | |
| 265 void existingMethod() {} | |
| 266 } | |
| 267 '''); | |
| 268 } | |
| 269 | |
| 270 void test_createConstructorSuperImplicit_fieldInitializer() { | |
| 271 _indexTestUnit(''' | |
| 272 class A { | |
| 273 int _field; | |
| 274 A(this._field); | |
| 275 } | |
| 276 class B extends A { | |
| 277 int existingField; | |
| 278 | |
| 279 void existingMethod() {} | |
| 280 } | |
| 281 '''); | |
| 282 assertHasFix(FixKind.CREATE_CONSTRUCTOR_SUPER, ''' | |
| 283 class A { | |
| 284 int _field; | |
| 285 A(this._field); | |
| 286 } | |
| 287 class B extends A { | |
| 288 int existingField; | |
| 289 | |
| 290 B(int field) : super(field); | |
| 291 | |
| 292 void existingMethod() {} | |
| 293 } | |
| 294 '''); | |
| 295 } | |
| 296 | |
| 297 void test_createConstructorSuperImplicit_named() { | |
| 298 _indexTestUnit(''' | |
| 299 class A { | |
| 300 A.named(p1, int p2); | |
| 301 } | |
| 302 class B extends A { | |
| 303 int existingField; | |
| 304 | |
| 305 void existingMethod() {} | |
| 306 } | |
| 307 '''); | |
| 308 assertHasFix(FixKind.CREATE_CONSTRUCTOR_SUPER, ''' | |
| 309 class A { | |
| 310 A.named(p1, int p2); | |
| 311 } | |
| 312 class B extends A { | |
| 313 int existingField; | |
| 314 | |
| 315 B.named(p1, int p2) : super.named(p1, p2); | |
| 316 | |
| 317 void existingMethod() {} | |
| 318 } | |
| 319 '''); | |
| 320 } | |
| 321 | |
| 322 void test_createConstructorSuperImplicit_private() { | |
| 323 _indexTestUnit(''' | |
| 324 class A { | |
| 325 A._named(p); | |
| 326 } | |
| 327 class B extends A { | |
| 328 } | |
| 329 '''); | |
| 330 assertNoFix(FixKind.CREATE_CONSTRUCTOR_SUPER); | |
| 331 } | |
| 332 | |
| 245 void test_createConstructor_insteadOfSyntheticDefault() { | 333 void test_createConstructor_insteadOfSyntheticDefault() { |
| 246 _indexTestUnit(''' | 334 _indexTestUnit(''' |
| 247 class A { | 335 class A { |
| 248 int field; | 336 int field; |
| 249 | 337 |
| 250 method() {} | 338 method() {} |
| 251 } | 339 } |
| 252 main() { | 340 main() { |
| 253 new A(1, 2.0); | 341 new A(1, 2.0); |
| 254 } | 342 } |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 283 } | 371 } |
| 284 | 372 |
| 285 method() {} | 373 method() {} |
| 286 } | 374 } |
| 287 main() { | 375 main() { |
| 288 new A.named(1, 2.0); | 376 new A.named(1, 2.0); |
| 289 } | 377 } |
| 290 '''); | 378 '''); |
| 291 } | 379 } |
| 292 | 380 |
| 381 void test_createMissingOverrides_functionType() { | |
| 382 _indexTestUnit(''' | |
| 383 abstract class A { | |
| 384 forEach(int f(double p1, String p2)); | |
| 385 } | |
| 386 | |
| 387 class B extends A { | |
| 388 } | |
| 389 '''); | |
| 390 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, ''' | |
| 391 abstract class A { | |
| 392 forEach(int f(double p1, String p2)); | |
| 393 } | |
| 394 | |
| 395 class B extends A { | |
| 396 @override | |
| 397 forEach(int f(double p1, String p2)) { | |
| 398 // TODO: implement forEach | |
| 399 } | |
| 400 } | |
| 401 '''); | |
| 402 } | |
| 403 | |
| 404 void test_createMissingOverrides_generics() { | |
| 405 _indexTestUnit(''' | |
| 406 class Iterator<T> { | |
| 407 } | |
| 408 | |
| 409 abstract class IterableMixin<T> { | |
| 410 Iterator<T> get iterator; | |
| 411 } | |
| 412 | |
| 413 class Test extends IterableMixin<int> { | |
| 414 } | |
| 415 '''); | |
| 416 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, ''' | |
| 417 class Iterator<T> { | |
| 418 } | |
| 419 | |
| 420 abstract class IterableMixin<T> { | |
| 421 Iterator<T> get iterator; | |
| 422 } | |
| 423 | |
| 424 class Test extends IterableMixin<int> { | |
| 425 // TODO: implement iterator | |
| 426 @override | |
| 427 Iterator<int> get iterator => null; | |
| 428 } | |
| 429 '''); | |
| 430 } | |
| 431 | |
| 432 void test_createMissingOverrides_getter() { | |
| 433 _indexTestUnit(''' | |
| 434 abstract class A { | |
| 435 get g1; | |
| 436 int get g2; | |
| 437 } | |
| 438 | |
| 439 class B extends A { | |
| 440 } | |
| 441 '''); | |
| 442 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, ''' | |
| 443 abstract class A { | |
| 444 get g1; | |
| 445 int get g2; | |
| 446 } | |
| 447 | |
| 448 class B extends A { | |
| 449 // TODO: implement g1 | |
| 450 @override | |
| 451 get g1 => null; | |
| 452 | |
| 453 // TODO: implement g2 | |
| 454 @override | |
| 455 int get g2 => null; | |
| 456 } | |
| 457 '''); | |
| 458 } | |
| 459 | |
| 460 void test_createMissingOverrides_importPrefix() { | |
| 461 _indexTestUnit(''' | |
| 462 import 'dart:async' as aaa; | |
| 463 abstract class A { | |
| 464 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p); | |
| 465 } | |
| 466 | |
| 467 class B extends A { | |
| 468 } | |
| 469 '''); | |
| 470 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, ''' | |
| 471 import 'dart:async' as aaa; | |
| 472 abstract class A { | |
| 473 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p); | |
| 474 } | |
| 475 | |
| 476 class B extends A { | |
| 477 @override | |
| 478 Map<aaa.Future, List<aaa.Future>> g(aaa.Future p) { | |
| 479 // TODO: implement g | |
| 480 } | |
| 481 } | |
| 482 '''); | |
| 483 } | |
| 484 | |
| 485 void test_createMissingOverrides_method() { | |
| 486 _indexTestUnit(''' | |
| 487 abstract class A { | |
| 488 m1(); | |
| 489 int m2(); | |
| 490 String m3(int p1, double p2, Map<int, List<String>> p3); | |
| 491 String m4(p1, p2); | |
| 492 String m5(p1, [int p2 = 2, int p3, p4 = 4]); | |
| 493 String m6(p1, {int p2: 2, int p3, p4: 4}); | |
| 494 } | |
| 495 | |
| 496 class B extends A { | |
| 497 } | |
| 498 '''); | |
| 499 String expectedCode = ''' | |
| 500 abstract class A { | |
| 501 m1(); | |
| 502 int m2(); | |
| 503 String m3(int p1, double p2, Map<int, List<String>> p3); | |
| 504 String m4(p1, p2); | |
| 505 String m5(p1, [int p2 = 2, int p3, p4 = 4]); | |
| 506 String m6(p1, {int p2: 2, int p3, p4: 4}); | |
| 507 } | |
| 508 | |
| 509 class B extends A { | |
| 510 @override | |
| 511 m1() { | |
| 512 // TODO: implement m1 | |
| 513 } | |
| 514 | |
| 515 @override | |
| 516 int m2() { | |
| 517 // TODO: implement m2 | |
| 518 } | |
| 519 | |
| 520 @override | |
| 521 String m3(int p1, double p2, Map<int, List<String>> p3) { | |
| 522 // TODO: implement m3 | |
| 523 } | |
| 524 | |
| 525 @override | |
| 526 String m4(p1, p2) { | |
| 527 // TODO: implement m4 | |
| 528 } | |
| 529 | |
| 530 @override | |
| 531 String m5(p1, [int p2 = 2, int p3, p4 = 4]) { | |
| 532 // TODO: implement m5 | |
| 533 } | |
| 534 | |
| 535 @override | |
| 536 String m6(p1, {int p2: 2, int p3, p4: 4}) { | |
| 537 // TODO: implement m6 | |
| 538 } | |
| 539 } | |
| 540 '''; | |
| 541 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, expectedCode); | |
| 542 // end position should be on "m1", not on "m2", "m3", etc | |
| 543 { | |
| 544 Position endPosition = change.endPosition; | |
| 545 expect(endPosition, isNotNull); | |
| 546 expect(endPosition.file, testFile); | |
| 547 int endOffset = endPosition.offset; | |
| 548 String endString = expectedCode.substring(endOffset, endOffset + 25); | |
| 549 expect(endString, contains('m1')); | |
| 550 expect(endString, isNot(contains('m2'))); | |
| 551 expect(endString, isNot(contains('m3'))); | |
| 552 expect(endString, isNot(contains('m4'))); | |
| 553 expect(endString, isNot(contains('m5'))); | |
| 554 expect(endString, isNot(contains('m6'))); | |
| 555 } | |
| 556 } | |
| 557 | |
| 558 void test_createMissingOverrides_operator() { | |
| 559 _indexTestUnit(''' | |
| 560 abstract class A { | |
| 561 int operator [](int index); | |
| 562 void operator []=(int index, String value); | |
| 563 } | |
| 564 | |
| 565 class B extends A { | |
| 566 } | |
| 567 '''); | |
| 568 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, ''' | |
| 569 abstract class A { | |
| 570 int operator [](int index); | |
| 571 void operator []=(int index, String value); | |
| 572 } | |
| 573 | |
| 574 class B extends A { | |
| 575 @override | |
| 576 int operator [](int index) { | |
| 577 // TODO: implement [] | |
| 578 } | |
| 579 | |
| 580 @override | |
| 581 void operator []=(int index, String value) { | |
| 582 // TODO: implement []= | |
| 583 } | |
| 584 } | |
| 585 '''); | |
| 586 } | |
| 587 | |
| 588 void test_createMissingOverrides_setter() { | |
| 589 _indexTestUnit(''' | |
| 590 abstract class A { | |
| 591 set s1(x); | |
| 592 set s2(int x); | |
| 593 void set s3(String x); | |
| 594 } | |
| 595 | |
| 596 class B extends A { | |
| 597 } | |
| 598 '''); | |
| 599 assertHasFix(FixKind.CREATE_MISSING_OVERRIDES, ''' | |
| 600 abstract class A { | |
| 601 set s1(x); | |
| 602 set s2(int x); | |
| 603 void set s3(String x); | |
| 604 } | |
| 605 | |
| 606 class B extends A { | |
| 607 @override | |
| 608 set s1(x) { | |
| 609 // TODO: implement s1 | |
| 610 } | |
| 611 | |
| 612 @override | |
| 613 set s2(int x) { | |
| 614 // TODO: implement s2 | |
| 615 } | |
| 616 | |
| 617 @override | |
| 618 void set s3(String x) { | |
| 619 // TODO: implement s3 | |
| 620 } | |
| 621 } | |
| 622 '''); | |
| 623 } | |
| 624 | |
| 625 void test_createNoSuchMethod() { | |
| 626 _indexTestUnit(''' | |
| 627 abstract class A { | |
| 628 m1(); | |
| 629 int m2(); | |
| 630 } | |
| 631 | |
| 632 class B extends A { | |
| 633 existing() {} | |
| 634 } | |
| 635 '''); | |
| 636 assertHasFix(FixKind.CREATE_NO_SUCH_METHOD, ''' | |
| 637 abstract class A { | |
| 638 m1(); | |
| 639 int m2(); | |
| 640 } | |
| 641 | |
| 642 class B extends A { | |
| 643 existing() {} | |
| 644 | |
| 645 noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | |
| 646 } | |
| 647 '''); | |
| 648 } | |
| 649 | |
| 650 void test_creationFunction_forFunctionType_cascadeSecond() { | |
| 651 _indexTestUnit(''' | |
| 652 class A { | |
| 653 B ma() => null; | |
| 654 } | |
| 655 class B { | |
| 656 useFunction(int g(double a, String b)) {} | |
| 657 } | |
| 658 | |
| 659 main() { | |
| 660 A a = new A(); | |
| 661 a..ma().useFunction(test); | |
| 662 } | |
| 663 '''); | |
| 664 assertHasFix(FixKind.CREATE_FUNCTION, ''' | |
| 665 class A { | |
| 666 B ma() => null; | |
| 667 } | |
| 668 class B { | |
| 669 useFunction(int g(double a, String b)) {} | |
| 670 } | |
| 671 | |
| 672 main() { | |
| 673 A a = new A(); | |
| 674 a..ma().useFunction(test); | |
| 675 } | |
| 676 | |
| 677 int test(double a, String b) { | |
| 678 } | |
| 679 '''); | |
| 680 } | |
| 681 | |
| 682 void test_creationFunction_forFunctionType_function() { | |
| 683 _indexTestUnit(''' | |
| 684 main() { | |
| 685 useFunction(test); | |
| 686 } | |
| 687 useFunction(int g(double a, String b)) {} | |
| 688 '''); | |
| 689 assertHasFix(FixKind.CREATE_FUNCTION, ''' | |
| 690 main() { | |
| 691 useFunction(test); | |
| 692 } | |
| 693 useFunction(int g(double a, String b)) {} | |
| 694 | |
| 695 int test(double a, String b) { | |
| 696 } | |
| 697 '''); | |
| 698 } | |
| 699 | |
| 700 void test_creationFunction_forFunctionType_method_enclosingClass_static() { | |
| 701 _indexTestUnit(''' | |
| 702 class A { | |
| 703 static foo() { | |
| 704 useFunction(test); | |
| 705 } | |
| 706 } | |
| 707 useFunction(int g(double a, String b)) {} | |
| 708 '''); | |
| 709 assertHasFix(FixKind.CREATE_METHOD, ''' | |
| 710 class A { | |
| 711 static foo() { | |
| 712 useFunction(test); | |
| 713 } | |
| 714 | |
| 715 static int test(double a, String b) { | |
| 716 } | |
| 717 } | |
| 718 useFunction(int g(double a, String b)) {} | |
| 719 '''); | |
| 720 } | |
| 721 | |
| 722 void test_creationFunction_forFunctionType_method_targetClass() { | |
| 723 _indexTestUnit(''' | |
| 724 main(A a) { | |
| 725 useFunction(a.test); | |
| 726 } | |
| 727 class A { | |
| 728 } | |
| 729 useFunction(int g(double a, String b)) {} | |
| 730 '''); | |
| 731 assertHasFix(FixKind.CREATE_METHOD, ''' | |
| 732 main(A a) { | |
| 733 useFunction(a.test); | |
| 734 } | |
| 735 class A { | |
| 736 int test(double a, String b) { | |
| 737 } | |
| 738 } | |
| 739 useFunction(int g(double a, String b)) {} | |
| 740 '''); | |
| 741 } | |
| 742 | |
| 743 void | |
| 744 test_creationFunction_forFunctionType_method_targetClass_hasOtherMember() { | |
| 745 _indexTestUnit(''' | |
| 746 main(A a) { | |
| 747 useFunction(a.test); | |
| 748 } | |
| 749 class A { | |
| 750 m() {} | |
| 751 } | |
| 752 useFunction(int g(double a, String b)) {} | |
| 753 '''); | |
| 754 assertHasFix(FixKind.CREATE_METHOD, ''' | |
| 755 main(A a) { | |
| 756 useFunction(a.test); | |
| 757 } | |
| 758 class A { | |
| 759 m() {} | |
| 760 | |
| 761 int test(double a, String b) { | |
| 762 } | |
| 763 } | |
| 764 useFunction(int g(double a, String b)) {} | |
| 765 '''); | |
| 766 } | |
| 767 | |
| 768 void test_creationFunction_forFunctionType_notFunctionType() { | |
| 769 _indexTestUnit(''' | |
| 770 main(A a) { | |
| 771 useFunction(a.test); | |
| 772 } | |
| 773 typedef A(); | |
| 774 useFunction(g) {} | |
| 775 '''); | |
| 776 assertNoFix(FixKind.CREATE_METHOD); | |
| 777 assertNoFix(FixKind.CREATE_FUNCTION); | |
| 778 } | |
| 779 | |
| 780 void test_creationFunction_forFunctionType_unknownTarget() { | |
| 781 _indexTestUnit(''' | |
| 782 main(A a) { | |
| 783 useFunction(a.test); | |
| 784 } | |
| 785 class A { | |
| 786 } | |
| 787 useFunction(g) {} | |
| 788 '''); | |
| 789 assertNoFix(FixKind.CREATE_METHOD); | |
| 790 } | |
| 791 | |
| 293 void test_expectedToken_semicolon() { | 792 void test_expectedToken_semicolon() { |
| 294 _indexTestUnit(''' | 793 _indexTestUnit(''' |
| 295 main() { | 794 main() { |
| 296 print(0) | 795 print(0) |
| 297 } | 796 } |
| 298 '''); | 797 '''); |
| 299 assertHasFix(FixKind.INSERT_SEMICOLON, ''' | 798 assertHasFix(FixKind.INSERT_SEMICOLON, ''' |
| 300 main() { | 799 main() { |
| 301 print(0); | 800 print(0); |
| 302 } | 801 } |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 458 const a = new A(); | 957 const a = new A(); |
| 459 '''); | 958 '''); |
| 460 assertHasFix(FixKind.USE_CONST, ''' | 959 assertHasFix(FixKind.USE_CONST, ''' |
| 461 class A { | 960 class A { |
| 462 const A(); | 961 const A(); |
| 463 } | 962 } |
| 464 const a = const A(); | 963 const a = const A(); |
| 465 '''); | 964 '''); |
| 466 } | 965 } |
| 467 | 966 |
| 967 void test_undefinedMethod_createQualified_fromClass() { | |
| 968 _indexTestUnit(''' | |
| 969 class A { | |
| 970 } | |
| 971 main() { | |
| 972 A.myUndefinedMethod(); | |
| 973 } | |
| 974 '''); | |
| 975 assertHasFix(FixKind.CREATE_METHOD, ''' | |
| 976 class A { | |
| 977 static void myUndefinedMethod() { | |
| 978 } | |
| 979 } | |
| 980 main() { | |
| 981 A.myUndefinedMethod(); | |
| 982 } | |
| 983 '''); | |
| 984 } | |
| 985 | |
| 986 void test_undefinedMethod_createQualified_fromClass_hasOtherMember() { | |
| 987 _indexTestUnit(''' | |
| 988 class A { | |
| 989 foo() {} | |
| 990 } | |
| 991 main() { | |
| 992 A.myUndefinedMethod(); | |
| 993 } | |
| 994 '''); | |
| 995 assertHasFix(FixKind.CREATE_METHOD, ''' | |
| 996 class A { | |
| 997 foo() {} | |
| 998 | |
| 999 static void myUndefinedMethod() { | |
| 1000 } | |
| 1001 } | |
| 1002 main() { | |
| 1003 A.myUndefinedMethod(); | |
| 1004 } | |
| 1005 '''); | |
| 1006 } | |
| 1007 | |
| 1008 void test_undefinedMethod_createQualified_fromClass_unresolved() { | |
| 1009 _indexTestUnit(''' | |
| 1010 main() { | |
| 1011 NoSuchClass.myUndefinedMethod(); | |
| 1012 } | |
| 1013 '''); | |
| 1014 assertNoFix(FixKind.CREATE_METHOD); | |
| 1015 } | |
| 1016 | |
| 468 void test_useEffectiveIntegerDivision() { | 1017 void test_useEffectiveIntegerDivision() { |
| 469 _indexTestUnit(''' | 1018 _indexTestUnit(''' |
| 470 main() { | 1019 main() { |
| 471 var a = 5; | 1020 var a = 5; |
| 472 var b = 2; | 1021 var b = 2; |
| 473 print((a / b).toInt()); | 1022 print((a / b).toInt()); |
| 474 } | 1023 } |
| 475 '''); | 1024 '''); |
| 476 assertHasFix(FixKind.USE_EFFECTIVE_INTEGER_DIVISION, ''' | 1025 assertHasFix(FixKind.USE_EFFECTIVE_INTEGER_DIVISION, ''' |
| 477 main() { | 1026 main() { |
| 478 var a = 5; | 1027 var a = 5; |
| 479 var b = 2; | 1028 var b = 2; |
| 480 print(a ~/ b); | 1029 print(a ~/ b); |
| 481 } | 1030 } |
| 482 '''); | 1031 '''); |
| 483 } | 1032 } |
| 484 | 1033 |
| 485 String _applyEdits(String code, List<Edit> edits) { | 1034 String _applyEdits(String code, List<Edit> edits) { |
| 486 edits.sort((a, b) => b.offset - a.offset); | 1035 edits.sort((a, b) => a.offset - b.offset); |
| 1036 edits = edits.reversed.toList(); | |
|
Paul Berry
2014/07/25 00:28:46
What's the motivation for this change?
scheglov
2014/07/25 03:20:51
In order to avoid fixing offsets for Edit objects
| |
| 487 edits.forEach((Edit edit) { | 1037 edits.forEach((Edit edit) { |
| 488 code = code.substring(0, edit.offset) + | 1038 code = code.substring(0, edit.offset) + |
| 489 edit.replacement + | 1039 edit.replacement + |
| 490 code.substring(edit.end); | 1040 code.substring(edit.end); |
| 491 }); | 1041 }); |
| 492 return code; | 1042 return code; |
| 493 } | 1043 } |
| 494 | 1044 |
| 495 /** | 1045 /** |
| 496 * Computes fixes and verifies that there is a fix of the given kind. | 1046 * Computes fixes and verifies that there is a fix of the given kind. |
| 497 */ | 1047 */ |
| 498 Fix _assertHasFix(FixKind kind, AnalysisError error) { | 1048 Fix _assertHasFix(FixKind kind, AnalysisError error) { |
| 499 List<Fix> fixes = computeFixes(searchEngine, testFile, testUnit, error); | 1049 List<Fix> fixes = computeFixes(searchEngine, testUnit, error); |
| 500 for (Fix fix in fixes) { | 1050 for (Fix fix in fixes) { |
| 501 if (fix.kind == kind) { | 1051 if (fix.kind == kind) { |
| 502 return fix; | 1052 return fix; |
| 503 } | 1053 } |
| 504 } | 1054 } |
| 505 throw fail('Expected to find fix $kind in\n${fixes.join('\n')}'); | 1055 throw fail('Expected to find fix $kind in\n${fixes.join('\n')}'); |
| 506 } | 1056 } |
| 507 | 1057 |
| 508 AnalysisError _findErrorToFix() { | 1058 AnalysisError _findErrorToFix() { |
| 509 List<AnalysisError> errors = context.computeErrors(testSource); | 1059 List<AnalysisError> errors = context.computeErrors(testSource); |
| 510 expect( | 1060 expect( |
| 511 errors, | 1061 errors, |
| 512 hasLength(1), | 1062 hasLength(1), |
| 513 reason: 'Exactly 1 error expected, but ${errors.length} found:\n' + | 1063 reason: 'Exactly 1 error expected, but ${errors.length} found:\n' + |
| 514 errors.join('\n')); | 1064 errors.join('\n')); |
| 515 return errors[0]; | 1065 return errors[0]; |
| 516 } | 1066 } |
| 517 | 1067 |
| 518 void _indexTestUnit(String code) { | 1068 void _indexTestUnit(String code) { |
| 519 resolveTestUnit(code); | 1069 resolveTestUnit(code); |
| 520 index.indexUnit(context, testUnit); | 1070 index.indexUnit(context, testUnit); |
| 521 } | 1071 } |
| 522 } | 1072 } |
| OLD | NEW |