| 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 engine.all_the_rest_test; | 8 library engine.all_the_rest_test; |
| 9 | 9 |
| 10 import 'dart:collection'; | 10 import 'dart:collection'; |
| (...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 } | 454 } |
| 455 JUnitTestCase.fail(buffer.toString()); | 455 JUnitTestCase.fail(buffer.toString()); |
| 456 } | 456 } |
| 457 return firstToken; | 457 return firstToken; |
| 458 } | 458 } |
| 459 } | 459 } |
| 460 | 460 |
| 461 | 461 |
| 462 class AngularCompilationUnitBuilderTest extends AngularTest { | 462 class AngularCompilationUnitBuilderTest extends AngularTest { |
| 463 void test_Decorator() { | 463 void test_Decorator() { |
| 464 String mainContent = _createAngularSource( | 464 String mainContent = _createAngularSource(r''' |
| 465 [ | 465 @Decorator(selector: '[my-dir]', |
| 466 "@Decorator(selector: '[my-dir]',", | 466 map: const { |
| 467 " map: const {", | 467 'my-dir' : '=>myPropA', |
| 468 " 'my-dir' : '=>myPropA',", | 468 '.' : '&myPropB', |
| 469 " '.' : '&myPropB',", | 469 }) |
| 470 " })", | 470 class MyDirective { |
| 471 "class MyDirective {", | 471 set myPropA(value) {} |
| 472 " set myPropA(value) {}", | 472 set myPropB(value) {} |
| 473 " set myPropB(value) {}", | 473 @NgTwoWay('my-prop-c') |
| 474 " @NgTwoWay('my-prop-c')", | 474 String myPropC; |
| 475 " String myPropC;", | 475 }'''); |
| 476 "}"]); | |
| 477 resolveMainSourceNoErrors(mainContent); | 476 resolveMainSourceNoErrors(mainContent); |
| 478 // prepare AngularDirectiveElement | 477 // prepare AngularDirectiveElement |
| 479 ClassElement classElement = mainUnitElement.getType("MyDirective"); | 478 ClassElement classElement = mainUnitElement.getType("MyDirective"); |
| 480 AngularDecoratorElement directive = | 479 AngularDecoratorElement directive = |
| 481 getAngularElement(classElement, (e) => e is AngularDecoratorElement); | 480 getAngularElement(classElement, (e) => e is AngularDecoratorElement); |
| 482 JUnitTestCase.assertNotNull(directive); | 481 JUnitTestCase.assertNotNull(directive); |
| 483 // verify | 482 // verify |
| 484 JUnitTestCase.assertEquals(null, directive.name); | 483 JUnitTestCase.assertEquals(null, directive.name); |
| 485 JUnitTestCase.assertEquals(-1, directive.nameOffset); | 484 JUnitTestCase.assertEquals(-1, directive.nameOffset); |
| 486 _assertHasAttributeSelector(directive.selector, "my-dir"); | 485 _assertHasAttributeSelector(directive.selector, "my-dir"); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 504 _assertProperty( | 503 _assertProperty( |
| 505 properties[2], | 504 properties[2], |
| 506 "my-prop-c", | 505 "my-prop-c", |
| 507 findMainOffset("my-prop-c'"), | 506 findMainOffset("my-prop-c'"), |
| 508 AngularPropertyKind.TWO_WAY, | 507 AngularPropertyKind.TWO_WAY, |
| 509 "myPropC", | 508 "myPropC", |
| 510 -1); | 509 -1); |
| 511 } | 510 } |
| 512 | 511 |
| 513 void test_Decorator_bad_cannotParseSelector() { | 512 void test_Decorator_bad_cannotParseSelector() { |
| 514 String mainContent = _createAngularSource( | 513 String mainContent = _createAngularSource(r''' |
| 515 [ | 514 @Decorator(selector: '~bad-selector', |
| 516 "@Decorator(selector: '~bad-selector',", | 515 map: const { |
| 517 " map: const {", | 516 'my-dir' : '=>myPropA', |
| 518 " 'my-dir' : '=>myPropA',", | 517 '.' : '&myPropB', |
| 519 " '.' : '&myPropB',", | 518 }) |
| 520 " })", | 519 class MyDirective { |
| 521 "class MyDirective {", | 520 set myPropA(value) {} |
| 522 " set myPropA(value) {}", | 521 set myPropB(value) {} |
| 523 " set myPropB(value) {}", | 522 }'''); |
| 524 "}"]); | |
| 525 resolveMainSource(mainContent); | 523 resolveMainSource(mainContent); |
| 526 // has error | 524 // has error |
| 527 assertMainErrors([AngularCode.CANNOT_PARSE_SELECTOR]); | 525 assertMainErrors([AngularCode.CANNOT_PARSE_SELECTOR]); |
| 528 } | 526 } |
| 529 | 527 |
| 530 void test_Decorator_bad_missingSelector() { | 528 void test_Decorator_bad_missingSelector() { |
| 531 String mainContent = _createAngularSource( | 529 String mainContent = _createAngularSource(r''' |
| 532 [ | 530 @Decorator(/*selector: '[my-dir]',*/ |
| 533 "@Decorator(/*selector: '[my-dir]',*/", | 531 map: const { |
| 534 " map: const {", | 532 'my-dir' : '=>myPropA', |
| 535 " 'my-dir' : '=>myPropA',", | 533 '.' : '&myPropB', |
| 536 " '.' : '&myPropB',", | 534 }) |
| 537 " })", | 535 class MyDirective { |
| 538 "class MyDirective {", | 536 set myPropA(value) {} |
| 539 " set myPropA(value) {}", | 537 set myPropB(value) {} |
| 540 " set myPropB(value) {}", | 538 }'''); |
| 541 "}"]); | |
| 542 resolveMainSource(mainContent); | 539 resolveMainSource(mainContent); |
| 543 // has error | 540 // has error |
| 544 assertMainErrors([AngularCode.MISSING_SELECTOR]); | 541 assertMainErrors([AngularCode.MISSING_SELECTOR]); |
| 545 } | 542 } |
| 546 | 543 |
| 547 void test_Formatter() { | 544 void test_Formatter() { |
| 548 String mainContent = _createAngularSource( | 545 String mainContent = _createAngularSource(r''' |
| 549 ["@Formatter(name: 'myFilter')", "class MyFilter {", " call(p1, p2) {}"
, "}"]); | 546 @Formatter(name: 'myFilter') |
| 547 class MyFilter { |
| 548 call(p1, p2) {} |
| 549 }'''); |
| 550 resolveMainSourceNoErrors(mainContent); | 550 resolveMainSourceNoErrors(mainContent); |
| 551 // prepare AngularFilterElement | 551 // prepare AngularFilterElement |
| 552 ClassElement classElement = mainUnitElement.getType("MyFilter"); | 552 ClassElement classElement = mainUnitElement.getType("MyFilter"); |
| 553 AngularFormatterElement filter = | 553 AngularFormatterElement filter = |
| 554 getAngularElement(classElement, (e) => e is AngularFormatterElement); | 554 getAngularElement(classElement, (e) => e is AngularFormatterElement); |
| 555 JUnitTestCase.assertNotNull(filter); | 555 JUnitTestCase.assertNotNull(filter); |
| 556 // verify | 556 // verify |
| 557 JUnitTestCase.assertEquals("myFilter", filter.name); | 557 JUnitTestCase.assertEquals("myFilter", filter.name); |
| 558 JUnitTestCase.assertEquals( | 558 JUnitTestCase.assertEquals( |
| 559 AngularTest.findOffset(mainContent, "myFilter'"), | 559 AngularTest.findOffset(mainContent, "myFilter'"), |
| 560 filter.nameOffset); | 560 filter.nameOffset); |
| 561 } | 561 } |
| 562 | 562 |
| 563 void test_Formatter_missingName() { | 563 void test_Formatter_missingName() { |
| 564 String mainContent = _createAngularSource( | 564 String mainContent = _createAngularSource(r''' |
| 565 ["@Formatter()", "class MyFilter {", " call(p1, p2) {}", "}"]); | 565 @Formatter() |
| 566 class MyFilter { |
| 567 call(p1, p2) {} |
| 568 }'''); |
| 566 resolveMainSource(mainContent); | 569 resolveMainSource(mainContent); |
| 567 // has error | 570 // has error |
| 568 assertMainErrors([AngularCode.MISSING_NAME]); | 571 assertMainErrors([AngularCode.MISSING_NAME]); |
| 569 // no filter | 572 // no filter |
| 570 ClassElement classElement = mainUnitElement.getType("MyFilter"); | 573 ClassElement classElement = mainUnitElement.getType("MyFilter"); |
| 571 AngularFormatterElement filter = | 574 AngularFormatterElement filter = |
| 572 getAngularElement(classElement, (e) => e is AngularFormatterElement); | 575 getAngularElement(classElement, (e) => e is AngularFormatterElement); |
| 573 JUnitTestCase.assertNull(filter); | 576 JUnitTestCase.assertNull(filter); |
| 574 } | 577 } |
| 575 | 578 |
| 576 void test_NgComponent_bad_cannotParseSelector() { | 579 void test_NgComponent_bad_cannotParseSelector() { |
| 577 contextHelper.addSource("/my_template.html", ""); | 580 contextHelper.addSource("/my_template.html", ""); |
| 578 contextHelper.addSource("/my_styles.css", ""); | 581 contextHelper.addSource("/my_styles.css", ""); |
| 579 String mainContent = _createAngularSource( | 582 String mainContent = _createAngularSource(r''' |
| 580 [ | 583 @Component(publishAs: 'ctrl', selector: '~myComp', |
| 581 "@Component(publishAs: 'ctrl', selector: '~myComp',", | 584 templateUrl: 'my_template.html', cssUrl: 'my_styles.css') |
| 582 " templateUrl: 'my_template.html', cssUrl: 'my_styles.cs
s')", | 585 class MyComponent { |
| 583 "class MyComponent {", | 586 }'''); |
| 584 "}"]); | |
| 585 resolveMainSource(mainContent); | 587 resolveMainSource(mainContent); |
| 586 // has error | 588 // has error |
| 587 assertMainErrors([AngularCode.CANNOT_PARSE_SELECTOR]); | 589 assertMainErrors([AngularCode.CANNOT_PARSE_SELECTOR]); |
| 588 } | 590 } |
| 589 | 591 |
| 590 void test_NgComponent_bad_missingSelector() { | 592 void test_NgComponent_bad_missingSelector() { |
| 591 contextHelper.addSource("/my_template.html", ""); | 593 contextHelper.addSource("/my_template.html", ""); |
| 592 contextHelper.addSource("/my_styles.css", ""); | 594 contextHelper.addSource("/my_styles.css", ""); |
| 593 String mainContent = _createAngularSource( | 595 String mainContent = _createAngularSource(r''' |
| 594 [ | 596 @Component(publishAs: 'ctrl', /*selector: 'myComp',*/ |
| 595 "@Component(publishAs: 'ctrl', /*selector: 'myComp',*/", | 597 templateUrl: 'my_template.html', cssUrl: 'my_styles.css') |
| 596 " templateUrl: 'my_template.html', cssUrl: 'my_styles.cs
s')", | 598 class MyComponent { |
| 597 "class MyComponent {", | 599 }'''); |
| 598 "}"]); | |
| 599 resolveMainSource(mainContent); | 600 resolveMainSource(mainContent); |
| 600 // has error | 601 // has error |
| 601 assertMainErrors([AngularCode.MISSING_SELECTOR]); | 602 assertMainErrors([AngularCode.MISSING_SELECTOR]); |
| 602 } | 603 } |
| 603 | 604 |
| 604 /** | 605 /** |
| 605 * | 606 * |
| 606 * https://code.google.com/p/dart/issues/detail?id=16346 | 607 * https://code.google.com/p/dart/issues/detail?id=16346 |
| 607 */ | 608 */ |
| 608 void test_NgComponent_bad_notHtmlTemplate() { | 609 void test_NgComponent_bad_notHtmlTemplate() { |
| 609 contextHelper.addSource("/my_template", ""); | 610 contextHelper.addSource("/my_template", ""); |
| 610 contextHelper.addSource("/my_styles.css", ""); | 611 contextHelper.addSource("/my_styles.css", ""); |
| 611 addMainSource( | 612 addMainSource( |
| 612 _createAngularSource( | 613 _createAngularSource(r''' |
| 613 [ | 614 @NgComponent(publishAs: 'ctrl', selector: 'myComp', |
| 614 "@NgComponent(publishAs: 'ctrl', selector: 'myComp',", | 615 templateUrl: 'my_template', cssUrl: 'my_styles.css') |
| 615 " templateUrl: 'my_template', cssUrl: 'my_styles.css
')", | 616 class MyComponent { |
| 616 "class MyComponent {", | 617 }''')); |
| 617 "}"])); | |
| 618 contextHelper.runTasks(); | 618 contextHelper.runTasks(); |
| 619 } | 619 } |
| 620 | 620 |
| 621 void test_NgComponent_bad_properties_invalidBinding() { | 621 void test_NgComponent_bad_properties_invalidBinding() { |
| 622 contextHelper.addSource("/my_template.html", ""); | 622 contextHelper.addSource("/my_template.html", ""); |
| 623 contextHelper.addSource("/my_styles.css", ""); | 623 contextHelper.addSource("/my_styles.css", ""); |
| 624 String mainContent = _createAngularSource( | 624 String mainContent = _createAngularSource(r''' |
| 625 [ | 625 @Component(publishAs: 'ctrl', selector: 'myComp', |
| 626 "@Component(publishAs: 'ctrl', selector: 'myComp',", | 626 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', |
| 627 " templateUrl: 'my_template.html', cssUrl: 'my_styles.cs
s',", | 627 map: const {'name' : '?field'}) |
| 628 " map: const {'name' : '?field'})", | 628 class MyComponent { |
| 629 "class MyComponent {", | 629 }'''); |
| 630 "}"]); | |
| 631 resolveMainSource(mainContent); | 630 resolveMainSource(mainContent); |
| 632 // has error | 631 // has error |
| 633 assertMainErrors([AngularCode.INVALID_PROPERTY_KIND]); | 632 assertMainErrors([AngularCode.INVALID_PROPERTY_KIND]); |
| 634 } | 633 } |
| 635 | 634 |
| 636 void test_NgComponent_bad_properties_nameNotStringLiteral() { | 635 void test_NgComponent_bad_properties_nameNotStringLiteral() { |
| 637 contextHelper.addSource("/my_template.html", ""); | 636 contextHelper.addSource("/my_template.html", ""); |
| 638 contextHelper.addSource("/my_styles.css", ""); | 637 contextHelper.addSource("/my_styles.css", ""); |
| 639 String mainContent = _createAngularSource( | 638 String mainContent = _createAngularSource(r''' |
| 640 [ | 639 @Component(publishAs: 'ctrl', selector: 'myComp', |
| 641 "@Component(publishAs: 'ctrl', selector: 'myComp',", | 640 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', |
| 642 " templateUrl: 'my_template.html', cssUrl: 'my_styles.cs
s',", | 641 map: const {null : 'field'}) |
| 643 " map: const {null : 'field'})", | 642 class MyComponent { |
| 644 "class MyComponent {", | 643 }'''); |
| 645 "}"]); | |
| 646 resolveMainSource(mainContent); | 644 resolveMainSource(mainContent); |
| 647 // has error | 645 // has error |
| 648 assertMainErrors([AngularCode.INVALID_PROPERTY_NAME]); | 646 assertMainErrors([AngularCode.INVALID_PROPERTY_NAME]); |
| 649 } | 647 } |
| 650 | 648 |
| 651 void test_NgComponent_bad_properties_noSuchField() { | 649 void test_NgComponent_bad_properties_noSuchField() { |
| 652 contextHelper.addSource("/my_template.html", ""); | 650 contextHelper.addSource("/my_template.html", ""); |
| 653 contextHelper.addSource("/my_styles.css", ""); | 651 contextHelper.addSource("/my_styles.css", ""); |
| 654 String mainContent = _createAngularSource( | 652 String mainContent = _createAngularSource(r''' |
| 655 [ | 653 @Component(publishAs: 'ctrl', selector: 'myComp', |
| 656 "@Component(publishAs: 'ctrl', selector: 'myComp',", | 654 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', |
| 657 " templateUrl: 'my_template.html', cssUrl: 'my_styles.cs
s',", | 655 map: const {'name' : '=>field'}) |
| 658 " map: const {'name' : '=>field'})", | 656 class MyComponent { |
| 659 "class MyComponent {", | 657 }'''); |
| 660 "}"]); | |
| 661 resolveMainSource(mainContent); | 658 resolveMainSource(mainContent); |
| 662 // has error | 659 // has error |
| 663 assertMainErrors([AngularCode.INVALID_PROPERTY_FIELD]); | 660 assertMainErrors([AngularCode.INVALID_PROPERTY_FIELD]); |
| 664 } | 661 } |
| 665 | 662 |
| 666 void test_NgComponent_bad_properties_notMapLiteral() { | 663 void test_NgComponent_bad_properties_notMapLiteral() { |
| 667 contextHelper.addSource("/my_template.html", ""); | 664 contextHelper.addSource("/my_template.html", ""); |
| 668 contextHelper.addSource("/my_styles.css", ""); | 665 contextHelper.addSource("/my_styles.css", ""); |
| 669 String mainContent = _createAngularSource( | 666 String mainContent = _createAngularSource(r''' |
| 670 [ | 667 @Component(publishAs: 'ctrl', selector: 'myComp', |
| 671 "@Component(publishAs: 'ctrl', selector: 'myComp',", | 668 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', |
| 672 " templateUrl: 'my_template.html', cssUrl: 'my_styles.cs
s',", | 669 map: null) |
| 673 " map: null)", | 670 class MyComponent { |
| 674 "class MyComponent {", | 671 }'''); |
| 675 "}"]); | |
| 676 resolveMainSource(mainContent); | 672 resolveMainSource(mainContent); |
| 677 // has error | 673 // has error |
| 678 assertMainErrors([AngularCode.INVALID_PROPERTY_MAP]); | 674 assertMainErrors([AngularCode.INVALID_PROPERTY_MAP]); |
| 679 } | 675 } |
| 680 | 676 |
| 681 void test_NgComponent_bad_properties_specNotStringLiteral() { | 677 void test_NgComponent_bad_properties_specNotStringLiteral() { |
| 682 contextHelper.addSource("/my_template.html", ""); | 678 contextHelper.addSource("/my_template.html", ""); |
| 683 contextHelper.addSource("/my_styles.css", ""); | 679 contextHelper.addSource("/my_styles.css", ""); |
| 684 String mainContent = _createAngularSource( | 680 String mainContent = _createAngularSource(r''' |
| 685 [ | 681 @Component(publishAs: 'ctrl', selector: 'myComp', |
| 686 "@Component(publishAs: 'ctrl', selector: 'myComp',", | 682 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', |
| 687 " templateUrl: 'my_template.html', cssUrl: 'my_styles.cs
s',", | 683 map: const {'name' : null}) |
| 688 " map: const {'name' : null})", | 684 class MyComponent { |
| 689 "class MyComponent {", | 685 }'''); |
| 690 "}"]); | |
| 691 resolveMainSource(mainContent); | 686 resolveMainSource(mainContent); |
| 692 // has error | 687 // has error |
| 693 assertMainErrors([AngularCode.INVALID_PROPERTY_SPEC]); | 688 assertMainErrors([AngularCode.INVALID_PROPERTY_SPEC]); |
| 694 } | 689 } |
| 695 | 690 |
| 696 void test_NgComponent_no_cssUrl() { | 691 void test_NgComponent_no_cssUrl() { |
| 697 contextHelper.addSource("/my_template.html", ""); | 692 contextHelper.addSource("/my_template.html", ""); |
| 698 contextHelper.addSource("/my_styles.css", ""); | 693 contextHelper.addSource("/my_styles.css", ""); |
| 699 String mainContent = _createAngularSource( | 694 String mainContent = _createAngularSource(r''' |
| 700 [ | 695 @Component(publishAs: 'ctrl', selector: 'myComp', |
| 701 "@Component(publishAs: 'ctrl', selector: 'myComp',", | 696 templateUrl: 'my_template.html'/*, cssUrl: 'my_styles.css'*/) |
| 702 " templateUrl: 'my_template.html'/*, cssUrl: 'my_styles.
css'*/)", | 697 class MyComponent { |
| 703 "class MyComponent {", | 698 }'''); |
| 704 "}"]); | |
| 705 resolveMainSource(mainContent); | 699 resolveMainSource(mainContent); |
| 706 // prepare AngularComponentElement | 700 // prepare AngularComponentElement |
| 707 ClassElement classElement = mainUnitElement.getType("MyComponent"); | 701 ClassElement classElement = mainUnitElement.getType("MyComponent"); |
| 708 AngularComponentElement component = | 702 AngularComponentElement component = |
| 709 getAngularElement(classElement, (e) => e is AngularComponentElement); | 703 getAngularElement(classElement, (e) => e is AngularComponentElement); |
| 710 JUnitTestCase.assertNotNull(component); | 704 JUnitTestCase.assertNotNull(component); |
| 711 // no CSS | 705 // no CSS |
| 712 JUnitTestCase.assertEquals(null, component.styleUri); | 706 JUnitTestCase.assertEquals(null, component.styleUri); |
| 713 JUnitTestCase.assertEquals(-1, component.styleUriOffset); | 707 JUnitTestCase.assertEquals(-1, component.styleUriOffset); |
| 714 } | 708 } |
| 715 | 709 |
| 716 void test_NgComponent_no_publishAs() { | 710 void test_NgComponent_no_publishAs() { |
| 717 contextHelper.addSource("/my_template.html", ""); | 711 contextHelper.addSource("/my_template.html", ""); |
| 718 contextHelper.addSource("/my_styles.css", ""); | 712 contextHelper.addSource("/my_styles.css", ""); |
| 719 String mainContent = _createAngularSource( | 713 String mainContent = _createAngularSource(r''' |
| 720 [ | 714 @Component(/*publishAs: 'ctrl',*/ selector: 'myComp', |
| 721 "@Component(/*publishAs: 'ctrl',*/ selector: 'myComp',", | 715 templateUrl: 'my_template.html', cssUrl: 'my_styles.css') |
| 722 " templateUrl: 'my_template.html', cssUrl: 'my_styles.cs
s')", | 716 class MyComponent { |
| 723 "class MyComponent {", | 717 }'''); |
| 724 "}"]); | |
| 725 resolveMainSource(mainContent); | 718 resolveMainSource(mainContent); |
| 726 // prepare AngularComponentElement | 719 // prepare AngularComponentElement |
| 727 ClassElement classElement = mainUnitElement.getType("MyComponent"); | 720 ClassElement classElement = mainUnitElement.getType("MyComponent"); |
| 728 AngularComponentElement component = | 721 AngularComponentElement component = |
| 729 getAngularElement(classElement, (e) => e is AngularComponentElement); | 722 getAngularElement(classElement, (e) => e is AngularComponentElement); |
| 730 JUnitTestCase.assertNotNull(component); | 723 JUnitTestCase.assertNotNull(component); |
| 731 // no name | 724 // no name |
| 732 JUnitTestCase.assertEquals(null, component.name); | 725 JUnitTestCase.assertEquals(null, component.name); |
| 733 JUnitTestCase.assertEquals(-1, component.nameOffset); | 726 JUnitTestCase.assertEquals(-1, component.nameOffset); |
| 734 } | 727 } |
| 735 | 728 |
| 736 void test_NgComponent_no_templateUrl() { | 729 void test_NgComponent_no_templateUrl() { |
| 737 contextHelper.addSource("/my_template.html", ""); | 730 contextHelper.addSource("/my_template.html", ""); |
| 738 contextHelper.addSource("/my_styles.css", ""); | 731 contextHelper.addSource("/my_styles.css", ""); |
| 739 String mainContent = _createAngularSource( | 732 String mainContent = _createAngularSource(r''' |
| 740 [ | 733 @Component(publishAs: 'ctrl', selector: 'myComp', |
| 741 "@Component(publishAs: 'ctrl', selector: 'myComp',", | 734 /*templateUrl: 'my_template.html',*/ cssUrl: 'my_styles.css') |
| 742 " /*templateUrl: 'my_template.html',*/ cssUrl: 'my_style
s.css')", | 735 class MyComponent { |
| 743 "class MyComponent {", | 736 }'''); |
| 744 "}"]); | |
| 745 resolveMainSource(mainContent); | 737 resolveMainSource(mainContent); |
| 746 // prepare AngularComponentElement | 738 // prepare AngularComponentElement |
| 747 ClassElement classElement = mainUnitElement.getType("MyComponent"); | 739 ClassElement classElement = mainUnitElement.getType("MyComponent"); |
| 748 AngularComponentElement component = | 740 AngularComponentElement component = |
| 749 getAngularElement(classElement, (e) => e is AngularComponentElement); | 741 getAngularElement(classElement, (e) => e is AngularComponentElement); |
| 750 JUnitTestCase.assertNotNull(component); | 742 JUnitTestCase.assertNotNull(component); |
| 751 // no template | 743 // no template |
| 752 JUnitTestCase.assertEquals(null, component.templateUri); | 744 JUnitTestCase.assertEquals(null, component.templateUri); |
| 753 JUnitTestCase.assertEquals(null, component.templateSource); | 745 JUnitTestCase.assertEquals(null, component.templateSource); |
| 754 JUnitTestCase.assertEquals(-1, component.templateUriOffset); | 746 JUnitTestCase.assertEquals(-1, component.templateUriOffset); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 769 class MyComponent { | 761 class MyComponent { |
| 770 }'''; | 762 }'''; |
| 771 resolveMainSource(mainContent); | 763 resolveMainSource(mainContent); |
| 772 assertNoMainErrors(); | 764 assertNoMainErrors(); |
| 773 } | 765 } |
| 774 | 766 |
| 775 void test_NgComponent_properties_fieldFromSuper() { | 767 void test_NgComponent_properties_fieldFromSuper() { |
| 776 contextHelper.addSource("/my_template.html", ""); | 768 contextHelper.addSource("/my_template.html", ""); |
| 777 contextHelper.addSource("/my_styles.css", ""); | 769 contextHelper.addSource("/my_styles.css", ""); |
| 778 resolveMainSourceNoErrors( | 770 resolveMainSourceNoErrors( |
| 779 _createAngularSource( | 771 _createAngularSource(r''' |
| 780 [ | 772 class MySuper { |
| 781 "class MySuper {", | 773 var myPropA; |
| 782 " var myPropA;", | 774 } |
| 783 "}", | 775 |
| 784 "", | 776 |
| 785 "", | 777 |
| 786 "", | 778 @Component(publishAs: 'ctrl', selector: 'myComp', |
| 787 "@Component(publishAs: 'ctrl', selector: 'myComp',", | 779 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', |
| 788 " templateUrl: 'my_template.html', cssUrl: 'my_style
s.css',", | 780 map: const { |
| 789 " map: const {", | 781 'prop-a' : '@myPropA' |
| 790 " 'prop-a' : '@myPropA'", | 782 }) |
| 791 " })", | 783 class MyComponent extends MySuper { |
| 792 "class MyComponent extends MySuper {", | 784 }''')); |
| 793 "}"])); | |
| 794 // prepare AngularComponentElement | 785 // prepare AngularComponentElement |
| 795 ClassElement classElement = mainUnitElement.getType("MyComponent"); | 786 ClassElement classElement = mainUnitElement.getType("MyComponent"); |
| 796 AngularComponentElement component = | 787 AngularComponentElement component = |
| 797 getAngularElement(classElement, (e) => e is AngularComponentElement); | 788 getAngularElement(classElement, (e) => e is AngularComponentElement); |
| 798 JUnitTestCase.assertNotNull(component); | 789 JUnitTestCase.assertNotNull(component); |
| 799 // verify | 790 // verify |
| 800 List<AngularPropertyElement> properties = component.properties; | 791 List<AngularPropertyElement> properties = component.properties; |
| 801 EngineTestCase.assertLength(1, properties); | 792 EngineTestCase.assertLength(1, properties); |
| 802 _assertProperty( | 793 _assertProperty( |
| 803 properties[0], | 794 properties[0], |
| 804 "prop-a", | 795 "prop-a", |
| 805 findMainOffset("prop-a' :"), | 796 findMainOffset("prop-a' :"), |
| 806 AngularPropertyKind.ATTR, | 797 AngularPropertyKind.ATTR, |
| 807 "myPropA", | 798 "myPropA", |
| 808 findMainOffset("myPropA'")); | 799 findMainOffset("myPropA'")); |
| 809 } | 800 } |
| 810 | 801 |
| 811 void test_NgComponent_properties_fromFields() { | 802 void test_NgComponent_properties_fromFields() { |
| 812 contextHelper.addSource("/my_template.html", ""); | 803 contextHelper.addSource("/my_template.html", ""); |
| 813 contextHelper.addSource("/my_styles.css", ""); | 804 contextHelper.addSource("/my_styles.css", ""); |
| 814 resolveMainSourceNoErrors( | 805 resolveMainSourceNoErrors( |
| 815 _createAngularSource( | 806 _createAngularSource(r''' |
| 816 [ | 807 @Component(publishAs: 'ctrl', selector: 'myComp', |
| 817 "@Component(publishAs: 'ctrl', selector: 'myComp',", | 808 templateUrl: 'my_template.html', cssUrl: 'my_styles.css') |
| 818 " templateUrl: 'my_template.html', cssUrl: 'my_style
s.css')", | 809 class MyComponent { |
| 819 "class MyComponent {", | 810 @NgAttr('prop-a') |
| 820 " @NgAttr('prop-a')", | 811 var myPropA; |
| 821 " var myPropA;", | 812 @NgCallback('prop-b') |
| 822 " @NgCallback('prop-b')", | 813 var myPropB; |
| 823 " var myPropB;", | 814 @NgOneWay('prop-c') |
| 824 " @NgOneWay('prop-c')", | 815 var myPropC; |
| 825 " var myPropC;", | 816 @NgOneWayOneTime('prop-d') |
| 826 " @NgOneWayOneTime('prop-d')", | 817 var myPropD; |
| 827 " var myPropD;", | 818 @NgTwoWay('prop-e') |
| 828 " @NgTwoWay('prop-e')", | 819 var myPropE; |
| 829 " var myPropE;", | 820 }''')); |
| 830 "}"])); | |
| 831 // prepare AngularComponentElement | 821 // prepare AngularComponentElement |
| 832 ClassElement classElement = mainUnitElement.getType("MyComponent"); | 822 ClassElement classElement = mainUnitElement.getType("MyComponent"); |
| 833 AngularComponentElement component = | 823 AngularComponentElement component = |
| 834 getAngularElement(classElement, (e) => e is AngularComponentElement); | 824 getAngularElement(classElement, (e) => e is AngularComponentElement); |
| 835 JUnitTestCase.assertNotNull(component); | 825 JUnitTestCase.assertNotNull(component); |
| 836 // verify | 826 // verify |
| 837 List<AngularPropertyElement> properties = component.properties; | 827 List<AngularPropertyElement> properties = component.properties; |
| 838 EngineTestCase.assertLength(5, properties); | 828 EngineTestCase.assertLength(5, properties); |
| 839 _assertProperty( | 829 _assertProperty( |
| 840 properties[0], | 830 properties[0], |
| (...skipping 29 matching lines...) Expand all Loading... |
| 870 findMainOffset("prop-e')"), | 860 findMainOffset("prop-e')"), |
| 871 AngularPropertyKind.TWO_WAY, | 861 AngularPropertyKind.TWO_WAY, |
| 872 "myPropE", | 862 "myPropE", |
| 873 -1); | 863 -1); |
| 874 } | 864 } |
| 875 | 865 |
| 876 void test_NgComponent_properties_fromMap() { | 866 void test_NgComponent_properties_fromMap() { |
| 877 contextHelper.addSource("/my_template.html", ""); | 867 contextHelper.addSource("/my_template.html", ""); |
| 878 contextHelper.addSource("/my_styles.css", ""); | 868 contextHelper.addSource("/my_styles.css", ""); |
| 879 resolveMainSourceNoErrors( | 869 resolveMainSourceNoErrors( |
| 880 _createAngularSource( | 870 _createAngularSource(r''' |
| 881 [ | 871 @Component(publishAs: 'ctrl', selector: 'myComp', |
| 882 "@Component(publishAs: 'ctrl', selector: 'myComp',", | 872 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', |
| 883 " templateUrl: 'my_template.html', cssUrl: 'my_style
s.css',", | 873 map: const { |
| 884 " map: const {", | 874 'prop-a' : '@myPropA', |
| 885 " 'prop-a' : '@myPropA',", | 875 'prop-b' : '&myPropB', |
| 886 " 'prop-b' : '&myPropB',", | 876 'prop-c' : '=>myPropC', |
| 887 " 'prop-c' : '=>myPropC',", | 877 'prop-d' : '=>!myPropD', |
| 888 " 'prop-d' : '=>!myPropD',", | 878 'prop-e' : '<=>myPropE' |
| 889 " 'prop-e' : '<=>myPropE'", | 879 }) |
| 890 " })", | 880 class MyComponent { |
| 891 "class MyComponent {", | 881 var myPropA; |
| 892 " var myPropA;", | 882 var myPropB; |
| 893 " var myPropB;", | 883 var myPropC; |
| 894 " var myPropC;", | 884 var myPropD; |
| 895 " var myPropD;", | 885 var myPropE; |
| 896 " var myPropE;", | 886 }''')); |
| 897 "}"])); | |
| 898 // prepare AngularComponentElement | 887 // prepare AngularComponentElement |
| 899 ClassElement classElement = mainUnitElement.getType("MyComponent"); | 888 ClassElement classElement = mainUnitElement.getType("MyComponent"); |
| 900 AngularComponentElement component = | 889 AngularComponentElement component = |
| 901 getAngularElement(classElement, (e) => e is AngularComponentElement); | 890 getAngularElement(classElement, (e) => e is AngularComponentElement); |
| 902 JUnitTestCase.assertNotNull(component); | 891 JUnitTestCase.assertNotNull(component); |
| 903 // verify | 892 // verify |
| 904 List<AngularPropertyElement> properties = component.properties; | 893 List<AngularPropertyElement> properties = component.properties; |
| 905 EngineTestCase.assertLength(5, properties); | 894 EngineTestCase.assertLength(5, properties); |
| 906 _assertProperty( | 895 _assertProperty( |
| 907 properties[0], | 896 properties[0], |
| (...skipping 28 matching lines...) Expand all Loading... |
| 936 "prop-e", | 925 "prop-e", |
| 937 findMainOffset("prop-e' :"), | 926 findMainOffset("prop-e' :"), |
| 938 AngularPropertyKind.TWO_WAY, | 927 AngularPropertyKind.TWO_WAY, |
| 939 "myPropE", | 928 "myPropE", |
| 940 findMainOffset("myPropE'")); | 929 findMainOffset("myPropE'")); |
| 941 } | 930 } |
| 942 | 931 |
| 943 void test_NgComponent_properties_no() { | 932 void test_NgComponent_properties_no() { |
| 944 contextHelper.addSource("/my_template.html", ""); | 933 contextHelper.addSource("/my_template.html", ""); |
| 945 contextHelper.addSource("/my_styles.css", ""); | 934 contextHelper.addSource("/my_styles.css", ""); |
| 946 String mainContent = _createAngularSource( | 935 String mainContent = _createAngularSource(r''' |
| 947 [ | 936 @Component(publishAs: 'ctrl', selector: 'myComp', |
| 948 "@Component(publishAs: 'ctrl', selector: 'myComp',", | 937 templateUrl: 'my_template.html', cssUrl: 'my_styles.css') |
| 949 " templateUrl: 'my_template.html', cssUrl: 'my_styles.cs
s')", | 938 class MyComponent { |
| 950 "class MyComponent {", | 939 }'''); |
| 951 "}"]); | |
| 952 resolveMainSourceNoErrors(mainContent); | 940 resolveMainSourceNoErrors(mainContent); |
| 953 // prepare AngularComponentElement | 941 // prepare AngularComponentElement |
| 954 ClassElement classElement = mainUnitElement.getType("MyComponent"); | 942 ClassElement classElement = mainUnitElement.getType("MyComponent"); |
| 955 AngularComponentElement component = | 943 AngularComponentElement component = |
| 956 getAngularElement(classElement, (e) => e is AngularComponentElement); | 944 getAngularElement(classElement, (e) => e is AngularComponentElement); |
| 957 JUnitTestCase.assertNotNull(component); | 945 JUnitTestCase.assertNotNull(component); |
| 958 // verify | 946 // verify |
| 959 JUnitTestCase.assertEquals("ctrl", component.name); | 947 JUnitTestCase.assertEquals("ctrl", component.name); |
| 960 JUnitTestCase.assertEquals( | 948 JUnitTestCase.assertEquals( |
| 961 AngularTest.findOffset(mainContent, "ctrl'"), | 949 AngularTest.findOffset(mainContent, "ctrl'"), |
| 962 component.nameOffset); | 950 component.nameOffset); |
| 963 _assertIsTagSelector(component.selector, "myComp"); | 951 _assertIsTagSelector(component.selector, "myComp"); |
| 964 JUnitTestCase.assertEquals("my_template.html", component.templateUri); | 952 JUnitTestCase.assertEquals("my_template.html", component.templateUri); |
| 965 JUnitTestCase.assertEquals( | 953 JUnitTestCase.assertEquals( |
| 966 AngularTest.findOffset(mainContent, "my_template.html'"), | 954 AngularTest.findOffset(mainContent, "my_template.html'"), |
| 967 component.templateUriOffset); | 955 component.templateUriOffset); |
| 968 JUnitTestCase.assertEquals("my_styles.css", component.styleUri); | 956 JUnitTestCase.assertEquals("my_styles.css", component.styleUri); |
| 969 JUnitTestCase.assertEquals( | 957 JUnitTestCase.assertEquals( |
| 970 AngularTest.findOffset(mainContent, "my_styles.css'"), | 958 AngularTest.findOffset(mainContent, "my_styles.css'"), |
| 971 component.styleUriOffset); | 959 component.styleUriOffset); |
| 972 EngineTestCase.assertLength(0, component.properties); | 960 EngineTestCase.assertLength(0, component.properties); |
| 973 } | 961 } |
| 974 | 962 |
| 975 void test_NgComponent_scopeProperties() { | 963 void test_NgComponent_scopeProperties() { |
| 976 contextHelper.addSource("/my_template.html", ""); | 964 contextHelper.addSource("/my_template.html", ""); |
| 977 contextHelper.addSource("/my_styles.css", ""); | 965 contextHelper.addSource("/my_styles.css", ""); |
| 978 String mainContent = _createAngularSource( | 966 String mainContent = _createAngularSource(r''' |
| 979 [ | 967 @Component(publishAs: 'ctrl', selector: 'myComp', |
| 980 "@Component(publishAs: 'ctrl', selector: 'myComp',", | 968 templateUrl: 'my_template.html', cssUrl: 'my_styles.css') |
| 981 " templateUrl: 'my_template.html', cssUrl: 'my_styles.cs
s')", | 969 class MyComponent { |
| 982 "class MyComponent {", | 970 MyComponent(Scope scope) { |
| 983 " MyComponent(Scope scope) {", | 971 scope.context['boolProp'] = true; |
| 984 " scope.context['boolProp'] = true;", | 972 scope.context['intProp'] = 42; |
| 985 " scope.context['intProp'] = 42;", | 973 scope.context['stringProp'] = 'foo'; |
| 986 " scope.context['stringProp'] = 'foo';", | 974 // duplicate is ignored |
| 987 " // duplicate is ignored", | 975 scope.context['boolProp'] = true; |
| 988 " scope.context['boolProp'] = true;", | 976 // LHS is not an IndexExpression |
| 989 " // LHS is not an IndexExpression", | 977 var v1; |
| 990 " var v1;", | 978 v1 = 1; |
| 991 " v1 = 1;", | 979 // LHS is not a Scope access |
| 992 " // LHS is not a Scope access", | 980 var v2; |
| 993 " var v2;", | 981 v2['name'] = 2; |
| 994 " v2['name'] = 2;", | 982 } |
| 995 " }", | 983 }'''); |
| 996 "}"]); | |
| 997 resolveMainSourceNoErrors(mainContent); | 984 resolveMainSourceNoErrors(mainContent); |
| 998 // prepare AngularComponentElement | 985 // prepare AngularComponentElement |
| 999 ClassElement classElement = mainUnitElement.getType("MyComponent"); | 986 ClassElement classElement = mainUnitElement.getType("MyComponent"); |
| 1000 AngularComponentElement component = | 987 AngularComponentElement component = |
| 1001 getAngularElement(classElement, (e) => e is AngularComponentElement); | 988 getAngularElement(classElement, (e) => e is AngularComponentElement); |
| 1002 JUnitTestCase.assertNotNull(component); | 989 JUnitTestCase.assertNotNull(component); |
| 1003 // verify | 990 // verify |
| 1004 List<AngularScopePropertyElement> scopeProperties = | 991 List<AngularScopePropertyElement> scopeProperties = |
| 1005 component.scopeProperties; | 992 component.scopeProperties; |
| 1006 EngineTestCase.assertLength(3, scopeProperties); | 993 EngineTestCase.assertLength(3, scopeProperties); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1027 JUnitTestCase.assertSame(property, findMainElement2("stringProp")); | 1014 JUnitTestCase.assertSame(property, findMainElement2("stringProp")); |
| 1028 JUnitTestCase.assertEquals("stringProp", property.name); | 1015 JUnitTestCase.assertEquals("stringProp", property.name); |
| 1029 JUnitTestCase.assertEquals( | 1016 JUnitTestCase.assertEquals( |
| 1030 AngularTest.findOffset(mainContent, "stringProp'"), | 1017 AngularTest.findOffset(mainContent, "stringProp'"), |
| 1031 property.nameOffset); | 1018 property.nameOffset); |
| 1032 JUnitTestCase.assertEquals("String", property.type.name); | 1019 JUnitTestCase.assertEquals("String", property.type.name); |
| 1033 } | 1020 } |
| 1034 } | 1021 } |
| 1035 | 1022 |
| 1036 void test_NgController() { | 1023 void test_NgController() { |
| 1037 String mainContent = _createAngularSource( | 1024 String mainContent = _createAngularSource(r''' |
| 1038 [ | 1025 @Controller(publishAs: 'ctrl', selector: '[myApp]') |
| 1039 "@Controller(publishAs: 'ctrl', selector: '[myApp]')", | 1026 class MyController { |
| 1040 "class MyController {", | 1027 }'''); |
| 1041 "}"]); | |
| 1042 resolveMainSourceNoErrors(mainContent); | 1028 resolveMainSourceNoErrors(mainContent); |
| 1043 // prepare AngularControllerElement | 1029 // prepare AngularControllerElement |
| 1044 ClassElement classElement = mainUnitElement.getType("MyController"); | 1030 ClassElement classElement = mainUnitElement.getType("MyController"); |
| 1045 AngularControllerElement controller = | 1031 AngularControllerElement controller = |
| 1046 getAngularElement(classElement, (e) => e is AngularControllerElement); | 1032 getAngularElement(classElement, (e) => e is AngularControllerElement); |
| 1047 JUnitTestCase.assertNotNull(controller); | 1033 JUnitTestCase.assertNotNull(controller); |
| 1048 // verify | 1034 // verify |
| 1049 JUnitTestCase.assertEquals("ctrl", controller.name); | 1035 JUnitTestCase.assertEquals("ctrl", controller.name); |
| 1050 JUnitTestCase.assertEquals( | 1036 JUnitTestCase.assertEquals( |
| 1051 AngularTest.findOffset(mainContent, "ctrl'"), | 1037 AngularTest.findOffset(mainContent, "ctrl'"), |
| 1052 controller.nameOffset); | 1038 controller.nameOffset); |
| 1053 _assertHasAttributeSelector(controller.selector, "myApp"); | 1039 _assertHasAttributeSelector(controller.selector, "myApp"); |
| 1054 } | 1040 } |
| 1055 | 1041 |
| 1056 void test_NgController_cannotParseSelector() { | 1042 void test_NgController_cannotParseSelector() { |
| 1057 String mainContent = _createAngularSource( | 1043 String mainContent = _createAngularSource(r''' |
| 1058 [ | 1044 @Controller(publishAs: 'ctrl', selector: '~unknown') |
| 1059 "@Controller(publishAs: 'ctrl', selector: '~unknown')", | 1045 class MyController { |
| 1060 "class MyController {", | 1046 }'''); |
| 1061 "}"]); | |
| 1062 resolveMainSource(mainContent); | 1047 resolveMainSource(mainContent); |
| 1063 // has error | 1048 // has error |
| 1064 assertMainErrors([AngularCode.CANNOT_PARSE_SELECTOR]); | 1049 assertMainErrors([AngularCode.CANNOT_PARSE_SELECTOR]); |
| 1065 } | 1050 } |
| 1066 | 1051 |
| 1067 void test_NgController_missingPublishAs() { | 1052 void test_NgController_missingPublishAs() { |
| 1068 String mainContent = _createAngularSource( | 1053 String mainContent = _createAngularSource(r''' |
| 1069 ["@Controller(selector: '[myApp]')", "class MyController {", "}"]); | 1054 @Controller(selector: '[myApp]') |
| 1055 class MyController { |
| 1056 }'''); |
| 1070 resolveMainSource(mainContent); | 1057 resolveMainSource(mainContent); |
| 1071 // has error | 1058 // has error |
| 1072 assertMainErrors([AngularCode.MISSING_PUBLISH_AS]); | 1059 assertMainErrors([AngularCode.MISSING_PUBLISH_AS]); |
| 1073 } | 1060 } |
| 1074 | 1061 |
| 1075 void test_NgController_missingSelector() { | 1062 void test_NgController_missingSelector() { |
| 1076 String mainContent = _createAngularSource( | 1063 String mainContent = _createAngularSource(r''' |
| 1077 ["@Controller(publishAs: 'ctrl')", "class MyController {", "}"]); | 1064 @Controller(publishAs: 'ctrl') |
| 1065 class MyController { |
| 1066 }'''); |
| 1078 resolveMainSource(mainContent); | 1067 resolveMainSource(mainContent); |
| 1079 // has error | 1068 // has error |
| 1080 assertMainErrors([AngularCode.MISSING_SELECTOR]); | 1069 assertMainErrors([AngularCode.MISSING_SELECTOR]); |
| 1081 } | 1070 } |
| 1082 | 1071 |
| 1083 void test_NgController_noAnnotationArguments() { | 1072 void test_NgController_noAnnotationArguments() { |
| 1084 String mainContent = | 1073 String mainContent = |
| 1085 _createAngularSource(["@NgController", "class MyController {", "}"]); | 1074 _createAngularSource(r''' |
| 1075 @NgController |
| 1076 class MyController { |
| 1077 }'''); |
| 1086 resolveMainSource(mainContent); | 1078 resolveMainSource(mainContent); |
| 1087 } | 1079 } |
| 1088 | 1080 |
| 1089 void test_bad_notConstructorAnnotation() { | 1081 void test_bad_notConstructorAnnotation() { |
| 1090 String mainContent = r''' | 1082 String mainContent = r''' |
| 1091 const MY_ANNOTATION = null; | 1083 const MY_ANNOTATION = null; |
| 1092 @MY_ANNOTATION() | 1084 @MY_ANNOTATION() |
| 1093 class MyFilter { | 1085 class MyFilter { |
| 1094 }'''; | 1086 }'''; |
| 1095 resolveMainSource(mainContent); | 1087 resolveMainSource(mainContent); |
| 1096 // prepare AngularFilterElement | 1088 // prepare AngularFilterElement |
| 1097 ClassElement classElement = mainUnitElement.getType("MyFilter"); | 1089 ClassElement classElement = mainUnitElement.getType("MyFilter"); |
| 1098 AngularFormatterElement filter = | 1090 AngularFormatterElement filter = |
| 1099 getAngularElement(classElement, (e) => e is AngularFormatterElement); | 1091 getAngularElement(classElement, (e) => e is AngularFormatterElement); |
| 1100 JUnitTestCase.assertNull(filter); | 1092 JUnitTestCase.assertNull(filter); |
| 1101 } | 1093 } |
| 1102 | 1094 |
| 1103 void test_getElement_SimpleStringLiteral_withToolkitElement() { | 1095 void test_getElement_SimpleStringLiteral_withToolkitElement() { |
| 1104 SimpleStringLiteral literal = AstFactory.string2("foo"); | 1096 SimpleStringLiteral literal = AstFactory.string2("foo"); |
| 1105 Element element = new AngularScopePropertyElementImpl("foo", 0, null); | 1097 Element element = new AngularScopePropertyElementImpl("foo", 0, null); |
| 1106 literal.toolkitElement = element; | 1098 literal.toolkitElement = element; |
| 1107 JUnitTestCase.assertSame( | 1099 JUnitTestCase.assertSame( |
| 1108 element, | 1100 element, |
| 1109 AngularCompilationUnitBuilder.getElement(literal, -1)); | 1101 AngularCompilationUnitBuilder.getElement(literal, -1)); |
| 1110 } | 1102 } |
| 1111 | 1103 |
| 1112 void test_getElement_component_name() { | 1104 void test_getElement_component_name() { |
| 1113 resolveMainSource( | 1105 resolveMainSource( |
| 1114 _createAngularSource( | 1106 _createAngularSource(r''' |
| 1115 [ | 1107 @Component(publishAs: 'ctrl', selector: 'myComp', |
| 1116 "@Component(publishAs: 'ctrl', selector: 'myComp',", | 1108 templateUrl: 'my_template.html', cssUrl: 'my_styles.css') |
| 1117 " templateUrl: 'my_template.html', cssUrl: 'my_style
s.css')", | 1109 class MyComponent {}''')); |
| 1118 "class MyComponent {}"])); | |
| 1119 SimpleStringLiteral node = | 1110 SimpleStringLiteral node = |
| 1120 _findMainNode("ctrl'", (n) => n is SimpleStringLiteral); | 1111 _findMainNode("ctrl'", (n) => n is SimpleStringLiteral); |
| 1121 int offset = node.offset; | 1112 int offset = node.offset; |
| 1122 // find AngularComponentElement | 1113 // find AngularComponentElement |
| 1123 Element element = AngularCompilationUnitBuilder.getElement(node, offset); | 1114 Element element = AngularCompilationUnitBuilder.getElement(node, offset); |
| 1124 EngineTestCase.assertInstanceOf( | 1115 EngineTestCase.assertInstanceOf( |
| 1125 (obj) => obj is AngularComponentElement, | 1116 (obj) => obj is AngularComponentElement, |
| 1126 AngularComponentElement, | 1117 AngularComponentElement, |
| 1127 element); | 1118 element); |
| 1128 } | 1119 } |
| 1129 | 1120 |
| 1130 void test_getElement_component_property_fromFieldAnnotation() { | 1121 void test_getElement_component_property_fromFieldAnnotation() { |
| 1131 resolveMainSource( | 1122 resolveMainSource( |
| 1132 _createAngularSource( | 1123 _createAngularSource(r''' |
| 1133 [ | 1124 @Component(publishAs: 'ctrl', selector: 'myComp', |
| 1134 "@Component(publishAs: 'ctrl', selector: 'myComp',", | 1125 templateUrl: 'my_template.html', cssUrl: 'my_styles.css') |
| 1135 " templateUrl: 'my_template.html', cssUrl: 'my_style
s.css')", | 1126 class MyComponent { |
| 1136 "class MyComponent {", | 1127 @NgOneWay('prop') |
| 1137 " @NgOneWay('prop')", | 1128 var field; |
| 1138 " var field;", | 1129 }''')); |
| 1139 "}"])); | |
| 1140 // prepare node | 1130 // prepare node |
| 1141 SimpleStringLiteral node = | 1131 SimpleStringLiteral node = |
| 1142 _findMainNode("prop'", (n) => n is SimpleStringLiteral); | 1132 _findMainNode("prop'", (n) => n is SimpleStringLiteral); |
| 1143 int offset = node.offset; | 1133 int offset = node.offset; |
| 1144 // prepare Element | 1134 // prepare Element |
| 1145 Element element = AngularCompilationUnitBuilder.getElement(node, offset); | 1135 Element element = AngularCompilationUnitBuilder.getElement(node, offset); |
| 1146 JUnitTestCase.assertNotNull(element); | 1136 JUnitTestCase.assertNotNull(element); |
| 1147 // check AngularPropertyElement | 1137 // check AngularPropertyElement |
| 1148 AngularPropertyElement property = element as AngularPropertyElement; | 1138 AngularPropertyElement property = element as AngularPropertyElement; |
| 1149 JUnitTestCase.assertEquals("prop", property.name); | 1139 JUnitTestCase.assertEquals("prop", property.name); |
| 1150 } | 1140 } |
| 1151 | 1141 |
| 1152 void test_getElement_component_property_fromMap() { | 1142 void test_getElement_component_property_fromMap() { |
| 1153 resolveMainSource( | 1143 resolveMainSource( |
| 1154 _createAngularSource( | 1144 _createAngularSource(r''' |
| 1155 [ | 1145 @Component(publishAs: 'ctrl', selector: 'myComp', |
| 1156 "@Component(publishAs: 'ctrl', selector: 'myComp',", | 1146 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', |
| 1157 " templateUrl: 'my_template.html', cssUrl: 'my_style
s.css',", | 1147 map: const { |
| 1158 " map: const {", | 1148 'prop' : '@field', |
| 1159 " 'prop' : '@field',", | 1149 }) |
| 1160 " })", | 1150 class MyComponent { |
| 1161 "class MyComponent {", | 1151 var field; |
| 1162 " var field;", | 1152 }''')); |
| 1163 "}"])); | |
| 1164 // AngularPropertyElement | 1153 // AngularPropertyElement |
| 1165 { | 1154 { |
| 1166 SimpleStringLiteral node = | 1155 SimpleStringLiteral node = |
| 1167 _findMainNode("prop'", (n) => n is SimpleStringLiteral); | 1156 _findMainNode("prop'", (n) => n is SimpleStringLiteral); |
| 1168 int offset = node.offset; | 1157 int offset = node.offset; |
| 1169 // prepare Element | 1158 // prepare Element |
| 1170 Element element = AngularCompilationUnitBuilder.getElement(node, offset); | 1159 Element element = AngularCompilationUnitBuilder.getElement(node, offset); |
| 1171 JUnitTestCase.assertNotNull(element); | 1160 JUnitTestCase.assertNotNull(element); |
| 1172 // check AngularPropertyElement | 1161 // check AngularPropertyElement |
| 1173 AngularPropertyElement property = element as AngularPropertyElement; | 1162 AngularPropertyElement property = element as AngularPropertyElement; |
| 1174 JUnitTestCase.assertEquals("prop", property.name); | 1163 JUnitTestCase.assertEquals("prop", property.name); |
| 1175 } | 1164 } |
| 1176 // FieldElement | 1165 // FieldElement |
| 1177 { | 1166 { |
| 1178 SimpleStringLiteral node = | 1167 SimpleStringLiteral node = |
| 1179 _findMainNode("@field'", (n) => n is SimpleStringLiteral); | 1168 _findMainNode("@field'", (n) => n is SimpleStringLiteral); |
| 1180 int offset = node.offset; | 1169 int offset = node.offset; |
| 1181 // prepare Element | 1170 // prepare Element |
| 1182 Element element = AngularCompilationUnitBuilder.getElement(node, offset); | 1171 Element element = AngularCompilationUnitBuilder.getElement(node, offset); |
| 1183 JUnitTestCase.assertNotNull(element); | 1172 JUnitTestCase.assertNotNull(element); |
| 1184 // check FieldElement | 1173 // check FieldElement |
| 1185 FieldElement field = element as FieldElement; | 1174 FieldElement field = element as FieldElement; |
| 1186 JUnitTestCase.assertEquals("field", field.name); | 1175 JUnitTestCase.assertEquals("field", field.name); |
| 1187 } | 1176 } |
| 1188 } | 1177 } |
| 1189 | 1178 |
| 1190 void test_getElement_component_selector() { | 1179 void test_getElement_component_selector() { |
| 1191 resolveMainSource( | 1180 resolveMainSource( |
| 1192 _createAngularSource( | 1181 _createAngularSource(r''' |
| 1193 [ | 1182 @Component(publishAs: 'ctrl', selector: 'myComp', |
| 1194 "@Component(publishAs: 'ctrl', selector: 'myComp',", | 1183 templateUrl: 'my_template.html', cssUrl: 'my_styles.css') |
| 1195 " templateUrl: 'my_template.html', cssUrl: 'my_style
s.css')", | 1184 class MyComponent {}''')); |
| 1196 "class MyComponent {}"])); | |
| 1197 SimpleStringLiteral node = | 1185 SimpleStringLiteral node = |
| 1198 _findMainNode("myComp'", (n) => n is SimpleStringLiteral); | 1186 _findMainNode("myComp'", (n) => n is SimpleStringLiteral); |
| 1199 int offset = node.offset; | 1187 int offset = node.offset; |
| 1200 // find AngularSelectorElement | 1188 // find AngularSelectorElement |
| 1201 Element element = AngularCompilationUnitBuilder.getElement(node, offset); | 1189 Element element = AngularCompilationUnitBuilder.getElement(node, offset); |
| 1202 EngineTestCase.assertInstanceOf( | 1190 EngineTestCase.assertInstanceOf( |
| 1203 (obj) => obj is AngularSelectorElement, | 1191 (obj) => obj is AngularSelectorElement, |
| 1204 AngularSelectorElement, | 1192 AngularSelectorElement, |
| 1205 element); | 1193 element); |
| 1206 } | 1194 } |
| 1207 | 1195 |
| 1208 void test_getElement_controller_name() { | 1196 void test_getElement_controller_name() { |
| 1209 resolveMainSource( | 1197 resolveMainSource( |
| 1210 _createAngularSource( | 1198 _createAngularSource(r''' |
| 1211 [ | 1199 @Controller(publishAs: 'ctrl', selector: '[myApp]') |
| 1212 "@Controller(publishAs: 'ctrl', selector: '[myApp]')", | 1200 class MyController { |
| 1213 "class MyController {", | 1201 }''')); |
| 1214 "}"])); | |
| 1215 SimpleStringLiteral node = | 1202 SimpleStringLiteral node = |
| 1216 _findMainNode("ctrl'", (n) => n is SimpleStringLiteral); | 1203 _findMainNode("ctrl'", (n) => n is SimpleStringLiteral); |
| 1217 int offset = node.offset; | 1204 int offset = node.offset; |
| 1218 // find AngularControllerElement | 1205 // find AngularControllerElement |
| 1219 Element element = AngularCompilationUnitBuilder.getElement(node, offset); | 1206 Element element = AngularCompilationUnitBuilder.getElement(node, offset); |
| 1220 EngineTestCase.assertInstanceOf( | 1207 EngineTestCase.assertInstanceOf( |
| 1221 (obj) => obj is AngularControllerElement, | 1208 (obj) => obj is AngularControllerElement, |
| 1222 AngularControllerElement, | 1209 AngularControllerElement, |
| 1223 element); | 1210 element); |
| 1224 } | 1211 } |
| 1225 | 1212 |
| 1226 void test_getElement_directive_property() { | 1213 void test_getElement_directive_property() { |
| 1227 resolveMainSource( | 1214 resolveMainSource( |
| 1228 _createAngularSource( | 1215 _createAngularSource(r''' |
| 1229 [ | 1216 @Decorator(selector: '[my-dir]', |
| 1230 "@Decorator(selector: '[my-dir]',", | 1217 map: const { |
| 1231 " map: const {", | 1218 'my-dir' : '=>field' |
| 1232 " 'my-dir' : '=>field'", | 1219 }) |
| 1233 " })", | 1220 class MyDirective { |
| 1234 "class MyDirective {", | 1221 set field(value) {} |
| 1235 " set field(value) {}", | 1222 }''')); |
| 1236 "}"])); | |
| 1237 // prepare node | 1223 // prepare node |
| 1238 SimpleStringLiteral node = | 1224 SimpleStringLiteral node = |
| 1239 _findMainNode("my-dir'", (n) => n is SimpleStringLiteral); | 1225 _findMainNode("my-dir'", (n) => n is SimpleStringLiteral); |
| 1240 int offset = node.offset; | 1226 int offset = node.offset; |
| 1241 // prepare Element | 1227 // prepare Element |
| 1242 Element element = AngularCompilationUnitBuilder.getElement(node, offset); | 1228 Element element = AngularCompilationUnitBuilder.getElement(node, offset); |
| 1243 JUnitTestCase.assertNotNull(element); | 1229 JUnitTestCase.assertNotNull(element); |
| 1244 // check AngularPropertyElement | 1230 // check AngularPropertyElement |
| 1245 AngularPropertyElement property = element as AngularPropertyElement; | 1231 AngularPropertyElement property = element as AngularPropertyElement; |
| 1246 JUnitTestCase.assertEquals("my-dir", property.name); | 1232 JUnitTestCase.assertEquals("my-dir", property.name); |
| 1247 } | 1233 } |
| 1248 | 1234 |
| 1249 void test_getElement_directive_selector() { | 1235 void test_getElement_directive_selector() { |
| 1250 resolveMainSource( | 1236 resolveMainSource( |
| 1251 _createAngularSource( | 1237 _createAngularSource(r''' |
| 1252 ["@Decorator(selector: '[my-dir]')", "class MyDirective {}"])); | 1238 @Decorator(selector: '[my-dir]') |
| 1239 class MyDirective {}''')); |
| 1253 SimpleStringLiteral node = | 1240 SimpleStringLiteral node = |
| 1254 _findMainNode("my-dir]'", (n) => n is SimpleStringLiteral); | 1241 _findMainNode("my-dir]'", (n) => n is SimpleStringLiteral); |
| 1255 int offset = node.offset; | 1242 int offset = node.offset; |
| 1256 // find AngularSelectorElement | 1243 // find AngularSelectorElement |
| 1257 Element element = AngularCompilationUnitBuilder.getElement(node, offset); | 1244 Element element = AngularCompilationUnitBuilder.getElement(node, offset); |
| 1258 EngineTestCase.assertInstanceOf( | 1245 EngineTestCase.assertInstanceOf( |
| 1259 (obj) => obj is AngularSelectorElement, | 1246 (obj) => obj is AngularSelectorElement, |
| 1260 AngularSelectorElement, | 1247 AngularSelectorElement, |
| 1261 element); | 1248 element); |
| 1262 } | 1249 } |
| 1263 | 1250 |
| 1264 void test_getElement_filter_name() { | 1251 void test_getElement_filter_name() { |
| 1265 resolveMainSource( | 1252 resolveMainSource( |
| 1266 _createAngularSource( | 1253 _createAngularSource(r''' |
| 1267 [ | 1254 @Formatter(name: 'myFilter') |
| 1268 "@Formatter(name: 'myFilter')", | 1255 class MyFilter { |
| 1269 "class MyFilter {", | 1256 call(p1, p2) {} |
| 1270 " call(p1, p2) {}", | 1257 }''')); |
| 1271 "}"])); | |
| 1272 SimpleStringLiteral node = | 1258 SimpleStringLiteral node = |
| 1273 _findMainNode("myFilter'", (n) => n is SimpleStringLiteral); | 1259 _findMainNode("myFilter'", (n) => n is SimpleStringLiteral); |
| 1274 int offset = node.offset; | 1260 int offset = node.offset; |
| 1275 // find FilterElement | 1261 // find FilterElement |
| 1276 Element element = AngularCompilationUnitBuilder.getElement(node, offset); | 1262 Element element = AngularCompilationUnitBuilder.getElement(node, offset); |
| 1277 EngineTestCase.assertInstanceOf( | 1263 EngineTestCase.assertInstanceOf( |
| 1278 (obj) => obj is AngularFormatterElement, | 1264 (obj) => obj is AngularFormatterElement, |
| 1279 AngularFormatterElement, | 1265 AngularFormatterElement, |
| 1280 element); | 1266 element); |
| 1281 } | 1267 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1382 void test_parseSelector_unknown() { | 1368 void test_parseSelector_unknown() { |
| 1383 AngularSelectorElement selector = | 1369 AngularSelectorElement selector = |
| 1384 AngularCompilationUnitBuilder.parseSelector(0, "~unknown"); | 1370 AngularCompilationUnitBuilder.parseSelector(0, "~unknown"); |
| 1385 JUnitTestCase.assertNull(selector); | 1371 JUnitTestCase.assertNull(selector); |
| 1386 } | 1372 } |
| 1387 | 1373 |
| 1388 void test_view() { | 1374 void test_view() { |
| 1389 contextHelper.addSource("/wrong.html", ""); | 1375 contextHelper.addSource("/wrong.html", ""); |
| 1390 contextHelper.addSource("/my_templateA.html", ""); | 1376 contextHelper.addSource("/my_templateA.html", ""); |
| 1391 contextHelper.addSource("/my_templateB.html", ""); | 1377 contextHelper.addSource("/my_templateB.html", ""); |
| 1392 String mainContent = _createAngularSource( | 1378 String mainContent = _createAngularSource(r''' |
| 1393 [ | 1379 class MyRouteInitializer { |
| 1394 "class MyRouteInitializer {", | 1380 init(ViewFactory view, foo) { |
| 1395 " init(ViewFactory view, foo) {", | 1381 foo.view('wrong.html'); // has target |
| 1396 " foo.view('wrong.html'); // has target", | 1382 foo(); // less than one argument |
| 1397 " foo(); // less than one argument", | 1383 foo('wrong.html', 'bar'); // more than one argument |
| 1398 " foo('wrong.html', 'bar'); // more than one argument", | 1384 foo('wrong' + '.html'); // not literal |
| 1399 " foo('wrong' + '.html'); // not literal", | 1385 foo('wrong.html'); // not ViewFactory |
| 1400 " foo('wrong.html'); // not ViewFactory", | 1386 view('my_templateA.html'); |
| 1401 " view('my_templateA.html');", | 1387 view('my_templateB.html'); |
| 1402 " view('my_templateB.html');", | 1388 } |
| 1403 " }", | 1389 }'''); |
| 1404 "}"]); | |
| 1405 resolveMainSourceNoErrors(mainContent); | 1390 resolveMainSourceNoErrors(mainContent); |
| 1406 // prepare AngularViewElement(s) | 1391 // prepare AngularViewElement(s) |
| 1407 List<AngularViewElement> views = mainUnitElement.angularViews; | 1392 List<AngularViewElement> views = mainUnitElement.angularViews; |
| 1408 EngineTestCase.assertLength(2, views); | 1393 EngineTestCase.assertLength(2, views); |
| 1409 { | 1394 { |
| 1410 AngularViewElement view = views[0]; | 1395 AngularViewElement view = views[0]; |
| 1411 JUnitTestCase.assertEquals("my_templateA.html", view.templateUri); | 1396 JUnitTestCase.assertEquals("my_templateA.html", view.templateUri); |
| 1412 JUnitTestCase.assertEquals(null, view.name); | 1397 JUnitTestCase.assertEquals(null, view.name); |
| 1413 JUnitTestCase.assertEquals(-1, view.nameOffset); | 1398 JUnitTestCase.assertEquals(-1, view.nameOffset); |
| 1414 JUnitTestCase.assertEquals( | 1399 JUnitTestCase.assertEquals( |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1479 String name) { | 1464 String name) { |
| 1480 EngineTestCase.assertInstanceOf( | 1465 EngineTestCase.assertInstanceOf( |
| 1481 (obj) => obj is AngularTagSelectorElementImpl, | 1466 (obj) => obj is AngularTagSelectorElementImpl, |
| 1482 AngularTagSelectorElementImpl, | 1467 AngularTagSelectorElementImpl, |
| 1483 selector); | 1468 selector); |
| 1484 JUnitTestCase.assertEquals( | 1469 JUnitTestCase.assertEquals( |
| 1485 name, | 1470 name, |
| 1486 (selector as AngularTagSelectorElementImpl).name); | 1471 (selector as AngularTagSelectorElementImpl).name); |
| 1487 } | 1472 } |
| 1488 | 1473 |
| 1489 static String _createAngularSource(List<String> lines) { | 1474 static String _createAngularSource(String code) { |
| 1490 String source = "import 'angular.dart';\n"; | 1475 return "import 'angular.dart';\n" + code; |
| 1491 source += EngineTestCase.createSource(lines); | |
| 1492 return source; | |
| 1493 } | 1476 } |
| 1494 } | 1477 } |
| 1495 | 1478 |
| 1496 | 1479 |
| 1497 class AngularHtmlUnitResolverTest extends AngularTest { | 1480 class AngularHtmlUnitResolverTest extends AngularTest { |
| 1498 void test_NgComponent_resolveTemplateFile() { | 1481 void test_NgComponent_resolveTemplateFile() { |
| 1499 addMainSource(r''' | 1482 addMainSource(r''' |
| 1500 import 'angular.dart'; | 1483 import 'angular.dart'; |
| 1501 | 1484 |
| 1502 @Component( | 1485 @Component( |
| 1503 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', | 1486 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', |
| 1504 publishAs: 'ctrl', | 1487 publishAs: 'ctrl', |
| 1505 selector: 'myComponent') | 1488 selector: 'myComponent') |
| 1506 class MyComponent { | 1489 class MyComponent { |
| 1507 String field; | 1490 String field; |
| 1508 }'''); | 1491 }'''); |
| 1509 contextHelper.addSource( | 1492 contextHelper.addSource( |
| 1510 "/entry-point.html", | 1493 "/entry-point.html", |
| 1511 AngularTest.createHtmlWithAngular([])); | 1494 AngularTest.createHtmlWithAngular('')); |
| 1512 addIndexSource2( | 1495 addIndexSource2( |
| 1513 "/my_template.html", | 1496 "/my_template.html", |
| 1514 r''' | 1497 r''' |
| 1515 <div> | 1498 <div> |
| 1516 {{ctrl.field}} | 1499 {{ctrl.field}} |
| 1517 </div>'''); | 1500 </div>'''); |
| 1518 contextHelper.addSource("/my_styles.css", ""); | 1501 contextHelper.addSource("/my_styles.css", ""); |
| 1519 contextHelper.runTasks(); | 1502 contextHelper.runTasks(); |
| 1520 resolveIndex(); | 1503 resolveIndex(); |
| 1521 assertNoErrors(); | 1504 assertNoErrors(); |
| 1522 assertResolvedIdentifier2("ctrl.", "MyComponent"); | 1505 assertResolvedIdentifier2("ctrl.", "MyComponent"); |
| 1523 assertResolvedIdentifier2("field}}", "String"); | 1506 assertResolvedIdentifier2("field}}", "String"); |
| 1524 } | 1507 } |
| 1525 | 1508 |
| 1526 void test_NgComponent_updateDartFile() { | 1509 void test_NgComponent_updateDartFile() { |
| 1527 Source componentSource = contextHelper.addSource( | 1510 Source componentSource = contextHelper.addSource( |
| 1528 "/my_component.dart", | 1511 "/my_component.dart", |
| 1529 r''' | 1512 r''' |
| 1530 library my.component; | 1513 library my.component; |
| 1531 import 'angular.dart'; | 1514 import 'angular.dart'; |
| 1532 @Component(selector: 'myComponent') | 1515 @Component(selector: 'myComponent') |
| 1533 class MyComponent { | 1516 class MyComponent { |
| 1534 }'''); | 1517 }'''); |
| 1535 contextHelper.addSource( | 1518 contextHelper.addSource( |
| 1536 "/my_module.dart", | 1519 "/my_module.dart", |
| 1537 r''' | 1520 r''' |
| 1538 library my.module; | 1521 library my.module; |
| 1539 import 'my_component.dart';'''); | 1522 import 'my_component.dart';'''); |
| 1540 addMainSource(r''' | 1523 addMainSource(r''' |
| 1541 library main; | 1524 library main; |
| 1542 import 'my_module.dart';'''); | 1525 import 'my_module.dart';'''); |
| 1543 _resolveIndexNoErrors( | 1526 _resolveIndexNoErrors( |
| 1544 AngularTest.createHtmlWithMyController(["<myComponent/>"])); | 1527 AngularTest.createHtmlWithMyController("<myComponent/>")); |
| 1545 // "myComponent" tag was resolved | 1528 // "myComponent" tag was resolved |
| 1546 { | 1529 { |
| 1547 ht.XmlTagNode tagNode = | 1530 ht.XmlTagNode tagNode = |
| 1548 ht.HtmlUnitUtils.getTagNode(indexUnit, findOffset2("myComponent")); | 1531 ht.HtmlUnitUtils.getTagNode(indexUnit, findOffset2("myComponent")); |
| 1549 AngularSelectorElement tagElement = | 1532 AngularSelectorElement tagElement = |
| 1550 tagNode.element as AngularSelectorElement; | 1533 tagNode.element as AngularSelectorElement; |
| 1551 JUnitTestCase.assertNotNull(tagElement); | 1534 JUnitTestCase.assertNotNull(tagElement); |
| 1552 JUnitTestCase.assertEquals("myComponent", tagElement.name); | 1535 JUnitTestCase.assertEquals("myComponent", tagElement.name); |
| 1553 } | 1536 } |
| 1554 // replace "myComponent" with "myComponent2" | 1537 // replace "myComponent" with "myComponent2" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1588 @Component( | 1571 @Component( |
| 1589 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', | 1572 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', |
| 1590 publishAs: 'ctrl', | 1573 publishAs: 'ctrl', |
| 1591 selector: 'myComponent', // selector | 1574 selector: 'myComponent', // selector |
| 1592 map: const {'attrA' : '=>setA', 'attrB' : '@setB'}) | 1575 map: const {'attrA' : '=>setA', 'attrB' : '@setB'}) |
| 1593 class MyComponent { | 1576 class MyComponent { |
| 1594 set setA(value) {} | 1577 set setA(value) {} |
| 1595 set setB(value) {} | 1578 set setB(value) {} |
| 1596 }'''); | 1579 }'''); |
| 1597 _resolveIndexNoErrors( | 1580 _resolveIndexNoErrors( |
| 1598 AngularTest.createHtmlWithMyController( | 1581 AngularTest.createHtmlWithMyController(r''' |
| 1599 [ | 1582 <input type='text' ng-model='someModel'/> |
| 1600 "<input type='text' ng-model='someModel'/>", | 1583 <myComponent attrA='someModel' attrB='bbb'/>''')); |
| 1601 "<myComponent attrA='someModel' attrB='bbb'/>"])); | |
| 1602 // "attrA" attribute expression was resolved | 1584 // "attrA" attribute expression was resolved |
| 1603 JUnitTestCase.assertNotNull(findIdentifier("someModel")); | 1585 JUnitTestCase.assertNotNull(findIdentifier("someModel")); |
| 1604 // "myComponent" tag was resolved | 1586 // "myComponent" tag was resolved |
| 1605 ht.XmlTagNode tagNode = | 1587 ht.XmlTagNode tagNode = |
| 1606 ht.HtmlUnitUtils.getTagNode(indexUnit, findOffset2("myComponent")); | 1588 ht.HtmlUnitUtils.getTagNode(indexUnit, findOffset2("myComponent")); |
| 1607 AngularSelectorElement tagElement = | 1589 AngularSelectorElement tagElement = |
| 1608 tagNode.element as AngularSelectorElement; | 1590 tagNode.element as AngularSelectorElement; |
| 1609 JUnitTestCase.assertNotNull(tagElement); | 1591 JUnitTestCase.assertNotNull(tagElement); |
| 1610 JUnitTestCase.assertEquals("myComponent", tagElement.name); | 1592 JUnitTestCase.assertEquals("myComponent", tagElement.name); |
| 1611 JUnitTestCase.assertEquals( | 1593 JUnitTestCase.assertEquals( |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1634 void test_NgDirective_noAttribute() { | 1616 void test_NgDirective_noAttribute() { |
| 1635 addMainSource(r''' | 1617 addMainSource(r''' |
| 1636 | 1618 |
| 1637 import 'angular.dart'; | 1619 import 'angular.dart'; |
| 1638 | 1620 |
| 1639 @NgDirective(selector: '[my-directive]', map: const {'foo': '=>input'}) | 1621 @NgDirective(selector: '[my-directive]', map: const {'foo': '=>input'}) |
| 1640 class MyDirective { | 1622 class MyDirective { |
| 1641 set input(value) {} | 1623 set input(value) {} |
| 1642 }'''); | 1624 }'''); |
| 1643 _resolveIndexNoErrors( | 1625 _resolveIndexNoErrors( |
| 1644 AngularTest.createHtmlWithMyController(["<div my-directive>", "</div>"])
); | 1626 AngularTest.createHtmlWithMyController(r''' |
| 1627 <div my-directive> |
| 1628 </div>''')); |
| 1645 } | 1629 } |
| 1646 | 1630 |
| 1647 void test_NgDirective_noExpression() { | 1631 void test_NgDirective_noExpression() { |
| 1648 addMainSource(r''' | 1632 addMainSource(r''' |
| 1649 | 1633 |
| 1650 import 'angular.dart'; | 1634 import 'angular.dart'; |
| 1651 | 1635 |
| 1652 @NgDirective(selector: '[my-directive]', map: const {'.': '=>input'}) | 1636 @NgDirective(selector: '[my-directive]', map: const {'.': '=>input'}) |
| 1653 class MyDirective { | 1637 class MyDirective { |
| 1654 set input(value) {} | 1638 set input(value) {} |
| 1655 }'''); | 1639 }'''); |
| 1656 _resolveIndexNoErrors( | 1640 _resolveIndexNoErrors( |
| 1657 AngularTest.createHtmlWithMyController(["<div my-directive>", "</div>"])
); | 1641 AngularTest.createHtmlWithMyController(r''' |
| 1642 <div my-directive> |
| 1643 </div>''')); |
| 1658 } | 1644 } |
| 1659 | 1645 |
| 1660 void test_NgDirective_resolvedExpression() { | 1646 void test_NgDirective_resolvedExpression() { |
| 1661 addMainSource(r''' | 1647 addMainSource(r''' |
| 1662 | 1648 |
| 1663 import 'angular.dart'; | 1649 import 'angular.dart'; |
| 1664 | 1650 |
| 1665 @Decorator(selector: '[my-directive]') | 1651 @Decorator(selector: '[my-directive]') |
| 1666 class MyDirective { | 1652 class MyDirective { |
| 1667 @NgOneWay('my-property') | 1653 @NgOneWay('my-property') |
| 1668 String condition; | 1654 String condition; |
| 1669 }'''); | 1655 }'''); |
| 1670 _resolveIndexNoErrors( | 1656 _resolveIndexNoErrors( |
| 1671 AngularTest.createHtmlWithMyController( | 1657 AngularTest.createHtmlWithMyController(r''' |
| 1672 [ | 1658 <input type='text' ng-model='name'> |
| 1673 "<input type='text' ng-model='name'>", | 1659 <div my-directive my-property='name != null'> |
| 1674 "<div my-directive my-property='name != null'>", | 1660 </div>''')); |
| 1675 "</div>"])); | |
| 1676 resolveMainNoErrors(); | 1661 resolveMainNoErrors(); |
| 1677 // "my-directive" attribute was resolved | 1662 // "my-directive" attribute was resolved |
| 1678 { | 1663 { |
| 1679 AngularSelectorElement selector = | 1664 AngularSelectorElement selector = |
| 1680 findMainElement(ElementKind.ANGULAR_SELECTOR, "my-directive"); | 1665 findMainElement(ElementKind.ANGULAR_SELECTOR, "my-directive"); |
| 1681 ht.XmlAttributeNode attrNodeSelector = | 1666 ht.XmlAttributeNode attrNodeSelector = |
| 1682 ht.HtmlUnitUtils.getAttributeNode(indexUnit, findOffset2("my-directive
")); | 1667 ht.HtmlUnitUtils.getAttributeNode(indexUnit, findOffset2("my-directive
")); |
| 1683 JUnitTestCase.assertNotNull(attrNodeSelector); | 1668 JUnitTestCase.assertNotNull(attrNodeSelector); |
| 1684 JUnitTestCase.assertSame(selector, attrNodeSelector.element); | 1669 JUnitTestCase.assertSame(selector, attrNodeSelector.element); |
| 1685 } | 1670 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1703 addMainSource(r''' | 1688 addMainSource(r''' |
| 1704 | 1689 |
| 1705 import 'angular.dart'; | 1690 import 'angular.dart'; |
| 1706 | 1691 |
| 1707 @NgDirective(selector: '[my-directive]) | 1692 @NgDirective(selector: '[my-directive]) |
| 1708 class MyDirective { | 1693 class MyDirective { |
| 1709 @NgAttr('my-property') | 1694 @NgAttr('my-property') |
| 1710 String property; | 1695 String property; |
| 1711 }'''); | 1696 }'''); |
| 1712 _resolveIndexNoErrors( | 1697 _resolveIndexNoErrors( |
| 1713 AngularTest.createHtmlWithMyController( | 1698 AngularTest.createHtmlWithMyController(r''' |
| 1714 [ | 1699 <input type='text' ng-model='name'> |
| 1715 "<input type='text' ng-model='name'>", | 1700 <div my-directive my-property='name != null'> |
| 1716 "<div my-directive my-property='name != null'>", | 1701 </div>''')); |
| 1717 "</div>"])); | |
| 1718 resolveMain(); | 1702 resolveMain(); |
| 1719 // @NgAttr means "string attribute", which we don't parse | 1703 // @NgAttr means "string attribute", which we don't parse |
| 1720 JUnitTestCase.assertNull(findIdentifierMaybe("name != null")); | 1704 JUnitTestCase.assertNull(findIdentifierMaybe("name != null")); |
| 1721 } | 1705 } |
| 1722 | 1706 |
| 1723 void test_NgDirective_resolvedExpression_dotAsName() { | 1707 void test_NgDirective_resolvedExpression_dotAsName() { |
| 1724 addMainSource(r''' | 1708 addMainSource(r''' |
| 1725 | 1709 |
| 1726 import 'angular.dart'; | 1710 import 'angular.dart'; |
| 1727 | 1711 |
| 1728 @Decorator( | 1712 @Decorator( |
| 1729 selector: '[my-directive]', | 1713 selector: '[my-directive]', |
| 1730 map: const {'.' : '=>condition'}) | 1714 map: const {'.' : '=>condition'}) |
| 1731 class MyDirective { | 1715 class MyDirective { |
| 1732 set condition(value) {} | 1716 set condition(value) {} |
| 1733 }'''); | 1717 }'''); |
| 1734 _resolveIndexNoErrors( | 1718 _resolveIndexNoErrors( |
| 1735 AngularTest.createHtmlWithMyController( | 1719 AngularTest.createHtmlWithMyController(r''' |
| 1736 [ | 1720 <input type='text' ng-model='name'> |
| 1737 "<input type='text' ng-model='name'>", | 1721 <div my-directive='name != null'> |
| 1738 "<div my-directive='name != null'>", | 1722 </div>''')); |
| 1739 "</div>"])); | |
| 1740 // "name" attribute was resolved | 1723 // "name" attribute was resolved |
| 1741 JUnitTestCase.assertNotNull(findIdentifier("name != null")); | 1724 JUnitTestCase.assertNotNull(findIdentifier("name != null")); |
| 1742 } | 1725 } |
| 1743 | 1726 |
| 1744 void fail_analysisContext_changeDart_invalidateApplication() { | 1727 void fail_analysisContext_changeDart_invalidateApplication() { |
| 1745 addMainSource(r''' | 1728 addMainSource(r''' |
| 1746 | 1729 |
| 1747 import 'angular.dart'; | 1730 import 'angular.dart'; |
| 1748 | 1731 |
| 1749 @Component( | 1732 @Component( |
| 1750 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', | 1733 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', |
| 1751 publishAs: 'ctrl', | 1734 publishAs: 'ctrl', |
| 1752 selector: 'myComponent') | 1735 selector: 'myComponent') |
| 1753 class MyComponent { | 1736 class MyComponent { |
| 1754 }'''); | 1737 }'''); |
| 1755 contextHelper.addSource( | 1738 contextHelper.addSource( |
| 1756 "/entry-point.html", | 1739 "/entry-point.html", |
| 1757 AngularTest.createHtmlWithAngular([])); | 1740 AngularTest.createHtmlWithAngular('')); |
| 1758 addIndexSource2( | 1741 addIndexSource2( |
| 1759 "/my_template.html", | 1742 "/my_template.html", |
| 1760 r''' | 1743 r''' |
| 1761 <div> | 1744 <div> |
| 1762 {{ctrl.noMethod()}} | 1745 {{ctrl.noMethod()}} |
| 1763 </div>'''); | 1746 </div>'''); |
| 1764 contextHelper.addSource("/my_styles.css", ""); | 1747 contextHelper.addSource("/my_styles.css", ""); |
| 1765 contextHelper.runTasks(); | 1748 contextHelper.runTasks(); |
| 1766 // there are some errors in my_template.html | 1749 // there are some errors in my_template.html |
| 1767 { | 1750 { |
| 1768 List<AnalysisError> errors = context.getErrors(indexSource).errors; | 1751 List<AnalysisError> errors = context.getErrors(indexSource).errors; |
| 1769 JUnitTestCase.assertTrue(errors.length != 0); | 1752 JUnitTestCase.assertTrue(errors.length != 0); |
| 1770 } | 1753 } |
| 1771 // change main.dart, there are no MyComponent anymore | 1754 // change main.dart, there are no MyComponent anymore |
| 1772 context.setContents(mainSource, ""); | 1755 context.setContents(mainSource, ""); |
| 1773 // ...errors in my_template.html should be removed | 1756 // ...errors in my_template.html should be removed |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1784 import 'angular.dart'; | 1767 import 'angular.dart'; |
| 1785 | 1768 |
| 1786 @Component( | 1769 @Component( |
| 1787 templateUrl: 'no-such-template.html', cssUrl: 'my_styles.css', | 1770 templateUrl: 'no-such-template.html', cssUrl: 'my_styles.css', |
| 1788 publishAs: 'ctrl', | 1771 publishAs: 'ctrl', |
| 1789 selector: 'myComponent') | 1772 selector: 'myComponent') |
| 1790 class MyComponent { | 1773 class MyComponent { |
| 1791 }'''); | 1774 }'''); |
| 1792 Source entrySource = contextHelper.addSource( | 1775 Source entrySource = contextHelper.addSource( |
| 1793 "/entry-point.html", | 1776 "/entry-point.html", |
| 1794 AngularTest.createHtmlWithAngular([])); | 1777 AngularTest.createHtmlWithAngular('')); |
| 1795 contextHelper.addSource("/my_styles.css", ""); | 1778 contextHelper.addSource("/my_styles.css", ""); |
| 1796 contextHelper.runTasks(); | 1779 contextHelper.runTasks(); |
| 1797 // there are some errors in MyComponent | 1780 // there are some errors in MyComponent |
| 1798 { | 1781 { |
| 1799 List<AnalysisError> errors = context.getErrors(mainSource).errors; | 1782 List<AnalysisError> errors = context.getErrors(mainSource).errors; |
| 1800 JUnitTestCase.assertTrue(errors.length != 0); | 1783 JUnitTestCase.assertTrue(errors.length != 0); |
| 1801 } | 1784 } |
| 1802 // make entry-point.html non-Angular | 1785 // make entry-point.html non-Angular |
| 1803 context.setContents(entrySource, "<html/>"); | 1786 context.setContents(entrySource, "<html/>"); |
| 1804 // ...errors in MyComponent should be removed | 1787 // ...errors in MyComponent should be removed |
| 1805 { | 1788 { |
| 1806 List<AnalysisError> errors = context.getErrors(mainSource).errors; | 1789 List<AnalysisError> errors = context.getErrors(mainSource).errors; |
| 1807 JUnitTestCase.assertTrue(errors.length == 0); | 1790 JUnitTestCase.assertTrue(errors.length == 0); |
| 1808 } | 1791 } |
| 1809 } | 1792 } |
| 1810 | 1793 |
| 1811 void test_analysisContext_changeEntryPoint_clearAngularErrors_inTemplate() { | 1794 void test_analysisContext_changeEntryPoint_clearAngularErrors_inTemplate() { |
| 1812 addMainSource(r''' | 1795 addMainSource(r''' |
| 1813 | 1796 |
| 1814 import 'angular.dart'; | 1797 import 'angular.dart'; |
| 1815 | 1798 |
| 1816 @Component( | 1799 @Component( |
| 1817 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', | 1800 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', |
| 1818 publishAs: 'ctrl', | 1801 publishAs: 'ctrl', |
| 1819 selector: 'myComponent') | 1802 selector: 'myComponent') |
| 1820 class MyComponent { | 1803 class MyComponent { |
| 1821 }'''); | 1804 }'''); |
| 1822 Source entrySource = contextHelper.addSource( | 1805 Source entrySource = contextHelper.addSource( |
| 1823 "/entry-point.html", | 1806 "/entry-point.html", |
| 1824 AngularTest.createHtmlWithAngular([])); | 1807 AngularTest.createHtmlWithAngular('')); |
| 1825 addIndexSource2( | 1808 addIndexSource2( |
| 1826 "/my_template.html", | 1809 "/my_template.html", |
| 1827 r''' | 1810 r''' |
| 1828 <div> | 1811 <div> |
| 1829 {{ctrl.noMethod()}} | 1812 {{ctrl.noMethod()}} |
| 1830 </div>'''); | 1813 </div>'''); |
| 1831 contextHelper.addSource("/my_styles.css", ""); | 1814 contextHelper.addSource("/my_styles.css", ""); |
| 1832 contextHelper.runTasks(); | 1815 contextHelper.runTasks(); |
| 1833 // there are some errors in my_template.html | 1816 // there are some errors in my_template.html |
| 1834 { | 1817 { |
| 1835 List<AnalysisError> errors = context.getErrors(indexSource).errors; | 1818 List<AnalysisError> errors = context.getErrors(indexSource).errors; |
| 1836 JUnitTestCase.assertTrue(errors.length != 0); | 1819 JUnitTestCase.assertTrue(errors.length != 0); |
| 1837 } | 1820 } |
| 1838 // make entry-point.html non-Angular | 1821 // make entry-point.html non-Angular |
| 1839 context.setContents(entrySource, "<html/>"); | 1822 context.setContents(entrySource, "<html/>"); |
| 1840 // ...errors in my_template.html should be removed | 1823 // ...errors in my_template.html should be removed |
| 1841 { | 1824 { |
| 1842 List<AnalysisError> errors = context.getErrors(indexSource).errors; | 1825 List<AnalysisError> errors = context.getErrors(indexSource).errors; |
| 1843 JUnitTestCase.assertTrue(errors.length == 0); | 1826 JUnitTestCase.assertTrue(errors.length == 0); |
| 1844 } | 1827 } |
| 1845 } | 1828 } |
| 1846 | 1829 |
| 1847 void test_analysisContext_removeEntryPoint_clearAngularErrors_inDart() { | 1830 void test_analysisContext_removeEntryPoint_clearAngularErrors_inDart() { |
| 1848 addMainSource(r''' | 1831 addMainSource(r''' |
| 1849 | 1832 |
| 1850 import 'angular.dart'; | 1833 import 'angular.dart'; |
| 1851 | 1834 |
| 1852 @Component( | 1835 @Component( |
| 1853 templateUrl: 'no-such-template.html', cssUrl: 'my_styles.css', | 1836 templateUrl: 'no-such-template.html', cssUrl: 'my_styles.css', |
| 1854 publishAs: 'ctrl', | 1837 publishAs: 'ctrl', |
| 1855 selector: 'myComponent') | 1838 selector: 'myComponent') |
| 1856 class MyComponent { | 1839 class MyComponent { |
| 1857 }'''); | 1840 }'''); |
| 1858 Source entrySource = contextHelper.addSource( | 1841 Source entrySource = contextHelper.addSource( |
| 1859 "/entry-point.html", | 1842 "/entry-point.html", |
| 1860 AngularTest.createHtmlWithAngular([])); | 1843 AngularTest.createHtmlWithAngular('')); |
| 1861 contextHelper.addSource("/my_styles.css", ""); | 1844 contextHelper.addSource("/my_styles.css", ""); |
| 1862 contextHelper.runTasks(); | 1845 contextHelper.runTasks(); |
| 1863 // there are some errors in MyComponent | 1846 // there are some errors in MyComponent |
| 1864 { | 1847 { |
| 1865 List<AnalysisError> errors = context.getErrors(mainSource).errors; | 1848 List<AnalysisError> errors = context.getErrors(mainSource).errors; |
| 1866 JUnitTestCase.assertTrue(errors.length != 0); | 1849 JUnitTestCase.assertTrue(errors.length != 0); |
| 1867 } | 1850 } |
| 1868 // remove entry-point.html | 1851 // remove entry-point.html |
| 1869 { | 1852 { |
| 1870 ChangeSet changeSet = new ChangeSet(); | 1853 ChangeSet changeSet = new ChangeSet(); |
| 1871 changeSet.removedSource(entrySource); | 1854 changeSet.removedSource(entrySource); |
| 1872 context.applyChanges(changeSet); | 1855 context.applyChanges(changeSet); |
| 1873 } | 1856 } |
| 1874 // ...errors in MyComponent should be removed | 1857 // ...errors in MyComponent should be removed |
| 1875 { | 1858 { |
| 1876 List<AnalysisError> errors = context.getErrors(mainSource).errors; | 1859 List<AnalysisError> errors = context.getErrors(mainSource).errors; |
| 1877 JUnitTestCase.assertTrue(errors.length == 0); | 1860 JUnitTestCase.assertTrue(errors.length == 0); |
| 1878 } | 1861 } |
| 1879 } | 1862 } |
| 1880 | 1863 |
| 1881 void test_contextProperties() { | 1864 void test_contextProperties() { |
| 1882 addMyController(); | 1865 addMyController(); |
| 1883 _resolveIndexNoErrors( | 1866 _resolveIndexNoErrors( |
| 1884 AngularTest.createHtmlWithAngular( | 1867 AngularTest.createHtmlWithAngular(r''' |
| 1885 ["<div>", " {{\$id}}", " {{\$parent}}", " {{\$root}}", "</div>"])
); | 1868 <div> |
| 1869 {{$id}} |
| 1870 {{$parent}} |
| 1871 {{$root}} |
| 1872 </div>''')); |
| 1886 assertResolvedIdentifier("\$id"); | 1873 assertResolvedIdentifier("\$id"); |
| 1887 assertResolvedIdentifier("\$parent"); | 1874 assertResolvedIdentifier("\$parent"); |
| 1888 assertResolvedIdentifier("\$root"); | 1875 assertResolvedIdentifier("\$root"); |
| 1889 } | 1876 } |
| 1890 | 1877 |
| 1891 void test_getAngularElement_isAngular() { | 1878 void test_getAngularElement_isAngular() { |
| 1892 // prepare local variable "name" in compilation unit | 1879 // prepare local variable "name" in compilation unit |
| 1893 CompilationUnitElementImpl unit = | 1880 CompilationUnitElementImpl unit = |
| 1894 ElementFactory.compilationUnit("test.dart"); | 1881 ElementFactory.compilationUnit("test.dart"); |
| 1895 FunctionElementImpl function = ElementFactory.functionElement("main"); | 1882 FunctionElementImpl function = ElementFactory.functionElement("main"); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1916 JUnitTestCase.assertNull( | 1903 JUnitTestCase.assertNull( |
| 1917 AngularHtmlUnitResolver.getAngularElement(element)); | 1904 AngularHtmlUnitResolver.getAngularElement(element)); |
| 1918 } | 1905 } |
| 1919 | 1906 |
| 1920 /** | 1907 /** |
| 1921 * Test that we resolve "ng-click" expression. | 1908 * Test that we resolve "ng-click" expression. |
| 1922 */ | 1909 */ |
| 1923 void test_ngClick() { | 1910 void test_ngClick() { |
| 1924 addMyController(); | 1911 addMyController(); |
| 1925 _resolveIndexNoErrors( | 1912 _resolveIndexNoErrors( |
| 1926 AngularTest.createHtmlWithMyController( | 1913 AngularTest.createHtmlWithMyController(r"<button ng-click='ctrl.doSometh
ing($event)'/>")); |
| 1927 ["<button ng-click='ctrl.doSomething(\$event)'/>"])); | |
| 1928 assertResolvedIdentifier("doSomething"); | 1914 assertResolvedIdentifier("doSomething"); |
| 1929 } | 1915 } |
| 1930 | 1916 |
| 1931 /** | 1917 /** |
| 1932 * Test that we resolve "ng-if" expression. | 1918 * Test that we resolve "ng-if" expression. |
| 1933 */ | 1919 */ |
| 1934 void test_ngIf() { | 1920 void test_ngIf() { |
| 1935 addMyController(); | 1921 addMyController(); |
| 1936 _resolveIndexNoErrors( | 1922 _resolveIndexNoErrors( |
| 1937 AngularTest.createHtmlWithMyController(["<div ng-if='ctrl.field != null'
/>"])); | 1923 AngularTest.createHtmlWithMyController("<div ng-if='ctrl.field != null'/
>")); |
| 1938 assertResolvedIdentifier("field"); | 1924 assertResolvedIdentifier("field"); |
| 1939 } | 1925 } |
| 1940 | 1926 |
| 1941 void test_ngModel_modelAfterUsage() { | 1927 void test_ngModel_modelAfterUsage() { |
| 1942 addMyController(); | 1928 addMyController(); |
| 1943 _resolveIndexNoErrors( | 1929 _resolveIndexNoErrors( |
| 1944 AngularTest.createHtmlWithMyController( | 1930 AngularTest.createHtmlWithMyController(r''' |
| 1945 ["<h3>Hello {{name}}!</h3>", "<input type='text' ng-model='name'>"])
); | 1931 <h3>Hello {{name}}!</h3> |
| 1932 <input type='text' ng-model='name'>''')); |
| 1946 assertResolvedIdentifier2("name}}!", "String"); | 1933 assertResolvedIdentifier2("name}}!", "String"); |
| 1947 assertResolvedIdentifier2("name'>", "String"); | 1934 assertResolvedIdentifier2("name'>", "String"); |
| 1948 } | 1935 } |
| 1949 | 1936 |
| 1950 void test_ngModel_modelBeforeUsage() { | 1937 void test_ngModel_modelBeforeUsage() { |
| 1951 addMyController(); | 1938 addMyController(); |
| 1952 _resolveIndexNoErrors( | 1939 _resolveIndexNoErrors( |
| 1953 AngularTest.createHtmlWithMyController( | 1940 AngularTest.createHtmlWithMyController(r''' |
| 1954 ["<input type='text' ng-model='name'>", "<h3>Hello {{name}}!</h3>"])
); | 1941 <input type='text' ng-model='name'> |
| 1942 <h3>Hello {{name}}!</h3>''')); |
| 1955 assertResolvedIdentifier2("name}}!", "String"); | 1943 assertResolvedIdentifier2("name}}!", "String"); |
| 1956 Element element = assertResolvedIdentifier2("name'>", "String"); | 1944 Element element = assertResolvedIdentifier2("name'>", "String"); |
| 1957 JUnitTestCase.assertEquals("name", element.name); | 1945 JUnitTestCase.assertEquals("name", element.name); |
| 1958 JUnitTestCase.assertEquals(findOffset2("name'>"), element.nameOffset); | 1946 JUnitTestCase.assertEquals(findOffset2("name'>"), element.nameOffset); |
| 1959 } | 1947 } |
| 1960 | 1948 |
| 1961 void test_ngModel_notIdentifier() { | 1949 void test_ngModel_notIdentifier() { |
| 1962 addMyController(); | 1950 addMyController(); |
| 1963 _resolveIndexNoErrors( | 1951 _resolveIndexNoErrors( |
| 1964 AngularTest.createHtmlWithMyController( | 1952 AngularTest.createHtmlWithMyController("<input type='text' ng-model='ctr
l.field'>")); |
| 1965 ["<input type='text' ng-model='ctrl.field'>"])); | |
| 1966 assertResolvedIdentifier2("field'>", "String"); | 1953 assertResolvedIdentifier2("field'>", "String"); |
| 1967 } | 1954 } |
| 1968 | 1955 |
| 1969 /** | 1956 /** |
| 1970 * Test that we resolve "ng-mouseout" expression. | 1957 * Test that we resolve "ng-mouseout" expression. |
| 1971 */ | 1958 */ |
| 1972 void test_ngMouseOut() { | 1959 void test_ngMouseOut() { |
| 1973 addMyController(); | 1960 addMyController(); |
| 1974 _resolveIndexNoErrors( | 1961 _resolveIndexNoErrors( |
| 1975 AngularTest.createHtmlWithMyController( | 1962 AngularTest.createHtmlWithMyController(r"<button ng-mouseout='ctrl.doSom
ething($event)'/>")); |
| 1976 ["<button ng-mouseout='ctrl.doSomething(\$event)'/>"])); | |
| 1977 assertResolvedIdentifier("doSomething"); | 1963 assertResolvedIdentifier("doSomething"); |
| 1978 } | 1964 } |
| 1979 | 1965 |
| 1980 void fail_ngRepeat_additionalVariables() { | 1966 void fail_ngRepeat_additionalVariables() { |
| 1981 addMyController(); | 1967 addMyController(); |
| 1982 _resolveIndexNoErrors( | 1968 _resolveIndexNoErrors( |
| 1983 AngularTest.createHtmlWithMyController( | 1969 AngularTest.createHtmlWithMyController(r''' |
| 1984 [ | 1970 <li ng-repeat='name in ctrl.names'> |
| 1985 "<li ng-repeat='name in ctrl.names'>", | 1971 {{$index}} {{$first}} {{$middle}} {{$last}} {{$even}} {{$odd}} |
| 1986 " {{\$index}} {{\$first}} {{\$middle}} {{\$last}} {{\$even}} {{
\$odd}}", | 1972 </li>''')); |
| 1987 "</li>"])); | |
| 1988 assertResolvedIdentifier2("\$index", "int"); | 1973 assertResolvedIdentifier2("\$index", "int"); |
| 1989 assertResolvedIdentifier2("\$first", "bool"); | 1974 assertResolvedIdentifier2("\$first", "bool"); |
| 1990 assertResolvedIdentifier2("\$middle", "bool"); | 1975 assertResolvedIdentifier2("\$middle", "bool"); |
| 1991 assertResolvedIdentifier2("\$last", "bool"); | 1976 assertResolvedIdentifier2("\$last", "bool"); |
| 1992 assertResolvedIdentifier2("\$even", "bool"); | 1977 assertResolvedIdentifier2("\$even", "bool"); |
| 1993 assertResolvedIdentifier2("\$odd", "bool"); | 1978 assertResolvedIdentifier2("\$odd", "bool"); |
| 1994 } | 1979 } |
| 1995 | 1980 |
| 1996 void fail_ngRepeat_bad_expectedIdentifier() { | 1981 void fail_ngRepeat_bad_expectedIdentifier() { |
| 1997 addMyController(); | 1982 addMyController(); |
| 1998 resolveIndex2( | 1983 resolveIndex2( |
| 1999 AngularTest.createHtmlWithMyController( | 1984 AngularTest.createHtmlWithMyController(r''' |
| 2000 ["<li ng-repeat='name + 42 in ctrl.names'>", "</li>"])); | 1985 <li ng-repeat='name + 42 in ctrl.names'> |
| 1986 </li>''')); |
| 2001 assertErrors(indexSource, [AngularCode.INVALID_REPEAT_ITEM_SYNTAX]); | 1987 assertErrors(indexSource, [AngularCode.INVALID_REPEAT_ITEM_SYNTAX]); |
| 2002 } | 1988 } |
| 2003 | 1989 |
| 2004 void fail_ngRepeat_bad_expectedIn() { | 1990 void fail_ngRepeat_bad_expectedIn() { |
| 2005 addMyController(); | 1991 addMyController(); |
| 2006 resolveIndex2( | 1992 resolveIndex2( |
| 2007 AngularTest.createHtmlWithMyController( | 1993 AngularTest.createHtmlWithMyController(r''' |
| 2008 ["<li ng-repeat='name : ctrl.names'>", "</li>"])); | 1994 <li ng-repeat='name : ctrl.names'> |
| 1995 </li>''')); |
| 2009 assertErrors(indexSource, [AngularCode.INVALID_REPEAT_SYNTAX]); | 1996 assertErrors(indexSource, [AngularCode.INVALID_REPEAT_SYNTAX]); |
| 2010 } | 1997 } |
| 2011 | 1998 |
| 2012 void fail_ngRepeat_filters_filter_literal() { | 1999 void fail_ngRepeat_filters_filter_literal() { |
| 2013 addMyController(); | 2000 addMyController(); |
| 2014 _resolveIndexNoErrors( | 2001 _resolveIndexNoErrors( |
| 2015 AngularTest.createHtmlWithMyController( | 2002 AngularTest.createHtmlWithMyController(r''' |
| 2016 ["<li ng-repeat='item in ctrl.items | filter:42:null'/>", "</li>"]))
; | 2003 <li ng-repeat='item in ctrl.items | filter:42:null'/> |
| 2004 </li>''')); |
| 2017 // filter "filter" is resolved | 2005 // filter "filter" is resolved |
| 2018 Element filterElement = assertResolvedIdentifier("filter"); | 2006 Element filterElement = assertResolvedIdentifier("filter"); |
| 2019 EngineTestCase.assertInstanceOf( | 2007 EngineTestCase.assertInstanceOf( |
| 2020 (obj) => obj is AngularFormatterElement, | 2008 (obj) => obj is AngularFormatterElement, |
| 2021 AngularFormatterElement, | 2009 AngularFormatterElement, |
| 2022 filterElement); | 2010 filterElement); |
| 2023 } | 2011 } |
| 2024 | 2012 |
| 2025 void fail_ngRepeat_filters_filter_propertyMap() { | 2013 void fail_ngRepeat_filters_filter_propertyMap() { |
| 2026 addMyController(); | 2014 addMyController(); |
| 2027 _resolveIndexNoErrors( | 2015 _resolveIndexNoErrors( |
| 2028 AngularTest.createHtmlWithMyController( | 2016 AngularTest.createHtmlWithMyController(r''' |
| 2029 [ | 2017 <li ng-repeat='item in ctrl.items | filter:{name:null, done:false}'/> |
| 2030 "<li ng-repeat='item in ctrl.items | filter:{name:null, done:fal
se}'/>", | 2018 </li>''')); |
| 2031 "</li>"])); | |
| 2032 assertResolvedIdentifier2("name:", "String"); | 2019 assertResolvedIdentifier2("name:", "String"); |
| 2033 assertResolvedIdentifier2("done:", "bool"); | 2020 assertResolvedIdentifier2("done:", "bool"); |
| 2034 } | 2021 } |
| 2035 | 2022 |
| 2036 void fail_ngRepeat_filters_missingColon() { | 2023 void fail_ngRepeat_filters_missingColon() { |
| 2037 addMyController(); | 2024 addMyController(); |
| 2038 resolveIndex2( | 2025 resolveIndex2( |
| 2039 AngularTest.createHtmlWithMyController( | 2026 AngularTest.createHtmlWithMyController(r''' |
| 2040 ["<li ng-repeat=\"item in ctrl.items | orderBy:'' true\"/>", "</li>"
])); | 2027 <li ng-repeat="item in ctrl.items | orderBy:'' true"/> |
| 2028 </li>''')); |
| 2041 assertErrors(indexSource, [AngularCode.MISSING_FORMATTER_COLON]); | 2029 assertErrors(indexSource, [AngularCode.MISSING_FORMATTER_COLON]); |
| 2042 } | 2030 } |
| 2043 | 2031 |
| 2044 void fail_ngRepeat_filters_noArgs() { | 2032 void fail_ngRepeat_filters_noArgs() { |
| 2045 addMyController(); | 2033 addMyController(); |
| 2046 _resolveIndexNoErrors( | 2034 _resolveIndexNoErrors( |
| 2047 AngularTest.createHtmlWithMyController( | 2035 AngularTest.createHtmlWithMyController(r''' |
| 2048 ["<li ng-repeat=\"item in ctrl.items | orderBy\"/>", "</li>"])); | 2036 <li ng-repeat="item in ctrl.items | orderBy"/> |
| 2037 </li>''')); |
| 2049 // filter "orderBy" is resolved | 2038 // filter "orderBy" is resolved |
| 2050 Element filterElement = assertResolvedIdentifier("orderBy"); | 2039 Element filterElement = assertResolvedIdentifier("orderBy"); |
| 2051 EngineTestCase.assertInstanceOf( | 2040 EngineTestCase.assertInstanceOf( |
| 2052 (obj) => obj is AngularFormatterElement, | 2041 (obj) => obj is AngularFormatterElement, |
| 2053 AngularFormatterElement, | 2042 AngularFormatterElement, |
| 2054 filterElement); | 2043 filterElement); |
| 2055 } | 2044 } |
| 2056 | 2045 |
| 2057 void fail_ngRepeat_filters_orderBy_emptyString() { | 2046 void fail_ngRepeat_filters_orderBy_emptyString() { |
| 2058 addMyController(); | 2047 addMyController(); |
| 2059 _resolveIndexNoErrors( | 2048 _resolveIndexNoErrors( |
| 2060 AngularTest.createHtmlWithMyController( | 2049 AngularTest.createHtmlWithMyController(r''' |
| 2061 ["<li ng-repeat=\"item in ctrl.items | orderBy:'':true\"/>", "</li>"
])); | 2050 <li ng-repeat="item in ctrl.items | orderBy:'':true"/> |
| 2051 </li>''')); |
| 2062 // filter "orderBy" is resolved | 2052 // filter "orderBy" is resolved |
| 2063 Element filterElement = assertResolvedIdentifier("orderBy"); | 2053 Element filterElement = assertResolvedIdentifier("orderBy"); |
| 2064 EngineTestCase.assertInstanceOf( | 2054 EngineTestCase.assertInstanceOf( |
| 2065 (obj) => obj is AngularFormatterElement, | 2055 (obj) => obj is AngularFormatterElement, |
| 2066 AngularFormatterElement, | 2056 AngularFormatterElement, |
| 2067 filterElement); | 2057 filterElement); |
| 2068 } | 2058 } |
| 2069 | 2059 |
| 2070 void fail_ngRepeat_filters_orderBy_propertyList() { | 2060 void fail_ngRepeat_filters_orderBy_propertyList() { |
| 2071 addMyController(); | 2061 addMyController(); |
| 2072 _resolveIndexNoErrors( | 2062 _resolveIndexNoErrors( |
| 2073 AngularTest.createHtmlWithMyController( | 2063 AngularTest.createHtmlWithMyController(r''' |
| 2074 [ | 2064 <li ng-repeat="item in ctrl.items | orderBy:['name', 'done']"/> |
| 2075 "<li ng-repeat=\"item in ctrl.items | orderBy:['name', 'done']\"
/>", | 2065 </li>''')); |
| 2076 "</li>"])); | |
| 2077 assertResolvedIdentifier2("name'", "String"); | 2066 assertResolvedIdentifier2("name'", "String"); |
| 2078 assertResolvedIdentifier2("done'", "bool"); | 2067 assertResolvedIdentifier2("done'", "bool"); |
| 2079 } | 2068 } |
| 2080 | 2069 |
| 2081 void fail_ngRepeat_filters_orderBy_propertyName() { | 2070 void fail_ngRepeat_filters_orderBy_propertyName() { |
| 2082 addMyController(); | 2071 addMyController(); |
| 2083 _resolveIndexNoErrors( | 2072 _resolveIndexNoErrors( |
| 2084 AngularTest.createHtmlWithMyController( | 2073 AngularTest.createHtmlWithMyController(r''' |
| 2085 ["<li ng-repeat=\"item in ctrl.items | orderBy:'name'\"/>", "</li>"]
)); | 2074 <li ng-repeat="item in ctrl.items | orderBy:'name'"/> |
| 2075 </li>''')); |
| 2086 assertResolvedIdentifier2("name'", "String"); | 2076 assertResolvedIdentifier2("name'", "String"); |
| 2087 } | 2077 } |
| 2088 | 2078 |
| 2089 void fail_ngRepeat_filters_orderBy_propertyName_minus() { | 2079 void fail_ngRepeat_filters_orderBy_propertyName_minus() { |
| 2090 addMyController(); | 2080 addMyController(); |
| 2091 _resolveIndexNoErrors( | 2081 _resolveIndexNoErrors( |
| 2092 AngularTest.createHtmlWithMyController( | 2082 AngularTest.createHtmlWithMyController(r''' |
| 2093 ["<li ng-repeat=\"item in ctrl.items | orderBy:'-name'\"/>", "</li>"
])); | 2083 <li ng-repeat="item in ctrl.items | orderBy:'-name'"/> |
| 2084 </li>''')); |
| 2094 assertResolvedIdentifier2("name'", "String"); | 2085 assertResolvedIdentifier2("name'", "String"); |
| 2095 } | 2086 } |
| 2096 | 2087 |
| 2097 void fail_ngRepeat_filters_orderBy_propertyName_plus() { | 2088 void fail_ngRepeat_filters_orderBy_propertyName_plus() { |
| 2098 addMyController(); | 2089 addMyController(); |
| 2099 _resolveIndexNoErrors( | 2090 _resolveIndexNoErrors( |
| 2100 AngularTest.createHtmlWithMyController( | 2091 AngularTest.createHtmlWithMyController(r''' |
| 2101 ["<li ng-repeat=\"item in ctrl.items | orderBy:'+name'\"/>", "</li>"
])); | 2092 <li ng-repeat="item in ctrl.items | orderBy:'+name'"/> |
| 2093 </li>''')); |
| 2102 assertResolvedIdentifier2("name'", "String"); | 2094 assertResolvedIdentifier2("name'", "String"); |
| 2103 } | 2095 } |
| 2104 | 2096 |
| 2105 void fail_ngRepeat_filters_orderBy_propertyName_untypedItems() { | 2097 void fail_ngRepeat_filters_orderBy_propertyName_untypedItems() { |
| 2106 addMyController(); | 2098 addMyController(); |
| 2107 _resolveIndexNoErrors( | 2099 _resolveIndexNoErrors( |
| 2108 AngularTest.createHtmlWithMyController( | 2100 AngularTest.createHtmlWithMyController(r''' |
| 2109 ["<li ng-repeat=\"item in ctrl.untypedItems | orderBy:'name'\"/>", "
</li>"])); | 2101 <li ng-repeat="item in ctrl.untypedItems | orderBy:'name'"/> |
| 2102 </li>''')); |
| 2110 assertResolvedIdentifier2("name'", "dynamic"); | 2103 assertResolvedIdentifier2("name'", "dynamic"); |
| 2111 } | 2104 } |
| 2112 | 2105 |
| 2113 void fail_ngRepeat_filters_two() { | 2106 void fail_ngRepeat_filters_two() { |
| 2114 addMyController(); | 2107 addMyController(); |
| 2115 _resolveIndexNoErrors( | 2108 _resolveIndexNoErrors( |
| 2116 AngularTest.createHtmlWithMyController( | 2109 AngularTest.createHtmlWithMyController(r''' |
| 2117 [ | 2110 <li ng-repeat="item in ctrl.items | orderBy:'+' | orderBy:'-'"/> |
| 2118 "<li ng-repeat=\"item in ctrl.items | orderBy:'+' | orderBy:'-'\
"/>", | 2111 </li>''')); |
| 2119 "</li>"])); | |
| 2120 EngineTestCase.assertInstanceOf( | 2112 EngineTestCase.assertInstanceOf( |
| 2121 (obj) => obj is AngularFormatterElement, | 2113 (obj) => obj is AngularFormatterElement, |
| 2122 AngularFormatterElement, | 2114 AngularFormatterElement, |
| 2123 assertResolvedIdentifier("orderBy:'+'")); | 2115 assertResolvedIdentifier("orderBy:'+'")); |
| 2124 EngineTestCase.assertInstanceOf( | 2116 EngineTestCase.assertInstanceOf( |
| 2125 (obj) => obj is AngularFormatterElement, | 2117 (obj) => obj is AngularFormatterElement, |
| 2126 AngularFormatterElement, | 2118 AngularFormatterElement, |
| 2127 assertResolvedIdentifier("orderBy:'-'")); | 2119 assertResolvedIdentifier("orderBy:'-'")); |
| 2128 } | 2120 } |
| 2129 | 2121 |
| 2130 void fail_ngRepeat_resolvedExpressions() { | 2122 void fail_ngRepeat_resolvedExpressions() { |
| 2131 addMyController(); | 2123 addMyController(); |
| 2132 _resolveIndexNoErrors( | 2124 _resolveIndexNoErrors( |
| 2133 AngularTest.createHtmlWithMyController( | 2125 AngularTest.createHtmlWithMyController(r''' |
| 2134 ["<li ng-repeat='name in ctrl.names'>", " {{name}}", "</li>"])); | 2126 <li ng-repeat='name in ctrl.names'> |
| 2127 {{name}} |
| 2128 </li>''')); |
| 2135 assertResolvedIdentifier2("name in", "String"); | 2129 assertResolvedIdentifier2("name in", "String"); |
| 2136 assertResolvedIdentifier2("ctrl.", "MyController"); | 2130 assertResolvedIdentifier2("ctrl.", "MyController"); |
| 2137 assertResolvedIdentifier2("names'", "List<String>"); | 2131 assertResolvedIdentifier2("names'", "List<String>"); |
| 2138 assertResolvedIdentifier2("name}}", "String"); | 2132 assertResolvedIdentifier2("name}}", "String"); |
| 2139 } | 2133 } |
| 2140 | 2134 |
| 2141 void fail_ngRepeat_trackBy() { | 2135 void fail_ngRepeat_trackBy() { |
| 2142 addMyController(); | 2136 addMyController(); |
| 2143 _resolveIndexNoErrors( | 2137 _resolveIndexNoErrors( |
| 2144 AngularTest.createHtmlWithMyController( | 2138 AngularTest.createHtmlWithMyController(r''' |
| 2145 ["<li ng-repeat='name in ctrl.names track by name.length'/>", "</li>
"])); | 2139 <li ng-repeat='name in ctrl.names track by name.length'/> |
| 2140 </li>''')); |
| 2146 assertResolvedIdentifier2("length'", "int"); | 2141 assertResolvedIdentifier2("length'", "int"); |
| 2147 } | 2142 } |
| 2148 | 2143 |
| 2149 /** | 2144 /** |
| 2150 * Test that we resolve "ng-show" expression. | 2145 * Test that we resolve "ng-show" expression. |
| 2151 */ | 2146 */ |
| 2152 void test_ngShow() { | 2147 void test_ngShow() { |
| 2153 addMyController(); | 2148 addMyController(); |
| 2154 _resolveIndexNoErrors( | 2149 _resolveIndexNoErrors( |
| 2155 AngularTest.createHtmlWithMyController( | 2150 AngularTest.createHtmlWithMyController("<div ng-show='ctrl.field != null
'/>")); |
| 2156 ["<div ng-show='ctrl.field != null'/>"])); | |
| 2157 assertResolvedIdentifier("field"); | 2151 assertResolvedIdentifier("field"); |
| 2158 } | 2152 } |
| 2159 | 2153 |
| 2160 void test_notResolved_noDartScript() { | 2154 void test_notResolved_noDartScript() { |
| 2161 resolveIndex2(r''' | 2155 resolveIndex2(r''' |
| 2162 <html ng-app> | 2156 <html ng-app> |
| 2163 <body> | 2157 <body> |
| 2164 <div my-marker> | 2158 <div my-marker> |
| 2165 {{ctrl.field}} | 2159 {{ctrl.field}} |
| 2166 </div> | 2160 </div> |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2262 // ...but not "invisibleScopeProperty" | 2256 // ...but not "invisibleScopeProperty" |
| 2263 { | 2257 { |
| 2264 SimpleIdentifier identifier = findIdentifier("invisibleScopeProperty"); | 2258 SimpleIdentifier identifier = findIdentifier("invisibleScopeProperty"); |
| 2265 JUnitTestCase.assertNull(identifier.bestElement); | 2259 JUnitTestCase.assertNull(identifier.bestElement); |
| 2266 } | 2260 } |
| 2267 } | 2261 } |
| 2268 | 2262 |
| 2269 void test_resolveExpression_inAttribute() { | 2263 void test_resolveExpression_inAttribute() { |
| 2270 addMyController(); | 2264 addMyController(); |
| 2271 _resolveIndexNoErrors( | 2265 _resolveIndexNoErrors( |
| 2272 AngularTest.createHtmlWithMyController( | 2266 AngularTest.createHtmlWithMyController("<button title='{{ctrl.field}}'><
/button>")); |
| 2273 ["<button title='{{ctrl.field}}'></button>"])); | |
| 2274 assertResolvedIdentifier2("ctrl", "MyController"); | 2267 assertResolvedIdentifier2("ctrl", "MyController"); |
| 2275 } | 2268 } |
| 2276 | 2269 |
| 2277 void test_resolveExpression_ngApp_onBody() { | 2270 void test_resolveExpression_ngApp_onBody() { |
| 2278 addMyController(); | 2271 addMyController(); |
| 2279 _resolveIndexNoErrors(r''' | 2272 _resolveIndexNoErrors(r''' |
| 2280 <html> | 2273 <html> |
| 2281 <body ng-app> | 2274 <body ng-app> |
| 2282 <div my-controller> | 2275 <div my-controller> |
| 2283 {{ctrl.field}} | 2276 {{ctrl.field}} |
| 2284 </div> | 2277 </div> |
| 2285 <script type='application/dart' src='main.dart'></script> | 2278 <script type='application/dart' src='main.dart'></script> |
| 2286 </body> | 2279 </body> |
| 2287 </html>'''); | 2280 </html>'''); |
| 2288 assertResolvedIdentifier2("ctrl", "MyController"); | 2281 assertResolvedIdentifier2("ctrl", "MyController"); |
| 2289 } | 2282 } |
| 2290 | 2283 |
| 2291 void test_resolveExpression_withFilter() { | 2284 void test_resolveExpression_withFilter() { |
| 2292 addMyController(); | 2285 addMyController(); |
| 2293 _resolveIndexNoErrors( | 2286 _resolveIndexNoErrors( |
| 2294 AngularTest.createHtmlWithMyController(["{{ctrl.field | uppercase}}"])); | 2287 AngularTest.createHtmlWithMyController("{{ctrl.field | uppercase}}")); |
| 2295 assertResolvedIdentifier2("ctrl", "MyController"); | 2288 assertResolvedIdentifier2("ctrl", "MyController"); |
| 2296 assertResolvedIdentifier("uppercase"); | 2289 assertResolvedIdentifier("uppercase"); |
| 2297 } | 2290 } |
| 2298 | 2291 |
| 2299 void test_resolveExpression_withFilter_notSimpleIdentifier() { | 2292 void test_resolveExpression_withFilter_notSimpleIdentifier() { |
| 2300 addMyController(); | 2293 addMyController(); |
| 2301 resolveIndex2( | 2294 resolveIndex2( |
| 2302 AngularTest.createHtmlWithMyController(["{{ctrl.field | not.supported}}"
])); | 2295 AngularTest.createHtmlWithMyController("{{ctrl.field | not.supported}}")
); |
| 2303 assertErrors(indexSource, [AngularCode.INVALID_FORMATTER_NAME]); | 2296 assertErrors(indexSource, [AngularCode.INVALID_FORMATTER_NAME]); |
| 2304 } | 2297 } |
| 2305 | 2298 |
| 2306 void test_scopeProperties() { | 2299 void test_scopeProperties() { |
| 2307 addMainSource(r''' | 2300 addMainSource(r''' |
| 2308 | 2301 |
| 2309 import 'angular.dart'; | 2302 import 'angular.dart'; |
| 2310 | 2303 |
| 2311 @Component( | 2304 @Component( |
| 2312 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', | 2305 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', |
| 2313 publishAs: 'ctrl', | 2306 publishAs: 'ctrl', |
| 2314 selector: 'myComponent') | 2307 selector: 'myComponent') |
| 2315 class MyComponent { | 2308 class MyComponent { |
| 2316 String field; | 2309 String field; |
| 2317 MyComponent(Scope scope) { | 2310 MyComponent(Scope scope) { |
| 2318 scope.context['scopeProperty'] = 'abc'; | 2311 scope.context['scopeProperty'] = 'abc'; |
| 2319 } | 2312 } |
| 2320 } | 2313 } |
| 2321 '''); | 2314 '''); |
| 2322 contextHelper.addSource( | 2315 contextHelper.addSource( |
| 2323 "/entry-point.html", | 2316 "/entry-point.html", |
| 2324 AngularTest.createHtmlWithAngular([])); | 2317 AngularTest.createHtmlWithAngular('')); |
| 2325 addIndexSource2( | 2318 addIndexSource2( |
| 2326 "/my_template.html", | 2319 "/my_template.html", |
| 2327 r''' | 2320 r''' |
| 2328 <div> | 2321 <div> |
| 2329 {{scopeProperty}} | 2322 {{scopeProperty}} |
| 2330 </div>'''); | 2323 </div>'''); |
| 2331 contextHelper.addSource("/my_styles.css", ""); | 2324 contextHelper.addSource("/my_styles.css", ""); |
| 2332 contextHelper.runTasks(); | 2325 contextHelper.runTasks(); |
| 2333 resolveIndex(); | 2326 resolveIndex(); |
| 2334 assertNoErrors(); | 2327 assertNoErrors(); |
| 2335 // "scopeProperty" is resolved | 2328 // "scopeProperty" is resolved |
| 2336 Element element = assertResolvedIdentifier2("scopeProperty}}", "String"); | 2329 Element element = assertResolvedIdentifier2("scopeProperty}}", "String"); |
| 2337 EngineTestCase.assertInstanceOf( | 2330 EngineTestCase.assertInstanceOf( |
| 2338 (obj) => obj is AngularScopePropertyElement, | 2331 (obj) => obj is AngularScopePropertyElement, |
| 2339 AngularScopePropertyElement, | 2332 AngularScopePropertyElement, |
| 2340 AngularHtmlUnitResolver.getAngularElement(element)); | 2333 AngularHtmlUnitResolver.getAngularElement(element)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2351 selector: 'myComponent') | 2344 selector: 'myComponent') |
| 2352 class MyComponent { | 2345 class MyComponent { |
| 2353 } | 2346 } |
| 2354 | 2347 |
| 2355 void setScopeProperties(Scope scope) { | 2348 void setScopeProperties(Scope scope) { |
| 2356 scope.context['ctrl'] = 1; | 2349 scope.context['ctrl'] = 1; |
| 2357 } | 2350 } |
| 2358 '''); | 2351 '''); |
| 2359 contextHelper.addSource( | 2352 contextHelper.addSource( |
| 2360 "/entry-point.html", | 2353 "/entry-point.html", |
| 2361 AngularTest.createHtmlWithAngular([])); | 2354 AngularTest.createHtmlWithAngular('')); |
| 2362 addIndexSource2( | 2355 addIndexSource2( |
| 2363 "/my_template.html", | 2356 "/my_template.html", |
| 2364 r''' | 2357 r''' |
| 2365 <div> | 2358 <div> |
| 2366 {{ctrl}} | 2359 {{ctrl}} |
| 2367 </div>'''); | 2360 </div>'''); |
| 2368 contextHelper.addSource("/my_styles.css", ""); | 2361 contextHelper.addSource("/my_styles.css", ""); |
| 2369 contextHelper.runTasks(); | 2362 contextHelper.runTasks(); |
| 2370 resolveIndex(); | 2363 resolveIndex(); |
| 2371 assertNoErrors(); | 2364 assertNoErrors(); |
| 2372 // "ctrl" is resolved | 2365 // "ctrl" is resolved |
| 2373 LocalVariableElement element = | 2366 LocalVariableElement element = |
| 2374 assertResolvedIdentifier("ctrl}}") as LocalVariableElement; | 2367 assertResolvedIdentifier("ctrl}}") as LocalVariableElement; |
| 2375 List<ToolkitObjectElement> toolkitObjects = element.toolkitObjects; | 2368 List<ToolkitObjectElement> toolkitObjects = element.toolkitObjects; |
| 2376 EngineTestCase.assertInstanceOf( | 2369 EngineTestCase.assertInstanceOf( |
| 2377 (obj) => obj is AngularComponentElement, | 2370 (obj) => obj is AngularComponentElement, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2391 String field; | 2384 String field; |
| 2392 } | 2385 } |
| 2393 | 2386 |
| 2394 class MyRouteInitializer { | 2387 class MyRouteInitializer { |
| 2395 init(ViewFactory view) { | 2388 init(ViewFactory view) { |
| 2396 view('my_template.html'); | 2389 view('my_template.html'); |
| 2397 } | 2390 } |
| 2398 }'''); | 2391 }'''); |
| 2399 contextHelper.addSource( | 2392 contextHelper.addSource( |
| 2400 "/entry-point.html", | 2393 "/entry-point.html", |
| 2401 AngularTest.createHtmlWithAngular([])); | 2394 AngularTest.createHtmlWithAngular('')); |
| 2402 addIndexSource2( | 2395 addIndexSource2( |
| 2403 "/my_template.html", | 2396 "/my_template.html", |
| 2404 r''' | 2397 r''' |
| 2405 <div my-controller> | 2398 <div my-controller> |
| 2406 {{ctrl.field}} | 2399 {{ctrl.field}} |
| 2407 </div>'''); | 2400 </div>'''); |
| 2408 contextHelper.addSource("/my_styles.css", ""); | 2401 contextHelper.addSource("/my_styles.css", ""); |
| 2409 contextHelper.runTasks(); | 2402 contextHelper.runTasks(); |
| 2410 resolveIndex(); | 2403 resolveIndex(); |
| 2411 assertNoErrors(); | 2404 assertNoErrors(); |
| 2412 assertResolvedIdentifier2("ctrl.", "MyController"); | 2405 assertResolvedIdentifier2("ctrl.", "MyController"); |
| 2413 assertResolvedIdentifier2("field}}", "String"); | 2406 assertResolvedIdentifier2("field}}", "String"); |
| 2414 } | 2407 } |
| 2415 | 2408 |
| 2416 String _getSourceContent(Source source) { | 2409 String _getSourceContent(Source source) { |
| 2417 return context.getContents(source).data.toString(); | 2410 return context.getContents(source).data.toString(); |
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2995 Injector ngBootstrap({ | 2988 Injector ngBootstrap({ |
| 2996 Module module: null, | 2989 Module module: null, |
| 2997 List<Module> modules: null, | 2990 List<Module> modules: null, |
| 2998 /*dom.Element*/ element: null, | 2991 /*dom.Element*/ element: null, |
| 2999 String selector: '[ng-app]', | 2992 String selector: '[ng-app]', |
| 3000 /*Injector*/ injectorFactory/*(List<Module> modules): _defaultInjectorFa
ctory*/}) {} | 2993 /*Injector*/ injectorFactory/*(List<Module> modules): _defaultInjectorFa
ctory*/}) {} |
| 3001 '''); | 2994 '''); |
| 3002 } | 2995 } |
| 3003 | 2996 |
| 3004 /** | 2997 /** |
| 3005 * Creates an HTML content that has Angular marker and script with "main.dart"
reference. | 2998 * Creates an HTML content that has Angular marker and script with |
| 2999 * the "main.dart" reference. |
| 3006 */ | 3000 */ |
| 3007 static String createHtmlWithAngular(List<String> lines) { | 3001 static String createHtmlWithAngular(String innerCode) { |
| 3008 String source = r''' | 3002 String source = ''' |
| 3009 <html ng-app> | 3003 <html ng-app> |
| 3010 <body>'''; | 3004 <body> |
| 3011 source += EngineTestCase.createSource(lines); | 3005 $innerCode |
| 3012 source += r''' | |
| 3013 <script type='application/dart' src='main.dart'></script> | 3006 <script type='application/dart' src='main.dart'></script> |
| 3014 </body> | 3007 </body> |
| 3015 </html>'''; | 3008 </html>'''; |
| 3016 return source; | 3009 return source; |
| 3017 } | 3010 } |
| 3018 | 3011 |
| 3019 /** | 3012 /** |
| 3020 * Creates an HTML content that has Angular marker, script with "main.dart" re
ference and | 3013 * Creates an HTML content that has Angular marker, script with "main.dart" re
ference and |
| 3021 * "MyController" injected. | 3014 * "MyController" injected. |
| 3022 */ | 3015 */ |
| 3023 static String createHtmlWithMyController(List<String> lines) { | 3016 static String createHtmlWithMyController(String innerHtml) { |
| 3024 String source = r''' | 3017 String source = ''' |
| 3025 <html ng-app> | 3018 <html ng-app> |
| 3026 <body> | 3019 <body> |
| 3027 <div my-controller>'''; | 3020 <div my-controller> |
| 3028 source += EngineTestCase.createSource(lines); | 3021 $innerHtml |
| 3029 source += r''' | |
| 3030 </div> | 3022 </div> |
| 3031 <script type='application/dart' src='main.dart'></script> | 3023 <script type='application/dart' src='main.dart'></script> |
| 3032 </body> | 3024 </body> |
| 3033 </html>'''; | 3025 </html>'''; |
| 3034 return source; | 3026 return source; |
| 3035 } | 3027 } |
| 3036 | 3028 |
| 3037 /** | 3029 /** |
| 3038 * Finds an [Element] with the given names inside of the given root [Element]. | 3030 * Finds an [Element] with the given names inside of the given root [Element]. |
| 3039 * | 3031 * |
| (...skipping 5391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8431 null, | 8423 null, |
| 8432 AstFactory.identifier3("main"), | 8424 AstFactory.identifier3("main"), |
| 8433 AstFactory.formalParameterList([formalParameter]), | 8425 AstFactory.formalParameterList([formalParameter]), |
| 8434 body); | 8426 body); |
| 8435 } | 8427 } |
| 8436 } | 8428 } |
| 8437 | 8429 |
| 8438 | 8430 |
| 8439 class ElementLocatorTest extends ResolverTestCase { | 8431 class ElementLocatorTest extends ResolverTestCase { |
| 8440 void fail_locate_ExportDirective() { | 8432 void fail_locate_ExportDirective() { |
| 8441 AstNode id = _findNodeIn("export", ["export 'dart:core';"]); | 8433 AstNode id = _findNodeIn("export", "export 'dart:core';"); |
| 8442 Element element = ElementLocator.locate(id); | 8434 Element element = ElementLocator.locate(id); |
| 8443 EngineTestCase.assertInstanceOf( | 8435 EngineTestCase.assertInstanceOf( |
| 8444 (obj) => obj is ImportElement, | 8436 (obj) => obj is ImportElement, |
| 8445 ImportElement, | 8437 ImportElement, |
| 8446 element); | 8438 element); |
| 8447 } | 8439 } |
| 8448 | 8440 |
| 8449 void fail_locate_Identifier_libraryDirective() { | 8441 void fail_locate_Identifier_libraryDirective() { |
| 8450 AstNode id = _findNodeIn("foo", ["library foo.bar;"]); | 8442 AstNode id = _findNodeIn("foo", "library foo.bar;"); |
| 8451 Element element = ElementLocator.locate(id); | 8443 Element element = ElementLocator.locate(id); |
| 8452 EngineTestCase.assertInstanceOf( | 8444 EngineTestCase.assertInstanceOf( |
| 8453 (obj) => obj is LibraryElement, | 8445 (obj) => obj is LibraryElement, |
| 8454 LibraryElement, | 8446 LibraryElement, |
| 8455 element); | 8447 element); |
| 8456 } | 8448 } |
| 8457 | 8449 |
| 8458 void fail_locate_Identifier_partOfDirective() { | 8450 void fail_locate_Identifier_partOfDirective() { |
| 8459 // Can't resolve the library element without the library declaration. | 8451 // Can't resolve the library element without the library declaration. |
| 8460 // AstNode id = findNodeIn("foo", "part of foo.bar;"); | 8452 // AstNode id = findNodeIn("foo", "part of foo.bar;"); |
| 8461 // Element element = ElementLocator.locate(id); | 8453 // Element element = ElementLocator.locate(id); |
| 8462 // assertInstanceOf(LibraryElement.class, element); | 8454 // assertInstanceOf(LibraryElement.class, element); |
| 8463 JUnitTestCase.fail("Test this case"); | 8455 JUnitTestCase.fail("Test this case"); |
| 8464 } | 8456 } |
| 8465 | 8457 |
| 8466 @override | 8458 @override |
| 8467 void reset() { | 8459 void reset() { |
| 8468 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); | 8460 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); |
| 8469 analysisOptions.hint = false; | 8461 analysisOptions.hint = false; |
| 8470 resetWithOptions(analysisOptions); | 8462 resetWithOptions(analysisOptions); |
| 8471 } | 8463 } |
| 8472 | 8464 |
| 8473 void test_locateWithOffset_BinaryExpression() { | 8465 void test_locateWithOffset_BinaryExpression() { |
| 8474 AstNode id = _findNodeIn("+", ["var x = 3 + 4;"]); | 8466 AstNode id = _findNodeIn("+", "var x = 3 + 4;"); |
| 8475 Element element = ElementLocator.locateWithOffset(id, 0); | 8467 Element element = ElementLocator.locateWithOffset(id, 0); |
| 8476 EngineTestCase.assertInstanceOf( | 8468 EngineTestCase.assertInstanceOf( |
| 8477 (obj) => obj is MethodElement, | 8469 (obj) => obj is MethodElement, |
| 8478 MethodElement, | 8470 MethodElement, |
| 8479 element); | 8471 element); |
| 8480 } | 8472 } |
| 8481 | 8473 |
| 8482 void test_locateWithOffset_StringLiteral() { | 8474 void test_locateWithOffset_StringLiteral() { |
| 8483 AstNode id = _findNodeIn("abc", ["var x = 'abc';"]); | 8475 AstNode id = _findNodeIn("abc", "var x = 'abc';"); |
| 8484 Element element = ElementLocator.locateWithOffset(id, 1); | 8476 Element element = ElementLocator.locateWithOffset(id, 1); |
| 8485 JUnitTestCase.assertNull(element); | 8477 JUnitTestCase.assertNull(element); |
| 8486 } | 8478 } |
| 8487 | 8479 |
| 8488 void test_locate_AssignmentExpression() { | 8480 void test_locate_AssignmentExpression() { |
| 8489 AstNode id = | 8481 AstNode id = |
| 8490 _findNodeIn("+=", ["int x = 0;", "void main() {", " x += 1;", "}"]); | 8482 _findNodeIn("+=", r''' |
| 8483 int x = 0; |
| 8484 void main() { |
| 8485 x += 1; |
| 8486 }'''); |
| 8491 Element element = ElementLocator.locate(id); | 8487 Element element = ElementLocator.locate(id); |
| 8492 EngineTestCase.assertInstanceOf( | 8488 EngineTestCase.assertInstanceOf( |
| 8493 (obj) => obj is MethodElement, | 8489 (obj) => obj is MethodElement, |
| 8494 MethodElement, | 8490 MethodElement, |
| 8495 element); | 8491 element); |
| 8496 } | 8492 } |
| 8497 | 8493 |
| 8498 void test_locate_BinaryExpression() { | 8494 void test_locate_BinaryExpression() { |
| 8499 AstNode id = _findNodeIn("+", ["var x = 3 + 4;"]); | 8495 AstNode id = _findNodeIn("+", "var x = 3 + 4;"); |
| 8500 Element element = ElementLocator.locate(id); | 8496 Element element = ElementLocator.locate(id); |
| 8501 EngineTestCase.assertInstanceOf( | 8497 EngineTestCase.assertInstanceOf( |
| 8502 (obj) => obj is MethodElement, | 8498 (obj) => obj is MethodElement, |
| 8503 MethodElement, | 8499 MethodElement, |
| 8504 element); | 8500 element); |
| 8505 } | 8501 } |
| 8506 | 8502 |
| 8507 void test_locate_ClassDeclaration() { | 8503 void test_locate_ClassDeclaration() { |
| 8508 AstNode id = _findNodeIn("class", ["class A { }"]); | 8504 AstNode id = _findNodeIn("class", "class A { }"); |
| 8509 Element element = ElementLocator.locate(id); | 8505 Element element = ElementLocator.locate(id); |
| 8510 EngineTestCase.assertInstanceOf( | 8506 EngineTestCase.assertInstanceOf( |
| 8511 (obj) => obj is ClassElement, | 8507 (obj) => obj is ClassElement, |
| 8512 ClassElement, | 8508 ClassElement, |
| 8513 element); | 8509 element); |
| 8514 } | 8510 } |
| 8515 | 8511 |
| 8516 void test_locate_CompilationUnit() { | 8512 void test_locate_CompilationUnit() { |
| 8517 CompilationUnit cu = _resolveContents(["// only comment"]); | 8513 CompilationUnit cu = _resolveContents("// only comment"); |
| 8518 JUnitTestCase.assertNotNull(cu.element); | 8514 JUnitTestCase.assertNotNull(cu.element); |
| 8519 Element element = ElementLocator.locate(cu); | 8515 Element element = ElementLocator.locate(cu); |
| 8520 JUnitTestCase.assertSame(cu.element, element); | 8516 JUnitTestCase.assertSame(cu.element, element); |
| 8521 } | 8517 } |
| 8522 | 8518 |
| 8523 void test_locate_ConstructorDeclaration() { | 8519 void test_locate_ConstructorDeclaration() { |
| 8524 AstNode id = | 8520 AstNode id = |
| 8525 _findNodeIndexedIn("bar", 0, ["class A {", " A.bar() {}", "}"]); | 8521 _findNodeIndexedIn("bar", 0, r''' |
| 8522 class A { |
| 8523 A.bar() {} |
| 8524 }'''); |
| 8526 ConstructorDeclaration declaration = | 8525 ConstructorDeclaration declaration = |
| 8527 id.getAncestor((node) => node is ConstructorDeclaration); | 8526 id.getAncestor((node) => node is ConstructorDeclaration); |
| 8528 Element element = ElementLocator.locate(declaration); | 8527 Element element = ElementLocator.locate(declaration); |
| 8529 EngineTestCase.assertInstanceOf( | 8528 EngineTestCase.assertInstanceOf( |
| 8530 (obj) => obj is ConstructorElement, | 8529 (obj) => obj is ConstructorElement, |
| 8531 ConstructorElement, | 8530 ConstructorElement, |
| 8532 element); | 8531 element); |
| 8533 } | 8532 } |
| 8534 | 8533 |
| 8535 void test_locate_FunctionDeclaration() { | 8534 void test_locate_FunctionDeclaration() { |
| 8536 AstNode id = _findNodeIn("f", ["int f() => 3;"]); | 8535 AstNode id = _findNodeIn("f", "int f() => 3;"); |
| 8537 FunctionDeclaration declaration = | 8536 FunctionDeclaration declaration = |
| 8538 id.getAncestor((node) => node is FunctionDeclaration); | 8537 id.getAncestor((node) => node is FunctionDeclaration); |
| 8539 Element element = ElementLocator.locate(declaration); | 8538 Element element = ElementLocator.locate(declaration); |
| 8540 EngineTestCase.assertInstanceOf( | 8539 EngineTestCase.assertInstanceOf( |
| 8541 (obj) => obj is FunctionElement, | 8540 (obj) => obj is FunctionElement, |
| 8542 FunctionElement, | 8541 FunctionElement, |
| 8543 element); | 8542 element); |
| 8544 } | 8543 } |
| 8545 | 8544 |
| 8546 void | 8545 void |
| 8547 test_locate_Identifier_annotationClass_namedConstructor_forSimpleFormalPar
ameter() { | 8546 test_locate_Identifier_annotationClass_namedConstructor_forSimpleFormalPar
ameter() { |
| 8548 AstNode id = _findNodeIndexedIn( | 8547 AstNode id = _findNodeIndexedIn( |
| 8549 "Class", | 8548 "Class", |
| 8550 2, | 8549 2, |
| 8551 [ | 8550 r''' |
| 8552 "class Class {", | 8551 class Class { |
| 8553 " const Class.name();", | 8552 const Class.name(); |
| 8554 "}", | 8553 } |
| 8555 "void main(@Class.name() parameter) {", | 8554 void main(@Class.name() parameter) { |
| 8556 "}"]); | 8555 }'''); |
| 8557 Element element = ElementLocator.locate(id); | 8556 Element element = ElementLocator.locate(id); |
| 8558 EngineTestCase.assertInstanceOf( | 8557 EngineTestCase.assertInstanceOf( |
| 8559 (obj) => obj is ClassElement, | 8558 (obj) => obj is ClassElement, |
| 8560 ClassElement, | 8559 ClassElement, |
| 8561 element); | 8560 element); |
| 8562 } | 8561 } |
| 8563 | 8562 |
| 8564 void | 8563 void |
| 8565 test_locate_Identifier_annotationClass_unnamedConstructor_forSimpleFormalP
arameter() { | 8564 test_locate_Identifier_annotationClass_unnamedConstructor_forSimpleFormalP
arameter() { |
| 8566 AstNode id = _findNodeIndexedIn( | 8565 AstNode id = _findNodeIndexedIn( |
| 8567 "Class", | 8566 "Class", |
| 8568 2, | 8567 2, |
| 8569 [ | 8568 r''' |
| 8570 "class Class {", | 8569 class Class { |
| 8571 " const Class();", | 8570 const Class(); |
| 8572 "}", | 8571 } |
| 8573 "void main(@Class() parameter) {", | 8572 void main(@Class() parameter) { |
| 8574 "}"]); | 8573 }'''); |
| 8575 Element element = ElementLocator.locate(id); | 8574 Element element = ElementLocator.locate(id); |
| 8576 EngineTestCase.assertInstanceOf( | 8575 EngineTestCase.assertInstanceOf( |
| 8577 (obj) => obj is ConstructorElement, | 8576 (obj) => obj is ConstructorElement, |
| 8578 ConstructorElement, | 8577 ConstructorElement, |
| 8579 element); | 8578 element); |
| 8580 } | 8579 } |
| 8581 | 8580 |
| 8582 void test_locate_Identifier_className() { | 8581 void test_locate_Identifier_className() { |
| 8583 AstNode id = _findNodeIn("A", ["class A { }"]); | 8582 AstNode id = _findNodeIn("A", "class A { }"); |
| 8584 Element element = ElementLocator.locate(id); | 8583 Element element = ElementLocator.locate(id); |
| 8585 EngineTestCase.assertInstanceOf( | 8584 EngineTestCase.assertInstanceOf( |
| 8586 (obj) => obj is ClassElement, | 8585 (obj) => obj is ClassElement, |
| 8587 ClassElement, | 8586 ClassElement, |
| 8588 element); | 8587 element); |
| 8589 } | 8588 } |
| 8590 | 8589 |
| 8591 void test_locate_Identifier_constructor_named() { | 8590 void test_locate_Identifier_constructor_named() { |
| 8592 AstNode id = | 8591 AstNode id = |
| 8593 _findNodeIndexedIn("bar", 0, ["class A {", " A.bar() {}", "}"]); | 8592 _findNodeIndexedIn("bar", 0, r''' |
| 8593 class A { |
| 8594 A.bar() {} |
| 8595 }'''); |
| 8594 Element element = ElementLocator.locate(id); | 8596 Element element = ElementLocator.locate(id); |
| 8595 EngineTestCase.assertInstanceOf( | 8597 EngineTestCase.assertInstanceOf( |
| 8596 (obj) => obj is ConstructorElement, | 8598 (obj) => obj is ConstructorElement, |
| 8597 ConstructorElement, | 8599 ConstructorElement, |
| 8598 element); | 8600 element); |
| 8599 } | 8601 } |
| 8600 | 8602 |
| 8601 void test_locate_Identifier_constructor_unnamed() { | 8603 void test_locate_Identifier_constructor_unnamed() { |
| 8602 AstNode id = _findNodeIndexedIn("A", 1, ["class A {", " A() {}", "}"]); | 8604 AstNode id = _findNodeIndexedIn("A", 1, r''' |
| 8605 class A { |
| 8606 A() {} |
| 8607 }'''); |
| 8603 Element element = ElementLocator.locate(id); | 8608 Element element = ElementLocator.locate(id); |
| 8604 EngineTestCase.assertInstanceOf( | 8609 EngineTestCase.assertInstanceOf( |
| 8605 (obj) => obj is ConstructorElement, | 8610 (obj) => obj is ConstructorElement, |
| 8606 ConstructorElement, | 8611 ConstructorElement, |
| 8607 element); | 8612 element); |
| 8608 } | 8613 } |
| 8609 | 8614 |
| 8610 void test_locate_Identifier_fieldName() { | 8615 void test_locate_Identifier_fieldName() { |
| 8611 AstNode id = _findNodeIn("x", ["class A { var x; }"]); | 8616 AstNode id = _findNodeIn("x", "class A { var x; }"); |
| 8612 Element element = ElementLocator.locate(id); | 8617 Element element = ElementLocator.locate(id); |
| 8613 EngineTestCase.assertInstanceOf( | 8618 EngineTestCase.assertInstanceOf( |
| 8614 (obj) => obj is FieldElement, | 8619 (obj) => obj is FieldElement, |
| 8615 FieldElement, | 8620 FieldElement, |
| 8616 element); | 8621 element); |
| 8617 } | 8622 } |
| 8618 | 8623 |
| 8619 void test_locate_Identifier_propertAccess() { | 8624 void test_locate_Identifier_propertAccess() { |
| 8620 AstNode id = | 8625 AstNode id = |
| 8621 _findNodeIn("length", ["void main() {", " int x = 'foo'.length;", "}"]); | 8626 _findNodeIn("length", r''' |
| 8627 void main() { |
| 8628 int x = 'foo'.length; |
| 8629 }'''); |
| 8622 Element element = ElementLocator.locate(id); | 8630 Element element = ElementLocator.locate(id); |
| 8623 EngineTestCase.assertInstanceOf( | 8631 EngineTestCase.assertInstanceOf( |
| 8624 (obj) => obj is PropertyAccessorElement, | 8632 (obj) => obj is PropertyAccessorElement, |
| 8625 PropertyAccessorElement, | 8633 PropertyAccessorElement, |
| 8626 element); | 8634 element); |
| 8627 } | 8635 } |
| 8628 | 8636 |
| 8629 void test_locate_ImportDirective() { | 8637 void test_locate_ImportDirective() { |
| 8630 AstNode id = _findNodeIn("import", ["import 'dart:core';"]); | 8638 AstNode id = _findNodeIn("import", "import 'dart:core';"); |
| 8631 Element element = ElementLocator.locate(id); | 8639 Element element = ElementLocator.locate(id); |
| 8632 EngineTestCase.assertInstanceOf( | 8640 EngineTestCase.assertInstanceOf( |
| 8633 (obj) => obj is ImportElement, | 8641 (obj) => obj is ImportElement, |
| 8634 ImportElement, | 8642 ImportElement, |
| 8635 element); | 8643 element); |
| 8636 } | 8644 } |
| 8637 | 8645 |
| 8638 void test_locate_IndexExpression() { | 8646 void test_locate_IndexExpression() { |
| 8639 AstNode id = _findNodeIndexedIn( | 8647 AstNode id = _findNodeIndexedIn( |
| 8640 "\\[", | 8648 "\\[", |
| 8641 1, | 8649 1, |
| 8642 ["void main() {", " List x = [1, 2];", " var y = x[0];", "}"]); | 8650 r''' |
| 8651 void main() { |
| 8652 List x = [1, 2]; |
| 8653 var y = x[0]; |
| 8654 }'''); |
| 8643 Element element = ElementLocator.locate(id); | 8655 Element element = ElementLocator.locate(id); |
| 8644 EngineTestCase.assertInstanceOf( | 8656 EngineTestCase.assertInstanceOf( |
| 8645 (obj) => obj is MethodElement, | 8657 (obj) => obj is MethodElement, |
| 8646 MethodElement, | 8658 MethodElement, |
| 8647 element); | 8659 element); |
| 8648 } | 8660 } |
| 8649 | 8661 |
| 8650 void test_locate_InstanceCreationExpression() { | 8662 void test_locate_InstanceCreationExpression() { |
| 8651 AstNode node = | 8663 AstNode node = |
| 8652 _findNodeIndexedIn("A(", 0, ["class A {}", "void main() {", " new A();",
"}"]); | 8664 _findNodeIndexedIn("A(", 0, r''' |
| 8665 class A {} |
| 8666 void main() { |
| 8667 new A(); |
| 8668 }'''); |
| 8653 Element element = ElementLocator.locate(node); | 8669 Element element = ElementLocator.locate(node); |
| 8654 EngineTestCase.assertInstanceOf( | 8670 EngineTestCase.assertInstanceOf( |
| 8655 (obj) => obj is ConstructorElement, | 8671 (obj) => obj is ConstructorElement, |
| 8656 ConstructorElement, | 8672 ConstructorElement, |
| 8657 element); | 8673 element); |
| 8658 } | 8674 } |
| 8659 | 8675 |
| 8660 void test_locate_InstanceCreationExpression_type_prefixedIdentifier() { | 8676 void test_locate_InstanceCreationExpression_type_prefixedIdentifier() { |
| 8661 // prepare: new pref.A() | 8677 // prepare: new pref.A() |
| 8662 SimpleIdentifier identifier = AstFactory.identifier3("A"); | 8678 SimpleIdentifier identifier = AstFactory.identifier3("A"); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 8693 // set ConstructorElement | 8709 // set ConstructorElement |
| 8694 ConstructorElement constructorElement = | 8710 ConstructorElement constructorElement = |
| 8695 ElementFactory.constructorElement2(classElement, null, []); | 8711 ElementFactory.constructorElement2(classElement, null, []); |
| 8696 creation.constructorName.staticElement = constructorElement; | 8712 creation.constructorName.staticElement = constructorElement; |
| 8697 // verify that "A" is resolved to ConstructorElement | 8713 // verify that "A" is resolved to ConstructorElement |
| 8698 Element element = ElementLocator.locate(identifier); | 8714 Element element = ElementLocator.locate(identifier); |
| 8699 JUnitTestCase.assertSame(classElement, element); | 8715 JUnitTestCase.assertSame(classElement, element); |
| 8700 } | 8716 } |
| 8701 | 8717 |
| 8702 void test_locate_LibraryDirective() { | 8718 void test_locate_LibraryDirective() { |
| 8703 AstNode id = _findNodeIn("library", ["library foo;"]); | 8719 AstNode id = _findNodeIn("library", "library foo;"); |
| 8704 Element element = ElementLocator.locate(id); | 8720 Element element = ElementLocator.locate(id); |
| 8705 EngineTestCase.assertInstanceOf( | 8721 EngineTestCase.assertInstanceOf( |
| 8706 (obj) => obj is LibraryElement, | 8722 (obj) => obj is LibraryElement, |
| 8707 LibraryElement, | 8723 LibraryElement, |
| 8708 element); | 8724 element); |
| 8709 } | 8725 } |
| 8710 | 8726 |
| 8711 void test_locate_MethodDeclaration() { | 8727 void test_locate_MethodDeclaration() { |
| 8712 AstNode id = _findNodeIn("m", ["class A {", " void m() {}", "}"]); | 8728 AstNode id = _findNodeIn("m", r''' |
| 8729 class A { |
| 8730 void m() {} |
| 8731 }'''); |
| 8713 MethodDeclaration declaration = | 8732 MethodDeclaration declaration = |
| 8714 id.getAncestor((node) => node is MethodDeclaration); | 8733 id.getAncestor((node) => node is MethodDeclaration); |
| 8715 Element element = ElementLocator.locate(declaration); | 8734 Element element = ElementLocator.locate(declaration); |
| 8716 EngineTestCase.assertInstanceOf( | 8735 EngineTestCase.assertInstanceOf( |
| 8717 (obj) => obj is MethodElement, | 8736 (obj) => obj is MethodElement, |
| 8718 MethodElement, | 8737 MethodElement, |
| 8719 element); | 8738 element); |
| 8720 } | 8739 } |
| 8721 | 8740 |
| 8722 void test_locate_MethodInvocation_method() { | 8741 void test_locate_MethodInvocation_method() { |
| 8723 AstNode id = _findNodeIndexedIn( | 8742 AstNode id = _findNodeIndexedIn( |
| 8724 "bar", | 8743 "bar", |
| 8725 1, | 8744 1, |
| 8726 [ | 8745 r''' |
| 8727 "class A {", | 8746 class A { |
| 8728 " int bar() => 42;", | 8747 int bar() => 42; |
| 8729 "}", | 8748 } |
| 8730 "void main() {", | 8749 void main() { |
| 8731 " var f = new A().bar();", | 8750 var f = new A().bar(); |
| 8732 "}"]); | 8751 }'''); |
| 8733 Element element = ElementLocator.locate(id); | 8752 Element element = ElementLocator.locate(id); |
| 8734 EngineTestCase.assertInstanceOf( | 8753 EngineTestCase.assertInstanceOf( |
| 8735 (obj) => obj is MethodElement, | 8754 (obj) => obj is MethodElement, |
| 8736 MethodElement, | 8755 MethodElement, |
| 8737 element); | 8756 element); |
| 8738 } | 8757 } |
| 8739 | 8758 |
| 8740 void test_locate_MethodInvocation_topLevel() { | 8759 void test_locate_MethodInvocation_topLevel() { |
| 8741 String contents = | 8760 String code = |
| 8742 r''' | 8761 r''' |
| 8743 foo(x) {} | 8762 foo(x) {} |
| 8744 void main() { | 8763 void main() { |
| 8745 foo(0); | 8764 foo(0); |
| 8746 }'''; | 8765 }'''; |
| 8747 CompilationUnit cu = _resolveContents([contents]); | 8766 CompilationUnit cu = _resolveContents(code); |
| 8748 int offset = contents.indexOf('foo(0)'); | 8767 int offset = code.indexOf('foo(0)'); |
| 8749 AstNode node = new NodeLocator.con1(offset).searchWithin(cu); | 8768 AstNode node = new NodeLocator.con1(offset).searchWithin(cu); |
| 8750 MethodInvocation invocation = | 8769 MethodInvocation invocation = |
| 8751 node.getAncestor((n) => n is MethodInvocation); | 8770 node.getAncestor((n) => n is MethodInvocation); |
| 8752 Element element = ElementLocator.locate(invocation); | 8771 Element element = ElementLocator.locate(invocation); |
| 8753 EngineTestCase.assertInstanceOf( | 8772 EngineTestCase.assertInstanceOf( |
| 8754 (obj) => obj is FunctionElement, | 8773 (obj) => obj is FunctionElement, |
| 8755 FunctionElement, | 8774 FunctionElement, |
| 8756 element); | 8775 element); |
| 8757 } | 8776 } |
| 8758 | 8777 |
| 8759 void test_locate_PostfixExpression() { | 8778 void test_locate_PostfixExpression() { |
| 8760 AstNode id = _findNodeIn("++", ["int addOne(int x) => x++;"]); | 8779 AstNode id = _findNodeIn("++", "int addOne(int x) => x++;"); |
| 8761 Element element = ElementLocator.locate(id); | 8780 Element element = ElementLocator.locate(id); |
| 8762 EngineTestCase.assertInstanceOf( | 8781 EngineTestCase.assertInstanceOf( |
| 8763 (obj) => obj is MethodElement, | 8782 (obj) => obj is MethodElement, |
| 8764 MethodElement, | 8783 MethodElement, |
| 8765 element); | 8784 element); |
| 8766 } | 8785 } |
| 8767 | 8786 |
| 8768 void test_locate_PrefixExpression() { | 8787 void test_locate_PrefixExpression() { |
| 8769 AstNode id = _findNodeIn("++", ["int addOne(int x) => ++x;"]); | 8788 AstNode id = _findNodeIn("++", "int addOne(int x) => ++x;"); |
| 8770 Element element = ElementLocator.locate(id); | 8789 Element element = ElementLocator.locate(id); |
| 8771 EngineTestCase.assertInstanceOf( | 8790 EngineTestCase.assertInstanceOf( |
| 8772 (obj) => obj is MethodElement, | 8791 (obj) => obj is MethodElement, |
| 8773 MethodElement, | 8792 MethodElement, |
| 8774 element); | 8793 element); |
| 8775 } | 8794 } |
| 8776 | 8795 |
| 8777 void test_locate_PrefixedIdentifier() { | 8796 void test_locate_PrefixedIdentifier() { |
| 8778 AstNode id = | 8797 AstNode id = |
| 8779 _findNodeIn("int", ["import 'dart:core' as core;", "core.int value;"]); | 8798 _findNodeIn("int", r''' |
| 8799 import 'dart:core' as core; |
| 8800 core.int value;'''); |
| 8780 PrefixedIdentifier identifier = | 8801 PrefixedIdentifier identifier = |
| 8781 id.getAncestor((node) => node is PrefixedIdentifier); | 8802 id.getAncestor((node) => node is PrefixedIdentifier); |
| 8782 Element element = ElementLocator.locate(identifier); | 8803 Element element = ElementLocator.locate(identifier); |
| 8783 EngineTestCase.assertInstanceOf( | 8804 EngineTestCase.assertInstanceOf( |
| 8784 (obj) => obj is ClassElement, | 8805 (obj) => obj is ClassElement, |
| 8785 ClassElement, | 8806 ClassElement, |
| 8786 element); | 8807 element); |
| 8787 } | 8808 } |
| 8788 | 8809 |
| 8789 void test_locate_StringLiteral_exportUri() { | 8810 void test_locate_StringLiteral_exportUri() { |
| 8790 addNamedSource("/foo.dart", "library foo;"); | 8811 addNamedSource("/foo.dart", "library foo;"); |
| 8791 AstNode id = _findNodeIn("'foo.dart'", ["export 'foo.dart';"]); | 8812 AstNode id = _findNodeIn("'foo.dart'", "export 'foo.dart';"); |
| 8792 Element element = ElementLocator.locate(id); | 8813 Element element = ElementLocator.locate(id); |
| 8793 EngineTestCase.assertInstanceOf( | 8814 EngineTestCase.assertInstanceOf( |
| 8794 (obj) => obj is LibraryElement, | 8815 (obj) => obj is LibraryElement, |
| 8795 LibraryElement, | 8816 LibraryElement, |
| 8796 element); | 8817 element); |
| 8797 } | 8818 } |
| 8798 | 8819 |
| 8799 void test_locate_StringLiteral_expression() { | 8820 void test_locate_StringLiteral_expression() { |
| 8800 AstNode id = _findNodeIn("abc", ["var x = 'abc';"]); | 8821 AstNode id = _findNodeIn("abc", "var x = 'abc';"); |
| 8801 Element element = ElementLocator.locate(id); | 8822 Element element = ElementLocator.locate(id); |
| 8802 JUnitTestCase.assertNull(element); | 8823 JUnitTestCase.assertNull(element); |
| 8803 } | 8824 } |
| 8804 | 8825 |
| 8805 void test_locate_StringLiteral_importUri() { | 8826 void test_locate_StringLiteral_importUri() { |
| 8806 addNamedSource("/foo.dart", "library foo; class A {}"); | 8827 addNamedSource("/foo.dart", "library foo; class A {}"); |
| 8807 AstNode id = | 8828 AstNode id = |
| 8808 _findNodeIn("'foo.dart'", ["import 'foo.dart'; class B extends A {}"]); | 8829 _findNodeIn("'foo.dart'", "import 'foo.dart'; class B extends A {}"); |
| 8809 Element element = ElementLocator.locate(id); | 8830 Element element = ElementLocator.locate(id); |
| 8810 EngineTestCase.assertInstanceOf( | 8831 EngineTestCase.assertInstanceOf( |
| 8811 (obj) => obj is LibraryElement, | 8832 (obj) => obj is LibraryElement, |
| 8812 LibraryElement, | 8833 LibraryElement, |
| 8813 element); | 8834 element); |
| 8814 } | 8835 } |
| 8815 | 8836 |
| 8816 void test_locate_StringLiteral_partUri() { | 8837 void test_locate_StringLiteral_partUri() { |
| 8817 addNamedSource("/foo.dart", "part of app;"); | 8838 addNamedSource("/foo.dart", "part of app;"); |
| 8818 AstNode id = _findNodeIn("'foo.dart'", ["library app; part 'foo.dart';"]); | 8839 AstNode id = _findNodeIn("'foo.dart'", "library app; part 'foo.dart';"); |
| 8819 Element element = ElementLocator.locate(id); | 8840 Element element = ElementLocator.locate(id); |
| 8820 EngineTestCase.assertInstanceOf( | 8841 EngineTestCase.assertInstanceOf( |
| 8821 (obj) => obj is CompilationUnitElement, | 8842 (obj) => obj is CompilationUnitElement, |
| 8822 CompilationUnitElement, | 8843 CompilationUnitElement, |
| 8823 element); | 8844 element); |
| 8824 } | 8845 } |
| 8825 | 8846 |
| 8826 void test_locate_VariableDeclaration() { | 8847 void test_locate_VariableDeclaration() { |
| 8827 AstNode id = _findNodeIn("x", ["var x = 'abc';"]); | 8848 AstNode id = _findNodeIn("x", "var x = 'abc';"); |
| 8828 VariableDeclaration declaration = | 8849 VariableDeclaration declaration = |
| 8829 id.getAncestor((node) => node is VariableDeclaration); | 8850 id.getAncestor((node) => node is VariableDeclaration); |
| 8830 Element element = ElementLocator.locate(declaration); | 8851 Element element = ElementLocator.locate(declaration); |
| 8831 EngineTestCase.assertInstanceOf( | 8852 EngineTestCase.assertInstanceOf( |
| 8832 (obj) => obj is TopLevelVariableElement, | 8853 (obj) => obj is TopLevelVariableElement, |
| 8833 TopLevelVariableElement, | 8854 TopLevelVariableElement, |
| 8834 element); | 8855 element); |
| 8835 } | 8856 } |
| 8836 | 8857 |
| 8837 /** | 8858 /** |
| 8838 * Find the first AST node matching a pattern in the resolved AST for the give
n source. | 8859 * Find the first AST node matching a pattern in the resolved AST for the give
n source. |
| 8839 * | 8860 * |
| 8840 * @param nodePattern the (unique) pattern used to identify the node of intere
st | 8861 * [nodePattern] the (unique) pattern used to identify the node of interest. |
| 8841 * @param lines the lines to be merged into a single source string | 8862 * [code] the code to resolve. |
| 8842 * @return the matched node in the resolved AST for the given source lines | 8863 * Returns the matched node in the resolved AST for the given source lines. |
| 8843 * @throws Exception if source cannot be verified | |
| 8844 */ | 8864 */ |
| 8845 AstNode _findNodeIn(String nodePattern, List<String> lines) { | 8865 AstNode _findNodeIn(String nodePattern, String code) { |
| 8846 return _findNodeIndexedIn(nodePattern, 0, lines); | 8866 return _findNodeIndexedIn(nodePattern, 0, code); |
| 8847 } | 8867 } |
| 8848 | 8868 |
| 8849 /** | 8869 /** |
| 8850 * Find the AST node matching the given indexed occurrence of a pattern in the
resolved AST for | 8870 * Find the AST node matching the given indexed occurrence of a pattern in the
resolved AST for |
| 8851 * the given source. | 8871 * the given source. |
| 8852 * | 8872 * |
| 8853 * @param nodePattern the pattern used to identify the node of interest | 8873 * [nodePattern] the pattern used to identify the node of interest. |
| 8854 * @param index the index of the pattern match of interest | 8874 * [index] the index of the pattern match of interest. |
| 8855 * @param lines the lines to be merged into a single source string | 8875 * [code] the code to resolve. |
| 8856 * @return the matched node in the resolved AST for the given source lines | 8876 * Returns the matched node in the resolved AST for the given source lines |
| 8857 * @throws Exception if source cannot be verified | |
| 8858 */ | 8877 */ |
| 8859 AstNode _findNodeIndexedIn(String nodePattern, int index, | 8878 AstNode _findNodeIndexedIn(String nodePattern, int index, |
| 8860 List<String> lines) { | 8879 String code) { |
| 8861 String contents = EngineTestCase.createSource(lines); | 8880 CompilationUnit cu = _resolveContents(code); |
| 8862 CompilationUnit cu = _resolveContents([contents]); | 8881 int start = _getOffsetOfMatch(code, nodePattern, index); |
| 8863 int start = _getOffsetOfMatch(contents, nodePattern, index); | |
| 8864 int end = start + nodePattern.length; | 8882 int end = start + nodePattern.length; |
| 8865 return new NodeLocator.con2(start, end).searchWithin(cu); | 8883 return new NodeLocator.con2(start, end).searchWithin(cu); |
| 8866 } | 8884 } |
| 8867 | 8885 |
| 8868 int _getOffsetOfMatch(String contents, String pattern, int matchIndex) { | 8886 int _getOffsetOfMatch(String contents, String pattern, int matchIndex) { |
| 8869 if (matchIndex == 0) { | 8887 if (matchIndex == 0) { |
| 8870 return contents.indexOf(pattern); | 8888 return contents.indexOf(pattern); |
| 8871 } | 8889 } |
| 8872 JavaPatternMatcher matcher = | 8890 JavaPatternMatcher matcher = |
| 8873 new JavaPatternMatcher(new RegExp(pattern), contents); | 8891 new JavaPatternMatcher(new RegExp(pattern), contents); |
| 8874 int count = 0; | 8892 int count = 0; |
| 8875 while (matcher.find()) { | 8893 while (matcher.find()) { |
| 8876 if (count == matchIndex) { | 8894 if (count == matchIndex) { |
| 8877 return matcher.start(); | 8895 return matcher.start(); |
| 8878 } | 8896 } |
| 8879 ++count; | 8897 ++count; |
| 8880 } | 8898 } |
| 8881 return -1; | 8899 return -1; |
| 8882 } | 8900 } |
| 8883 | 8901 |
| 8884 /** | 8902 /** |
| 8885 * Parse, resolve and verify the given source lines to produce a fully resolve
d AST. | 8903 * Parse, resolve and verify the given source lines to produce a fully |
| 8904 * resolved AST. |
| 8886 * | 8905 * |
| 8887 * @param lines the lines to be merged into a single source string | 8906 * [code] the code to resolve. |
| 8888 * @return the result of resolving the AST structure representing the content
of the source | 8907 * |
| 8889 * @throws Exception if source cannot be verified | 8908 * Returns the result of resolving the AST structure representing the content |
| 8909 * of the source. |
| 8910 * |
| 8911 * Throws if source cannot be verified. |
| 8890 */ | 8912 */ |
| 8891 CompilationUnit _resolveContents(List<String> lines) { | 8913 CompilationUnit _resolveContents(String code) { |
| 8892 Source source = addSource(EngineTestCase.createSource(lines)); | 8914 Source source = addSource(code); |
| 8893 LibraryElement library = resolve(source); | 8915 LibraryElement library = resolve(source); |
| 8894 assertNoErrors(source); | 8916 assertNoErrors(source); |
| 8895 verify([source]); | 8917 verify([source]); |
| 8896 return analysisContext.resolveCompilationUnit(source, library); | 8918 return analysisContext.resolveCompilationUnit(source, library); |
| 8897 } | 8919 } |
| 8898 } | 8920 } |
| 8899 | 8921 |
| 8900 | 8922 |
| 8901 class EnumMemberBuilderTest extends EngineTestCase { | 8923 class EnumMemberBuilderTest extends EngineTestCase { |
| 8902 void test_visitEnumDeclaration_multiple() { | 8924 void test_visitEnumDeclaration_multiple() { |
| (...skipping 2181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11084 } else { | 11106 } else { |
| 11085 JUnitTestCase.assertNotNullMsg("script ${scriptIndex}", scriptSource); | 11107 JUnitTestCase.assertNotNullMsg("script ${scriptIndex}", scriptSource); |
| 11086 String actualExternalScriptName = scriptSource.shortName; | 11108 String actualExternalScriptName = scriptSource.shortName; |
| 11087 JUnitTestCase.assertEqualsMsg( | 11109 JUnitTestCase.assertEqualsMsg( |
| 11088 "script ${scriptIndex}", | 11110 "script ${scriptIndex}", |
| 11089 _expectedExternalScriptName, | 11111 _expectedExternalScriptName, |
| 11090 actualExternalScriptName); | 11112 actualExternalScriptName); |
| 11091 } | 11113 } |
| 11092 } | 11114 } |
| 11093 } | 11115 } |
| OLD | NEW |