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 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 return ht.TokenType.DECLARATION; | 361 return ht.TokenType.DECLARATION; |
362 } | 362 } |
363 if (lexeme.startsWith("<?")) { | 363 if (lexeme.startsWith("<?")) { |
364 return ht.TokenType.DIRECTIVE; | 364 return ht.TokenType.DIRECTIVE; |
365 } | 365 } |
366 if (_isTag(lexeme)) { | 366 if (_isTag(lexeme)) { |
367 return ht.TokenType.TAG; | 367 return ht.TokenType.TAG; |
368 } | 368 } |
369 return ht.TokenType.TEXT; | 369 return ht.TokenType.TEXT; |
370 } | 370 } |
371 fail("Unknown expected token $count: ${expected != null ? expected.runtimeTy
pe : "null"}"); | 371 fail( |
| 372 "Unknown expected token $count: ${expected != null ? expected.runtimeTyp
e : "null"}"); |
372 return null; | 373 return null; |
373 } | 374 } |
374 | 375 |
375 bool _isTag(String lexeme) { | 376 bool _isTag(String lexeme) { |
376 if (lexeme.length == 0 || !Character.isLetter(lexeme.codeUnitAt(0))) { | 377 if (lexeme.length == 0 || !Character.isLetter(lexeme.codeUnitAt(0))) { |
377 return false; | 378 return false; |
378 } | 379 } |
379 for (int index = 1; index < lexeme.length; index++) { | 380 for (int index = 1; index < lexeme.length; index++) { |
380 int ch = lexeme.codeUnitAt(index); | 381 int ch = lexeme.codeUnitAt(index); |
381 if (!Character.isLetterOrDigit(ch) && ch != 0x2D && ch != 0x5F) { | 382 if (!Character.isLetterOrDigit(ch) && ch != 0x2D && ch != 0x5F) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 buffer.write(", "); | 446 buffer.write(", "); |
446 } | 447 } |
447 fail(buffer.toString()); | 448 fail(buffer.toString()); |
448 } | 449 } |
449 return firstToken; | 450 return firstToken; |
450 } | 451 } |
451 } | 452 } |
452 | 453 |
453 | 454 |
454 class AngularCompilationUnitBuilderTest extends AngularTest { | 455 class AngularCompilationUnitBuilderTest extends AngularTest { |
| 456 void test_bad_notConstructorAnnotation() { |
| 457 String mainContent = r''' |
| 458 const MY_ANNOTATION = null; |
| 459 @MY_ANNOTATION() |
| 460 class MyFilter { |
| 461 }'''; |
| 462 resolveMainSource(mainContent); |
| 463 // prepare AngularFilterElement |
| 464 ClassElement classElement = mainUnitElement.getType("MyFilter"); |
| 465 AngularFormatterElement filter = |
| 466 getAngularElement(classElement, (e) => e is AngularFormatterElement); |
| 467 expect(filter, isNull); |
| 468 } |
| 469 |
455 void test_Decorator() { | 470 void test_Decorator() { |
456 String mainContent = _createAngularSource(r''' | 471 String mainContent = _createAngularSource(r''' |
457 @Decorator(selector: '[my-dir]', | 472 @Decorator(selector: '[my-dir]', |
458 map: const { | 473 map: const { |
459 'my-dir' : '=>myPropA', | 474 'my-dir' : '=>myPropA', |
460 '.' : '&myPropB', | 475 '.' : '&myPropB', |
461 }) | 476 }) |
462 class MyDirective { | 477 class MyDirective { |
463 set myPropA(value) {} | 478 set myPropA(value) {} |
464 set myPropB(value) {} | 479 set myPropB(value) {} |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 resolveMainSource(mainContent); | 574 resolveMainSource(mainContent); |
560 // has error | 575 // has error |
561 assertMainErrors([AngularCode.MISSING_NAME]); | 576 assertMainErrors([AngularCode.MISSING_NAME]); |
562 // no filter | 577 // no filter |
563 ClassElement classElement = mainUnitElement.getType("MyFilter"); | 578 ClassElement classElement = mainUnitElement.getType("MyFilter"); |
564 AngularFormatterElement filter = | 579 AngularFormatterElement filter = |
565 getAngularElement(classElement, (e) => e is AngularFormatterElement); | 580 getAngularElement(classElement, (e) => e is AngularFormatterElement); |
566 expect(filter, isNull); | 581 expect(filter, isNull); |
567 } | 582 } |
568 | 583 |
| 584 void test_getElement_component_name() { |
| 585 resolveMainSource(_createAngularSource(r''' |
| 586 @Component(publishAs: 'ctrl', selector: 'myComp', |
| 587 templateUrl: 'my_template.html', cssUrl: 'my_styles.css') |
| 588 class MyComponent {}''')); |
| 589 SimpleStringLiteral node = |
| 590 _findMainNode("ctrl'", (n) => n is SimpleStringLiteral); |
| 591 int offset = node.offset; |
| 592 // find AngularComponentElement |
| 593 Element element = AngularCompilationUnitBuilder.getElement(node, offset); |
| 594 EngineTestCase.assertInstanceOf( |
| 595 (obj) => obj is AngularComponentElement, |
| 596 AngularComponentElement, |
| 597 element); |
| 598 } |
| 599 |
| 600 void test_getElement_component_property_fromFieldAnnotation() { |
| 601 resolveMainSource(_createAngularSource(r''' |
| 602 @Component(publishAs: 'ctrl', selector: 'myComp', |
| 603 templateUrl: 'my_template.html', cssUrl: 'my_styles.css') |
| 604 class MyComponent { |
| 605 @NgOneWay('prop') |
| 606 var field; |
| 607 }''')); |
| 608 // prepare node |
| 609 SimpleStringLiteral node = |
| 610 _findMainNode("prop'", (n) => n is SimpleStringLiteral); |
| 611 int offset = node.offset; |
| 612 // prepare Element |
| 613 Element element = AngularCompilationUnitBuilder.getElement(node, offset); |
| 614 expect(element, isNotNull); |
| 615 // check AngularPropertyElement |
| 616 AngularPropertyElement property = element as AngularPropertyElement; |
| 617 expect(property.name, "prop"); |
| 618 } |
| 619 |
| 620 void test_getElement_component_property_fromMap() { |
| 621 resolveMainSource(_createAngularSource(r''' |
| 622 @Component(publishAs: 'ctrl', selector: 'myComp', |
| 623 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', |
| 624 map: const { |
| 625 'prop' : '@field', |
| 626 }) |
| 627 class MyComponent { |
| 628 var field; |
| 629 }''')); |
| 630 // AngularPropertyElement |
| 631 { |
| 632 SimpleStringLiteral node = |
| 633 _findMainNode("prop'", (n) => n is SimpleStringLiteral); |
| 634 int offset = node.offset; |
| 635 // prepare Element |
| 636 Element element = AngularCompilationUnitBuilder.getElement(node, offset); |
| 637 expect(element, isNotNull); |
| 638 // check AngularPropertyElement |
| 639 AngularPropertyElement property = element as AngularPropertyElement; |
| 640 expect(property.name, "prop"); |
| 641 } |
| 642 // FieldElement |
| 643 { |
| 644 SimpleStringLiteral node = |
| 645 _findMainNode("@field'", (n) => n is SimpleStringLiteral); |
| 646 int offset = node.offset; |
| 647 // prepare Element |
| 648 Element element = AngularCompilationUnitBuilder.getElement(node, offset); |
| 649 expect(element, isNotNull); |
| 650 // check FieldElement |
| 651 FieldElement field = element as FieldElement; |
| 652 expect(field.name, "field"); |
| 653 } |
| 654 } |
| 655 |
| 656 void test_getElement_component_selector() { |
| 657 resolveMainSource(_createAngularSource(r''' |
| 658 @Component(publishAs: 'ctrl', selector: 'myComp', |
| 659 templateUrl: 'my_template.html', cssUrl: 'my_styles.css') |
| 660 class MyComponent {}''')); |
| 661 SimpleStringLiteral node = |
| 662 _findMainNode("myComp'", (n) => n is SimpleStringLiteral); |
| 663 int offset = node.offset; |
| 664 // find AngularSelectorElement |
| 665 Element element = AngularCompilationUnitBuilder.getElement(node, offset); |
| 666 EngineTestCase.assertInstanceOf( |
| 667 (obj) => obj is AngularSelectorElement, |
| 668 AngularSelectorElement, |
| 669 element); |
| 670 } |
| 671 |
| 672 void test_getElement_controller_name() { |
| 673 resolveMainSource(_createAngularSource(r''' |
| 674 @Controller(publishAs: 'ctrl', selector: '[myApp]') |
| 675 class MyController { |
| 676 }''')); |
| 677 SimpleStringLiteral node = |
| 678 _findMainNode("ctrl'", (n) => n is SimpleStringLiteral); |
| 679 int offset = node.offset; |
| 680 // find AngularControllerElement |
| 681 Element element = AngularCompilationUnitBuilder.getElement(node, offset); |
| 682 EngineTestCase.assertInstanceOf( |
| 683 (obj) => obj is AngularControllerElement, |
| 684 AngularControllerElement, |
| 685 element); |
| 686 } |
| 687 |
| 688 void test_getElement_directive_property() { |
| 689 resolveMainSource(_createAngularSource(r''' |
| 690 @Decorator(selector: '[my-dir]', |
| 691 map: const { |
| 692 'my-dir' : '=>field' |
| 693 }) |
| 694 class MyDirective { |
| 695 set field(value) {} |
| 696 }''')); |
| 697 // prepare node |
| 698 SimpleStringLiteral node = |
| 699 _findMainNode("my-dir'", (n) => n is SimpleStringLiteral); |
| 700 int offset = node.offset; |
| 701 // prepare Element |
| 702 Element element = AngularCompilationUnitBuilder.getElement(node, offset); |
| 703 expect(element, isNotNull); |
| 704 // check AngularPropertyElement |
| 705 AngularPropertyElement property = element as AngularPropertyElement; |
| 706 expect(property.name, "my-dir"); |
| 707 } |
| 708 |
| 709 void test_getElement_directive_selector() { |
| 710 resolveMainSource(_createAngularSource(r''' |
| 711 @Decorator(selector: '[my-dir]') |
| 712 class MyDirective {}''')); |
| 713 SimpleStringLiteral node = |
| 714 _findMainNode("my-dir]'", (n) => n is SimpleStringLiteral); |
| 715 int offset = node.offset; |
| 716 // find AngularSelectorElement |
| 717 Element element = AngularCompilationUnitBuilder.getElement(node, offset); |
| 718 EngineTestCase.assertInstanceOf( |
| 719 (obj) => obj is AngularSelectorElement, |
| 720 AngularSelectorElement, |
| 721 element); |
| 722 } |
| 723 |
| 724 void test_getElement_filter_name() { |
| 725 resolveMainSource(_createAngularSource(r''' |
| 726 @Formatter(name: 'myFilter') |
| 727 class MyFilter { |
| 728 call(p1, p2) {} |
| 729 }''')); |
| 730 SimpleStringLiteral node = |
| 731 _findMainNode("myFilter'", (n) => n is SimpleStringLiteral); |
| 732 int offset = node.offset; |
| 733 // find FilterElement |
| 734 Element element = AngularCompilationUnitBuilder.getElement(node, offset); |
| 735 EngineTestCase.assertInstanceOf( |
| 736 (obj) => obj is AngularFormatterElement, |
| 737 AngularFormatterElement, |
| 738 element); |
| 739 } |
| 740 |
| 741 void test_getElement_noClassDeclaration() { |
| 742 resolveMainSource("var foo = 'bar';"); |
| 743 SimpleStringLiteral node = |
| 744 _findMainNode("bar'", (n) => n is SimpleStringLiteral); |
| 745 Element element = AngularCompilationUnitBuilder.getElement(node, 0); |
| 746 expect(element, isNull); |
| 747 } |
| 748 |
| 749 void test_getElement_noClassElement() { |
| 750 resolveMainSource(r''' |
| 751 class A { |
| 752 const A(p); |
| 753 } |
| 754 |
| 755 @A('bar') |
| 756 class B {}'''); |
| 757 SimpleStringLiteral node = |
| 758 _findMainNode("bar'", (n) => n is SimpleStringLiteral); |
| 759 // reset B element |
| 760 ClassDeclaration classDeclaration = |
| 761 node.getAncestor((node) => node is ClassDeclaration); |
| 762 classDeclaration.name.staticElement = null; |
| 763 // class is not resolved - no element |
| 764 Element element = AngularCompilationUnitBuilder.getElement(node, 0); |
| 765 expect(element, isNull); |
| 766 } |
| 767 |
| 768 void test_getElement_noNode() { |
| 769 Element element = AngularCompilationUnitBuilder.getElement(null, 0); |
| 770 expect(element, isNull); |
| 771 } |
| 772 |
| 773 void test_getElement_notFound() { |
| 774 resolveMainSource(r''' |
| 775 class MyComponent { |
| 776 var str = 'some string'; |
| 777 }'''); |
| 778 // prepare node |
| 779 SimpleStringLiteral node = |
| 780 _findMainNode("some string'", (n) => n is SimpleStringLiteral); |
| 781 int offset = node.offset; |
| 782 // no Element |
| 783 Element element = AngularCompilationUnitBuilder.getElement(node, offset); |
| 784 expect(element, isNull); |
| 785 } |
| 786 |
| 787 void test_getElement_SimpleStringLiteral_withToolkitElement() { |
| 788 SimpleStringLiteral literal = AstFactory.string2("foo"); |
| 789 Element element = new AngularScopePropertyElementImpl("foo", 0, null); |
| 790 literal.toolkitElement = element; |
| 791 expect( |
| 792 AngularCompilationUnitBuilder.getElement(literal, -1), |
| 793 same(element)); |
| 794 } |
| 795 |
569 void test_NgComponent_bad_cannotParseSelector() { | 796 void test_NgComponent_bad_cannotParseSelector() { |
570 contextHelper.addSource("/my_template.html", ""); | 797 contextHelper.addSource("/my_template.html", ""); |
571 contextHelper.addSource("/my_styles.css", ""); | 798 contextHelper.addSource("/my_styles.css", ""); |
572 String mainContent = _createAngularSource(r''' | 799 String mainContent = _createAngularSource(r''' |
573 @Component(publishAs: 'ctrl', selector: '~myComp', | 800 @Component(publishAs: 'ctrl', selector: '~myComp', |
574 templateUrl: 'my_template.html', cssUrl: 'my_styles.css') | 801 templateUrl: 'my_template.html', cssUrl: 'my_styles.css') |
575 class MyComponent { | 802 class MyComponent { |
576 }'''); | 803 }'''); |
577 resolveMainSource(mainContent); | 804 resolveMainSource(mainContent); |
578 // has error | 805 // has error |
(...skipping 13 matching lines...) Expand all Loading... |
592 assertMainErrors([AngularCode.MISSING_SELECTOR]); | 819 assertMainErrors([AngularCode.MISSING_SELECTOR]); |
593 } | 820 } |
594 | 821 |
595 /** | 822 /** |
596 * | 823 * |
597 * https://code.google.com/p/dart/issues/detail?id=16346 | 824 * https://code.google.com/p/dart/issues/detail?id=16346 |
598 */ | 825 */ |
599 void test_NgComponent_bad_notHtmlTemplate() { | 826 void test_NgComponent_bad_notHtmlTemplate() { |
600 contextHelper.addSource("/my_template", ""); | 827 contextHelper.addSource("/my_template", ""); |
601 contextHelper.addSource("/my_styles.css", ""); | 828 contextHelper.addSource("/my_styles.css", ""); |
602 addMainSource( | 829 addMainSource(_createAngularSource(r''' |
603 _createAngularSource(r''' | |
604 @NgComponent(publishAs: 'ctrl', selector: 'myComp', | 830 @NgComponent(publishAs: 'ctrl', selector: 'myComp', |
605 templateUrl: 'my_template', cssUrl: 'my_styles.css') | 831 templateUrl: 'my_template', cssUrl: 'my_styles.css') |
606 class MyComponent { | 832 class MyComponent { |
607 }''')); | 833 }''')); |
608 contextHelper.runTasks(); | 834 contextHelper.runTasks(); |
609 } | 835 } |
610 | 836 |
611 void test_NgComponent_bad_properties_invalidBinding() { | 837 void test_NgComponent_bad_properties_invalidBinding() { |
612 contextHelper.addSource("/my_template.html", ""); | 838 contextHelper.addSource("/my_template.html", ""); |
613 contextHelper.addSource("/my_styles.css", ""); | 839 contextHelper.addSource("/my_styles.css", ""); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
750 @Component('foo', 42) | 976 @Component('foo', 42) |
751 class MyComponent { | 977 class MyComponent { |
752 }'''; | 978 }'''; |
753 resolveMainSource(mainContent); | 979 resolveMainSource(mainContent); |
754 assertNoMainErrors(); | 980 assertNoMainErrors(); |
755 } | 981 } |
756 | 982 |
757 void test_NgComponent_properties_fieldFromSuper() { | 983 void test_NgComponent_properties_fieldFromSuper() { |
758 contextHelper.addSource("/my_template.html", ""); | 984 contextHelper.addSource("/my_template.html", ""); |
759 contextHelper.addSource("/my_styles.css", ""); | 985 contextHelper.addSource("/my_styles.css", ""); |
760 resolveMainSourceNoErrors( | 986 resolveMainSourceNoErrors(_createAngularSource(r''' |
761 _createAngularSource(r''' | |
762 class MySuper { | 987 class MySuper { |
763 var myPropA; | 988 var myPropA; |
764 } | 989 } |
765 | 990 |
766 | 991 |
767 | 992 |
768 @Component(publishAs: 'ctrl', selector: 'myComp', | 993 @Component(publishAs: 'ctrl', selector: 'myComp', |
769 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', | 994 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', |
770 map: const { | 995 map: const { |
771 'prop-a' : '@myPropA' | 996 'prop-a' : '@myPropA' |
(...skipping 13 matching lines...) Expand all Loading... |
785 "prop-a", | 1010 "prop-a", |
786 findMainOffset("prop-a' :"), | 1011 findMainOffset("prop-a' :"), |
787 AngularPropertyKind.ATTR, | 1012 AngularPropertyKind.ATTR, |
788 "myPropA", | 1013 "myPropA", |
789 findMainOffset("myPropA'")); | 1014 findMainOffset("myPropA'")); |
790 } | 1015 } |
791 | 1016 |
792 void test_NgComponent_properties_fromFields() { | 1017 void test_NgComponent_properties_fromFields() { |
793 contextHelper.addSource("/my_template.html", ""); | 1018 contextHelper.addSource("/my_template.html", ""); |
794 contextHelper.addSource("/my_styles.css", ""); | 1019 contextHelper.addSource("/my_styles.css", ""); |
795 resolveMainSourceNoErrors( | 1020 resolveMainSourceNoErrors(_createAngularSource(r''' |
796 _createAngularSource(r''' | |
797 @Component(publishAs: 'ctrl', selector: 'myComp', | 1021 @Component(publishAs: 'ctrl', selector: 'myComp', |
798 templateUrl: 'my_template.html', cssUrl: 'my_styles.css') | 1022 templateUrl: 'my_template.html', cssUrl: 'my_styles.css') |
799 class MyComponent { | 1023 class MyComponent { |
800 @NgAttr('prop-a') | 1024 @NgAttr('prop-a') |
801 var myPropA; | 1025 var myPropA; |
802 @NgCallback('prop-b') | 1026 @NgCallback('prop-b') |
803 var myPropB; | 1027 var myPropB; |
804 @NgOneWay('prop-c') | 1028 @NgOneWay('prop-c') |
805 var myPropC; | 1029 var myPropC; |
806 @NgOneWayOneTime('prop-d') | 1030 @NgOneWayOneTime('prop-d') |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 "prop-e", | 1073 "prop-e", |
850 findMainOffset("prop-e')"), | 1074 findMainOffset("prop-e')"), |
851 AngularPropertyKind.TWO_WAY, | 1075 AngularPropertyKind.TWO_WAY, |
852 "myPropE", | 1076 "myPropE", |
853 -1); | 1077 -1); |
854 } | 1078 } |
855 | 1079 |
856 void test_NgComponent_properties_fromMap() { | 1080 void test_NgComponent_properties_fromMap() { |
857 contextHelper.addSource("/my_template.html", ""); | 1081 contextHelper.addSource("/my_template.html", ""); |
858 contextHelper.addSource("/my_styles.css", ""); | 1082 contextHelper.addSource("/my_styles.css", ""); |
859 resolveMainSourceNoErrors( | 1083 resolveMainSourceNoErrors(_createAngularSource(r''' |
860 _createAngularSource(r''' | |
861 @Component(publishAs: 'ctrl', selector: 'myComp', | 1084 @Component(publishAs: 'ctrl', selector: 'myComp', |
862 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', | 1085 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', |
863 map: const { | 1086 map: const { |
864 'prop-a' : '@myPropA', | 1087 'prop-a' : '@myPropA', |
865 'prop-b' : '&myPropB', | 1088 'prop-b' : '&myPropB', |
866 'prop-c' : '=>myPropC', | 1089 'prop-c' : '=>myPropC', |
867 'prop-d' : '=>!myPropD', | 1090 'prop-d' : '=>!myPropD', |
868 'prop-e' : '<=>myPropE' | 1091 'prop-e' : '<=>myPropE' |
869 }) | 1092 }) |
870 class MyComponent { | 1093 class MyComponent { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
931 // prepare AngularComponentElement | 1154 // prepare AngularComponentElement |
932 ClassElement classElement = mainUnitElement.getType("MyComponent"); | 1155 ClassElement classElement = mainUnitElement.getType("MyComponent"); |
933 AngularComponentElement component = | 1156 AngularComponentElement component = |
934 getAngularElement(classElement, (e) => e is AngularComponentElement); | 1157 getAngularElement(classElement, (e) => e is AngularComponentElement); |
935 expect(component, isNotNull); | 1158 expect(component, isNotNull); |
936 // verify | 1159 // verify |
937 expect(component.name, "ctrl"); | 1160 expect(component.name, "ctrl"); |
938 expect(component.nameOffset, AngularTest.findOffset(mainContent, "ctrl'")); | 1161 expect(component.nameOffset, AngularTest.findOffset(mainContent, "ctrl'")); |
939 _assertIsTagSelector(component.selector, "myComp"); | 1162 _assertIsTagSelector(component.selector, "myComp"); |
940 expect(component.templateUri, "my_template.html"); | 1163 expect(component.templateUri, "my_template.html"); |
941 expect(component.templateUriOffset, AngularTest.findOffset(mainContent, "my_
template.html'")); | 1164 expect( |
| 1165 component.templateUriOffset, |
| 1166 AngularTest.findOffset(mainContent, "my_template.html'")); |
942 expect(component.styleUri, "my_styles.css"); | 1167 expect(component.styleUri, "my_styles.css"); |
943 expect(component.styleUriOffset, AngularTest.findOffset(mainContent, "my_sty
les.css'")); | 1168 expect( |
| 1169 component.styleUriOffset, |
| 1170 AngularTest.findOffset(mainContent, "my_styles.css'")); |
944 expect(component.properties, hasLength(0)); | 1171 expect(component.properties, hasLength(0)); |
945 } | 1172 } |
946 | 1173 |
947 void test_NgComponent_scopeProperties() { | 1174 void test_NgComponent_scopeProperties() { |
948 contextHelper.addSource("/my_template.html", ""); | 1175 contextHelper.addSource("/my_template.html", ""); |
949 contextHelper.addSource("/my_styles.css", ""); | 1176 contextHelper.addSource("/my_styles.css", ""); |
950 String mainContent = _createAngularSource(r''' | 1177 String mainContent = _createAngularSource(r''' |
951 @Component(publishAs: 'ctrl', selector: 'myComp', | 1178 @Component(publishAs: 'ctrl', selector: 'myComp', |
952 templateUrl: 'my_template.html', cssUrl: 'my_styles.css') | 1179 templateUrl: 'my_template.html', cssUrl: 'my_styles.css') |
953 class MyComponent { | 1180 class MyComponent { |
(...skipping 18 matching lines...) Expand all Loading... |
972 getAngularElement(classElement, (e) => e is AngularComponentElement); | 1199 getAngularElement(classElement, (e) => e is AngularComponentElement); |
973 expect(component, isNotNull); | 1200 expect(component, isNotNull); |
974 // verify | 1201 // verify |
975 List<AngularScopePropertyElement> scopeProperties = | 1202 List<AngularScopePropertyElement> scopeProperties = |
976 component.scopeProperties; | 1203 component.scopeProperties; |
977 expect(scopeProperties, hasLength(3)); | 1204 expect(scopeProperties, hasLength(3)); |
978 { | 1205 { |
979 AngularScopePropertyElement property = scopeProperties[0]; | 1206 AngularScopePropertyElement property = scopeProperties[0]; |
980 expect(findMainElement2("boolProp"), same(property)); | 1207 expect(findMainElement2("boolProp"), same(property)); |
981 expect(property.name, "boolProp"); | 1208 expect(property.name, "boolProp"); |
982 expect(property.nameOffset, AngularTest.findOffset(mainContent, "boolProp'
")); | 1209 expect( |
| 1210 property.nameOffset, |
| 1211 AngularTest.findOffset(mainContent, "boolProp'")); |
983 expect(property.type.name, "bool"); | 1212 expect(property.type.name, "bool"); |
984 } | 1213 } |
985 { | 1214 { |
986 AngularScopePropertyElement property = scopeProperties[1]; | 1215 AngularScopePropertyElement property = scopeProperties[1]; |
987 expect(findMainElement2("intProp"), same(property)); | 1216 expect(findMainElement2("intProp"), same(property)); |
988 expect(property.name, "intProp"); | 1217 expect(property.name, "intProp"); |
989 expect(property.nameOffset, AngularTest.findOffset(mainContent, "intProp'"
)); | 1218 expect( |
| 1219 property.nameOffset, |
| 1220 AngularTest.findOffset(mainContent, "intProp'")); |
990 expect(property.type.name, "int"); | 1221 expect(property.type.name, "int"); |
991 } | 1222 } |
992 { | 1223 { |
993 AngularScopePropertyElement property = scopeProperties[2]; | 1224 AngularScopePropertyElement property = scopeProperties[2]; |
994 expect(findMainElement2("stringProp"), same(property)); | 1225 expect(findMainElement2("stringProp"), same(property)); |
995 expect(property.name, "stringProp"); | 1226 expect(property.name, "stringProp"); |
996 expect(property.nameOffset, AngularTest.findOffset(mainContent, "stringPro
p'")); | 1227 expect( |
| 1228 property.nameOffset, |
| 1229 AngularTest.findOffset(mainContent, "stringProp'")); |
997 expect(property.type.name, "String"); | 1230 expect(property.type.name, "String"); |
998 } | 1231 } |
999 } | 1232 } |
1000 | 1233 |
1001 void test_NgController() { | 1234 void test_NgController() { |
1002 String mainContent = _createAngularSource(r''' | 1235 String mainContent = _createAngularSource(r''' |
1003 @Controller(publishAs: 'ctrl', selector: '[myApp]') | 1236 @Controller(publishAs: 'ctrl', selector: '[myApp]') |
1004 class MyController { | 1237 class MyController { |
1005 }'''); | 1238 }'''); |
1006 resolveMainSourceNoErrors(mainContent); | 1239 resolveMainSourceNoErrors(mainContent); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1039 String mainContent = _createAngularSource(r''' | 1272 String mainContent = _createAngularSource(r''' |
1040 @Controller(publishAs: 'ctrl') | 1273 @Controller(publishAs: 'ctrl') |
1041 class MyController { | 1274 class MyController { |
1042 }'''); | 1275 }'''); |
1043 resolveMainSource(mainContent); | 1276 resolveMainSource(mainContent); |
1044 // has error | 1277 // has error |
1045 assertMainErrors([AngularCode.MISSING_SELECTOR]); | 1278 assertMainErrors([AngularCode.MISSING_SELECTOR]); |
1046 } | 1279 } |
1047 | 1280 |
1048 void test_NgController_noAnnotationArguments() { | 1281 void test_NgController_noAnnotationArguments() { |
1049 String mainContent = | 1282 String mainContent = _createAngularSource(r''' |
1050 _createAngularSource(r''' | |
1051 @NgController | 1283 @NgController |
1052 class MyController { | 1284 class MyController { |
1053 }'''); | 1285 }'''); |
1054 resolveMainSource(mainContent); | 1286 resolveMainSource(mainContent); |
1055 } | 1287 } |
1056 | 1288 |
1057 void test_bad_notConstructorAnnotation() { | |
1058 String mainContent = r''' | |
1059 const MY_ANNOTATION = null; | |
1060 @MY_ANNOTATION() | |
1061 class MyFilter { | |
1062 }'''; | |
1063 resolveMainSource(mainContent); | |
1064 // prepare AngularFilterElement | |
1065 ClassElement classElement = mainUnitElement.getType("MyFilter"); | |
1066 AngularFormatterElement filter = | |
1067 getAngularElement(classElement, (e) => e is AngularFormatterElement); | |
1068 expect(filter, isNull); | |
1069 } | |
1070 | |
1071 void test_getElement_SimpleStringLiteral_withToolkitElement() { | |
1072 SimpleStringLiteral literal = AstFactory.string2("foo"); | |
1073 Element element = new AngularScopePropertyElementImpl("foo", 0, null); | |
1074 literal.toolkitElement = element; | |
1075 expect(AngularCompilationUnitBuilder.getElement(literal, -1), same(element))
; | |
1076 } | |
1077 | |
1078 void test_getElement_component_name() { | |
1079 resolveMainSource( | |
1080 _createAngularSource(r''' | |
1081 @Component(publishAs: 'ctrl', selector: 'myComp', | |
1082 templateUrl: 'my_template.html', cssUrl: 'my_styles.css') | |
1083 class MyComponent {}''')); | |
1084 SimpleStringLiteral node = | |
1085 _findMainNode("ctrl'", (n) => n is SimpleStringLiteral); | |
1086 int offset = node.offset; | |
1087 // find AngularComponentElement | |
1088 Element element = AngularCompilationUnitBuilder.getElement(node, offset); | |
1089 EngineTestCase.assertInstanceOf( | |
1090 (obj) => obj is AngularComponentElement, | |
1091 AngularComponentElement, | |
1092 element); | |
1093 } | |
1094 | |
1095 void test_getElement_component_property_fromFieldAnnotation() { | |
1096 resolveMainSource( | |
1097 _createAngularSource(r''' | |
1098 @Component(publishAs: 'ctrl', selector: 'myComp', | |
1099 templateUrl: 'my_template.html', cssUrl: 'my_styles.css') | |
1100 class MyComponent { | |
1101 @NgOneWay('prop') | |
1102 var field; | |
1103 }''')); | |
1104 // prepare node | |
1105 SimpleStringLiteral node = | |
1106 _findMainNode("prop'", (n) => n is SimpleStringLiteral); | |
1107 int offset = node.offset; | |
1108 // prepare Element | |
1109 Element element = AngularCompilationUnitBuilder.getElement(node, offset); | |
1110 expect(element, isNotNull); | |
1111 // check AngularPropertyElement | |
1112 AngularPropertyElement property = element as AngularPropertyElement; | |
1113 expect(property.name, "prop"); | |
1114 } | |
1115 | |
1116 void test_getElement_component_property_fromMap() { | |
1117 resolveMainSource( | |
1118 _createAngularSource(r''' | |
1119 @Component(publishAs: 'ctrl', selector: 'myComp', | |
1120 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', | |
1121 map: const { | |
1122 'prop' : '@field', | |
1123 }) | |
1124 class MyComponent { | |
1125 var field; | |
1126 }''')); | |
1127 // AngularPropertyElement | |
1128 { | |
1129 SimpleStringLiteral node = | |
1130 _findMainNode("prop'", (n) => n is SimpleStringLiteral); | |
1131 int offset = node.offset; | |
1132 // prepare Element | |
1133 Element element = AngularCompilationUnitBuilder.getElement(node, offset); | |
1134 expect(element, isNotNull); | |
1135 // check AngularPropertyElement | |
1136 AngularPropertyElement property = element as AngularPropertyElement; | |
1137 expect(property.name, "prop"); | |
1138 } | |
1139 // FieldElement | |
1140 { | |
1141 SimpleStringLiteral node = | |
1142 _findMainNode("@field'", (n) => n is SimpleStringLiteral); | |
1143 int offset = node.offset; | |
1144 // prepare Element | |
1145 Element element = AngularCompilationUnitBuilder.getElement(node, offset); | |
1146 expect(element, isNotNull); | |
1147 // check FieldElement | |
1148 FieldElement field = element as FieldElement; | |
1149 expect(field.name, "field"); | |
1150 } | |
1151 } | |
1152 | |
1153 void test_getElement_component_selector() { | |
1154 resolveMainSource( | |
1155 _createAngularSource(r''' | |
1156 @Component(publishAs: 'ctrl', selector: 'myComp', | |
1157 templateUrl: 'my_template.html', cssUrl: 'my_styles.css') | |
1158 class MyComponent {}''')); | |
1159 SimpleStringLiteral node = | |
1160 _findMainNode("myComp'", (n) => n is SimpleStringLiteral); | |
1161 int offset = node.offset; | |
1162 // find AngularSelectorElement | |
1163 Element element = AngularCompilationUnitBuilder.getElement(node, offset); | |
1164 EngineTestCase.assertInstanceOf( | |
1165 (obj) => obj is AngularSelectorElement, | |
1166 AngularSelectorElement, | |
1167 element); | |
1168 } | |
1169 | |
1170 void test_getElement_controller_name() { | |
1171 resolveMainSource( | |
1172 _createAngularSource(r''' | |
1173 @Controller(publishAs: 'ctrl', selector: '[myApp]') | |
1174 class MyController { | |
1175 }''')); | |
1176 SimpleStringLiteral node = | |
1177 _findMainNode("ctrl'", (n) => n is SimpleStringLiteral); | |
1178 int offset = node.offset; | |
1179 // find AngularControllerElement | |
1180 Element element = AngularCompilationUnitBuilder.getElement(node, offset); | |
1181 EngineTestCase.assertInstanceOf( | |
1182 (obj) => obj is AngularControllerElement, | |
1183 AngularControllerElement, | |
1184 element); | |
1185 } | |
1186 | |
1187 void test_getElement_directive_property() { | |
1188 resolveMainSource( | |
1189 _createAngularSource(r''' | |
1190 @Decorator(selector: '[my-dir]', | |
1191 map: const { | |
1192 'my-dir' : '=>field' | |
1193 }) | |
1194 class MyDirective { | |
1195 set field(value) {} | |
1196 }''')); | |
1197 // prepare node | |
1198 SimpleStringLiteral node = | |
1199 _findMainNode("my-dir'", (n) => n is SimpleStringLiteral); | |
1200 int offset = node.offset; | |
1201 // prepare Element | |
1202 Element element = AngularCompilationUnitBuilder.getElement(node, offset); | |
1203 expect(element, isNotNull); | |
1204 // check AngularPropertyElement | |
1205 AngularPropertyElement property = element as AngularPropertyElement; | |
1206 expect(property.name, "my-dir"); | |
1207 } | |
1208 | |
1209 void test_getElement_directive_selector() { | |
1210 resolveMainSource( | |
1211 _createAngularSource(r''' | |
1212 @Decorator(selector: '[my-dir]') | |
1213 class MyDirective {}''')); | |
1214 SimpleStringLiteral node = | |
1215 _findMainNode("my-dir]'", (n) => n is SimpleStringLiteral); | |
1216 int offset = node.offset; | |
1217 // find AngularSelectorElement | |
1218 Element element = AngularCompilationUnitBuilder.getElement(node, offset); | |
1219 EngineTestCase.assertInstanceOf( | |
1220 (obj) => obj is AngularSelectorElement, | |
1221 AngularSelectorElement, | |
1222 element); | |
1223 } | |
1224 | |
1225 void test_getElement_filter_name() { | |
1226 resolveMainSource( | |
1227 _createAngularSource(r''' | |
1228 @Formatter(name: 'myFilter') | |
1229 class MyFilter { | |
1230 call(p1, p2) {} | |
1231 }''')); | |
1232 SimpleStringLiteral node = | |
1233 _findMainNode("myFilter'", (n) => n is SimpleStringLiteral); | |
1234 int offset = node.offset; | |
1235 // find FilterElement | |
1236 Element element = AngularCompilationUnitBuilder.getElement(node, offset); | |
1237 EngineTestCase.assertInstanceOf( | |
1238 (obj) => obj is AngularFormatterElement, | |
1239 AngularFormatterElement, | |
1240 element); | |
1241 } | |
1242 | |
1243 void test_getElement_noClassDeclaration() { | |
1244 resolveMainSource("var foo = 'bar';"); | |
1245 SimpleStringLiteral node = | |
1246 _findMainNode("bar'", (n) => n is SimpleStringLiteral); | |
1247 Element element = AngularCompilationUnitBuilder.getElement(node, 0); | |
1248 expect(element, isNull); | |
1249 } | |
1250 | |
1251 void test_getElement_noClassElement() { | |
1252 resolveMainSource(r''' | |
1253 class A { | |
1254 const A(p); | |
1255 } | |
1256 | |
1257 @A('bar') | |
1258 class B {}'''); | |
1259 SimpleStringLiteral node = | |
1260 _findMainNode("bar'", (n) => n is SimpleStringLiteral); | |
1261 // reset B element | |
1262 ClassDeclaration classDeclaration = | |
1263 node.getAncestor((node) => node is ClassDeclaration); | |
1264 classDeclaration.name.staticElement = null; | |
1265 // class is not resolved - no element | |
1266 Element element = AngularCompilationUnitBuilder.getElement(node, 0); | |
1267 expect(element, isNull); | |
1268 } | |
1269 | |
1270 void test_getElement_noNode() { | |
1271 Element element = AngularCompilationUnitBuilder.getElement(null, 0); | |
1272 expect(element, isNull); | |
1273 } | |
1274 | |
1275 void test_getElement_notFound() { | |
1276 resolveMainSource(r''' | |
1277 class MyComponent { | |
1278 var str = 'some string'; | |
1279 }'''); | |
1280 // prepare node | |
1281 SimpleStringLiteral node = | |
1282 _findMainNode("some string'", (n) => n is SimpleStringLiteral); | |
1283 int offset = node.offset; | |
1284 // no Element | |
1285 Element element = AngularCompilationUnitBuilder.getElement(node, offset); | |
1286 expect(element, isNull); | |
1287 } | |
1288 | |
1289 void test_parseSelector_hasAttribute() { | 1289 void test_parseSelector_hasAttribute() { |
1290 AngularSelectorElement selector = | 1290 AngularSelectorElement selector = |
1291 AngularCompilationUnitBuilder.parseSelector(42, "[name]"); | 1291 AngularCompilationUnitBuilder.parseSelector(42, "[name]"); |
1292 _assertHasAttributeSelector(selector, "name"); | 1292 _assertHasAttributeSelector(selector, "name"); |
1293 expect(selector.nameOffset, 42 + 1); | 1293 expect(selector.nameOffset, 42 + 1); |
1294 } | 1294 } |
1295 | 1295 |
1296 void test_parseSelector_hasClass() { | 1296 void test_parseSelector_hasClass() { |
1297 AngularSelectorElement selector = | 1297 AngularSelectorElement selector = |
1298 AngularCompilationUnitBuilder.parseSelector(42, ".my-class"); | 1298 AngularCompilationUnitBuilder.parseSelector(42, ".my-class"); |
(...skipping 26 matching lines...) Expand all Loading... |
1325 void test_parseSelector_isTag_hasAttribute() { | 1325 void test_parseSelector_isTag_hasAttribute() { |
1326 AngularSelectorElement selector = | 1326 AngularSelectorElement selector = |
1327 AngularCompilationUnitBuilder.parseSelector(42, "tag[attr]"); | 1327 AngularCompilationUnitBuilder.parseSelector(42, "tag[attr]"); |
1328 EngineTestCase.assertInstanceOf( | 1328 EngineTestCase.assertInstanceOf( |
1329 (obj) => obj is IsTagHasAttributeSelectorElementImpl, | 1329 (obj) => obj is IsTagHasAttributeSelectorElementImpl, |
1330 IsTagHasAttributeSelectorElementImpl, | 1330 IsTagHasAttributeSelectorElementImpl, |
1331 selector); | 1331 selector); |
1332 expect(selector.name, "tag[attr]"); | 1332 expect(selector.name, "tag[attr]"); |
1333 expect(selector.nameOffset, -1); | 1333 expect(selector.nameOffset, -1); |
1334 expect((selector as IsTagHasAttributeSelectorElementImpl).tagName, "tag"); | 1334 expect((selector as IsTagHasAttributeSelectorElementImpl).tagName, "tag"); |
1335 expect((selector as IsTagHasAttributeSelectorElementImpl).attributeName, "at
tr"); | 1335 expect( |
| 1336 (selector as IsTagHasAttributeSelectorElementImpl).attributeName, |
| 1337 "attr"); |
1336 } | 1338 } |
1337 | 1339 |
1338 void test_parseSelector_unknown() { | 1340 void test_parseSelector_unknown() { |
1339 AngularSelectorElement selector = | 1341 AngularSelectorElement selector = |
1340 AngularCompilationUnitBuilder.parseSelector(0, "~unknown"); | 1342 AngularCompilationUnitBuilder.parseSelector(0, "~unknown"); |
1341 expect(selector, isNull); | 1343 expect(selector, isNull); |
1342 } | 1344 } |
1343 | 1345 |
1344 void test_view() { | 1346 void test_view() { |
1345 contextHelper.addSource("/wrong.html", ""); | 1347 contextHelper.addSource("/wrong.html", ""); |
(...skipping 13 matching lines...) Expand all Loading... |
1359 }'''); | 1361 }'''); |
1360 resolveMainSourceNoErrors(mainContent); | 1362 resolveMainSourceNoErrors(mainContent); |
1361 // prepare AngularViewElement(s) | 1363 // prepare AngularViewElement(s) |
1362 List<AngularViewElement> views = mainUnitElement.angularViews; | 1364 List<AngularViewElement> views = mainUnitElement.angularViews; |
1363 expect(views, hasLength(2)); | 1365 expect(views, hasLength(2)); |
1364 { | 1366 { |
1365 AngularViewElement view = views[0]; | 1367 AngularViewElement view = views[0]; |
1366 expect(view.templateUri, "my_templateA.html"); | 1368 expect(view.templateUri, "my_templateA.html"); |
1367 expect(view.name, null); | 1369 expect(view.name, null); |
1368 expect(view.nameOffset, -1); | 1370 expect(view.nameOffset, -1); |
1369 expect(view.templateUriOffset, AngularTest.findOffset(mainContent, "my_tem
plateA.html'")); | 1371 expect( |
| 1372 view.templateUriOffset, |
| 1373 AngularTest.findOffset(mainContent, "my_templateA.html'")); |
1370 } | 1374 } |
1371 { | 1375 { |
1372 AngularViewElement view = views[1]; | 1376 AngularViewElement view = views[1]; |
1373 expect(view.templateUri, "my_templateB.html"); | 1377 expect(view.templateUri, "my_templateB.html"); |
1374 expect(view.name, null); | 1378 expect(view.name, null); |
1375 expect(view.nameOffset, -1); | 1379 expect(view.nameOffset, -1); |
1376 expect(view.templateUriOffset, AngularTest.findOffset(mainContent, "my_tem
plateB.html'")); | 1380 expect( |
| 1381 view.templateUriOffset, |
| 1382 AngularTest.findOffset(mainContent, "my_templateB.html'")); |
1377 } | 1383 } |
1378 } | 1384 } |
1379 | 1385 |
1380 void _assertProperty(AngularPropertyElement property, String expectedName, | 1386 void _assertProperty(AngularPropertyElement property, String expectedName, |
1381 int expectedNameOffset, AngularPropertyKind expectedKind, | 1387 int expectedNameOffset, AngularPropertyKind expectedKind, |
1382 String expectedFieldName, int expectedFieldOffset) { | 1388 String expectedFieldName, int expectedFieldOffset) { |
1383 expect(property.name, expectedName); | 1389 expect(property.name, expectedName); |
1384 expect(property.nameOffset, expectedNameOffset); | 1390 expect(property.nameOffset, expectedNameOffset); |
1385 expect(property.propertyKind, same(expectedKind)); | 1391 expect(property.propertyKind, same(expectedKind)); |
1386 expect(property.field.name, expectedFieldName); | 1392 expect(property.field.name, expectedFieldName); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1433 expect((selector as AngularTagSelectorElementImpl).name, name); | 1439 expect((selector as AngularTagSelectorElementImpl).name, name); |
1434 } | 1440 } |
1435 | 1441 |
1436 static String _createAngularSource(String code) { | 1442 static String _createAngularSource(String code) { |
1437 return "import 'angular.dart';\n" + code; | 1443 return "import 'angular.dart';\n" + code; |
1438 } | 1444 } |
1439 } | 1445 } |
1440 | 1446 |
1441 | 1447 |
1442 class AngularHtmlUnitResolverTest extends AngularTest { | 1448 class AngularHtmlUnitResolverTest extends AngularTest { |
1443 void test_NgComponent_resolveTemplateFile() { | 1449 void fail_analysisContext_changeDart_invalidateApplication() { |
1444 addMainSource(r''' | 1450 addMainSource(r''' |
| 1451 |
1445 import 'angular.dart'; | 1452 import 'angular.dart'; |
1446 | 1453 |
1447 @Component( | 1454 @Component( |
1448 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', | 1455 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', |
1449 publishAs: 'ctrl', | 1456 publishAs: 'ctrl', |
1450 selector: 'myComponent') | 1457 selector: 'myComponent') |
1451 class MyComponent { | 1458 class MyComponent { |
1452 String field; | |
1453 }'''); | 1459 }'''); |
1454 contextHelper.addSource( | 1460 contextHelper.addSource( |
1455 "/entry-point.html", | 1461 "/entry-point.html", |
1456 AngularTest.createHtmlWithAngular('')); | 1462 AngularTest.createHtmlWithAngular('')); |
1457 addIndexSource2( | 1463 addIndexSource2("/my_template.html", r''' |
1458 "/my_template.html", | |
1459 r''' | |
1460 <div> | 1464 <div> |
1461 {{ctrl.field}} | 1465 {{ctrl.noMethod()}} |
1462 </div>'''); | 1466 </div>'''); |
1463 contextHelper.addSource("/my_styles.css", ""); | 1467 contextHelper.addSource("/my_styles.css", ""); |
1464 contextHelper.runTasks(); | 1468 contextHelper.runTasks(); |
1465 resolveIndex(); | 1469 // there are some errors in my_template.html |
1466 assertNoErrors(); | 1470 { |
1467 assertResolvedIdentifier2("ctrl.", "MyComponent"); | 1471 List<AnalysisError> errors = context.getErrors(indexSource).errors; |
1468 assertResolvedIdentifier2("field}}", "String"); | 1472 expect(errors.length != 0, isTrue); |
1469 } | 1473 } |
1470 | 1474 // change main.dart, there are no MyComponent anymore |
1471 void test_NgComponent_updateDartFile() { | 1475 context.setContents(mainSource, ""); |
1472 Source componentSource = contextHelper.addSource( | 1476 // ...errors in my_template.html should be removed |
1473 "/my_component.dart", | 1477 { |
1474 r''' | 1478 List<AnalysisError> errors = context.getErrors(indexSource).errors; |
1475 library my.component; | 1479 expect(errors, isEmpty); |
| 1480 expect(errors.length == 0, isTrue); |
| 1481 } |
| 1482 } |
| 1483 |
| 1484 void fail_ngRepeat_additionalVariables() { |
| 1485 addMyController(); |
| 1486 _resolveIndexNoErrors(AngularTest.createHtmlWithMyController(r''' |
| 1487 <li ng-repeat='name in ctrl.names'> |
| 1488 {{$index}} {{$first}} {{$middle}} {{$last}} {{$even}} {{$odd}} |
| 1489 </li>''')); |
| 1490 assertResolvedIdentifier2("\$index", "int"); |
| 1491 assertResolvedIdentifier2("\$first", "bool"); |
| 1492 assertResolvedIdentifier2("\$middle", "bool"); |
| 1493 assertResolvedIdentifier2("\$last", "bool"); |
| 1494 assertResolvedIdentifier2("\$even", "bool"); |
| 1495 assertResolvedIdentifier2("\$odd", "bool"); |
| 1496 } |
| 1497 |
| 1498 void fail_ngRepeat_bad_expectedIdentifier() { |
| 1499 addMyController(); |
| 1500 resolveIndex2(AngularTest.createHtmlWithMyController(r''' |
| 1501 <li ng-repeat='name + 42 in ctrl.names'> |
| 1502 </li>''')); |
| 1503 assertErrors(indexSource, [AngularCode.INVALID_REPEAT_ITEM_SYNTAX]); |
| 1504 } |
| 1505 |
| 1506 void fail_ngRepeat_bad_expectedIn() { |
| 1507 addMyController(); |
| 1508 resolveIndex2(AngularTest.createHtmlWithMyController(r''' |
| 1509 <li ng-repeat='name : ctrl.names'> |
| 1510 </li>''')); |
| 1511 assertErrors(indexSource, [AngularCode.INVALID_REPEAT_SYNTAX]); |
| 1512 } |
| 1513 |
| 1514 void fail_ngRepeat_filters_filter_literal() { |
| 1515 addMyController(); |
| 1516 _resolveIndexNoErrors(AngularTest.createHtmlWithMyController(r''' |
| 1517 <li ng-repeat='item in ctrl.items | filter:42:null'/> |
| 1518 </li>''')); |
| 1519 // filter "filter" is resolved |
| 1520 Element filterElement = assertResolvedIdentifier("filter"); |
| 1521 EngineTestCase.assertInstanceOf( |
| 1522 (obj) => obj is AngularFormatterElement, |
| 1523 AngularFormatterElement, |
| 1524 filterElement); |
| 1525 } |
| 1526 |
| 1527 void fail_ngRepeat_filters_filter_propertyMap() { |
| 1528 addMyController(); |
| 1529 _resolveIndexNoErrors(AngularTest.createHtmlWithMyController(r''' |
| 1530 <li ng-repeat='item in ctrl.items | filter:{name:null, done:false}'/> |
| 1531 </li>''')); |
| 1532 assertResolvedIdentifier2("name:", "String"); |
| 1533 assertResolvedIdentifier2("done:", "bool"); |
| 1534 } |
| 1535 |
| 1536 void fail_ngRepeat_filters_missingColon() { |
| 1537 addMyController(); |
| 1538 resolveIndex2(AngularTest.createHtmlWithMyController(r''' |
| 1539 <li ng-repeat="item in ctrl.items | orderBy:'' true"/> |
| 1540 </li>''')); |
| 1541 assertErrors(indexSource, [AngularCode.MISSING_FORMATTER_COLON]); |
| 1542 } |
| 1543 |
| 1544 void fail_ngRepeat_filters_noArgs() { |
| 1545 addMyController(); |
| 1546 _resolveIndexNoErrors(AngularTest.createHtmlWithMyController(r''' |
| 1547 <li ng-repeat="item in ctrl.items | orderBy"/> |
| 1548 </li>''')); |
| 1549 // filter "orderBy" is resolved |
| 1550 Element filterElement = assertResolvedIdentifier("orderBy"); |
| 1551 EngineTestCase.assertInstanceOf( |
| 1552 (obj) => obj is AngularFormatterElement, |
| 1553 AngularFormatterElement, |
| 1554 filterElement); |
| 1555 } |
| 1556 |
| 1557 void fail_ngRepeat_filters_orderBy_emptyString() { |
| 1558 addMyController(); |
| 1559 _resolveIndexNoErrors(AngularTest.createHtmlWithMyController(r''' |
| 1560 <li ng-repeat="item in ctrl.items | orderBy:'':true"/> |
| 1561 </li>''')); |
| 1562 // filter "orderBy" is resolved |
| 1563 Element filterElement = assertResolvedIdentifier("orderBy"); |
| 1564 EngineTestCase.assertInstanceOf( |
| 1565 (obj) => obj is AngularFormatterElement, |
| 1566 AngularFormatterElement, |
| 1567 filterElement); |
| 1568 } |
| 1569 |
| 1570 void fail_ngRepeat_filters_orderBy_propertyList() { |
| 1571 addMyController(); |
| 1572 _resolveIndexNoErrors(AngularTest.createHtmlWithMyController(r''' |
| 1573 <li ng-repeat="item in ctrl.items | orderBy:['name', 'done']"/> |
| 1574 </li>''')); |
| 1575 assertResolvedIdentifier2("name'", "String"); |
| 1576 assertResolvedIdentifier2("done'", "bool"); |
| 1577 } |
| 1578 |
| 1579 void fail_ngRepeat_filters_orderBy_propertyName() { |
| 1580 addMyController(); |
| 1581 _resolveIndexNoErrors(AngularTest.createHtmlWithMyController(r''' |
| 1582 <li ng-repeat="item in ctrl.items | orderBy:'name'"/> |
| 1583 </li>''')); |
| 1584 assertResolvedIdentifier2("name'", "String"); |
| 1585 } |
| 1586 |
| 1587 void fail_ngRepeat_filters_orderBy_propertyName_minus() { |
| 1588 addMyController(); |
| 1589 _resolveIndexNoErrors(AngularTest.createHtmlWithMyController(r''' |
| 1590 <li ng-repeat="item in ctrl.items | orderBy:'-name'"/> |
| 1591 </li>''')); |
| 1592 assertResolvedIdentifier2("name'", "String"); |
| 1593 } |
| 1594 |
| 1595 void fail_ngRepeat_filters_orderBy_propertyName_plus() { |
| 1596 addMyController(); |
| 1597 _resolveIndexNoErrors(AngularTest.createHtmlWithMyController(r''' |
| 1598 <li ng-repeat="item in ctrl.items | orderBy:'+name'"/> |
| 1599 </li>''')); |
| 1600 assertResolvedIdentifier2("name'", "String"); |
| 1601 } |
| 1602 |
| 1603 void fail_ngRepeat_filters_orderBy_propertyName_untypedItems() { |
| 1604 addMyController(); |
| 1605 _resolveIndexNoErrors(AngularTest.createHtmlWithMyController(r''' |
| 1606 <li ng-repeat="item in ctrl.untypedItems | orderBy:'name'"/> |
| 1607 </li>''')); |
| 1608 assertResolvedIdentifier2("name'", "dynamic"); |
| 1609 } |
| 1610 |
| 1611 void fail_ngRepeat_filters_two() { |
| 1612 addMyController(); |
| 1613 _resolveIndexNoErrors(AngularTest.createHtmlWithMyController(r''' |
| 1614 <li ng-repeat="item in ctrl.items | orderBy:'+' | orderBy:'-'"/> |
| 1615 </li>''')); |
| 1616 EngineTestCase.assertInstanceOf( |
| 1617 (obj) => obj is AngularFormatterElement, |
| 1618 AngularFormatterElement, |
| 1619 assertResolvedIdentifier("orderBy:'+'")); |
| 1620 EngineTestCase.assertInstanceOf( |
| 1621 (obj) => obj is AngularFormatterElement, |
| 1622 AngularFormatterElement, |
| 1623 assertResolvedIdentifier("orderBy:'-'")); |
| 1624 } |
| 1625 |
| 1626 void fail_ngRepeat_resolvedExpressions() { |
| 1627 addMyController(); |
| 1628 _resolveIndexNoErrors(AngularTest.createHtmlWithMyController(r''' |
| 1629 <li ng-repeat='name in ctrl.names'> |
| 1630 {{name}} |
| 1631 </li>''')); |
| 1632 assertResolvedIdentifier2("name in", "String"); |
| 1633 assertResolvedIdentifier2("ctrl.", "MyController"); |
| 1634 assertResolvedIdentifier2("names'", "List<String>"); |
| 1635 assertResolvedIdentifier2("name}}", "String"); |
| 1636 } |
| 1637 |
| 1638 void fail_ngRepeat_trackBy() { |
| 1639 addMyController(); |
| 1640 _resolveIndexNoErrors(AngularTest.createHtmlWithMyController(r''' |
| 1641 <li ng-repeat='name in ctrl.names track by name.length'/> |
| 1642 </li>''')); |
| 1643 assertResolvedIdentifier2("length'", "int"); |
| 1644 } |
| 1645 |
| 1646 void test_analysisContext_changeEntryPoint_clearAngularErrors_inDart() { |
| 1647 addMainSource(r''' |
| 1648 |
1476 import 'angular.dart'; | 1649 import 'angular.dart'; |
1477 @Component(selector: 'myComponent') | 1650 |
| 1651 @Component( |
| 1652 templateUrl: 'no-such-template.html', cssUrl: 'my_styles.css', |
| 1653 publishAs: 'ctrl', |
| 1654 selector: 'myComponent') |
1478 class MyComponent { | 1655 class MyComponent { |
1479 }'''); | 1656 }'''); |
1480 contextHelper.addSource( | 1657 Source entrySource = contextHelper.addSource( |
1481 "/my_module.dart", | 1658 "/entry-point.html", |
1482 r''' | 1659 AngularTest.createHtmlWithAngular('')); |
1483 library my.module; | 1660 contextHelper.addSource("/my_styles.css", ""); |
1484 import 'my_component.dart';'''); | 1661 contextHelper.runTasks(); |
| 1662 // there are some errors in MyComponent |
| 1663 { |
| 1664 List<AnalysisError> errors = context.getErrors(mainSource).errors; |
| 1665 expect(errors.length != 0, isTrue); |
| 1666 } |
| 1667 // make entry-point.html non-Angular |
| 1668 context.setContents(entrySource, "<html/>"); |
| 1669 // ...errors in MyComponent should be removed |
| 1670 { |
| 1671 List<AnalysisError> errors = context.getErrors(mainSource).errors; |
| 1672 expect(errors.length == 0, isTrue); |
| 1673 } |
| 1674 } |
| 1675 |
| 1676 void test_analysisContext_changeEntryPoint_clearAngularErrors_inTemplate() { |
1485 addMainSource(r''' | 1677 addMainSource(r''' |
1486 library main; | |
1487 import 'my_module.dart';'''); | |
1488 _resolveIndexNoErrors( | |
1489 AngularTest.createHtmlWithMyController("<myComponent/>")); | |
1490 // "myComponent" tag was resolved | |
1491 { | |
1492 ht.XmlTagNode tagNode = | |
1493 ht.HtmlUnitUtils.getTagNode(indexUnit, findOffset2("myComponent")); | |
1494 AngularSelectorElement tagElement = | |
1495 tagNode.element as AngularSelectorElement; | |
1496 expect(tagElement, isNotNull); | |
1497 expect(tagElement.name, "myComponent"); | |
1498 } | |
1499 // replace "myComponent" with "myComponent2" | |
1500 // in my_component.dart and index.html | |
1501 { | |
1502 context.setContents( | |
1503 componentSource, | |
1504 _getSourceContent(componentSource).replaceAll("myComponent", "myCompon
ent2")); | |
1505 indexContent = | |
1506 _getSourceContent(indexSource).replaceAll("myComponent", "myComponent2
"); | |
1507 context.setContents(indexSource, indexContent); | |
1508 } | |
1509 contextHelper.runTasks(); | |
1510 resolveIndex(); | |
1511 // "myComponent2" tag should be resolved | |
1512 { | |
1513 ht.XmlTagNode tagNode = | |
1514 ht.HtmlUnitUtils.getTagNode(indexUnit, findOffset2("myComponent2")); | |
1515 AngularSelectorElement tagElement = | |
1516 tagNode.element as AngularSelectorElement; | |
1517 expect(tagElement, isNotNull); | |
1518 expect(tagElement.name, "myComponent2"); | |
1519 } | |
1520 } | |
1521 | |
1522 void test_NgComponent_use_resolveAttributes() { | |
1523 contextHelper.addSource( | |
1524 "/my_template.html", | |
1525 r''' | |
1526 <div> | |
1527 {{ctrl.field}} | |
1528 </div>'''); | |
1529 addMainSource(r''' | |
1530 | 1678 |
1531 import 'angular.dart'; | 1679 import 'angular.dart'; |
1532 | |
1533 @Component( | |
1534 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', | |
1535 publishAs: 'ctrl', | |
1536 selector: 'myComponent', // selector | |
1537 map: const {'attrA' : '=>setA', 'attrB' : '@setB'}) | |
1538 class MyComponent { | |
1539 set setA(value) {} | |
1540 set setB(value) {} | |
1541 }'''); | |
1542 _resolveIndexNoErrors( | |
1543 AngularTest.createHtmlWithMyController(r''' | |
1544 <input type='text' ng-model='someModel'/> | |
1545 <myComponent attrA='someModel' attrB='bbb'/>''')); | |
1546 // "attrA" attribute expression was resolved | |
1547 expect(findIdentifier("someModel"), isNotNull); | |
1548 // "myComponent" tag was resolved | |
1549 ht.XmlTagNode tagNode = | |
1550 ht.HtmlUnitUtils.getTagNode(indexUnit, findOffset2("myComponent")); | |
1551 AngularSelectorElement tagElement = | |
1552 tagNode.element as AngularSelectorElement; | |
1553 expect(tagElement, isNotNull); | |
1554 expect(tagElement.name, "myComponent"); | |
1555 expect(tagElement.nameOffset, findMainOffset("myComponent', // selector")); | |
1556 // "attrA" attribute was resolved | |
1557 { | |
1558 ht.XmlAttributeNode node = | |
1559 ht.HtmlUnitUtils.getAttributeNode(indexUnit, findOffset2("attrA='")); | |
1560 AngularPropertyElement element = node.element as AngularPropertyElement; | |
1561 expect(element, isNotNull); | |
1562 expect(element.name, "attrA"); | |
1563 expect(element.field.name, "setA"); | |
1564 } | |
1565 // "attrB" attribute was resolved, even if it @binding | |
1566 { | |
1567 ht.XmlAttributeNode node = | |
1568 ht.HtmlUnitUtils.getAttributeNode(indexUnit, findOffset2("attrB='")); | |
1569 AngularPropertyElement element = node.element as AngularPropertyElement; | |
1570 expect(element, isNotNull); | |
1571 expect(element.name, "attrB"); | |
1572 expect(element.field.name, "setB"); | |
1573 } | |
1574 } | |
1575 | |
1576 void test_NgDirective_noAttribute() { | |
1577 addMainSource(r''' | |
1578 | |
1579 import 'angular.dart'; | |
1580 | |
1581 @NgDirective(selector: '[my-directive]', map: const {'foo': '=>input'}) | |
1582 class MyDirective { | |
1583 set input(value) {} | |
1584 }'''); | |
1585 _resolveIndexNoErrors( | |
1586 AngularTest.createHtmlWithMyController(r''' | |
1587 <div my-directive> | |
1588 </div>''')); | |
1589 } | |
1590 | |
1591 void test_NgDirective_noExpression() { | |
1592 addMainSource(r''' | |
1593 | |
1594 import 'angular.dart'; | |
1595 | |
1596 @NgDirective(selector: '[my-directive]', map: const {'.': '=>input'}) | |
1597 class MyDirective { | |
1598 set input(value) {} | |
1599 }'''); | |
1600 _resolveIndexNoErrors( | |
1601 AngularTest.createHtmlWithMyController(r''' | |
1602 <div my-directive> | |
1603 </div>''')); | |
1604 } | |
1605 | |
1606 void test_NgDirective_resolvedExpression() { | |
1607 addMainSource(r''' | |
1608 | |
1609 import 'angular.dart'; | |
1610 | |
1611 @Decorator(selector: '[my-directive]') | |
1612 class MyDirective { | |
1613 @NgOneWay('my-property') | |
1614 String condition; | |
1615 }'''); | |
1616 _resolveIndexNoErrors( | |
1617 AngularTest.createHtmlWithMyController(r''' | |
1618 <input type='text' ng-model='name'> | |
1619 <div my-directive my-property='name != null'> | |
1620 </div>''')); | |
1621 resolveMainNoErrors(); | |
1622 // "my-directive" attribute was resolved | |
1623 { | |
1624 AngularSelectorElement selector = | |
1625 findMainElement(ElementKind.ANGULAR_SELECTOR, "my-directive"); | |
1626 ht.XmlAttributeNode attrNodeSelector = | |
1627 ht.HtmlUnitUtils.getAttributeNode(indexUnit, findOffset2("my-directive
")); | |
1628 expect(attrNodeSelector, isNotNull); | |
1629 expect(attrNodeSelector.element, same(selector)); | |
1630 } | |
1631 // "my-property" attribute was resolved | |
1632 { | |
1633 ht.XmlAttributeNode attrNodeProperty = | |
1634 ht.HtmlUnitUtils.getAttributeNode(indexUnit, findOffset2("my-property=
'")); | |
1635 AngularPropertyElement propertyElement = | |
1636 attrNodeProperty.element as AngularPropertyElement; | |
1637 expect(propertyElement, isNotNull); | |
1638 expect(propertyElement.propertyKind, same(AngularPropertyKind.ONE_WAY)); | |
1639 expect(propertyElement.field.name, "condition"); | |
1640 } | |
1641 // "name" expression was resolved | |
1642 expect(findIdentifier("name != null"), isNotNull); | |
1643 } | |
1644 | |
1645 void test_NgDirective_resolvedExpression_attrString() { | |
1646 addMainSource(r''' | |
1647 | |
1648 import 'angular.dart'; | |
1649 | |
1650 @NgDirective(selector: '[my-directive]) | |
1651 class MyDirective { | |
1652 @NgAttr('my-property') | |
1653 String property; | |
1654 }'''); | |
1655 _resolveIndexNoErrors( | |
1656 AngularTest.createHtmlWithMyController(r''' | |
1657 <input type='text' ng-model='name'> | |
1658 <div my-directive my-property='name != null'> | |
1659 </div>''')); | |
1660 resolveMain(); | |
1661 // @NgAttr means "string attribute", which we don't parse | |
1662 expect(findIdentifierMaybe("name != null"), isNull); | |
1663 } | |
1664 | |
1665 void test_NgDirective_resolvedExpression_dotAsName() { | |
1666 addMainSource(r''' | |
1667 | |
1668 import 'angular.dart'; | |
1669 | |
1670 @Decorator( | |
1671 selector: '[my-directive]', | |
1672 map: const {'.' : '=>condition'}) | |
1673 class MyDirective { | |
1674 set condition(value) {} | |
1675 }'''); | |
1676 _resolveIndexNoErrors( | |
1677 AngularTest.createHtmlWithMyController(r''' | |
1678 <input type='text' ng-model='name'> | |
1679 <div my-directive='name != null'> | |
1680 </div>''')); | |
1681 // "name" attribute was resolved | |
1682 expect(findIdentifier("name != null"), isNotNull); | |
1683 } | |
1684 | |
1685 void fail_analysisContext_changeDart_invalidateApplication() { | |
1686 addMainSource(r''' | |
1687 | |
1688 import 'angular.dart'; | |
1689 | 1680 |
1690 @Component( | 1681 @Component( |
1691 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', | 1682 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', |
1692 publishAs: 'ctrl', | 1683 publishAs: 'ctrl', |
1693 selector: 'myComponent') | 1684 selector: 'myComponent') |
1694 class MyComponent { | 1685 class MyComponent { |
1695 }'''); | 1686 }'''); |
1696 contextHelper.addSource( | 1687 Source entrySource = contextHelper.addSource( |
1697 "/entry-point.html", | 1688 "/entry-point.html", |
1698 AngularTest.createHtmlWithAngular('')); | 1689 AngularTest.createHtmlWithAngular('')); |
1699 addIndexSource2( | 1690 addIndexSource2("/my_template.html", r''' |
1700 "/my_template.html", | |
1701 r''' | |
1702 <div> | 1691 <div> |
1703 {{ctrl.noMethod()}} | 1692 {{ctrl.noMethod()}} |
1704 </div>'''); | 1693 </div>'''); |
1705 contextHelper.addSource("/my_styles.css", ""); | 1694 contextHelper.addSource("/my_styles.css", ""); |
1706 contextHelper.runTasks(); | 1695 contextHelper.runTasks(); |
1707 // there are some errors in my_template.html | 1696 // there are some errors in my_template.html |
1708 { | 1697 { |
1709 List<AnalysisError> errors = context.getErrors(indexSource).errors; | 1698 List<AnalysisError> errors = context.getErrors(indexSource).errors; |
1710 expect(errors.length != 0, isTrue); | 1699 expect(errors.length != 0, isTrue); |
1711 } | 1700 } |
1712 // change main.dart, there are no MyComponent anymore | 1701 // make entry-point.html non-Angular |
1713 context.setContents(mainSource, ""); | 1702 context.setContents(entrySource, "<html/>"); |
1714 // ...errors in my_template.html should be removed | 1703 // ...errors in my_template.html should be removed |
1715 { | 1704 { |
1716 List<AnalysisError> errors = context.getErrors(indexSource).errors; | 1705 List<AnalysisError> errors = context.getErrors(indexSource).errors; |
1717 expect(errors, isEmpty); | |
1718 expect(errors.length == 0, isTrue); | 1706 expect(errors.length == 0, isTrue); |
1719 } | 1707 } |
1720 } | 1708 } |
1721 | 1709 |
1722 void test_analysisContext_changeEntryPoint_clearAngularErrors_inDart() { | 1710 void test_analysisContext_removeEntryPoint_clearAngularErrors_inDart() { |
1723 addMainSource(r''' | 1711 addMainSource(r''' |
1724 | 1712 |
1725 import 'angular.dart'; | 1713 import 'angular.dart'; |
1726 | 1714 |
1727 @Component( | 1715 @Component( |
1728 templateUrl: 'no-such-template.html', cssUrl: 'my_styles.css', | 1716 templateUrl: 'no-such-template.html', cssUrl: 'my_styles.css', |
1729 publishAs: 'ctrl', | 1717 publishAs: 'ctrl', |
1730 selector: 'myComponent') | 1718 selector: 'myComponent') |
1731 class MyComponent { | 1719 class MyComponent { |
1732 }'''); | 1720 }'''); |
1733 Source entrySource = contextHelper.addSource( | 1721 Source entrySource = contextHelper.addSource( |
1734 "/entry-point.html", | 1722 "/entry-point.html", |
1735 AngularTest.createHtmlWithAngular('')); | 1723 AngularTest.createHtmlWithAngular('')); |
1736 contextHelper.addSource("/my_styles.css", ""); | 1724 contextHelper.addSource("/my_styles.css", ""); |
1737 contextHelper.runTasks(); | 1725 contextHelper.runTasks(); |
1738 // there are some errors in MyComponent | 1726 // there are some errors in MyComponent |
1739 { | 1727 { |
1740 List<AnalysisError> errors = context.getErrors(mainSource).errors; | 1728 List<AnalysisError> errors = context.getErrors(mainSource).errors; |
1741 expect(errors.length != 0, isTrue); | 1729 expect(errors.length != 0, isTrue); |
1742 } | 1730 } |
1743 // make entry-point.html non-Angular | 1731 // remove entry-point.html |
1744 context.setContents(entrySource, "<html/>"); | 1732 { |
| 1733 ChangeSet changeSet = new ChangeSet(); |
| 1734 changeSet.removedSource(entrySource); |
| 1735 context.applyChanges(changeSet); |
| 1736 } |
1745 // ...errors in MyComponent should be removed | 1737 // ...errors in MyComponent should be removed |
1746 { | 1738 { |
1747 List<AnalysisError> errors = context.getErrors(mainSource).errors; | 1739 List<AnalysisError> errors = context.getErrors(mainSource).errors; |
1748 expect(errors.length == 0, isTrue); | 1740 expect(errors.length == 0, isTrue); |
1749 } | 1741 } |
1750 } | 1742 } |
1751 | 1743 |
1752 void test_analysisContext_changeEntryPoint_clearAngularErrors_inTemplate() { | 1744 void test_contextProperties() { |
| 1745 addMyController(); |
| 1746 _resolveIndexNoErrors(AngularTest.createHtmlWithAngular(r''' |
| 1747 <div> |
| 1748 {{$id}} |
| 1749 {{$parent}} |
| 1750 {{$root}} |
| 1751 </div>''')); |
| 1752 assertResolvedIdentifier("\$id"); |
| 1753 assertResolvedIdentifier("\$parent"); |
| 1754 assertResolvedIdentifier("\$root"); |
| 1755 } |
| 1756 |
| 1757 void test_getAngularElement_isAngular() { |
| 1758 // prepare local variable "name" in compilation unit |
| 1759 CompilationUnitElementImpl unit = |
| 1760 ElementFactory.compilationUnit("test.dart"); |
| 1761 FunctionElementImpl function = ElementFactory.functionElement("main"); |
| 1762 unit.functions = <FunctionElement>[function]; |
| 1763 LocalVariableElementImpl local = |
| 1764 ElementFactory.localVariableElement2("name"); |
| 1765 function.localVariables = <LocalVariableElement>[local]; |
| 1766 // set AngularElement |
| 1767 AngularElement angularElement = new AngularControllerElementImpl("ctrl", 0); |
| 1768 local.toolkitObjects = <AngularElement>[angularElement]; |
| 1769 expect( |
| 1770 AngularHtmlUnitResolver.getAngularElement(local), |
| 1771 same(angularElement)); |
| 1772 } |
| 1773 |
| 1774 void test_getAngularElement_notAngular() { |
| 1775 Element element = ElementFactory.localVariableElement2("name"); |
| 1776 expect(AngularHtmlUnitResolver.getAngularElement(element), isNull); |
| 1777 } |
| 1778 |
| 1779 void test_getAngularElement_notLocal() { |
| 1780 Element element = ElementFactory.classElement2("Test"); |
| 1781 expect(AngularHtmlUnitResolver.getAngularElement(element), isNull); |
| 1782 } |
| 1783 |
| 1784 /** |
| 1785 * Test that we resolve "ng-click" expression. |
| 1786 */ |
| 1787 void test_ngClick() { |
| 1788 addMyController(); |
| 1789 _resolveIndexNoErrors( |
| 1790 AngularTest.createHtmlWithMyController( |
| 1791 r"<button ng-click='ctrl.doSomething($event)'/>")); |
| 1792 assertResolvedIdentifier("doSomething"); |
| 1793 } |
| 1794 |
| 1795 void test_NgComponent_resolveTemplateFile() { |
1753 addMainSource(r''' | 1796 addMainSource(r''' |
1754 | |
1755 import 'angular.dart'; | 1797 import 'angular.dart'; |
1756 | 1798 |
1757 @Component( | 1799 @Component( |
1758 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', | 1800 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', |
1759 publishAs: 'ctrl', | 1801 publishAs: 'ctrl', |
1760 selector: 'myComponent') | 1802 selector: 'myComponent') |
1761 class MyComponent { | 1803 class MyComponent { |
1762 }'''); | 1804 String field; |
1763 Source entrySource = contextHelper.addSource( | 1805 }'''); |
| 1806 contextHelper.addSource( |
1764 "/entry-point.html", | 1807 "/entry-point.html", |
1765 AngularTest.createHtmlWithAngular('')); | 1808 AngularTest.createHtmlWithAngular('')); |
1766 addIndexSource2( | 1809 addIndexSource2("/my_template.html", r''' |
1767 "/my_template.html", | |
1768 r''' | |
1769 <div> | 1810 <div> |
1770 {{ctrl.noMethod()}} | 1811 {{ctrl.field}} |
1771 </div>'''); | 1812 </div>'''); |
1772 contextHelper.addSource("/my_styles.css", ""); | 1813 contextHelper.addSource("/my_styles.css", ""); |
1773 contextHelper.runTasks(); | 1814 contextHelper.runTasks(); |
1774 // there are some errors in my_template.html | 1815 resolveIndex(); |
1775 { | 1816 assertNoErrors(); |
1776 List<AnalysisError> errors = context.getErrors(indexSource).errors; | 1817 assertResolvedIdentifier2("ctrl.", "MyComponent"); |
1777 expect(errors.length != 0, isTrue); | 1818 assertResolvedIdentifier2("field}}", "String"); |
1778 } | 1819 } |
1779 // make entry-point.html non-Angular | 1820 |
1780 context.setContents(entrySource, "<html/>"); | 1821 void test_NgComponent_updateDartFile() { |
1781 // ...errors in my_template.html should be removed | 1822 Source componentSource = contextHelper.addSource("/my_component.dart", r''' |
1782 { | 1823 library my.component; |
1783 List<AnalysisError> errors = context.getErrors(indexSource).errors; | 1824 import 'angular.dart'; |
1784 expect(errors.length == 0, isTrue); | 1825 @Component(selector: 'myComponent') |
1785 } | 1826 class MyComponent { |
1786 } | 1827 }'''); |
1787 | 1828 contextHelper.addSource("/my_module.dart", r''' |
1788 void test_analysisContext_removeEntryPoint_clearAngularErrors_inDart() { | 1829 library my.module; |
| 1830 import 'my_component.dart';'''); |
| 1831 addMainSource(r''' |
| 1832 library main; |
| 1833 import 'my_module.dart';'''); |
| 1834 _resolveIndexNoErrors( |
| 1835 AngularTest.createHtmlWithMyController("<myComponent/>")); |
| 1836 // "myComponent" tag was resolved |
| 1837 { |
| 1838 ht.XmlTagNode tagNode = |
| 1839 ht.HtmlUnitUtils.getTagNode(indexUnit, findOffset2("myComponent")); |
| 1840 AngularSelectorElement tagElement = |
| 1841 tagNode.element as AngularSelectorElement; |
| 1842 expect(tagElement, isNotNull); |
| 1843 expect(tagElement.name, "myComponent"); |
| 1844 } |
| 1845 // replace "myComponent" with "myComponent2" |
| 1846 // in my_component.dart and index.html |
| 1847 { |
| 1848 context.setContents( |
| 1849 componentSource, |
| 1850 _getSourceContent(componentSource).replaceAll("myComponent", "myCompon
ent2")); |
| 1851 indexContent = |
| 1852 _getSourceContent(indexSource).replaceAll("myComponent", "myComponent2
"); |
| 1853 context.setContents(indexSource, indexContent); |
| 1854 } |
| 1855 contextHelper.runTasks(); |
| 1856 resolveIndex(); |
| 1857 // "myComponent2" tag should be resolved |
| 1858 { |
| 1859 ht.XmlTagNode tagNode = |
| 1860 ht.HtmlUnitUtils.getTagNode(indexUnit, findOffset2("myComponent2")); |
| 1861 AngularSelectorElement tagElement = |
| 1862 tagNode.element as AngularSelectorElement; |
| 1863 expect(tagElement, isNotNull); |
| 1864 expect(tagElement.name, "myComponent2"); |
| 1865 } |
| 1866 } |
| 1867 |
| 1868 void test_NgComponent_use_resolveAttributes() { |
| 1869 contextHelper.addSource("/my_template.html", r''' |
| 1870 <div> |
| 1871 {{ctrl.field}} |
| 1872 </div>'''); |
1789 addMainSource(r''' | 1873 addMainSource(r''' |
1790 | 1874 |
1791 import 'angular.dart'; | 1875 import 'angular.dart'; |
1792 | 1876 |
1793 @Component( | 1877 @Component( |
1794 templateUrl: 'no-such-template.html', cssUrl: 'my_styles.css', | 1878 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', |
1795 publishAs: 'ctrl', | 1879 publishAs: 'ctrl', |
1796 selector: 'myComponent') | 1880 selector: 'myComponent', // selector |
| 1881 map: const {'attrA' : '=>setA', 'attrB' : '@setB'}) |
1797 class MyComponent { | 1882 class MyComponent { |
1798 }'''); | 1883 set setA(value) {} |
1799 Source entrySource = contextHelper.addSource( | 1884 set setB(value) {} |
1800 "/entry-point.html", | 1885 }'''); |
1801 AngularTest.createHtmlWithAngular('')); | 1886 _resolveIndexNoErrors(AngularTest.createHtmlWithMyController(r''' |
1802 contextHelper.addSource("/my_styles.css", ""); | 1887 <input type='text' ng-model='someModel'/> |
1803 contextHelper.runTasks(); | 1888 <myComponent attrA='someModel' attrB='bbb'/>''')); |
1804 // there are some errors in MyComponent | 1889 // "attrA" attribute expression was resolved |
1805 { | 1890 expect(findIdentifier("someModel"), isNotNull); |
1806 List<AnalysisError> errors = context.getErrors(mainSource).errors; | 1891 // "myComponent" tag was resolved |
1807 expect(errors.length != 0, isTrue); | 1892 ht.XmlTagNode tagNode = |
1808 } | 1893 ht.HtmlUnitUtils.getTagNode(indexUnit, findOffset2("myComponent")); |
1809 // remove entry-point.html | 1894 AngularSelectorElement tagElement = |
1810 { | 1895 tagNode.element as AngularSelectorElement; |
1811 ChangeSet changeSet = new ChangeSet(); | 1896 expect(tagElement, isNotNull); |
1812 changeSet.removedSource(entrySource); | 1897 expect(tagElement.name, "myComponent"); |
1813 context.applyChanges(changeSet); | 1898 expect(tagElement.nameOffset, findMainOffset("myComponent', // selector")); |
1814 } | 1899 // "attrA" attribute was resolved |
1815 // ...errors in MyComponent should be removed | 1900 { |
1816 { | 1901 ht.XmlAttributeNode node = |
1817 List<AnalysisError> errors = context.getErrors(mainSource).errors; | 1902 ht.HtmlUnitUtils.getAttributeNode(indexUnit, findOffset2("attrA='")); |
1818 expect(errors.length == 0, isTrue); | 1903 AngularPropertyElement element = node.element as AngularPropertyElement; |
1819 } | 1904 expect(element, isNotNull); |
1820 } | 1905 expect(element.name, "attrA"); |
1821 | 1906 expect(element.field.name, "setA"); |
1822 void test_contextProperties() { | 1907 } |
1823 addMyController(); | 1908 // "attrB" attribute was resolved, even if it @binding |
1824 _resolveIndexNoErrors( | 1909 { |
1825 AngularTest.createHtmlWithAngular(r''' | 1910 ht.XmlAttributeNode node = |
1826 <div> | 1911 ht.HtmlUnitUtils.getAttributeNode(indexUnit, findOffset2("attrB='")); |
1827 {{$id}} | 1912 AngularPropertyElement element = node.element as AngularPropertyElement; |
1828 {{$parent}} | 1913 expect(element, isNotNull); |
1829 {{$root}} | 1914 expect(element.name, "attrB"); |
1830 </div>''')); | 1915 expect(element.field.name, "setB"); |
1831 assertResolvedIdentifier("\$id"); | 1916 } |
1832 assertResolvedIdentifier("\$parent"); | 1917 } |
1833 assertResolvedIdentifier("\$root"); | 1918 |
1834 } | 1919 void test_NgDirective_noAttribute() { |
1835 | 1920 addMainSource(r''' |
1836 void test_getAngularElement_isAngular() { | 1921 |
1837 // prepare local variable "name" in compilation unit | 1922 import 'angular.dart'; |
1838 CompilationUnitElementImpl unit = | 1923 |
1839 ElementFactory.compilationUnit("test.dart"); | 1924 @NgDirective(selector: '[my-directive]', map: const {'foo': '=>input'}) |
1840 FunctionElementImpl function = ElementFactory.functionElement("main"); | 1925 class MyDirective { |
1841 unit.functions = <FunctionElement>[function]; | 1926 set input(value) {} |
1842 LocalVariableElementImpl local = | 1927 }'''); |
1843 ElementFactory.localVariableElement2("name"); | 1928 _resolveIndexNoErrors(AngularTest.createHtmlWithMyController(r''' |
1844 function.localVariables = <LocalVariableElement>[local]; | 1929 <div my-directive> |
1845 // set AngularElement | 1930 </div>''')); |
1846 AngularElement angularElement = new AngularControllerElementImpl("ctrl", 0); | 1931 } |
1847 local.toolkitObjects = <AngularElement>[angularElement]; | 1932 |
1848 expect(AngularHtmlUnitResolver.getAngularElement(local), same(angularElement
)); | 1933 void test_NgDirective_noExpression() { |
1849 } | 1934 addMainSource(r''' |
1850 | 1935 |
1851 void test_getAngularElement_notAngular() { | 1936 import 'angular.dart'; |
1852 Element element = ElementFactory.localVariableElement2("name"); | 1937 |
1853 expect(AngularHtmlUnitResolver.getAngularElement(element), isNull); | 1938 @NgDirective(selector: '[my-directive]', map: const {'.': '=>input'}) |
1854 } | 1939 class MyDirective { |
1855 | 1940 set input(value) {} |
1856 void test_getAngularElement_notLocal() { | 1941 }'''); |
1857 Element element = ElementFactory.classElement2("Test"); | 1942 _resolveIndexNoErrors(AngularTest.createHtmlWithMyController(r''' |
1858 expect(AngularHtmlUnitResolver.getAngularElement(element), isNull); | 1943 <div my-directive> |
| 1944 </div>''')); |
| 1945 } |
| 1946 |
| 1947 void test_NgDirective_resolvedExpression() { |
| 1948 addMainSource(r''' |
| 1949 |
| 1950 import 'angular.dart'; |
| 1951 |
| 1952 @Decorator(selector: '[my-directive]') |
| 1953 class MyDirective { |
| 1954 @NgOneWay('my-property') |
| 1955 String condition; |
| 1956 }'''); |
| 1957 _resolveIndexNoErrors(AngularTest.createHtmlWithMyController(r''' |
| 1958 <input type='text' ng-model='name'> |
| 1959 <div my-directive my-property='name != null'> |
| 1960 </div>''')); |
| 1961 resolveMainNoErrors(); |
| 1962 // "my-directive" attribute was resolved |
| 1963 { |
| 1964 AngularSelectorElement selector = |
| 1965 findMainElement(ElementKind.ANGULAR_SELECTOR, "my-directive"); |
| 1966 ht.XmlAttributeNode attrNodeSelector = |
| 1967 ht.HtmlUnitUtils.getAttributeNode(indexUnit, findOffset2("my-directive
")); |
| 1968 expect(attrNodeSelector, isNotNull); |
| 1969 expect(attrNodeSelector.element, same(selector)); |
| 1970 } |
| 1971 // "my-property" attribute was resolved |
| 1972 { |
| 1973 ht.XmlAttributeNode attrNodeProperty = |
| 1974 ht.HtmlUnitUtils.getAttributeNode(indexUnit, findOffset2("my-property=
'")); |
| 1975 AngularPropertyElement propertyElement = |
| 1976 attrNodeProperty.element as AngularPropertyElement; |
| 1977 expect(propertyElement, isNotNull); |
| 1978 expect(propertyElement.propertyKind, same(AngularPropertyKind.ONE_WAY)); |
| 1979 expect(propertyElement.field.name, "condition"); |
| 1980 } |
| 1981 // "name" expression was resolved |
| 1982 expect(findIdentifier("name != null"), isNotNull); |
| 1983 } |
| 1984 |
| 1985 void test_NgDirective_resolvedExpression_attrString() { |
| 1986 addMainSource(r''' |
| 1987 |
| 1988 import 'angular.dart'; |
| 1989 |
| 1990 @NgDirective(selector: '[my-directive]) |
| 1991 class MyDirective { |
| 1992 @NgAttr('my-property') |
| 1993 String property; |
| 1994 }'''); |
| 1995 _resolveIndexNoErrors(AngularTest.createHtmlWithMyController(r''' |
| 1996 <input type='text' ng-model='name'> |
| 1997 <div my-directive my-property='name != null'> |
| 1998 </div>''')); |
| 1999 resolveMain(); |
| 2000 // @NgAttr means "string attribute", which we don't parse |
| 2001 expect(findIdentifierMaybe("name != null"), isNull); |
| 2002 } |
| 2003 |
| 2004 void test_NgDirective_resolvedExpression_dotAsName() { |
| 2005 addMainSource(r''' |
| 2006 |
| 2007 import 'angular.dart'; |
| 2008 |
| 2009 @Decorator( |
| 2010 selector: '[my-directive]', |
| 2011 map: const {'.' : '=>condition'}) |
| 2012 class MyDirective { |
| 2013 set condition(value) {} |
| 2014 }'''); |
| 2015 _resolveIndexNoErrors(AngularTest.createHtmlWithMyController(r''' |
| 2016 <input type='text' ng-model='name'> |
| 2017 <div my-directive='name != null'> |
| 2018 </div>''')); |
| 2019 // "name" attribute was resolved |
| 2020 expect(findIdentifier("name != null"), isNotNull); |
1859 } | 2021 } |
1860 | 2022 |
1861 /** | 2023 /** |
1862 * Test that we resolve "ng-click" expression. | |
1863 */ | |
1864 void test_ngClick() { | |
1865 addMyController(); | |
1866 _resolveIndexNoErrors( | |
1867 AngularTest.createHtmlWithMyController(r"<button ng-click='ctrl.doSometh
ing($event)'/>")); | |
1868 assertResolvedIdentifier("doSomething"); | |
1869 } | |
1870 | |
1871 /** | |
1872 * Test that we resolve "ng-if" expression. | 2024 * Test that we resolve "ng-if" expression. |
1873 */ | 2025 */ |
1874 void test_ngIf() { | 2026 void test_ngIf() { |
1875 addMyController(); | 2027 addMyController(); |
1876 _resolveIndexNoErrors( | 2028 _resolveIndexNoErrors( |
1877 AngularTest.createHtmlWithMyController("<div ng-if='ctrl.field != null'/
>")); | 2029 AngularTest.createHtmlWithMyController("<div ng-if='ctrl.field != null'/
>")); |
1878 assertResolvedIdentifier("field"); | 2030 assertResolvedIdentifier("field"); |
1879 } | 2031 } |
1880 | 2032 |
1881 void test_ngModel_modelAfterUsage() { | 2033 void test_ngModel_modelAfterUsage() { |
1882 addMyController(); | 2034 addMyController(); |
1883 _resolveIndexNoErrors( | 2035 _resolveIndexNoErrors(AngularTest.createHtmlWithMyController(r''' |
1884 AngularTest.createHtmlWithMyController(r''' | |
1885 <h3>Hello {{name}}!</h3> | 2036 <h3>Hello {{name}}!</h3> |
1886 <input type='text' ng-model='name'>''')); | 2037 <input type='text' ng-model='name'>''')); |
1887 assertResolvedIdentifier2("name}}!", "String"); | 2038 assertResolvedIdentifier2("name}}!", "String"); |
1888 assertResolvedIdentifier2("name'>", "String"); | 2039 assertResolvedIdentifier2("name'>", "String"); |
1889 } | 2040 } |
1890 | 2041 |
1891 void test_ngModel_modelBeforeUsage() { | 2042 void test_ngModel_modelBeforeUsage() { |
1892 addMyController(); | 2043 addMyController(); |
1893 _resolveIndexNoErrors( | 2044 _resolveIndexNoErrors(AngularTest.createHtmlWithMyController(r''' |
1894 AngularTest.createHtmlWithMyController(r''' | |
1895 <input type='text' ng-model='name'> | 2045 <input type='text' ng-model='name'> |
1896 <h3>Hello {{name}}!</h3>''')); | 2046 <h3>Hello {{name}}!</h3>''')); |
1897 assertResolvedIdentifier2("name}}!", "String"); | 2047 assertResolvedIdentifier2("name}}!", "String"); |
1898 Element element = assertResolvedIdentifier2("name'>", "String"); | 2048 Element element = assertResolvedIdentifier2("name'>", "String"); |
1899 expect(element.name, "name"); | 2049 expect(element.name, "name"); |
1900 expect(element.nameOffset, findOffset2("name'>")); | 2050 expect(element.nameOffset, findOffset2("name'>")); |
1901 } | 2051 } |
1902 | 2052 |
1903 void test_ngModel_notIdentifier() { | 2053 void test_ngModel_notIdentifier() { |
1904 addMyController(); | 2054 addMyController(); |
1905 _resolveIndexNoErrors( | 2055 _resolveIndexNoErrors( |
1906 AngularTest.createHtmlWithMyController("<input type='text' ng-model='ctr
l.field'>")); | 2056 AngularTest.createHtmlWithMyController( |
| 2057 "<input type='text' ng-model='ctrl.field'>")); |
1907 assertResolvedIdentifier2("field'>", "String"); | 2058 assertResolvedIdentifier2("field'>", "String"); |
1908 } | 2059 } |
1909 | 2060 |
1910 /** | 2061 /** |
1911 * Test that we resolve "ng-mouseout" expression. | 2062 * Test that we resolve "ng-mouseout" expression. |
1912 */ | 2063 */ |
1913 void test_ngMouseOut() { | 2064 void test_ngMouseOut() { |
1914 addMyController(); | 2065 addMyController(); |
1915 _resolveIndexNoErrors( | 2066 _resolveIndexNoErrors( |
1916 AngularTest.createHtmlWithMyController(r"<button ng-mouseout='ctrl.doSom
ething($event)'/>")); | 2067 AngularTest.createHtmlWithMyController( |
| 2068 r"<button ng-mouseout='ctrl.doSomething($event)'/>")); |
1917 assertResolvedIdentifier("doSomething"); | 2069 assertResolvedIdentifier("doSomething"); |
1918 } | 2070 } |
1919 | 2071 |
1920 void fail_ngRepeat_additionalVariables() { | |
1921 addMyController(); | |
1922 _resolveIndexNoErrors( | |
1923 AngularTest.createHtmlWithMyController(r''' | |
1924 <li ng-repeat='name in ctrl.names'> | |
1925 {{$index}} {{$first}} {{$middle}} {{$last}} {{$even}} {{$odd}} | |
1926 </li>''')); | |
1927 assertResolvedIdentifier2("\$index", "int"); | |
1928 assertResolvedIdentifier2("\$first", "bool"); | |
1929 assertResolvedIdentifier2("\$middle", "bool"); | |
1930 assertResolvedIdentifier2("\$last", "bool"); | |
1931 assertResolvedIdentifier2("\$even", "bool"); | |
1932 assertResolvedIdentifier2("\$odd", "bool"); | |
1933 } | |
1934 | |
1935 void fail_ngRepeat_bad_expectedIdentifier() { | |
1936 addMyController(); | |
1937 resolveIndex2( | |
1938 AngularTest.createHtmlWithMyController(r''' | |
1939 <li ng-repeat='name + 42 in ctrl.names'> | |
1940 </li>''')); | |
1941 assertErrors(indexSource, [AngularCode.INVALID_REPEAT_ITEM_SYNTAX]); | |
1942 } | |
1943 | |
1944 void fail_ngRepeat_bad_expectedIn() { | |
1945 addMyController(); | |
1946 resolveIndex2( | |
1947 AngularTest.createHtmlWithMyController(r''' | |
1948 <li ng-repeat='name : ctrl.names'> | |
1949 </li>''')); | |
1950 assertErrors(indexSource, [AngularCode.INVALID_REPEAT_SYNTAX]); | |
1951 } | |
1952 | |
1953 void fail_ngRepeat_filters_filter_literal() { | |
1954 addMyController(); | |
1955 _resolveIndexNoErrors( | |
1956 AngularTest.createHtmlWithMyController(r''' | |
1957 <li ng-repeat='item in ctrl.items | filter:42:null'/> | |
1958 </li>''')); | |
1959 // filter "filter" is resolved | |
1960 Element filterElement = assertResolvedIdentifier("filter"); | |
1961 EngineTestCase.assertInstanceOf( | |
1962 (obj) => obj is AngularFormatterElement, | |
1963 AngularFormatterElement, | |
1964 filterElement); | |
1965 } | |
1966 | |
1967 void fail_ngRepeat_filters_filter_propertyMap() { | |
1968 addMyController(); | |
1969 _resolveIndexNoErrors( | |
1970 AngularTest.createHtmlWithMyController(r''' | |
1971 <li ng-repeat='item in ctrl.items | filter:{name:null, done:false}'/> | |
1972 </li>''')); | |
1973 assertResolvedIdentifier2("name:", "String"); | |
1974 assertResolvedIdentifier2("done:", "bool"); | |
1975 } | |
1976 | |
1977 void fail_ngRepeat_filters_missingColon() { | |
1978 addMyController(); | |
1979 resolveIndex2( | |
1980 AngularTest.createHtmlWithMyController(r''' | |
1981 <li ng-repeat="item in ctrl.items | orderBy:'' true"/> | |
1982 </li>''')); | |
1983 assertErrors(indexSource, [AngularCode.MISSING_FORMATTER_COLON]); | |
1984 } | |
1985 | |
1986 void fail_ngRepeat_filters_noArgs() { | |
1987 addMyController(); | |
1988 _resolveIndexNoErrors( | |
1989 AngularTest.createHtmlWithMyController(r''' | |
1990 <li ng-repeat="item in ctrl.items | orderBy"/> | |
1991 </li>''')); | |
1992 // filter "orderBy" is resolved | |
1993 Element filterElement = assertResolvedIdentifier("orderBy"); | |
1994 EngineTestCase.assertInstanceOf( | |
1995 (obj) => obj is AngularFormatterElement, | |
1996 AngularFormatterElement, | |
1997 filterElement); | |
1998 } | |
1999 | |
2000 void fail_ngRepeat_filters_orderBy_emptyString() { | |
2001 addMyController(); | |
2002 _resolveIndexNoErrors( | |
2003 AngularTest.createHtmlWithMyController(r''' | |
2004 <li ng-repeat="item in ctrl.items | orderBy:'':true"/> | |
2005 </li>''')); | |
2006 // filter "orderBy" is resolved | |
2007 Element filterElement = assertResolvedIdentifier("orderBy"); | |
2008 EngineTestCase.assertInstanceOf( | |
2009 (obj) => obj is AngularFormatterElement, | |
2010 AngularFormatterElement, | |
2011 filterElement); | |
2012 } | |
2013 | |
2014 void fail_ngRepeat_filters_orderBy_propertyList() { | |
2015 addMyController(); | |
2016 _resolveIndexNoErrors( | |
2017 AngularTest.createHtmlWithMyController(r''' | |
2018 <li ng-repeat="item in ctrl.items | orderBy:['name', 'done']"/> | |
2019 </li>''')); | |
2020 assertResolvedIdentifier2("name'", "String"); | |
2021 assertResolvedIdentifier2("done'", "bool"); | |
2022 } | |
2023 | |
2024 void fail_ngRepeat_filters_orderBy_propertyName() { | |
2025 addMyController(); | |
2026 _resolveIndexNoErrors( | |
2027 AngularTest.createHtmlWithMyController(r''' | |
2028 <li ng-repeat="item in ctrl.items | orderBy:'name'"/> | |
2029 </li>''')); | |
2030 assertResolvedIdentifier2("name'", "String"); | |
2031 } | |
2032 | |
2033 void fail_ngRepeat_filters_orderBy_propertyName_minus() { | |
2034 addMyController(); | |
2035 _resolveIndexNoErrors( | |
2036 AngularTest.createHtmlWithMyController(r''' | |
2037 <li ng-repeat="item in ctrl.items | orderBy:'-name'"/> | |
2038 </li>''')); | |
2039 assertResolvedIdentifier2("name'", "String"); | |
2040 } | |
2041 | |
2042 void fail_ngRepeat_filters_orderBy_propertyName_plus() { | |
2043 addMyController(); | |
2044 _resolveIndexNoErrors( | |
2045 AngularTest.createHtmlWithMyController(r''' | |
2046 <li ng-repeat="item in ctrl.items | orderBy:'+name'"/> | |
2047 </li>''')); | |
2048 assertResolvedIdentifier2("name'", "String"); | |
2049 } | |
2050 | |
2051 void fail_ngRepeat_filters_orderBy_propertyName_untypedItems() { | |
2052 addMyController(); | |
2053 _resolveIndexNoErrors( | |
2054 AngularTest.createHtmlWithMyController(r''' | |
2055 <li ng-repeat="item in ctrl.untypedItems | orderBy:'name'"/> | |
2056 </li>''')); | |
2057 assertResolvedIdentifier2("name'", "dynamic"); | |
2058 } | |
2059 | |
2060 void fail_ngRepeat_filters_two() { | |
2061 addMyController(); | |
2062 _resolveIndexNoErrors( | |
2063 AngularTest.createHtmlWithMyController(r''' | |
2064 <li ng-repeat="item in ctrl.items | orderBy:'+' | orderBy:'-'"/> | |
2065 </li>''')); | |
2066 EngineTestCase.assertInstanceOf( | |
2067 (obj) => obj is AngularFormatterElement, | |
2068 AngularFormatterElement, | |
2069 assertResolvedIdentifier("orderBy:'+'")); | |
2070 EngineTestCase.assertInstanceOf( | |
2071 (obj) => obj is AngularFormatterElement, | |
2072 AngularFormatterElement, | |
2073 assertResolvedIdentifier("orderBy:'-'")); | |
2074 } | |
2075 | |
2076 void fail_ngRepeat_resolvedExpressions() { | |
2077 addMyController(); | |
2078 _resolveIndexNoErrors( | |
2079 AngularTest.createHtmlWithMyController(r''' | |
2080 <li ng-repeat='name in ctrl.names'> | |
2081 {{name}} | |
2082 </li>''')); | |
2083 assertResolvedIdentifier2("name in", "String"); | |
2084 assertResolvedIdentifier2("ctrl.", "MyController"); | |
2085 assertResolvedIdentifier2("names'", "List<String>"); | |
2086 assertResolvedIdentifier2("name}}", "String"); | |
2087 } | |
2088 | |
2089 void fail_ngRepeat_trackBy() { | |
2090 addMyController(); | |
2091 _resolveIndexNoErrors( | |
2092 AngularTest.createHtmlWithMyController(r''' | |
2093 <li ng-repeat='name in ctrl.names track by name.length'/> | |
2094 </li>''')); | |
2095 assertResolvedIdentifier2("length'", "int"); | |
2096 } | |
2097 | |
2098 /** | 2072 /** |
2099 * Test that we resolve "ng-show" expression. | 2073 * Test that we resolve "ng-show" expression. |
2100 */ | 2074 */ |
2101 void test_ngShow() { | 2075 void test_ngShow() { |
2102 addMyController(); | 2076 addMyController(); |
2103 _resolveIndexNoErrors( | 2077 _resolveIndexNoErrors( |
2104 AngularTest.createHtmlWithMyController("<div ng-show='ctrl.field != null
'/>")); | 2078 AngularTest.createHtmlWithMyController("<div ng-show='ctrl.field != null
'/>")); |
2105 assertResolvedIdentifier("field"); | 2079 assertResolvedIdentifier("field"); |
2106 } | 2080 } |
2107 | 2081 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2210 // ...but not "invisibleScopeProperty" | 2184 // ...but not "invisibleScopeProperty" |
2211 { | 2185 { |
2212 SimpleIdentifier identifier = findIdentifier("invisibleScopeProperty"); | 2186 SimpleIdentifier identifier = findIdentifier("invisibleScopeProperty"); |
2213 expect(identifier.bestElement, isNull); | 2187 expect(identifier.bestElement, isNull); |
2214 } | 2188 } |
2215 } | 2189 } |
2216 | 2190 |
2217 void test_resolveExpression_inAttribute() { | 2191 void test_resolveExpression_inAttribute() { |
2218 addMyController(); | 2192 addMyController(); |
2219 _resolveIndexNoErrors( | 2193 _resolveIndexNoErrors( |
2220 AngularTest.createHtmlWithMyController("<button title='{{ctrl.field}}'><
/button>")); | 2194 AngularTest.createHtmlWithMyController( |
| 2195 "<button title='{{ctrl.field}}'></button>")); |
2221 assertResolvedIdentifier2("ctrl", "MyController"); | 2196 assertResolvedIdentifier2("ctrl", "MyController"); |
2222 } | 2197 } |
2223 | 2198 |
2224 void test_resolveExpression_ngApp_onBody() { | 2199 void test_resolveExpression_ngApp_onBody() { |
2225 addMyController(); | 2200 addMyController(); |
2226 _resolveIndexNoErrors(r''' | 2201 _resolveIndexNoErrors(r''' |
2227 <html> | 2202 <html> |
2228 <body ng-app> | 2203 <body ng-app> |
2229 <div my-controller> | 2204 <div my-controller> |
2230 {{ctrl.field}} | 2205 {{ctrl.field}} |
2231 </div> | 2206 </div> |
2232 <script type='application/dart' src='main.dart'></script> | 2207 <script type='application/dart' src='main.dart'></script> |
2233 </body> | 2208 </body> |
2234 </html>'''); | 2209 </html>'''); |
2235 assertResolvedIdentifier2("ctrl", "MyController"); | 2210 assertResolvedIdentifier2("ctrl", "MyController"); |
2236 } | 2211 } |
2237 | 2212 |
2238 void test_resolveExpression_withFormatter() { | 2213 void test_resolveExpression_withFormatter() { |
2239 addMyController(); | 2214 addMyController(); |
2240 _resolveIndexNoErrors( | 2215 _resolveIndexNoErrors( |
2241 AngularTest.createHtmlWithMyController("{{ctrl.field | uppercase}}")); | 2216 AngularTest.createHtmlWithMyController("{{ctrl.field | uppercase}}")); |
2242 assertResolvedIdentifier2("ctrl", "MyController"); | 2217 assertResolvedIdentifier2("ctrl", "MyController"); |
2243 assertResolvedIdentifier("uppercase"); | 2218 assertResolvedIdentifier("uppercase"); |
2244 } | 2219 } |
2245 | 2220 |
2246 void test_resolveExpression_withFormatter_missingColon() { | 2221 void test_resolveExpression_withFormatter_missingColon() { |
2247 addMyController(); | 2222 addMyController(); |
2248 resolveIndex2( | 2223 resolveIndex2( |
2249 AngularTest.createHtmlWithMyController("{{ctrl.field | uppercase, lowerc
ase}}")); | 2224 AngularTest.createHtmlWithMyController( |
| 2225 "{{ctrl.field | uppercase, lowercase}}")); |
2250 assertErrors(indexSource, [AngularCode.MISSING_FORMATTER_COLON]); | 2226 assertErrors(indexSource, [AngularCode.MISSING_FORMATTER_COLON]); |
2251 } | 2227 } |
2252 | 2228 |
2253 void test_resolveExpression_withFormatter_notSimpleIdentifier() { | 2229 void test_resolveExpression_withFormatter_notSimpleIdentifier() { |
2254 addMyController(); | 2230 addMyController(); |
2255 resolveIndex2( | 2231 resolveIndex2( |
2256 AngularTest.createHtmlWithMyController("{{ctrl.field | not.supported}}")
); | 2232 AngularTest.createHtmlWithMyController("{{ctrl.field | not.supported}}")
); |
2257 assertErrors(indexSource, [AngularCode.INVALID_FORMATTER_NAME]); | 2233 assertErrors(indexSource, [AngularCode.INVALID_FORMATTER_NAME]); |
2258 } | 2234 } |
2259 | 2235 |
2260 void test_scopeProperties() { | 2236 void test_scopeProperties() { |
2261 addMainSource(r''' | 2237 addMainSource(r''' |
2262 | 2238 |
2263 import 'angular.dart'; | 2239 import 'angular.dart'; |
2264 | 2240 |
2265 @Component( | 2241 @Component( |
2266 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', | 2242 templateUrl: 'my_template.html', cssUrl: 'my_styles.css', |
2267 publishAs: 'ctrl', | 2243 publishAs: 'ctrl', |
2268 selector: 'myComponent') | 2244 selector: 'myComponent') |
2269 class MyComponent { | 2245 class MyComponent { |
2270 String field; | 2246 String field; |
2271 MyComponent(Scope scope) { | 2247 MyComponent(Scope scope) { |
2272 scope.context['scopeProperty'] = 'abc'; | 2248 scope.context['scopeProperty'] = 'abc'; |
2273 } | 2249 } |
2274 } | 2250 } |
2275 '''); | 2251 '''); |
2276 contextHelper.addSource( | 2252 contextHelper.addSource( |
2277 "/entry-point.html", | 2253 "/entry-point.html", |
2278 AngularTest.createHtmlWithAngular('')); | 2254 AngularTest.createHtmlWithAngular('')); |
2279 addIndexSource2( | 2255 addIndexSource2("/my_template.html", r''' |
2280 "/my_template.html", | |
2281 r''' | |
2282 <div> | 2256 <div> |
2283 {{scopeProperty}} | 2257 {{scopeProperty}} |
2284 </div>'''); | 2258 </div>'''); |
2285 contextHelper.addSource("/my_styles.css", ""); | 2259 contextHelper.addSource("/my_styles.css", ""); |
2286 contextHelper.runTasks(); | 2260 contextHelper.runTasks(); |
2287 resolveIndex(); | 2261 resolveIndex(); |
2288 assertNoErrors(); | 2262 assertNoErrors(); |
2289 // "scopeProperty" is resolved | 2263 // "scopeProperty" is resolved |
2290 Element element = assertResolvedIdentifier2("scopeProperty}}", "String"); | 2264 Element element = assertResolvedIdentifier2("scopeProperty}}", "String"); |
2291 EngineTestCase.assertInstanceOf( | 2265 EngineTestCase.assertInstanceOf( |
(...skipping 14 matching lines...) Expand all Loading... |
2306 class MyComponent { | 2280 class MyComponent { |
2307 } | 2281 } |
2308 | 2282 |
2309 void setScopeProperties(Scope scope) { | 2283 void setScopeProperties(Scope scope) { |
2310 scope.context['ctrl'] = 1; | 2284 scope.context['ctrl'] = 1; |
2311 } | 2285 } |
2312 '''); | 2286 '''); |
2313 contextHelper.addSource( | 2287 contextHelper.addSource( |
2314 "/entry-point.html", | 2288 "/entry-point.html", |
2315 AngularTest.createHtmlWithAngular('')); | 2289 AngularTest.createHtmlWithAngular('')); |
2316 addIndexSource2( | 2290 addIndexSource2("/my_template.html", r''' |
2317 "/my_template.html", | |
2318 r''' | |
2319 <div> | 2291 <div> |
2320 {{ctrl}} | 2292 {{ctrl}} |
2321 </div>'''); | 2293 </div>'''); |
2322 contextHelper.addSource("/my_styles.css", ""); | 2294 contextHelper.addSource("/my_styles.css", ""); |
2323 contextHelper.runTasks(); | 2295 contextHelper.runTasks(); |
2324 resolveIndex(); | 2296 resolveIndex(); |
2325 assertNoErrors(); | 2297 assertNoErrors(); |
2326 // "ctrl" is resolved | 2298 // "ctrl" is resolved |
2327 LocalVariableElement element = | 2299 LocalVariableElement element = |
2328 assertResolvedIdentifier("ctrl}}") as LocalVariableElement; | 2300 assertResolvedIdentifier("ctrl}}") as LocalVariableElement; |
(...skipping 17 matching lines...) Expand all Loading... |
2346 } | 2318 } |
2347 | 2319 |
2348 class MyRouteInitializer { | 2320 class MyRouteInitializer { |
2349 init(ViewFactory view) { | 2321 init(ViewFactory view) { |
2350 view('my_template.html'); | 2322 view('my_template.html'); |
2351 } | 2323 } |
2352 }'''); | 2324 }'''); |
2353 contextHelper.addSource( | 2325 contextHelper.addSource( |
2354 "/entry-point.html", | 2326 "/entry-point.html", |
2355 AngularTest.createHtmlWithAngular('')); | 2327 AngularTest.createHtmlWithAngular('')); |
2356 addIndexSource2( | 2328 addIndexSource2("/my_template.html", r''' |
2357 "/my_template.html", | |
2358 r''' | |
2359 <div my-controller> | 2329 <div my-controller> |
2360 {{ctrl.field}} | 2330 {{ctrl.field}} |
2361 </div>'''); | 2331 </div>'''); |
2362 contextHelper.addSource("/my_styles.css", ""); | 2332 contextHelper.addSource("/my_styles.css", ""); |
2363 contextHelper.runTasks(); | 2333 contextHelper.runTasks(); |
2364 resolveIndex(); | 2334 resolveIndex(); |
2365 assertNoErrors(); | 2335 assertNoErrors(); |
2366 assertResolvedIdentifier2("ctrl.", "MyController"); | 2336 assertResolvedIdentifier2("ctrl.", "MyController"); |
2367 assertResolvedIdentifier2("field}}", "String"); | 2337 assertResolvedIdentifier2("field}}", "String"); |
2368 } | 2338 } |
2369 | 2339 |
2370 String _getSourceContent(Source source) { | 2340 String _getSourceContent(Source source) { |
2371 return context.getContents(source).data.toString(); | 2341 return context.getContents(source).data.toString(); |
2372 } | 2342 } |
2373 | 2343 |
2374 void _resolveIndexNoErrors(String content) { | 2344 void _resolveIndexNoErrors(String content) { |
2375 resolveIndex2(content); | 2345 resolveIndex2(content); |
2376 assertNoErrors(); | 2346 assertNoErrors(); |
2377 verify([indexSource]); | 2347 verify([indexSource]); |
2378 } | 2348 } |
2379 } | 2349 } |
2380 | 2350 |
2381 | 2351 |
2382 /** | 2352 /** |
2383 * Tests for [HtmlUnitUtils] for Angular HTMLs. | 2353 * Tests for [HtmlUnitUtils] for Angular HTMLs. |
2384 */ | 2354 */ |
2385 class AngularHtmlUnitUtilsTest extends AngularTest { | 2355 class AngularHtmlUnitUtilsTest extends AngularTest { |
2386 void test_getElementToOpen_controller() { | |
2387 addMyController(); | |
2388 _resolveSimpleCtrlFieldHtml(); | |
2389 // prepare expression | |
2390 int offset = indexContent.indexOf("ctrl"); | |
2391 Expression expression = ht.HtmlUnitUtils.getExpression(indexUnit, offset); | |
2392 // get element | |
2393 Element element = ht.HtmlUnitUtils.getElementToOpen(indexUnit, expression); | |
2394 EngineTestCase.assertInstanceOf( | |
2395 (obj) => obj is AngularControllerElement, | |
2396 AngularControllerElement, | |
2397 element); | |
2398 expect(element.name, "ctrl"); | |
2399 } | |
2400 | |
2401 void test_getElementToOpen_field() { | |
2402 addMyController(); | |
2403 _resolveSimpleCtrlFieldHtml(); | |
2404 // prepare expression | |
2405 int offset = indexContent.indexOf("field"); | |
2406 Expression expression = ht.HtmlUnitUtils.getExpression(indexUnit, offset); | |
2407 // get element | |
2408 Element element = ht.HtmlUnitUtils.getElementToOpen(indexUnit, expression); | |
2409 EngineTestCase.assertInstanceOf( | |
2410 (obj) => obj is PropertyAccessorElement, | |
2411 PropertyAccessorElement, | |
2412 element); | |
2413 expect(element.name, "field"); | |
2414 } | |
2415 | |
2416 void test_getElement_forExpression() { | 2356 void test_getElement_forExpression() { |
2417 addMyController(); | 2357 addMyController(); |
2418 _resolveSimpleCtrlFieldHtml(); | 2358 _resolveSimpleCtrlFieldHtml(); |
2419 // prepare expression | 2359 // prepare expression |
2420 int offset = indexContent.indexOf("ctrl"); | 2360 int offset = indexContent.indexOf("ctrl"); |
2421 Expression expression = ht.HtmlUnitUtils.getExpression(indexUnit, offset); | 2361 Expression expression = ht.HtmlUnitUtils.getExpression(indexUnit, offset); |
2422 // get element | 2362 // get element |
2423 Element element = ht.HtmlUnitUtils.getElement(expression); | 2363 Element element = ht.HtmlUnitUtils.getElement(expression); |
2424 EngineTestCase.assertInstanceOf( | 2364 EngineTestCase.assertInstanceOf( |
2425 (obj) => obj is VariableElement, | 2365 (obj) => obj is VariableElement, |
(...skipping 20 matching lines...) Expand all Loading... |
2446 int offset = indexContent.indexOf("field"); | 2386 int offset = indexContent.indexOf("field"); |
2447 Element element = ht.HtmlUnitUtils.getElementAtOffset(indexUnit, offset); | 2387 Element element = ht.HtmlUnitUtils.getElementAtOffset(indexUnit, offset); |
2448 EngineTestCase.assertInstanceOf( | 2388 EngineTestCase.assertInstanceOf( |
2449 (obj) => obj is PropertyAccessorElement, | 2389 (obj) => obj is PropertyAccessorElement, |
2450 PropertyAccessorElement, | 2390 PropertyAccessorElement, |
2451 element); | 2391 element); |
2452 expect(element.name, "field"); | 2392 expect(element.name, "field"); |
2453 } | 2393 } |
2454 } | 2394 } |
2455 | 2395 |
| 2396 void test_getElementToOpen_controller() { |
| 2397 addMyController(); |
| 2398 _resolveSimpleCtrlFieldHtml(); |
| 2399 // prepare expression |
| 2400 int offset = indexContent.indexOf("ctrl"); |
| 2401 Expression expression = ht.HtmlUnitUtils.getExpression(indexUnit, offset); |
| 2402 // get element |
| 2403 Element element = ht.HtmlUnitUtils.getElementToOpen(indexUnit, expression); |
| 2404 EngineTestCase.assertInstanceOf( |
| 2405 (obj) => obj is AngularControllerElement, |
| 2406 AngularControllerElement, |
| 2407 element); |
| 2408 expect(element.name, "ctrl"); |
| 2409 } |
| 2410 |
| 2411 void test_getElementToOpen_field() { |
| 2412 addMyController(); |
| 2413 _resolveSimpleCtrlFieldHtml(); |
| 2414 // prepare expression |
| 2415 int offset = indexContent.indexOf("field"); |
| 2416 Expression expression = ht.HtmlUnitUtils.getExpression(indexUnit, offset); |
| 2417 // get element |
| 2418 Element element = ht.HtmlUnitUtils.getElementToOpen(indexUnit, expression); |
| 2419 EngineTestCase.assertInstanceOf( |
| 2420 (obj) => obj is PropertyAccessorElement, |
| 2421 PropertyAccessorElement, |
| 2422 element); |
| 2423 expect(element.name, "field"); |
| 2424 } |
| 2425 |
2456 void test_getEnclosingTagNode() { | 2426 void test_getEnclosingTagNode() { |
2457 resolveIndex2(r''' | 2427 resolveIndex2(r''' |
2458 <html> | 2428 <html> |
2459 <body ng-app> | 2429 <body ng-app> |
2460 <badge name='abc'> 123 </badge> | 2430 <badge name='abc'> 123 </badge> |
2461 </body> | 2431 </body> |
2462 </html>'''); | 2432 </html>'''); |
2463 // no unit | 2433 // no unit |
2464 expect(ht.HtmlUnitUtils.getEnclosingTagNode(null, 0), isNull); | 2434 expect(ht.HtmlUnitUtils.getEnclosingTagNode(null, 0), isNull); |
2465 // wrong offset | 2435 // wrong offset |
(...skipping 11 matching lines...) Expand all Loading... |
2477 void test_getExpression() { | 2447 void test_getExpression() { |
2478 addMyController(); | 2448 addMyController(); |
2479 _resolveSimpleCtrlFieldHtml(); | 2449 _resolveSimpleCtrlFieldHtml(); |
2480 // try offset without expression | 2450 // try offset without expression |
2481 expect(ht.HtmlUnitUtils.getExpression(indexUnit, 0), isNull); | 2451 expect(ht.HtmlUnitUtils.getExpression(indexUnit, 0), isNull); |
2482 // try offset with expression | 2452 // try offset with expression |
2483 int offset = indexContent.indexOf("ctrl"); | 2453 int offset = indexContent.indexOf("ctrl"); |
2484 expect(ht.HtmlUnitUtils.getExpression(indexUnit, offset), isNotNull); | 2454 expect(ht.HtmlUnitUtils.getExpression(indexUnit, offset), isNotNull); |
2485 expect(ht.HtmlUnitUtils.getExpression(indexUnit, offset + 1), isNotNull); | 2455 expect(ht.HtmlUnitUtils.getExpression(indexUnit, offset + 1), isNotNull); |
2486 expect(ht.HtmlUnitUtils.getExpression(indexUnit, offset + 2), isNotNull); | 2456 expect(ht.HtmlUnitUtils.getExpression(indexUnit, offset + 2), isNotNull); |
2487 expect(ht.HtmlUnitUtils.getExpression(indexUnit, offset + "ctrl.field".lengt
h), isNotNull); | 2457 expect( |
| 2458 ht.HtmlUnitUtils.getExpression(indexUnit, offset + "ctrl.field".length), |
| 2459 isNotNull); |
2488 // try without unit | 2460 // try without unit |
2489 expect(ht.HtmlUnitUtils.getExpression(null, offset), isNull); | 2461 expect(ht.HtmlUnitUtils.getExpression(null, offset), isNull); |
2490 } | 2462 } |
2491 | 2463 |
2492 void test_getTagNode() { | 2464 void test_getTagNode() { |
2493 resolveIndex2(r''' | 2465 resolveIndex2(r''' |
2494 <html> | 2466 <html> |
2495 <body ng-app> | 2467 <body ng-app> |
2496 <badge name='abc'> 123 </badge> done | 2468 <badge name='abc'> 123 </badge> done |
2497 </body> | 2469 </body> |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2601 * Assert that the number of errors reported against the given source matches
the number of errors | 2573 * Assert that the number of errors reported against the given source matches
the number of errors |
2602 * that are given and that they have the expected error codes. The order in wh
ich the errors were | 2574 * that are given and that they have the expected error codes. The order in wh
ich the errors were |
2603 * gathered is ignored. | 2575 * gathered is ignored. |
2604 * | 2576 * |
2605 * @param source the source against which the errors should have been reported | 2577 * @param source the source against which the errors should have been reported |
2606 * @param expectedErrorCodes the error codes of the errors that should have be
en reported | 2578 * @param expectedErrorCodes the error codes of the errors that should have be
en reported |
2607 * @throws AnalysisException if the reported errors could not be computed | 2579 * @throws AnalysisException if the reported errors could not be computed |
2608 * @throws AssertionFailedError if a different number of errors have been repo
rted than were | 2580 * @throws AssertionFailedError if a different number of errors have been repo
rted than were |
2609 * expected | 2581 * expected |
2610 */ | 2582 */ |
2611 void assertErrors(Source source, [List<ErrorCode> expectedErrorCodes = ErrorCo
de.EMPTY_LIST]) { | 2583 void assertErrors(Source source, [List<ErrorCode> expectedErrorCodes = |
| 2584 ErrorCode.EMPTY_LIST]) { |
2612 GatheringErrorListener errorListener = new GatheringErrorListener(); | 2585 GatheringErrorListener errorListener = new GatheringErrorListener(); |
2613 AnalysisErrorInfo errorsInfo = context.getErrors(source); | 2586 AnalysisErrorInfo errorsInfo = context.getErrors(source); |
2614 for (AnalysisError error in errorsInfo.errors) { | 2587 for (AnalysisError error in errorsInfo.errors) { |
2615 errorListener.onError(error); | 2588 errorListener.onError(error); |
2616 } | 2589 } |
2617 errorListener.assertErrorsWithCodes(expectedErrorCodes); | 2590 errorListener.assertErrorsWithCodes(expectedErrorCodes); |
2618 } | 2591 } |
2619 | 2592 |
2620 void assertMainErrors(List<ErrorCode> expectedErrorCodes) { | 2593 void assertMainErrors(List<ErrorCode> expectedErrorCodes) { |
2621 assertErrors(mainSource, expectedErrorCodes); | 2594 assertErrors(mainSource, expectedErrorCodes); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2807 void verify(List<Source> sources) { | 2780 void verify(List<Source> sources) { |
2808 ResolutionVerifier verifier = new ResolutionVerifier(); | 2781 ResolutionVerifier verifier = new ResolutionVerifier(); |
2809 for (Source source in sources) { | 2782 for (Source source in sources) { |
2810 ht.HtmlUnit htmlUnit = context.getResolvedHtmlUnit(source); | 2783 ht.HtmlUnit htmlUnit = context.getResolvedHtmlUnit(source); |
2811 htmlUnit.accept(new ExpressionVisitor_AngularTest_verify(verifier)); | 2784 htmlUnit.accept(new ExpressionVisitor_AngularTest_verify(verifier)); |
2812 } | 2785 } |
2813 verifier.assertResolved(); | 2786 verifier.assertResolved(); |
2814 } | 2787 } |
2815 | 2788 |
2816 void _configureForAngular(AnalysisContextHelper contextHelper) { | 2789 void _configureForAngular(AnalysisContextHelper contextHelper) { |
2817 contextHelper.addSource( | 2790 contextHelper.addSource("/angular.dart", r''' |
2818 "/angular.dart", | |
2819 r''' | |
2820 library angular; | 2791 library angular; |
2821 | 2792 |
2822 class Scope { | 2793 class Scope { |
2823 Map context; | 2794 Map context; |
2824 } | 2795 } |
2825 | 2796 |
2826 class Formatter { | 2797 class Formatter { |
2827 final String name; | 2798 final String name; |
2828 const Formatter({this.name}); | 2799 const Formatter({this.name}); |
2829 } | 2800 } |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3176 | 3147 |
3177 void test_equal_invalidRight() { | 3148 void test_equal_invalidRight() { |
3178 EvaluationResult result = _getExpressionValue("2 == a"); | 3149 EvaluationResult result = _getExpressionValue("2 == a"); |
3179 expect(result.isValid, isFalse); | 3150 expect(result.isValid, isFalse); |
3180 } | 3151 } |
3181 | 3152 |
3182 void test_equal_string_string() { | 3153 void test_equal_string_string() { |
3183 _assertValue(false, "'a' == 'b'"); | 3154 _assertValue(false, "'a' == 'b'"); |
3184 } | 3155 } |
3185 | 3156 |
| 3157 void test_greaterThan_int_int() { |
| 3158 _assertValue(false, "2 > 3"); |
| 3159 } |
| 3160 |
3186 void test_greaterThanOrEqual_int_int() { | 3161 void test_greaterThanOrEqual_int_int() { |
3187 _assertValue(false, "2 >= 3"); | 3162 _assertValue(false, "2 >= 3"); |
3188 } | 3163 } |
3189 | 3164 |
3190 void test_greaterThan_int_int() { | |
3191 _assertValue(false, "2 > 3"); | |
3192 } | |
3193 | |
3194 void test_leftShift_int_int() { | 3165 void test_leftShift_int_int() { |
3195 _assertValue3(64, "16 << 2"); | 3166 _assertValue3(64, "16 << 2"); |
3196 } | 3167 } |
| 3168 void test_lessThan_int_int() { |
| 3169 _assertValue(true, "2 < 3"); |
| 3170 } |
| 3171 |
3197 void test_lessThanOrEqual_int_int() { | 3172 void test_lessThanOrEqual_int_int() { |
3198 _assertValue(true, "2 <= 3"); | 3173 _assertValue(true, "2 <= 3"); |
3199 } | 3174 } |
3200 | 3175 |
3201 void test_lessThan_int_int() { | |
3202 _assertValue(true, "2 < 3"); | |
3203 } | |
3204 | |
3205 void test_literal_boolean_false() { | 3176 void test_literal_boolean_false() { |
3206 _assertValue(false, "false"); | 3177 _assertValue(false, "false"); |
3207 } | 3178 } |
3208 | 3179 |
3209 void test_literal_boolean_true() { | 3180 void test_literal_boolean_true() { |
3210 _assertValue(true, "true"); | 3181 _assertValue(true, "true"); |
3211 } | 3182 } |
3212 | 3183 |
3213 void test_literal_list() { | 3184 void test_literal_list() { |
3214 EvaluationResult result = _getExpressionValue("const ['a', 'b', 'c']"); | 3185 EvaluationResult result = _getExpressionValue("const ['a', 'b', 'c']"); |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3550 _validate(true, (members[0] as TopLevelVariableDeclaration).variables); | 3521 _validate(true, (members[0] as TopLevelVariableDeclaration).variables); |
3551 _validate(true, (members[1] as TopLevelVariableDeclaration).variables); | 3522 _validate(true, (members[1] as TopLevelVariableDeclaration).variables); |
3552 } | 3523 } |
3553 | 3524 |
3554 void test_computeValues_empty() { | 3525 void test_computeValues_empty() { |
3555 ConstantValueComputer computer = _makeConstantValueComputer(); | 3526 ConstantValueComputer computer = _makeConstantValueComputer(); |
3556 computer.computeValues(); | 3527 computer.computeValues(); |
3557 } | 3528 } |
3558 | 3529 |
3559 void test_computeValues_multipleSources() { | 3530 void test_computeValues_multipleSources() { |
3560 Source librarySource = addNamedSource( | 3531 Source librarySource = addNamedSource("/lib.dart", r''' |
3561 "/lib.dart", | |
3562 r''' | |
3563 library lib; | 3532 library lib; |
3564 part 'part.dart'; | 3533 part 'part.dart'; |
3565 const int c = b; | 3534 const int c = b; |
3566 const int a = 0;'''); | 3535 const int a = 0;'''); |
3567 Source partSource = addNamedSource( | 3536 Source partSource = addNamedSource("/part.dart", r''' |
3568 "/part.dart", | |
3569 r''' | |
3570 part of lib; | 3537 part of lib; |
3571 const int b = a; | 3538 const int b = a; |
3572 const int d = c;'''); | 3539 const int d = c;'''); |
3573 LibraryElement libraryElement = resolve(librarySource); | 3540 LibraryElement libraryElement = resolve(librarySource); |
3574 CompilationUnit libraryUnit = | 3541 CompilationUnit libraryUnit = |
3575 analysisContext.resolveCompilationUnit(librarySource, libraryElement); | 3542 analysisContext.resolveCompilationUnit(librarySource, libraryElement); |
3576 expect(libraryUnit, isNotNull); | 3543 expect(libraryUnit, isNotNull); |
3577 CompilationUnit partUnit = | 3544 CompilationUnit partUnit = |
3578 analysisContext.resolveCompilationUnit(partSource, libraryElement); | 3545 analysisContext.resolveCompilationUnit(partSource, libraryElement); |
3579 expect(partUnit, isNotNull); | 3546 expect(partUnit, isNotNull); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3747 }'''); | 3714 }'''); |
3748 } | 3715 } |
3749 | 3716 |
3750 void test_dependencyOnNonFactoryRedirect_toMissing() { | 3717 void test_dependencyOnNonFactoryRedirect_toMissing() { |
3751 // a depends on A.foo() which depends on nothing, since A.bar() is | 3718 // a depends on A.foo() which depends on nothing, since A.bar() is |
3752 // missing. | 3719 // missing. |
3753 _assertProperDependencies(r''' | 3720 _assertProperDependencies(r''' |
3754 const A a = const A.foo(); | 3721 const A a = const A.foo(); |
3755 class A { | 3722 class A { |
3756 const A.foo() : this.bar(); | 3723 const A.foo() : this.bar(); |
3757 }''', | 3724 }''', [CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_MISSING_CONSTRUCTOR]); |
3758 [CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_MISSING_CONSTRUCTOR]); | |
3759 } | 3725 } |
3760 | 3726 |
3761 void test_dependencyOnNonFactoryRedirect_toNonConst() { | 3727 void test_dependencyOnNonFactoryRedirect_toNonConst() { |
3762 // a depends on A.foo() which depends on nothing, since A.bar() is | 3728 // a depends on A.foo() which depends on nothing, since A.bar() is |
3763 // non-const. | 3729 // non-const. |
3764 _assertProperDependencies(r''' | 3730 _assertProperDependencies(r''' |
3765 const A a = const A.foo(); | 3731 const A a = const A.foo(); |
3766 class A { | 3732 class A { |
3767 const A.foo() : this.bar(); | 3733 const A.foo() : this.bar(); |
3768 A.bar(); | 3734 A.bar(); |
(...skipping 28 matching lines...) Expand all Loading... |
3797 _assertProperDependencies(r''' | 3763 _assertProperDependencies(r''' |
3798 const x = y + 1; | 3764 const x = y + 1; |
3799 const y = 2;'''); | 3765 const y = 2;'''); |
3800 } | 3766 } |
3801 | 3767 |
3802 void test_fromEnvironment_bool_default_false() { | 3768 void test_fromEnvironment_bool_default_false() { |
3803 expect(_assertValidBool(_check_fromEnvironment_bool(null, "false")), false); | 3769 expect(_assertValidBool(_check_fromEnvironment_bool(null, "false")), false); |
3804 } | 3770 } |
3805 | 3771 |
3806 void test_fromEnvironment_bool_default_overridden() { | 3772 void test_fromEnvironment_bool_default_overridden() { |
3807 expect(_assertValidBool(_check_fromEnvironment_bool("false", "true")), false
); | 3773 expect( |
| 3774 _assertValidBool(_check_fromEnvironment_bool("false", "true")), |
| 3775 false); |
3808 } | 3776 } |
3809 | 3777 |
3810 void test_fromEnvironment_bool_default_parseError() { | 3778 void test_fromEnvironment_bool_default_parseError() { |
3811 expect(_assertValidBool(_check_fromEnvironment_bool("parseError", "true")),
true); | 3779 expect( |
| 3780 _assertValidBool(_check_fromEnvironment_bool("parseError", "true")), |
| 3781 true); |
3812 } | 3782 } |
3813 | 3783 |
3814 void test_fromEnvironment_bool_default_true() { | 3784 void test_fromEnvironment_bool_default_true() { |
3815 expect(_assertValidBool(_check_fromEnvironment_bool(null, "true")), true); | 3785 expect(_assertValidBool(_check_fromEnvironment_bool(null, "true")), true); |
3816 } | 3786 } |
3817 | 3787 |
3818 void test_fromEnvironment_bool_false() { | 3788 void test_fromEnvironment_bool_false() { |
3819 expect(_assertValidBool(_check_fromEnvironment_bool("false", null)), false); | 3789 expect(_assertValidBool(_check_fromEnvironment_bool("false", null)), false); |
3820 } | 3790 } |
3821 | 3791 |
3822 void test_fromEnvironment_bool_parseError() { | 3792 void test_fromEnvironment_bool_parseError() { |
3823 expect(_assertValidBool(_check_fromEnvironment_bool("parseError", null)), fa
lse); | 3793 expect( |
| 3794 _assertValidBool(_check_fromEnvironment_bool("parseError", null)), |
| 3795 false); |
3824 } | 3796 } |
3825 | 3797 |
3826 void test_fromEnvironment_bool_true() { | 3798 void test_fromEnvironment_bool_true() { |
3827 expect(_assertValidBool(_check_fromEnvironment_bool("true", null)), true); | 3799 expect(_assertValidBool(_check_fromEnvironment_bool("true", null)), true); |
3828 } | 3800 } |
3829 | 3801 |
3830 void test_fromEnvironment_bool_undeclared() { | 3802 void test_fromEnvironment_bool_undeclared() { |
3831 _assertValidUnknown(_check_fromEnvironment_bool(null, null)); | 3803 _assertValidUnknown(_check_fromEnvironment_bool(null, null)); |
3832 } | 3804 } |
3833 | 3805 |
3834 void test_fromEnvironment_int_default_overridden() { | 3806 void test_fromEnvironment_int_default_overridden() { |
3835 expect(_assertValidInt(_check_fromEnvironment_int("234", "123")), 234); | 3807 expect(_assertValidInt(_check_fromEnvironment_int("234", "123")), 234); |
3836 } | 3808 } |
3837 | 3809 |
3838 void test_fromEnvironment_int_default_parseError() { | 3810 void test_fromEnvironment_int_default_parseError() { |
3839 expect(_assertValidInt(_check_fromEnvironment_int("parseError", "123")), 123
); | 3811 expect( |
| 3812 _assertValidInt(_check_fromEnvironment_int("parseError", "123")), |
| 3813 123); |
3840 } | 3814 } |
3841 | 3815 |
3842 void test_fromEnvironment_int_default_undeclared() { | 3816 void test_fromEnvironment_int_default_undeclared() { |
3843 expect(_assertValidInt(_check_fromEnvironment_int(null, "123")), 123); | 3817 expect(_assertValidInt(_check_fromEnvironment_int(null, "123")), 123); |
3844 } | 3818 } |
3845 | 3819 |
3846 void test_fromEnvironment_int_ok() { | 3820 void test_fromEnvironment_int_ok() { |
3847 expect(_assertValidInt(_check_fromEnvironment_int("234", null)), 234); | 3821 expect(_assertValidInt(_check_fromEnvironment_int("234", null)), 234); |
3848 } | 3822 } |
3849 | 3823 |
3850 void test_fromEnvironment_int_parseError() { | 3824 void test_fromEnvironment_int_parseError() { |
3851 _assertValidNull(_check_fromEnvironment_int("parseError", null)); | 3825 _assertValidNull(_check_fromEnvironment_int("parseError", null)); |
3852 } | 3826 } |
3853 | 3827 |
3854 void test_fromEnvironment_int_parseError_nullDefault() { | 3828 void test_fromEnvironment_int_parseError_nullDefault() { |
3855 _assertValidNull(_check_fromEnvironment_int("parseError", "null")); | 3829 _assertValidNull(_check_fromEnvironment_int("parseError", "null")); |
3856 } | 3830 } |
3857 | 3831 |
3858 void test_fromEnvironment_int_undeclared() { | 3832 void test_fromEnvironment_int_undeclared() { |
3859 _assertValidUnknown(_check_fromEnvironment_int(null, null)); | 3833 _assertValidUnknown(_check_fromEnvironment_int(null, null)); |
3860 } | 3834 } |
3861 | 3835 |
3862 void test_fromEnvironment_int_undeclared_nullDefault() { | 3836 void test_fromEnvironment_int_undeclared_nullDefault() { |
3863 _assertValidNull(_check_fromEnvironment_int(null, "null")); | 3837 _assertValidNull(_check_fromEnvironment_int(null, "null")); |
3864 } | 3838 } |
3865 | 3839 |
3866 void test_fromEnvironment_string_default_overridden() { | 3840 void test_fromEnvironment_string_default_overridden() { |
3867 expect(_assertValidString(_check_fromEnvironment_string("abc", "'def'")), "a
bc"); | 3841 expect( |
| 3842 _assertValidString(_check_fromEnvironment_string("abc", "'def'")), |
| 3843 "abc"); |
3868 } | 3844 } |
3869 | 3845 |
3870 void test_fromEnvironment_string_default_undeclared() { | 3846 void test_fromEnvironment_string_default_undeclared() { |
3871 expect(_assertValidString(_check_fromEnvironment_string(null, "'def'")), "de
f"); | 3847 expect( |
| 3848 _assertValidString(_check_fromEnvironment_string(null, "'def'")), |
| 3849 "def"); |
3872 } | 3850 } |
3873 | 3851 |
3874 void test_fromEnvironment_string_empty() { | 3852 void test_fromEnvironment_string_empty() { |
3875 expect(_assertValidString(_check_fromEnvironment_string("", null)), ""); | 3853 expect(_assertValidString(_check_fromEnvironment_string("", null)), ""); |
3876 } | 3854 } |
3877 | 3855 |
3878 void test_fromEnvironment_string_ok() { | 3856 void test_fromEnvironment_string_ok() { |
3879 expect(_assertValidString(_check_fromEnvironment_string("abc", null)), "abc"
); | 3857 expect( |
| 3858 _assertValidString(_check_fromEnvironment_string("abc", null)), |
| 3859 "abc"); |
3880 } | 3860 } |
3881 | 3861 |
3882 void test_fromEnvironment_string_undeclared() { | 3862 void test_fromEnvironment_string_undeclared() { |
3883 _assertValidUnknown(_check_fromEnvironment_string(null, null)); | 3863 _assertValidUnknown(_check_fromEnvironment_string(null, null)); |
3884 } | 3864 } |
3885 | 3865 |
3886 void test_fromEnvironment_string_undeclared_nullDefault() { | 3866 void test_fromEnvironment_string_undeclared_nullDefault() { |
3887 _assertValidNull(_check_fromEnvironment_string(null, "null")); | 3867 _assertValidNull(_check_fromEnvironment_string(null, "null")); |
3888 } | 3868 } |
3889 | 3869 |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4053 } | 4033 } |
4054 | 4034 |
4055 void test_instanceCreationExpression_nonFactoryRedirect() { | 4035 void test_instanceCreationExpression_nonFactoryRedirect() { |
4056 CompilationUnit compilationUnit = resolveSource(r''' | 4036 CompilationUnit compilationUnit = resolveSource(r''' |
4057 const foo = const A.a1(); | 4037 const foo = const A.a1(); |
4058 class A { | 4038 class A { |
4059 const A.a1() : this.a2(); | 4039 const A.a1() : this.a2(); |
4060 const A.a2() : x = 5; | 4040 const A.a2() : x = 5; |
4061 final int x; | 4041 final int x; |
4062 }'''); | 4042 }'''); |
4063 Map<String, DartObjectImpl> aFields = _assertType( | 4043 Map<String, DartObjectImpl> aFields = |
4064 _evaluateInstanceCreationExpression(compilationUnit, "foo"), | 4044 _assertType(_evaluateInstanceCreationExpression(compilationUnit, "foo"),
"A"); |
4065 "A"); | |
4066 _assertIntField(aFields, 'x', 5); | 4045 _assertIntField(aFields, 'x', 5); |
4067 } | 4046 } |
4068 | 4047 |
4069 void test_instanceCreationExpression_nonFactoryRedirect_arg() { | 4048 void test_instanceCreationExpression_nonFactoryRedirect_arg() { |
4070 CompilationUnit compilationUnit = resolveSource(r''' | 4049 CompilationUnit compilationUnit = resolveSource(r''' |
4071 const foo = const A.a1(1); | 4050 const foo = const A.a1(1); |
4072 class A { | 4051 class A { |
4073 const A.a1(x) : this.a2(x + 100); | 4052 const A.a1(x) : this.a2(x + 100); |
4074 const A.a2(x) : y = x + 10; | 4053 const A.a2(x) : y = x + 10; |
4075 final int y; | 4054 final int y; |
4076 }'''); | 4055 }'''); |
4077 Map<String, DartObjectImpl> aFields = _assertType( | 4056 Map<String, DartObjectImpl> aFields = |
4078 _evaluateInstanceCreationExpression(compilationUnit, "foo"), | 4057 _assertType(_evaluateInstanceCreationExpression(compilationUnit, "foo"),
"A"); |
4079 "A"); | |
4080 _assertIntField(aFields, 'y', 111); | 4058 _assertIntField(aFields, 'y', 111); |
4081 } | 4059 } |
4082 | 4060 |
4083 void test_instanceCreationExpression_nonFactoryRedirect_cycle() { | 4061 void test_instanceCreationExpression_nonFactoryRedirect_cycle() { |
4084 // It is an error to have a cycle in non-factory redirects; however, we | 4062 // It is an error to have a cycle in non-factory redirects; however, we |
4085 // need to make sure that even if the error occurs, attempting to evaluate | 4063 // need to make sure that even if the error occurs, attempting to evaluate |
4086 // the constant will terminate. | 4064 // the constant will terminate. |
4087 CompilationUnit compilationUnit = resolveSource(r''' | 4065 CompilationUnit compilationUnit = resolveSource(r''' |
4088 const foo = const A(); | 4066 const foo = const A(); |
4089 class A { | 4067 class A { |
4090 const A() : this.b(); | 4068 const A() : this.b(); |
4091 const A.b() : this(); | 4069 const A.b() : this(); |
4092 }'''); | 4070 }'''); |
4093 _assertValidUnknown( | 4071 _assertValidUnknown( |
4094 _evaluateInstanceCreationExpression(compilationUnit, "foo")); | 4072 _evaluateInstanceCreationExpression(compilationUnit, "foo")); |
4095 } | 4073 } |
4096 | 4074 |
4097 void test_instanceCreationExpression_nonFactoryRedirect_defaultArg() { | 4075 void test_instanceCreationExpression_nonFactoryRedirect_defaultArg() { |
4098 CompilationUnit compilationUnit = resolveSource(r''' | 4076 CompilationUnit compilationUnit = resolveSource(r''' |
4099 const foo = const A.a1(); | 4077 const foo = const A.a1(); |
4100 class A { | 4078 class A { |
4101 const A.a1() : this.a2(); | 4079 const A.a1() : this.a2(); |
4102 const A.a2([x = 100]) : y = x + 10; | 4080 const A.a2([x = 100]) : y = x + 10; |
4103 final int y; | 4081 final int y; |
4104 }'''); | 4082 }'''); |
4105 Map<String, DartObjectImpl> aFields = _assertType( | 4083 Map<String, DartObjectImpl> aFields = |
4106 _evaluateInstanceCreationExpression(compilationUnit, "foo"), | 4084 _assertType(_evaluateInstanceCreationExpression(compilationUnit, "foo"),
"A"); |
4107 "A"); | |
4108 _assertIntField(aFields, 'y', 110); | 4085 _assertIntField(aFields, 'y', 110); |
4109 } | 4086 } |
4110 | 4087 |
4111 void test_instanceCreationExpression_nonFactoryRedirect_toMissing() { | 4088 void test_instanceCreationExpression_nonFactoryRedirect_toMissing() { |
4112 CompilationUnit compilationUnit = resolveSource(r''' | 4089 CompilationUnit compilationUnit = resolveSource(r''' |
4113 const foo = const A.a1(); | 4090 const foo = const A.a1(); |
4114 class A { | 4091 class A { |
4115 const A.a1() : this.a2(); | 4092 const A.a1() : this.a2(); |
4116 }'''); | 4093 }'''); |
4117 // We don't care what value foo evaluates to (since there is a compile | 4094 // We don't care what value foo evaluates to (since there is a compile |
(...skipping 20 matching lines...) Expand all Loading... |
4138 } | 4115 } |
4139 | 4116 |
4140 void test_instanceCreationExpression_nonFactoryRedirect_unnamed() { | 4117 void test_instanceCreationExpression_nonFactoryRedirect_unnamed() { |
4141 CompilationUnit compilationUnit = resolveSource(r''' | 4118 CompilationUnit compilationUnit = resolveSource(r''' |
4142 const foo = const A.a1(); | 4119 const foo = const A.a1(); |
4143 class A { | 4120 class A { |
4144 const A.a1() : this(); | 4121 const A.a1() : this(); |
4145 const A() : x = 5; | 4122 const A() : x = 5; |
4146 final int x; | 4123 final int x; |
4147 }'''); | 4124 }'''); |
4148 Map<String, DartObjectImpl> aFields = _assertType( | 4125 Map<String, DartObjectImpl> aFields = |
4149 _evaluateInstanceCreationExpression(compilationUnit, "foo"), | 4126 _assertType(_evaluateInstanceCreationExpression(compilationUnit, "foo"),
"A"); |
4150 "A"); | |
4151 _assertIntField(aFields, 'x', 5); | 4127 _assertIntField(aFields, 'x', 5); |
4152 } | 4128 } |
4153 | 4129 |
4154 void test_instanceCreationExpression_redirect() { | 4130 void test_instanceCreationExpression_redirect() { |
4155 CompilationUnit compilationUnit = resolveSource(r''' | 4131 CompilationUnit compilationUnit = resolveSource(r''' |
4156 const foo = const A(); | 4132 const foo = const A(); |
4157 class A { | 4133 class A { |
4158 const factory A() = B; | 4134 const factory A() = B; |
4159 } | 4135 } |
4160 class B implements A { | 4136 class B implements A { |
4161 const B(); | 4137 const B(); |
4162 }'''); | 4138 }'''); |
4163 _assertType( | 4139 _assertType( |
4164 _evaluateInstanceCreationExpression(compilationUnit, "foo"), | 4140 _evaluateInstanceCreationExpression(compilationUnit, "foo"), |
4165 "B"); | 4141 "B"); |
4166 } | 4142 } |
4167 | 4143 |
| 4144 void test_instanceCreationExpression_redirect_cycle() { |
| 4145 // It is an error to have a cycle in factory redirects; however, we need |
| 4146 // to make sure that even if the error occurs, attempting to evaluate the |
| 4147 // constant will terminate. |
| 4148 CompilationUnit compilationUnit = resolveSource(r''' |
| 4149 const foo = const A(); |
| 4150 class A { |
| 4151 const factory A() = A.b; |
| 4152 const factory A.b() = A; |
| 4153 }'''); |
| 4154 _assertValidUnknown( |
| 4155 _evaluateInstanceCreationExpression(compilationUnit, "foo")); |
| 4156 } |
| 4157 |
| 4158 void test_instanceCreationExpression_redirect_extern() { |
| 4159 CompilationUnit compilationUnit = resolveSource(r''' |
| 4160 const foo = const A(); |
| 4161 class A { |
| 4162 external const factory A(); |
| 4163 }'''); |
| 4164 _assertValidUnknown( |
| 4165 _evaluateInstanceCreationExpression(compilationUnit, "foo")); |
| 4166 } |
| 4167 |
| 4168 void test_instanceCreationExpression_redirect_nonConst() { |
| 4169 // It is an error for a const factory constructor redirect to a non-const |
| 4170 // constructor; however, we need to make sure that even if the error |
| 4171 // attempting to evaluate the constant won't cause a crash. |
| 4172 CompilationUnit compilationUnit = resolveSource(r''' |
| 4173 const foo = const A(); |
| 4174 class A { |
| 4175 const factory A() = A.b; |
| 4176 A.b(); |
| 4177 }'''); |
| 4178 _assertValidUnknown( |
| 4179 _evaluateInstanceCreationExpression(compilationUnit, "foo")); |
| 4180 } |
| 4181 |
4168 void test_instanceCreationExpression_redirectWithTypeParams() { | 4182 void test_instanceCreationExpression_redirectWithTypeParams() { |
4169 CompilationUnit compilationUnit = resolveSource(r''' | 4183 CompilationUnit compilationUnit = resolveSource(r''' |
4170 class A { | 4184 class A { |
4171 const factory A(var a) = B<int>; | 4185 const factory A(var a) = B<int>; |
4172 } | 4186 } |
4173 | 4187 |
4174 class B<T> implements A { | 4188 class B<T> implements A { |
4175 final T x; | 4189 final T x; |
4176 const B(this.x); | 4190 const B(this.x); |
4177 } | 4191 } |
(...skipping 21 matching lines...) Expand all Loading... |
4199 } | 4213 } |
4200 | 4214 |
4201 const A<int> a = const A<int>(10);'''); | 4215 const A<int> a = const A<int>(10);'''); |
4202 EvaluationResultImpl result = | 4216 EvaluationResultImpl result = |
4203 _evaluateInstanceCreationExpression(compilationUnit, "a"); | 4217 _evaluateInstanceCreationExpression(compilationUnit, "a"); |
4204 Map<String, DartObjectImpl> fields = _assertType(result, "B<int>"); | 4218 Map<String, DartObjectImpl> fields = _assertType(result, "B<int>"); |
4205 expect(fields, hasLength(1)); | 4219 expect(fields, hasLength(1)); |
4206 _assertIntField(fields, "x", 10); | 4220 _assertIntField(fields, "x", 10); |
4207 } | 4221 } |
4208 | 4222 |
4209 void test_instanceCreationExpression_redirect_cycle() { | |
4210 // It is an error to have a cycle in factory redirects; however, we need | |
4211 // to make sure that even if the error occurs, attempting to evaluate the | |
4212 // constant will terminate. | |
4213 CompilationUnit compilationUnit = resolveSource(r''' | |
4214 const foo = const A(); | |
4215 class A { | |
4216 const factory A() = A.b; | |
4217 const factory A.b() = A; | |
4218 }'''); | |
4219 _assertValidUnknown( | |
4220 _evaluateInstanceCreationExpression(compilationUnit, "foo")); | |
4221 } | |
4222 | |
4223 void test_instanceCreationExpression_redirect_extern() { | |
4224 CompilationUnit compilationUnit = resolveSource(r''' | |
4225 const foo = const A(); | |
4226 class A { | |
4227 external const factory A(); | |
4228 }'''); | |
4229 _assertValidUnknown( | |
4230 _evaluateInstanceCreationExpression(compilationUnit, "foo")); | |
4231 } | |
4232 | |
4233 void test_instanceCreationExpression_redirect_nonConst() { | |
4234 // It is an error for a const factory constructor redirect to a non-const | |
4235 // constructor; however, we need to make sure that even if the error | |
4236 // attempting to evaluate the constant won't cause a crash. | |
4237 CompilationUnit compilationUnit = resolveSource(r''' | |
4238 const foo = const A(); | |
4239 class A { | |
4240 const factory A() = A.b; | |
4241 A.b(); | |
4242 }'''); | |
4243 _assertValidUnknown( | |
4244 _evaluateInstanceCreationExpression(compilationUnit, "foo")); | |
4245 } | |
4246 | |
4247 void test_instanceCreationExpression_symbol() { | 4223 void test_instanceCreationExpression_symbol() { |
4248 CompilationUnit compilationUnit = | 4224 CompilationUnit compilationUnit = |
4249 resolveSource("const foo = const Symbol('a');"); | 4225 resolveSource("const foo = const Symbol('a');"); |
4250 EvaluationResultImpl evaluationResult = | 4226 EvaluationResultImpl evaluationResult = |
4251 _evaluateInstanceCreationExpression(compilationUnit, "foo"); | 4227 _evaluateInstanceCreationExpression(compilationUnit, "foo"); |
4252 expect(evaluationResult.value, isNotNull); | 4228 expect(evaluationResult.value, isNotNull); |
4253 DartObjectImpl value = evaluationResult.value; | 4229 DartObjectImpl value = evaluationResult.value; |
4254 expect(value.type, typeProvider.symbolType); | 4230 expect(value.type, typeProvider.symbolType); |
4255 expect(value.value, "a"); | 4231 expect(value.value, "a"); |
4256 } | 4232 } |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4388 expect(value.type, typeProvider.stringType); | 4364 expect(value.type, typeProvider.stringType); |
4389 return value.stringValue; | 4365 return value.stringValue; |
4390 } | 4366 } |
4391 | 4367 |
4392 void _assertValidUnknown(EvaluationResultImpl result) { | 4368 void _assertValidUnknown(EvaluationResultImpl result) { |
4393 expect(result.value, isNotNull); | 4369 expect(result.value, isNotNull); |
4394 DartObjectImpl value = result.value; | 4370 DartObjectImpl value = result.value; |
4395 expect(value.isUnknown, isTrue); | 4371 expect(value.isUnknown, isTrue); |
4396 } | 4372 } |
4397 | 4373 |
4398 void _checkInstanceCreationOptionalParams(bool isFieldFormal, bool isNamed, | |
4399 bool hasDefault) { | |
4400 String fieldName = "j"; | |
4401 String paramName = isFieldFormal ? fieldName : "i"; | |
4402 String formalParam = | |
4403 "${isFieldFormal ? "this." : "int "}$paramName${hasDefault ? " = 3" : ""
}"; | |
4404 CompilationUnit compilationUnit = resolveSource(""" | |
4405 const x = const A(); | |
4406 const y = const A(${isNamed ? '$paramName: ' : ''}10); | |
4407 class A { | |
4408 const A(${isNamed ? "{$formalParam}" : "[$formalParam]"})${isFieldFormal ? ""
: " : $fieldName = $paramName"}; | |
4409 final int $fieldName; | |
4410 }"""); | |
4411 EvaluationResultImpl x = | |
4412 _evaluateInstanceCreationExpression(compilationUnit, "x"); | |
4413 Map<String, DartObjectImpl> fieldsOfX = _assertType(x, "A"); | |
4414 expect(fieldsOfX, hasLength(1)); | |
4415 if (hasDefault) { | |
4416 _assertIntField(fieldsOfX, fieldName, 3); | |
4417 } else { | |
4418 _assertNullField(fieldsOfX, fieldName); | |
4419 } | |
4420 EvaluationResultImpl y = | |
4421 _evaluateInstanceCreationExpression(compilationUnit, "y"); | |
4422 Map<String, DartObjectImpl> fieldsOfY = _assertType(y, "A"); | |
4423 expect(fieldsOfY, hasLength(1)); | |
4424 _assertIntField(fieldsOfY, fieldName, 10); | |
4425 } | |
4426 | |
4427 void _checkInstanceCreation_withSupertypeParams(bool isExplicit) { | |
4428 String superCall = isExplicit ? " : super()" : ""; | |
4429 CompilationUnit compilationUnit = resolveSource(""" | |
4430 class A<T> { | |
4431 const A(); | |
4432 } | |
4433 class B<T, U> extends A<T> { | |
4434 const B()$superCall; | |
4435 } | |
4436 class C<T, U> extends A<U> { | |
4437 const C()$superCall; | |
4438 } | |
4439 const b_int_num = const B<int, num>(); | |
4440 const c_int_num = const C<int, num>();"""); | |
4441 EvaluationResultImpl b_int_num = | |
4442 _evaluateInstanceCreationExpression(compilationUnit, "b_int_num"); | |
4443 Map<String, DartObjectImpl> b_int_num_fields = | |
4444 _assertType(b_int_num, "B<int, num>"); | |
4445 _assertFieldType(b_int_num_fields, GenericState.SUPERCLASS_FIELD, "A<int>"); | |
4446 EvaluationResultImpl c_int_num = | |
4447 _evaluateInstanceCreationExpression(compilationUnit, "c_int_num"); | |
4448 Map<String, DartObjectImpl> c_int_num_fields = | |
4449 _assertType(c_int_num, "C<int, num>"); | |
4450 _assertFieldType(c_int_num_fields, GenericState.SUPERCLASS_FIELD, "A<num>"); | |
4451 } | |
4452 | |
4453 EvaluationResultImpl _check_fromEnvironment_bool(String valueInEnvironment, | 4374 EvaluationResultImpl _check_fromEnvironment_bool(String valueInEnvironment, |
4454 String defaultExpr) { | 4375 String defaultExpr) { |
4455 String envVarName = "x"; | 4376 String envVarName = "x"; |
4456 String varName = "foo"; | 4377 String varName = "foo"; |
| 4378 if (valueInEnvironment != null) { |
| 4379 analysisContext2.declaredVariables.define(envVarName, valueInEnvironment); |
| 4380 } |
| 4381 String defaultArg = |
| 4382 defaultExpr == null ? "" : ", defaultValue: $defaultExpr"; |
| 4383 CompilationUnit compilationUnit = resolveSource( |
| 4384 "const $varName = const bool.fromEnvironment('$envVarName'$defaultArg);"
); |
| 4385 return _evaluateInstanceCreationExpression(compilationUnit, varName); |
| 4386 } |
| 4387 |
| 4388 EvaluationResultImpl _check_fromEnvironment_int(String valueInEnvironment, |
| 4389 String defaultExpr) { |
| 4390 String envVarName = "x"; |
| 4391 String varName = "foo"; |
4457 if (valueInEnvironment != null) { | 4392 if (valueInEnvironment != null) { |
4458 analysisContext2.declaredVariables.define(envVarName, valueInEnvironment); | 4393 analysisContext2.declaredVariables.define(envVarName, valueInEnvironment); |
4459 } | 4394 } |
4460 String defaultArg = | 4395 String defaultArg = |
4461 defaultExpr == null ? "" : ", defaultValue: $defaultExpr"; | 4396 defaultExpr == null ? "" : ", defaultValue: $defaultExpr"; |
4462 CompilationUnit compilationUnit = resolveSource( | 4397 CompilationUnit compilationUnit = resolveSource( |
4463 "const $varName = const bool.fromEnvironment('$envVarName'$defau
ltArg);"); | 4398 "const $varName = const int.fromEnvironment('$envVarName'$defaultArg);")
; |
4464 return _evaluateInstanceCreationExpression(compilationUnit, varName); | 4399 return _evaluateInstanceCreationExpression(compilationUnit, varName); |
4465 } | 4400 } |
4466 | 4401 |
4467 EvaluationResultImpl _check_fromEnvironment_int(String valueInEnvironment, | 4402 EvaluationResultImpl _check_fromEnvironment_string(String valueInEnvironment, |
4468 String defaultExpr) { | 4403 String defaultExpr) { |
4469 String envVarName = "x"; | 4404 String envVarName = "x"; |
4470 String varName = "foo"; | 4405 String varName = "foo"; |
4471 if (valueInEnvironment != null) { | 4406 if (valueInEnvironment != null) { |
4472 analysisContext2.declaredVariables.define(envVarName, valueInEnvironment); | 4407 analysisContext2.declaredVariables.define(envVarName, valueInEnvironment); |
4473 } | 4408 } |
4474 String defaultArg = | 4409 String defaultArg = |
4475 defaultExpr == null ? "" : ", defaultValue: $defaultExpr"; | 4410 defaultExpr == null ? "" : ", defaultValue: $defaultExpr"; |
4476 CompilationUnit compilationUnit = resolveSource( | 4411 CompilationUnit compilationUnit = resolveSource( |
4477 "const $varName = const int.fromEnvironment('$envVarName'$defaul
tArg);"); | 4412 "const $varName = const String.fromEnvironment('$envVarName'$defaultArg)
;"); |
4478 return _evaluateInstanceCreationExpression(compilationUnit, varName); | 4413 return _evaluateInstanceCreationExpression(compilationUnit, varName); |
4479 } | 4414 } |
4480 | 4415 |
4481 EvaluationResultImpl _check_fromEnvironment_string(String valueInEnvironment, | 4416 void _checkInstanceCreation_withSupertypeParams(bool isExplicit) { |
4482 String defaultExpr) { | 4417 String superCall = isExplicit ? " : super()" : ""; |
4483 String envVarName = "x"; | 4418 CompilationUnit compilationUnit = resolveSource(""" |
4484 String varName = "foo"; | 4419 class A<T> { |
4485 if (valueInEnvironment != null) { | 4420 const A(); |
4486 analysisContext2.declaredVariables.define(envVarName, valueInEnvironment); | 4421 } |
| 4422 class B<T, U> extends A<T> { |
| 4423 const B()$superCall; |
| 4424 } |
| 4425 class C<T, U> extends A<U> { |
| 4426 const C()$superCall; |
| 4427 } |
| 4428 const b_int_num = const B<int, num>(); |
| 4429 const c_int_num = const C<int, num>();"""); |
| 4430 EvaluationResultImpl b_int_num = |
| 4431 _evaluateInstanceCreationExpression(compilationUnit, "b_int_num"); |
| 4432 Map<String, DartObjectImpl> b_int_num_fields = |
| 4433 _assertType(b_int_num, "B<int, num>"); |
| 4434 _assertFieldType(b_int_num_fields, GenericState.SUPERCLASS_FIELD, "A<int>"); |
| 4435 EvaluationResultImpl c_int_num = |
| 4436 _evaluateInstanceCreationExpression(compilationUnit, "c_int_num"); |
| 4437 Map<String, DartObjectImpl> c_int_num_fields = |
| 4438 _assertType(c_int_num, "C<int, num>"); |
| 4439 _assertFieldType(c_int_num_fields, GenericState.SUPERCLASS_FIELD, "A<num>"); |
| 4440 } |
| 4441 |
| 4442 void _checkInstanceCreationOptionalParams(bool isFieldFormal, bool isNamed, |
| 4443 bool hasDefault) { |
| 4444 String fieldName = "j"; |
| 4445 String paramName = isFieldFormal ? fieldName : "i"; |
| 4446 String formalParam = |
| 4447 "${isFieldFormal ? "this." : "int "}$paramName${hasDefault ? " = 3" : ""
}"; |
| 4448 CompilationUnit compilationUnit = resolveSource(""" |
| 4449 const x = const A(); |
| 4450 const y = const A(${isNamed ? '$paramName: ' : ''}10); |
| 4451 class A { |
| 4452 const A(${isNamed ? "{$formalParam}" : "[$formalParam]"})${isFieldFormal ? ""
: " : $fieldName = $paramName"}; |
| 4453 final int $fieldName; |
| 4454 }"""); |
| 4455 EvaluationResultImpl x = |
| 4456 _evaluateInstanceCreationExpression(compilationUnit, "x"); |
| 4457 Map<String, DartObjectImpl> fieldsOfX = _assertType(x, "A"); |
| 4458 expect(fieldsOfX, hasLength(1)); |
| 4459 if (hasDefault) { |
| 4460 _assertIntField(fieldsOfX, fieldName, 3); |
| 4461 } else { |
| 4462 _assertNullField(fieldsOfX, fieldName); |
4487 } | 4463 } |
4488 String defaultArg = | 4464 EvaluationResultImpl y = |
4489 defaultExpr == null ? "" : ", defaultValue: $defaultExpr"; | 4465 _evaluateInstanceCreationExpression(compilationUnit, "y"); |
4490 CompilationUnit compilationUnit = resolveSource( | 4466 Map<String, DartObjectImpl> fieldsOfY = _assertType(y, "A"); |
4491 "const $varName = const String.fromEnvironment('$envVarName'$def
aultArg);"); | 4467 expect(fieldsOfY, hasLength(1)); |
4492 return _evaluateInstanceCreationExpression(compilationUnit, varName); | 4468 _assertIntField(fieldsOfY, fieldName, 10); |
4493 } | 4469 } |
4494 | 4470 |
4495 EvaluationResultImpl | 4471 EvaluationResultImpl |
4496 _evaluateInstanceCreationExpression(CompilationUnit compilationUnit, | 4472 _evaluateInstanceCreationExpression(CompilationUnit compilationUnit, |
4497 String name) { | 4473 String name) { |
4498 Expression expression = | 4474 Expression expression = |
4499 findTopLevelConstantExpression(compilationUnit, name); | 4475 findTopLevelConstantExpression(compilationUnit, name); |
4500 return (expression as InstanceCreationExpression).evaluationResult; | 4476 return (expression as InstanceCreationExpression).evaluationResult; |
4501 } | 4477 } |
4502 | 4478 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4553 GatheringErrorListener errorListener = new GatheringErrorListener(); | 4529 GatheringErrorListener errorListener = new GatheringErrorListener(); |
4554 ErrorReporter errorReporter = | 4530 ErrorReporter errorReporter = |
4555 new ErrorReporter(errorListener, _dummySource()); | 4531 new ErrorReporter(errorListener, _dummySource()); |
4556 _assertValue( | 4532 _assertValue( |
4557 0, | 4533 0, |
4558 expression.accept( | 4534 expression.accept( |
4559 new ConstantVisitor.con1(new TestTypeProvider(), errorReporter))); | 4535 new ConstantVisitor.con1(new TestTypeProvider(), errorReporter))); |
4560 errorListener.assertNoErrors(); | 4536 errorListener.assertNoErrors(); |
4561 } | 4537 } |
4562 | 4538 |
4563 void test_visitConditionalExpression_instanceCreation_invalidFieldInitializer(
) { | 4539 void |
| 4540 test_visitConditionalExpression_instanceCreation_invalidFieldInitializer()
{ |
4564 TestTypeProvider typeProvider = new TestTypeProvider(); | 4541 TestTypeProvider typeProvider = new TestTypeProvider(); |
4565 LibraryElementImpl libraryElement = ElementFactory.library(null, "lib"); | 4542 LibraryElementImpl libraryElement = ElementFactory.library(null, "lib"); |
4566 String className = "C"; | 4543 String className = "C"; |
4567 ClassElementImpl classElement = ElementFactory.classElement2(className); | 4544 ClassElementImpl classElement = ElementFactory.classElement2(className); |
4568 (libraryElement.definingCompilationUnit as CompilationUnitElementImpl).types
= | 4545 (libraryElement.definingCompilationUnit as CompilationUnitElementImpl).types
= |
4569 <ClassElement>[classElement]; | 4546 <ClassElement>[classElement]; |
4570 ConstructorElementImpl constructorElement = | 4547 ConstructorElementImpl constructorElement = |
4571 ElementFactory.constructorElement( | 4548 ElementFactory.constructorElement( |
4572 classElement, | 4549 classElement, |
4573 null, | 4550 null, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4652 ErrorReporter errorReporter = | 4629 ErrorReporter errorReporter = |
4653 new ErrorReporter(errorListener, _dummySource()); | 4630 new ErrorReporter(errorListener, _dummySource()); |
4654 _assertValue( | 4631 _assertValue( |
4655 1, | 4632 1, |
4656 expression.accept( | 4633 expression.accept( |
4657 new ConstantVisitor.con1(new TestTypeProvider(), errorReporter))); | 4634 new ConstantVisitor.con1(new TestTypeProvider(), errorReporter))); |
4658 errorListener.assertNoErrors(); | 4635 errorListener.assertNoErrors(); |
4659 } | 4636 } |
4660 | 4637 |
4661 void test_visitSimpleIdentifier_inEnvironment() { | 4638 void test_visitSimpleIdentifier_inEnvironment() { |
4662 CompilationUnit compilationUnit = | 4639 CompilationUnit compilationUnit = resolveSource(r''' |
4663 resolveSource(r''' | |
4664 const a = b; | 4640 const a = b; |
4665 const b = 3;'''); | 4641 const b = 3;'''); |
4666 Map<String, DartObjectImpl> environment = new Map<String, DartObjectImpl>(); | 4642 Map<String, DartObjectImpl> environment = new Map<String, DartObjectImpl>(); |
4667 DartObjectImpl six = | 4643 DartObjectImpl six = |
4668 new DartObjectImpl(typeProvider.intType, new IntState(6)); | 4644 new DartObjectImpl(typeProvider.intType, new IntState(6)); |
4669 environment["b"] = six; | 4645 environment["b"] = six; |
4670 _assertValue(6, _evaluateConstant(compilationUnit, "a", environment)); | 4646 _assertValue(6, _evaluateConstant(compilationUnit, "a", environment)); |
4671 } | 4647 } |
4672 | 4648 |
4673 void test_visitSimpleIdentifier_notInEnvironment() { | 4649 void test_visitSimpleIdentifier_notInEnvironment() { |
4674 CompilationUnit compilationUnit = | 4650 CompilationUnit compilationUnit = resolveSource(r''' |
4675 resolveSource(r''' | |
4676 const a = b; | 4651 const a = b; |
4677 const b = 3;'''); | 4652 const b = 3;'''); |
4678 Map<String, DartObjectImpl> environment = new Map<String, DartObjectImpl>(); | 4653 Map<String, DartObjectImpl> environment = new Map<String, DartObjectImpl>(); |
4679 DartObjectImpl six = | 4654 DartObjectImpl six = |
4680 new DartObjectImpl(typeProvider.intType, new IntState(6)); | 4655 new DartObjectImpl(typeProvider.intType, new IntState(6)); |
4681 environment["c"] = six; | 4656 environment["c"] = six; |
4682 _assertValue(3, _evaluateConstant(compilationUnit, "a", environment)); | 4657 _assertValue(3, _evaluateConstant(compilationUnit, "a", environment)); |
4683 } | 4658 } |
4684 | 4659 |
4685 void test_visitSimpleIdentifier_withoutEnvironment() { | 4660 void test_visitSimpleIdentifier_withoutEnvironment() { |
4686 CompilationUnit compilationUnit = | 4661 CompilationUnit compilationUnit = resolveSource(r''' |
4687 resolveSource(r''' | |
4688 const a = b; | 4662 const a = b; |
4689 const b = 3;'''); | 4663 const b = 3;'''); |
4690 _assertValue(3, _evaluateConstant(compilationUnit, "a", null)); | 4664 _assertValue(3, _evaluateConstant(compilationUnit, "a", null)); |
4691 } | 4665 } |
4692 | 4666 |
4693 void _assertValue(int expectedValue, DartObjectImpl result) { | 4667 void _assertValue(int expectedValue, DartObjectImpl result) { |
4694 expect(result, isNotNull); | 4668 expect(result, isNotNull); |
4695 expect(result.type.name, "int"); | 4669 expect(result.type.name, "int"); |
4696 expect(result.intValue, expectedValue); | 4670 expect(result.intValue, expectedValue); |
4697 } | 4671 } |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5043 } | 5017 } |
5044 | 5018 |
5045 void test_equalEqual_string_unknown() { | 5019 void test_equalEqual_string_unknown() { |
5046 _assertEqualEqual( | 5020 _assertEqualEqual( |
5047 _boolValue(null), | 5021 _boolValue(null), |
5048 _stringValue(null), | 5022 _stringValue(null), |
5049 _stringValue("def")); | 5023 _stringValue("def")); |
5050 } | 5024 } |
5051 | 5025 |
5052 void test_equals_list_false_differentSizes() { | 5026 void test_equals_list_false_differentSizes() { |
5053 expect(_listValue([_boolValue(true)]) == | 5027 expect( |
5054 _listValue([_boolValue(true), _boolValue(false)]), isFalse); | 5028 _listValue([_boolValue(true)]) == |
| 5029 _listValue([_boolValue(true), _boolValue(false)]), |
| 5030 isFalse); |
5055 } | 5031 } |
5056 | 5032 |
5057 void test_equals_list_false_sameSize() { | 5033 void test_equals_list_false_sameSize() { |
5058 expect(_listValue([_boolValue(true)]) == _listValue([_boolValue(false)]), is
False); | 5034 expect( |
| 5035 _listValue([_boolValue(true)]) == _listValue([_boolValue(false)]), |
| 5036 isFalse); |
5059 } | 5037 } |
5060 | 5038 |
5061 void test_equals_list_true_empty() { | 5039 void test_equals_list_true_empty() { |
5062 expect(_listValue(), _listValue()); | 5040 expect(_listValue(), _listValue()); |
5063 } | 5041 } |
5064 | 5042 |
5065 void test_equals_list_true_nonEmpty() { | 5043 void test_equals_list_true_nonEmpty() { |
5066 expect(_listValue([_boolValue(true)]), _listValue([_boolValue(true)])); | 5044 expect(_listValue([_boolValue(true)]), _listValue([_boolValue(true)])); |
5067 } | 5045 } |
5068 | 5046 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5143 | 5121 |
5144 void test_getValue_string_known() { | 5122 void test_getValue_string_known() { |
5145 String value = "twenty-three"; | 5123 String value = "twenty-three"; |
5146 expect(_stringValue(value).value, value); | 5124 expect(_stringValue(value).value, value); |
5147 } | 5125 } |
5148 | 5126 |
5149 void test_getValue_string_unknown() { | 5127 void test_getValue_string_unknown() { |
5150 expect(_stringValue(null).value, isNull); | 5128 expect(_stringValue(null).value, isNull); |
5151 } | 5129 } |
5152 | 5130 |
| 5131 void test_greaterThan_knownDouble_knownDouble_false() { |
| 5132 _assertGreaterThan(_boolValue(false), _doubleValue(1.0), _doubleValue(2.0)); |
| 5133 } |
| 5134 |
| 5135 void test_greaterThan_knownDouble_knownDouble_true() { |
| 5136 _assertGreaterThan(_boolValue(true), _doubleValue(2.0), _doubleValue(1.0)); |
| 5137 } |
| 5138 |
| 5139 void test_greaterThan_knownDouble_knownInt_false() { |
| 5140 _assertGreaterThan(_boolValue(false), _doubleValue(1.0), _intValue(2)); |
| 5141 } |
| 5142 |
| 5143 void test_greaterThan_knownDouble_knownInt_true() { |
| 5144 _assertGreaterThan(_boolValue(true), _doubleValue(2.0), _intValue(1)); |
| 5145 } |
| 5146 |
| 5147 void test_greaterThan_knownDouble_unknownDouble() { |
| 5148 _assertGreaterThan(_boolValue(null), _doubleValue(1.0), _doubleValue(null)); |
| 5149 } |
| 5150 |
| 5151 void test_greaterThan_knownDouble_unknownInt() { |
| 5152 _assertGreaterThan(_boolValue(null), _doubleValue(1.0), _intValue(null)); |
| 5153 } |
| 5154 |
| 5155 void test_greaterThan_knownInt_knownInt_false() { |
| 5156 _assertGreaterThan(_boolValue(false), _intValue(1), _intValue(2)); |
| 5157 } |
| 5158 |
| 5159 void test_greaterThan_knownInt_knownInt_true() { |
| 5160 _assertGreaterThan(_boolValue(true), _intValue(2), _intValue(1)); |
| 5161 } |
| 5162 |
| 5163 void test_greaterThan_knownInt_knownString() { |
| 5164 _assertGreaterThan(null, _intValue(1), _stringValue("2")); |
| 5165 } |
| 5166 |
| 5167 void test_greaterThan_knownInt_unknownDouble() { |
| 5168 _assertGreaterThan(_boolValue(null), _intValue(1), _doubleValue(null)); |
| 5169 } |
| 5170 |
| 5171 void test_greaterThan_knownInt_unknownInt() { |
| 5172 _assertGreaterThan(_boolValue(null), _intValue(1), _intValue(null)); |
| 5173 } |
| 5174 |
| 5175 void test_greaterThan_knownString_knownInt() { |
| 5176 _assertGreaterThan(null, _stringValue("1"), _intValue(2)); |
| 5177 } |
| 5178 |
| 5179 void test_greaterThan_unknownDouble_knownDouble() { |
| 5180 _assertGreaterThan(_boolValue(null), _doubleValue(null), _doubleValue(2.0)); |
| 5181 } |
| 5182 |
| 5183 void test_greaterThan_unknownDouble_knownInt() { |
| 5184 _assertGreaterThan(_boolValue(null), _doubleValue(null), _intValue(2)); |
| 5185 } |
| 5186 |
| 5187 void test_greaterThan_unknownInt_knownDouble() { |
| 5188 _assertGreaterThan(_boolValue(null), _intValue(null), _doubleValue(2.0)); |
| 5189 } |
| 5190 |
| 5191 void test_greaterThan_unknownInt_knownInt() { |
| 5192 _assertGreaterThan(_boolValue(null), _intValue(null), _intValue(2)); |
| 5193 } |
| 5194 |
5153 void test_greaterThanOrEqual_knownDouble_knownDouble_false() { | 5195 void test_greaterThanOrEqual_knownDouble_knownDouble_false() { |
5154 _assertGreaterThanOrEqual( | 5196 _assertGreaterThanOrEqual( |
5155 _boolValue(false), | 5197 _boolValue(false), |
5156 _doubleValue(1.0), | 5198 _doubleValue(1.0), |
5157 _doubleValue(2.0)); | 5199 _doubleValue(2.0)); |
5158 } | 5200 } |
5159 | 5201 |
5160 void test_greaterThanOrEqual_knownDouble_knownDouble_true() { | 5202 void test_greaterThanOrEqual_knownDouble_knownDouble_true() { |
5161 _assertGreaterThanOrEqual( | 5203 _assertGreaterThanOrEqual( |
5162 _boolValue(true), | 5204 _boolValue(true), |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5237 _assertGreaterThanOrEqual( | 5279 _assertGreaterThanOrEqual( |
5238 _boolValue(null), | 5280 _boolValue(null), |
5239 _intValue(null), | 5281 _intValue(null), |
5240 _doubleValue(2.0)); | 5282 _doubleValue(2.0)); |
5241 } | 5283 } |
5242 | 5284 |
5243 void test_greaterThanOrEqual_unknownInt_knownInt() { | 5285 void test_greaterThanOrEqual_unknownInt_knownInt() { |
5244 _assertGreaterThanOrEqual(_boolValue(null), _intValue(null), _intValue(2)); | 5286 _assertGreaterThanOrEqual(_boolValue(null), _intValue(null), _intValue(2)); |
5245 } | 5287 } |
5246 | 5288 |
5247 void test_greaterThan_knownDouble_knownDouble_false() { | |
5248 _assertGreaterThan(_boolValue(false), _doubleValue(1.0), _doubleValue(2.0)); | |
5249 } | |
5250 | |
5251 void test_greaterThan_knownDouble_knownDouble_true() { | |
5252 _assertGreaterThan(_boolValue(true), _doubleValue(2.0), _doubleValue(1.0)); | |
5253 } | |
5254 | |
5255 void test_greaterThan_knownDouble_knownInt_false() { | |
5256 _assertGreaterThan(_boolValue(false), _doubleValue(1.0), _intValue(2)); | |
5257 } | |
5258 | |
5259 void test_greaterThan_knownDouble_knownInt_true() { | |
5260 _assertGreaterThan(_boolValue(true), _doubleValue(2.0), _intValue(1)); | |
5261 } | |
5262 | |
5263 void test_greaterThan_knownDouble_unknownDouble() { | |
5264 _assertGreaterThan(_boolValue(null), _doubleValue(1.0), _doubleValue(null)); | |
5265 } | |
5266 | |
5267 void test_greaterThan_knownDouble_unknownInt() { | |
5268 _assertGreaterThan(_boolValue(null), _doubleValue(1.0), _intValue(null)); | |
5269 } | |
5270 | |
5271 void test_greaterThan_knownInt_knownInt_false() { | |
5272 _assertGreaterThan(_boolValue(false), _intValue(1), _intValue(2)); | |
5273 } | |
5274 | |
5275 void test_greaterThan_knownInt_knownInt_true() { | |
5276 _assertGreaterThan(_boolValue(true), _intValue(2), _intValue(1)); | |
5277 } | |
5278 | |
5279 void test_greaterThan_knownInt_knownString() { | |
5280 _assertGreaterThan(null, _intValue(1), _stringValue("2")); | |
5281 } | |
5282 | |
5283 void test_greaterThan_knownInt_unknownDouble() { | |
5284 _assertGreaterThan(_boolValue(null), _intValue(1), _doubleValue(null)); | |
5285 } | |
5286 | |
5287 void test_greaterThan_knownInt_unknownInt() { | |
5288 _assertGreaterThan(_boolValue(null), _intValue(1), _intValue(null)); | |
5289 } | |
5290 | |
5291 void test_greaterThan_knownString_knownInt() { | |
5292 _assertGreaterThan(null, _stringValue("1"), _intValue(2)); | |
5293 } | |
5294 | |
5295 void test_greaterThan_unknownDouble_knownDouble() { | |
5296 _assertGreaterThan(_boolValue(null), _doubleValue(null), _doubleValue(2.0)); | |
5297 } | |
5298 | |
5299 void test_greaterThan_unknownDouble_knownInt() { | |
5300 _assertGreaterThan(_boolValue(null), _doubleValue(null), _intValue(2)); | |
5301 } | |
5302 | |
5303 void test_greaterThan_unknownInt_knownDouble() { | |
5304 _assertGreaterThan(_boolValue(null), _intValue(null), _doubleValue(2.0)); | |
5305 } | |
5306 | |
5307 void test_greaterThan_unknownInt_knownInt() { | |
5308 _assertGreaterThan(_boolValue(null), _intValue(null), _intValue(2)); | |
5309 } | |
5310 | |
5311 void test_hasExactValue_bool_false() { | 5289 void test_hasExactValue_bool_false() { |
5312 expect(_boolValue(false).hasExactValue, isTrue); | 5290 expect(_boolValue(false).hasExactValue, isTrue); |
5313 } | 5291 } |
5314 | 5292 |
5315 void test_hasExactValue_bool_true() { | 5293 void test_hasExactValue_bool_true() { |
5316 expect(_boolValue(true).hasExactValue, isTrue); | 5294 expect(_boolValue(true).hasExactValue, isTrue); |
5317 } | 5295 } |
5318 | 5296 |
5319 void test_hasExactValue_bool_unknown() { | 5297 void test_hasExactValue_bool_unknown() { |
5320 expect(_boolValue(null).hasExactValue, isTrue); | 5298 expect(_boolValue(null).hasExactValue, isTrue); |
(...skipping 29 matching lines...) Expand all Loading... |
5350 | 5328 |
5351 void test_hasExactValue_list_valid() { | 5329 void test_hasExactValue_list_valid() { |
5352 expect(_listValue([_intValue(23)]).hasExactValue, isTrue); | 5330 expect(_listValue([_intValue(23)]).hasExactValue, isTrue); |
5353 } | 5331 } |
5354 | 5332 |
5355 void test_hasExactValue_map_empty() { | 5333 void test_hasExactValue_map_empty() { |
5356 expect(_mapValue().hasExactValue, isTrue); | 5334 expect(_mapValue().hasExactValue, isTrue); |
5357 } | 5335 } |
5358 | 5336 |
5359 void test_hasExactValue_map_invalidKey() { | 5337 void test_hasExactValue_map_invalidKey() { |
5360 expect(_mapValue([_dynamicValue(), _stringValue("value")]).hasExactValue, is
False); | 5338 expect( |
| 5339 _mapValue([_dynamicValue(), _stringValue("value")]).hasExactValue, |
| 5340 isFalse); |
5361 } | 5341 } |
5362 | 5342 |
5363 void test_hasExactValue_map_invalidValue() { | 5343 void test_hasExactValue_map_invalidValue() { |
5364 expect(_mapValue([_stringValue("key"), _dynamicValue()]).hasExactValue, isFa
lse); | 5344 expect( |
| 5345 _mapValue([_stringValue("key"), _dynamicValue()]).hasExactValue, |
| 5346 isFalse); |
5365 } | 5347 } |
5366 | 5348 |
5367 void test_hasExactValue_map_valid() { | 5349 void test_hasExactValue_map_valid() { |
5368 expect(_mapValue([_stringValue("key"), _stringValue("value")]).hasExactValue
, isTrue); | 5350 expect( |
| 5351 _mapValue([_stringValue("key"), _stringValue("value")]).hasExactValue, |
| 5352 isTrue); |
5369 } | 5353 } |
5370 | 5354 |
5371 void test_hasExactValue_null() { | 5355 void test_hasExactValue_null() { |
5372 expect(_nullValue().hasExactValue, isTrue); | 5356 expect(_nullValue().hasExactValue, isTrue); |
5373 } | 5357 } |
5374 | 5358 |
5375 void test_hasExactValue_num() { | 5359 void test_hasExactValue_num() { |
5376 expect(_numValue().hasExactValue, isFalse); | 5360 expect(_numValue().hasExactValue, isFalse); |
5377 } | 5361 } |
5378 | 5362 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5418 | 5402 |
5419 void test_identical_int_unknown() { | 5403 void test_identical_int_unknown() { |
5420 _assertIdentical(_boolValue(null), _intValue(null), _intValue(3)); | 5404 _assertIdentical(_boolValue(null), _intValue(null), _intValue(3)); |
5421 } | 5405 } |
5422 | 5406 |
5423 void test_identical_list_empty() { | 5407 void test_identical_list_empty() { |
5424 _assertIdentical(_boolValue(true), _listValue(), _listValue()); | 5408 _assertIdentical(_boolValue(true), _listValue(), _listValue()); |
5425 } | 5409 } |
5426 | 5410 |
5427 void test_identical_list_false() { | 5411 void test_identical_list_false() { |
5428 _assertIdentical(_boolValue(false), _listValue(), | 5412 _assertIdentical( |
| 5413 _boolValue(false), |
| 5414 _listValue(), |
5429 _listValue([_intValue(3)])); | 5415 _listValue([_intValue(3)])); |
5430 } | 5416 } |
5431 | 5417 |
5432 void test_identical_map_empty() { | 5418 void test_identical_map_empty() { |
5433 _assertIdentical(_boolValue(true), _mapValue(), _mapValue()); | 5419 _assertIdentical(_boolValue(true), _mapValue(), _mapValue()); |
5434 } | 5420 } |
5435 | 5421 |
5436 void test_identical_map_false() { | 5422 void test_identical_map_false() { |
5437 _assertIdentical(_boolValue(false), _mapValue(), | 5423 _assertIdentical( |
| 5424 _boolValue(false), |
| 5425 _mapValue(), |
5438 _mapValue([_intValue(1), _intValue(2)])); | 5426 _mapValue([_intValue(1), _intValue(2)])); |
5439 } | 5427 } |
5440 | 5428 |
5441 void test_identical_null() { | 5429 void test_identical_null() { |
5442 _assertIdentical(_boolValue(true), _nullValue(), _nullValue()); | 5430 _assertIdentical(_boolValue(true), _nullValue(), _nullValue()); |
5443 } | 5431 } |
5444 | 5432 |
5445 void test_identical_string_false() { | 5433 void test_identical_string_false() { |
5446 _assertIdentical( | 5434 _assertIdentical( |
5447 _boolValue(false), | 5435 _boolValue(false), |
5448 _stringValue("abc"), | 5436 _stringValue("abc"), |
5449 _stringValue("def")); | 5437 _stringValue("def")); |
5450 } | 5438 } |
5451 | 5439 |
5452 void test_identical_string_true() { | 5440 void test_identical_string_true() { |
5453 _assertIdentical( | 5441 _assertIdentical( |
5454 _boolValue(true), | 5442 _boolValue(true), |
5455 _stringValue("abc"), | 5443 _stringValue("abc"), |
5456 _stringValue("abc")); | 5444 _stringValue("abc")); |
5457 } | 5445 } |
5458 | 5446 |
5459 void test_identical_string_unknown() { | 5447 void test_identical_string_unknown() { |
5460 _assertIdentical( | 5448 _assertIdentical(_boolValue(null), _stringValue(null), _stringValue("def")); |
5461 _boolValue(null), | |
5462 _stringValue(null), | |
5463 _stringValue("def")); | |
5464 } | 5449 } |
5465 | 5450 |
5466 void test_integerDivide_knownDouble_knownDouble() { | 5451 void test_integerDivide_knownDouble_knownDouble() { |
5467 _assertIntegerDivide(_intValue(3), _doubleValue(6.0), _doubleValue(2.0)); | 5452 _assertIntegerDivide(_intValue(3), _doubleValue(6.0), _doubleValue(2.0)); |
5468 } | 5453 } |
5469 | 5454 |
5470 void test_integerDivide_knownDouble_knownInt() { | 5455 void test_integerDivide_knownDouble_knownInt() { |
5471 _assertIntegerDivide(_intValue(3), _doubleValue(6.0), _intValue(2)); | 5456 _assertIntegerDivide(_intValue(3), _doubleValue(6.0), _intValue(2)); |
5472 } | 5457 } |
5473 | 5458 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5566 } | 5551 } |
5567 | 5552 |
5568 void test_isBoolNumStringOrNull_string_known() { | 5553 void test_isBoolNumStringOrNull_string_known() { |
5569 expect(_stringValue("twenty-three").isBoolNumStringOrNull, isTrue); | 5554 expect(_stringValue("twenty-three").isBoolNumStringOrNull, isTrue); |
5570 } | 5555 } |
5571 | 5556 |
5572 void test_isBoolNumStringOrNull_string_unknown() { | 5557 void test_isBoolNumStringOrNull_string_unknown() { |
5573 expect(_stringValue(null).isBoolNumStringOrNull, isTrue); | 5558 expect(_stringValue(null).isBoolNumStringOrNull, isTrue); |
5574 } | 5559 } |
5575 | 5560 |
| 5561 void test_lessThan_knownDouble_knownDouble_false() { |
| 5562 _assertLessThan(_boolValue(false), _doubleValue(2.0), _doubleValue(1.0)); |
| 5563 } |
| 5564 |
| 5565 void test_lessThan_knownDouble_knownDouble_true() { |
| 5566 _assertLessThan(_boolValue(true), _doubleValue(1.0), _doubleValue(2.0)); |
| 5567 } |
| 5568 |
| 5569 void test_lessThan_knownDouble_knownInt_false() { |
| 5570 _assertLessThan(_boolValue(false), _doubleValue(2.0), _intValue(1)); |
| 5571 } |
| 5572 |
| 5573 void test_lessThan_knownDouble_knownInt_true() { |
| 5574 _assertLessThan(_boolValue(true), _doubleValue(1.0), _intValue(2)); |
| 5575 } |
| 5576 |
| 5577 void test_lessThan_knownDouble_unknownDouble() { |
| 5578 _assertLessThan(_boolValue(null), _doubleValue(1.0), _doubleValue(null)); |
| 5579 } |
| 5580 |
| 5581 void test_lessThan_knownDouble_unknownInt() { |
| 5582 _assertLessThan(_boolValue(null), _doubleValue(1.0), _intValue(null)); |
| 5583 } |
| 5584 |
| 5585 void test_lessThan_knownInt_knownInt_false() { |
| 5586 _assertLessThan(_boolValue(false), _intValue(2), _intValue(1)); |
| 5587 } |
| 5588 |
| 5589 void test_lessThan_knownInt_knownInt_true() { |
| 5590 _assertLessThan(_boolValue(true), _intValue(1), _intValue(2)); |
| 5591 } |
| 5592 |
| 5593 void test_lessThan_knownInt_knownString() { |
| 5594 _assertLessThan(null, _intValue(1), _stringValue("2")); |
| 5595 } |
| 5596 |
| 5597 void test_lessThan_knownInt_unknownDouble() { |
| 5598 _assertLessThan(_boolValue(null), _intValue(1), _doubleValue(null)); |
| 5599 } |
| 5600 |
| 5601 void test_lessThan_knownInt_unknownInt() { |
| 5602 _assertLessThan(_boolValue(null), _intValue(1), _intValue(null)); |
| 5603 } |
| 5604 |
| 5605 void test_lessThan_knownString_knownInt() { |
| 5606 _assertLessThan(null, _stringValue("1"), _intValue(2)); |
| 5607 } |
| 5608 |
| 5609 void test_lessThan_unknownDouble_knownDouble() { |
| 5610 _assertLessThan(_boolValue(null), _doubleValue(null), _doubleValue(2.0)); |
| 5611 } |
| 5612 |
| 5613 void test_lessThan_unknownDouble_knownInt() { |
| 5614 _assertLessThan(_boolValue(null), _doubleValue(null), _intValue(2)); |
| 5615 } |
| 5616 |
| 5617 void test_lessThan_unknownInt_knownDouble() { |
| 5618 _assertLessThan(_boolValue(null), _intValue(null), _doubleValue(2.0)); |
| 5619 } |
| 5620 |
| 5621 void test_lessThan_unknownInt_knownInt() { |
| 5622 _assertLessThan(_boolValue(null), _intValue(null), _intValue(2)); |
| 5623 } |
| 5624 |
5576 void test_lessThanOrEqual_knownDouble_knownDouble_false() { | 5625 void test_lessThanOrEqual_knownDouble_knownDouble_false() { |
5577 _assertLessThanOrEqual( | 5626 _assertLessThanOrEqual( |
5578 _boolValue(false), | 5627 _boolValue(false), |
5579 _doubleValue(2.0), | 5628 _doubleValue(2.0), |
5580 _doubleValue(1.0)); | 5629 _doubleValue(1.0)); |
5581 } | 5630 } |
5582 | 5631 |
5583 void test_lessThanOrEqual_knownDouble_knownDouble_true() { | 5632 void test_lessThanOrEqual_knownDouble_knownDouble_true() { |
5584 _assertLessThanOrEqual( | 5633 _assertLessThanOrEqual( |
5585 _boolValue(true), | 5634 _boolValue(true), |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5648 _assertLessThanOrEqual( | 5697 _assertLessThanOrEqual( |
5649 _boolValue(null), | 5698 _boolValue(null), |
5650 _intValue(null), | 5699 _intValue(null), |
5651 _doubleValue(2.0)); | 5700 _doubleValue(2.0)); |
5652 } | 5701 } |
5653 | 5702 |
5654 void test_lessThanOrEqual_unknownInt_knownInt() { | 5703 void test_lessThanOrEqual_unknownInt_knownInt() { |
5655 _assertLessThanOrEqual(_boolValue(null), _intValue(null), _intValue(2)); | 5704 _assertLessThanOrEqual(_boolValue(null), _intValue(null), _intValue(2)); |
5656 } | 5705 } |
5657 | 5706 |
5658 void test_lessThan_knownDouble_knownDouble_false() { | |
5659 _assertLessThan(_boolValue(false), _doubleValue(2.0), _doubleValue(1.0)); | |
5660 } | |
5661 | |
5662 void test_lessThan_knownDouble_knownDouble_true() { | |
5663 _assertLessThan(_boolValue(true), _doubleValue(1.0), _doubleValue(2.0)); | |
5664 } | |
5665 | |
5666 void test_lessThan_knownDouble_knownInt_false() { | |
5667 _assertLessThan(_boolValue(false), _doubleValue(2.0), _intValue(1)); | |
5668 } | |
5669 | |
5670 void test_lessThan_knownDouble_knownInt_true() { | |
5671 _assertLessThan(_boolValue(true), _doubleValue(1.0), _intValue(2)); | |
5672 } | |
5673 | |
5674 void test_lessThan_knownDouble_unknownDouble() { | |
5675 _assertLessThan(_boolValue(null), _doubleValue(1.0), _doubleValue(null)); | |
5676 } | |
5677 | |
5678 void test_lessThan_knownDouble_unknownInt() { | |
5679 _assertLessThan(_boolValue(null), _doubleValue(1.0), _intValue(null)); | |
5680 } | |
5681 | |
5682 void test_lessThan_knownInt_knownInt_false() { | |
5683 _assertLessThan(_boolValue(false), _intValue(2), _intValue(1)); | |
5684 } | |
5685 | |
5686 void test_lessThan_knownInt_knownInt_true() { | |
5687 _assertLessThan(_boolValue(true), _intValue(1), _intValue(2)); | |
5688 } | |
5689 | |
5690 void test_lessThan_knownInt_knownString() { | |
5691 _assertLessThan(null, _intValue(1), _stringValue("2")); | |
5692 } | |
5693 | |
5694 void test_lessThan_knownInt_unknownDouble() { | |
5695 _assertLessThan(_boolValue(null), _intValue(1), _doubleValue(null)); | |
5696 } | |
5697 | |
5698 void test_lessThan_knownInt_unknownInt() { | |
5699 _assertLessThan(_boolValue(null), _intValue(1), _intValue(null)); | |
5700 } | |
5701 | |
5702 void test_lessThan_knownString_knownInt() { | |
5703 _assertLessThan(null, _stringValue("1"), _intValue(2)); | |
5704 } | |
5705 | |
5706 void test_lessThan_unknownDouble_knownDouble() { | |
5707 _assertLessThan(_boolValue(null), _doubleValue(null), _doubleValue(2.0)); | |
5708 } | |
5709 | |
5710 void test_lessThan_unknownDouble_knownInt() { | |
5711 _assertLessThan(_boolValue(null), _doubleValue(null), _intValue(2)); | |
5712 } | |
5713 | |
5714 void test_lessThan_unknownInt_knownDouble() { | |
5715 _assertLessThan(_boolValue(null), _intValue(null), _doubleValue(2.0)); | |
5716 } | |
5717 | |
5718 void test_lessThan_unknownInt_knownInt() { | |
5719 _assertLessThan(_boolValue(null), _intValue(null), _intValue(2)); | |
5720 } | |
5721 | |
5722 void test_logicalAnd_false_false() { | 5707 void test_logicalAnd_false_false() { |
5723 _assertLogicalAnd(_boolValue(false), _boolValue(false), _boolValue(false)); | 5708 _assertLogicalAnd(_boolValue(false), _boolValue(false), _boolValue(false)); |
5724 } | 5709 } |
5725 | 5710 |
5726 void test_logicalAnd_false_null() { | 5711 void test_logicalAnd_false_null() { |
5727 try { | 5712 try { |
5728 _assertLogicalAnd(_boolValue(false), _boolValue(false), _nullValue()); | 5713 _assertLogicalAnd(_boolValue(false), _boolValue(false), _nullValue()); |
5729 fail("Expected EvaluationException"); | 5714 fail("Expected EvaluationException"); |
5730 } on EvaluationException catch (exception) { | 5715 } on EvaluationException catch (exception) { |
5731 } | 5716 } |
(...skipping 1190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6922 } | 6907 } |
6923 | 6908 |
6924 DartObjectImpl _intValue(int value) { | 6909 DartObjectImpl _intValue(int value) { |
6925 if (value == null) { | 6910 if (value == null) { |
6926 return new DartObjectImpl(_typeProvider.intType, IntState.UNKNOWN_VALUE); | 6911 return new DartObjectImpl(_typeProvider.intType, IntState.UNKNOWN_VALUE); |
6927 } else { | 6912 } else { |
6928 return new DartObjectImpl(_typeProvider.intType, new IntState(value)); | 6913 return new DartObjectImpl(_typeProvider.intType, new IntState(value)); |
6929 } | 6914 } |
6930 } | 6915 } |
6931 | 6916 |
6932 DartObjectImpl _listValue([List<DartObjectImpl> elements = DartObjectImpl.EMPT
Y_LIST]) { | 6917 DartObjectImpl _listValue([List<DartObjectImpl> elements = |
| 6918 DartObjectImpl.EMPTY_LIST]) { |
6933 return new DartObjectImpl(_typeProvider.listType, new ListState(elements)); | 6919 return new DartObjectImpl(_typeProvider.listType, new ListState(elements)); |
6934 } | 6920 } |
6935 | 6921 |
6936 DartObjectImpl _mapValue([List<DartObjectImpl> keyElementPairs = DartObjectImp
l.EMPTY_LIST]) { | 6922 DartObjectImpl _mapValue([List<DartObjectImpl> keyElementPairs = |
| 6923 DartObjectImpl.EMPTY_LIST]) { |
6937 Map<DartObjectImpl, DartObjectImpl> map = | 6924 Map<DartObjectImpl, DartObjectImpl> map = |
6938 new Map<DartObjectImpl, DartObjectImpl>(); | 6925 new Map<DartObjectImpl, DartObjectImpl>(); |
6939 int count = keyElementPairs.length; | 6926 int count = keyElementPairs.length; |
6940 for (int i = 0; i < count; ) { | 6927 for (int i = 0; i < count; ) { |
6941 map[keyElementPairs[i++]] = keyElementPairs[i++]; | 6928 map[keyElementPairs[i++]] = keyElementPairs[i++]; |
6942 } | 6929 } |
6943 return new DartObjectImpl(_typeProvider.mapType, new MapState(map)); | 6930 return new DartObjectImpl(_typeProvider.mapType, new MapState(map)); |
6944 } | 6931 } |
6945 | 6932 |
6946 DartObjectImpl _nullValue() { | 6933 DartObjectImpl _nullValue() { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7042 variables.define(variableName, "true"); | 7029 variables.define(variableName, "true"); |
7043 DartObject object = variables.getBool(typeProvider, variableName); | 7030 DartObject object = variables.getBool(typeProvider, variableName); |
7044 expect(object, isNotNull); | 7031 expect(object, isNotNull); |
7045 expect(object.boolValue, true); | 7032 expect(object.boolValue, true); |
7046 } | 7033 } |
7047 | 7034 |
7048 void test_getBool_undefined() { | 7035 void test_getBool_undefined() { |
7049 TestTypeProvider typeProvider = new TestTypeProvider(); | 7036 TestTypeProvider typeProvider = new TestTypeProvider(); |
7050 String variableName = "var"; | 7037 String variableName = "var"; |
7051 DeclaredVariables variables = new DeclaredVariables(); | 7038 DeclaredVariables variables = new DeclaredVariables(); |
7052 _assertUnknownDartObject(typeProvider.boolType, | 7039 _assertUnknownDartObject( |
| 7040 typeProvider.boolType, |
7053 variables.getBool(typeProvider, variableName)); | 7041 variables.getBool(typeProvider, variableName)); |
7054 } | 7042 } |
7055 | 7043 |
7056 void test_getInt_invalid() { | 7044 void test_getInt_invalid() { |
7057 TestTypeProvider typeProvider = new TestTypeProvider(); | 7045 TestTypeProvider typeProvider = new TestTypeProvider(); |
7058 String variableName = "var"; | 7046 String variableName = "var"; |
7059 DeclaredVariables variables = new DeclaredVariables(); | 7047 DeclaredVariables variables = new DeclaredVariables(); |
7060 variables.define(variableName, "four score and seven years"); | 7048 variables.define(variableName, "four score and seven years"); |
7061 _assertNullDartObject( | 7049 _assertNullDartObject( |
7062 typeProvider, | 7050 typeProvider, |
7063 variables.getInt(typeProvider, variableName)); | 7051 variables.getInt(typeProvider, variableName)); |
7064 } | 7052 } |
7065 | 7053 |
7066 void test_getInt_undefined() { | 7054 void test_getInt_undefined() { |
7067 TestTypeProvider typeProvider = new TestTypeProvider(); | 7055 TestTypeProvider typeProvider = new TestTypeProvider(); |
7068 String variableName = "var"; | 7056 String variableName = "var"; |
7069 DeclaredVariables variables = new DeclaredVariables(); | 7057 DeclaredVariables variables = new DeclaredVariables(); |
7070 _assertUnknownDartObject(typeProvider.intType, | 7058 _assertUnknownDartObject( |
| 7059 typeProvider.intType, |
7071 variables.getInt(typeProvider, variableName)); | 7060 variables.getInt(typeProvider, variableName)); |
7072 } | 7061 } |
7073 | 7062 |
7074 void test_getInt_valid() { | 7063 void test_getInt_valid() { |
7075 TestTypeProvider typeProvider = new TestTypeProvider(); | 7064 TestTypeProvider typeProvider = new TestTypeProvider(); |
7076 String variableName = "var"; | 7065 String variableName = "var"; |
7077 DeclaredVariables variables = new DeclaredVariables(); | 7066 DeclaredVariables variables = new DeclaredVariables(); |
7078 variables.define(variableName, "23"); | 7067 variables.define(variableName, "23"); |
7079 DartObject object = variables.getInt(typeProvider, variableName); | 7068 DartObject object = variables.getInt(typeProvider, variableName); |
7080 expect(object, isNotNull); | 7069 expect(object, isNotNull); |
7081 expect(object.intValue, 23); | 7070 expect(object.intValue, 23); |
7082 } | 7071 } |
7083 | 7072 |
7084 void test_getString_defined() { | 7073 void test_getString_defined() { |
7085 TestTypeProvider typeProvider = new TestTypeProvider(); | 7074 TestTypeProvider typeProvider = new TestTypeProvider(); |
7086 String variableName = "var"; | 7075 String variableName = "var"; |
7087 String value = "value"; | 7076 String value = "value"; |
7088 DeclaredVariables variables = new DeclaredVariables(); | 7077 DeclaredVariables variables = new DeclaredVariables(); |
7089 variables.define(variableName, value); | 7078 variables.define(variableName, value); |
7090 DartObject object = variables.getString(typeProvider, variableName); | 7079 DartObject object = variables.getString(typeProvider, variableName); |
7091 expect(object, isNotNull); | 7080 expect(object, isNotNull); |
7092 expect(object.stringValue, value); | 7081 expect(object.stringValue, value); |
7093 } | 7082 } |
7094 | 7083 |
7095 void test_getString_undefined() { | 7084 void test_getString_undefined() { |
7096 TestTypeProvider typeProvider = new TestTypeProvider(); | 7085 TestTypeProvider typeProvider = new TestTypeProvider(); |
7097 String variableName = "var"; | 7086 String variableName = "var"; |
7098 DeclaredVariables variables = new DeclaredVariables(); | 7087 DeclaredVariables variables = new DeclaredVariables(); |
7099 _assertUnknownDartObject(typeProvider.stringType, | 7088 _assertUnknownDartObject( |
| 7089 typeProvider.stringType, |
7100 variables.getString(typeProvider, variableName)); | 7090 variables.getString(typeProvider, variableName)); |
7101 } | 7091 } |
7102 | 7092 |
7103 void _assertNullDartObject(TestTypeProvider typeProvider, DartObject result) { | 7093 void _assertNullDartObject(TestTypeProvider typeProvider, DartObject result) { |
7104 expect(result.type, typeProvider.nullType); | 7094 expect(result.type, typeProvider.nullType); |
7105 } | 7095 } |
7106 | 7096 |
7107 void _assertUnknownDartObject(ParameterizedType expectedType, | 7097 void _assertUnknownDartObject(ParameterizedType expectedType, |
7108 DartObject result) { | 7098 DartObject result) { |
7109 expect((result as DartObjectImpl).isUnknown, isTrue); | 7099 expect((result as DartObjectImpl).isUnknown, isTrue); |
7110 expect(result.type, expectedType); | 7100 expect(result.type, expectedType); |
7111 } | 7101 } |
7112 } | 7102 } |
7113 | 7103 |
7114 | 7104 |
7115 class DirectoryBasedDartSdkTest { | 7105 class DirectoryBasedDartSdkTest { |
7116 void fail_getDocFileFor() { | 7106 void fail_getDocFileFor() { |
7117 DirectoryBasedDartSdk sdk = _createDartSdk(); | 7107 DirectoryBasedDartSdk sdk = _createDartSdk(); |
7118 JavaFile docFile = sdk.getDocFileFor("html"); | 7108 JavaFile docFile = sdk.getDocFileFor("html"); |
7119 expect(docFile, isNotNull); | 7109 expect(docFile, isNotNull); |
7120 } | 7110 } |
7121 | 7111 |
7122 void test_creation() { | 7112 void test_creation() { |
7123 DirectoryBasedDartSdk sdk = _createDartSdk(); | 7113 DirectoryBasedDartSdk sdk = _createDartSdk(); |
7124 expect(sdk, isNotNull); | 7114 expect(sdk, isNotNull); |
7125 } | 7115 } |
7126 | 7116 |
7127 void test_fromFile_invalid() { | 7117 void test_fromFile_invalid() { |
7128 DirectoryBasedDartSdk sdk = _createDartSdk(); | 7118 DirectoryBasedDartSdk sdk = _createDartSdk(); |
7129 expect(sdk.fromFileUri(new JavaFile("/not/in/the/sdk.dart").toURI()), isNull
); | 7119 expect( |
| 7120 sdk.fromFileUri(new JavaFile("/not/in/the/sdk.dart").toURI()), |
| 7121 isNull); |
7130 } | 7122 } |
7131 | 7123 |
7132 void test_fromFile_library() { | 7124 void test_fromFile_library() { |
7133 DirectoryBasedDartSdk sdk = _createDartSdk(); | 7125 DirectoryBasedDartSdk sdk = _createDartSdk(); |
7134 Source source = sdk.fromFileUri( | 7126 Source source = sdk.fromFileUri( |
7135 new JavaFile.relative( | 7127 new JavaFile.relative( |
7136 new JavaFile.relative(sdk.libraryDirectory, "core"), | 7128 new JavaFile.relative(sdk.libraryDirectory, "core"), |
7137 "core.dart").toURI()); | 7129 "core.dart").toURI()); |
7138 expect(source, isNotNull); | 7130 expect(source, isNotNull); |
7139 expect(source.isInSystemLibrary, isTrue); | 7131 expect(source.isInSystemLibrary, isTrue); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7205 void test_getVmExecutable() { | 7197 void test_getVmExecutable() { |
7206 DirectoryBasedDartSdk sdk = _createDartSdk(); | 7198 DirectoryBasedDartSdk sdk = _createDartSdk(); |
7207 JavaFile executable = sdk.vmExecutable; | 7199 JavaFile executable = sdk.vmExecutable; |
7208 expect(executable, isNotNull); | 7200 expect(executable, isNotNull); |
7209 expect(executable.exists(), isTrue); | 7201 expect(executable.exists(), isTrue); |
7210 expect(executable.isExecutable(), isTrue); | 7202 expect(executable.isExecutable(), isTrue); |
7211 } | 7203 } |
7212 | 7204 |
7213 DirectoryBasedDartSdk _createDartSdk() { | 7205 DirectoryBasedDartSdk _createDartSdk() { |
7214 JavaFile sdkDirectory = DirectoryBasedDartSdk.defaultSdkDirectory; | 7206 JavaFile sdkDirectory = DirectoryBasedDartSdk.defaultSdkDirectory; |
7215 expect(sdkDirectory, isNotNull, reason: "No SDK configured; set the property
'com.google.dart.sdk' on the command line"); | 7207 expect( |
| 7208 sdkDirectory, |
| 7209 isNotNull, |
| 7210 reason: |
| 7211 "No SDK configured; set the property 'com.google.dart.sdk' on the co
mmand line"); |
7216 return new DirectoryBasedDartSdk(sdkDirectory); | 7212 return new DirectoryBasedDartSdk(sdkDirectory); |
7217 } | 7213 } |
7218 } | 7214 } |
7219 | 7215 |
7220 | 7216 |
7221 class DirectoryBasedSourceContainerTest { | 7217 class DirectoryBasedSourceContainerTest { |
7222 void test_contains() { | 7218 void test_contains() { |
7223 JavaFile dir = FileUtilities2.createFile("/does/not/exist"); | 7219 JavaFile dir = FileUtilities2.createFile("/does/not/exist"); |
7224 JavaFile file1 = FileUtilities2.createFile("/does/not/exist/some.dart"); | 7220 JavaFile file1 = FileUtilities2.createFile("/does/not/exist/some.dart"); |
7225 JavaFile file2 = | 7221 JavaFile file2 = |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7391 ElementHolder holder = new ElementHolder(); | 7387 ElementHolder holder = new ElementHolder(); |
7392 ElementBuilder builder = new ElementBuilder(holder); | 7388 ElementBuilder builder = new ElementBuilder(holder); |
7393 ClassElementImpl classB = ElementFactory.classElement2('B', []); | 7389 ClassElementImpl classB = ElementFactory.classElement2('B', []); |
7394 ConstructorElementImpl constructorB = | 7390 ConstructorElementImpl constructorB = |
7395 ElementFactory.constructorElement2(classB, '', []); | 7391 ElementFactory.constructorElement2(classB, '', []); |
7396 constructorB.setModifier(Modifier.SYNTHETIC, true); | 7392 constructorB.setModifier(Modifier.SYNTHETIC, true); |
7397 classB.constructors = [constructorB]; | 7393 classB.constructors = [constructorB]; |
7398 ClassElement classM = ElementFactory.classElement2('M', []); | 7394 ClassElement classM = ElementFactory.classElement2('M', []); |
7399 WithClause withClause = | 7395 WithClause withClause = |
7400 AstFactory.withClause([AstFactory.typeName(classM, [])]); | 7396 AstFactory.withClause([AstFactory.typeName(classM, [])]); |
7401 ClassTypeAlias alias = AstFactory.classTypeAlias('C', null, null, | 7397 ClassTypeAlias alias = AstFactory.classTypeAlias( |
7402 AstFactory.typeName(classB, []), withClause, null); | 7398 'C', |
| 7399 null, |
| 7400 null, |
| 7401 AstFactory.typeName(classB, []), |
| 7402 withClause, |
| 7403 null); |
7403 alias.accept(builder); | 7404 alias.accept(builder); |
7404 List<ClassElement> types = holder.types; | 7405 List<ClassElement> types = holder.types; |
7405 expect(types, hasLength(1)); | 7406 expect(types, hasLength(1)); |
7406 ClassElement type = types[0]; | 7407 ClassElement type = types[0]; |
7407 expect(alias.element, same(type)); | 7408 expect(alias.element, same(type)); |
7408 expect(type.name, equals('C')); | 7409 expect(type.name, equals('C')); |
7409 expect(type.isAbstract, isFalse); | 7410 expect(type.isAbstract, isFalse); |
7410 expect(type.isSynthetic, isFalse); | 7411 expect(type.isSynthetic, isFalse); |
7411 expect(type.typeParameters, isEmpty); | 7412 expect(type.typeParameters, isEmpty); |
7412 expect(type.fields, isEmpty); | 7413 expect(type.fields, isEmpty); |
7413 expect(type.methods, isEmpty); | 7414 expect(type.methods, isEmpty); |
7414 } | 7415 } |
7415 | 7416 |
7416 void test_visitClassTypeAlias_abstract() { | 7417 void test_visitClassTypeAlias_abstract() { |
7417 // class B {} | 7418 // class B {} |
7418 // class M {} | 7419 // class M {} |
7419 // abstract class C = B with M | 7420 // abstract class C = B with M |
7420 ElementHolder holder = new ElementHolder(); | 7421 ElementHolder holder = new ElementHolder(); |
7421 ElementBuilder builder = new ElementBuilder(holder); | 7422 ElementBuilder builder = new ElementBuilder(holder); |
7422 ClassElementImpl classB = ElementFactory.classElement2('B', []); | 7423 ClassElementImpl classB = ElementFactory.classElement2('B', []); |
7423 ConstructorElementImpl constructorB = | 7424 ConstructorElementImpl constructorB = |
7424 ElementFactory.constructorElement2(classB, '', []); | 7425 ElementFactory.constructorElement2(classB, '', []); |
7425 constructorB.setModifier(Modifier.SYNTHETIC, true); | 7426 constructorB.setModifier(Modifier.SYNTHETIC, true); |
7426 classB.constructors = [constructorB]; | 7427 classB.constructors = [constructorB]; |
7427 ClassElement classM = ElementFactory.classElement2('M', []); | 7428 ClassElement classM = ElementFactory.classElement2('M', []); |
7428 WithClause withClause = | 7429 WithClause withClause = |
7429 AstFactory.withClause([AstFactory.typeName(classM, [])]); | 7430 AstFactory.withClause([AstFactory.typeName(classM, [])]); |
7430 ClassTypeAlias classCAst = AstFactory.classTypeAlias('C', null, | 7431 ClassTypeAlias classCAst = AstFactory.classTypeAlias( |
7431 Keyword.ABSTRACT, AstFactory.typeName(classB, []), withClause, null); | 7432 'C', |
| 7433 null, |
| 7434 Keyword.ABSTRACT, |
| 7435 AstFactory.typeName(classB, []), |
| 7436 withClause, |
| 7437 null); |
7432 classCAst.accept(builder); | 7438 classCAst.accept(builder); |
7433 List<ClassElement> types = holder.types; | 7439 List<ClassElement> types = holder.types; |
7434 expect(types, hasLength(1)); | 7440 expect(types, hasLength(1)); |
7435 ClassElement type = types[0]; | 7441 ClassElement type = types[0]; |
7436 expect(type.isAbstract, isTrue); | 7442 expect(type.isAbstract, isTrue); |
7437 } | 7443 } |
7438 | 7444 |
7439 void test_visitClassTypeAlias_typeParams() { | 7445 void test_visitClassTypeAlias_typeParams() { |
7440 // class B {} | 7446 // class B {} |
7441 // class M {} | 7447 // class M {} |
7442 // class C<T> = B with M | 7448 // class C<T> = B with M |
7443 ElementHolder holder = new ElementHolder(); | 7449 ElementHolder holder = new ElementHolder(); |
7444 ElementBuilder builder = new ElementBuilder(holder); | 7450 ElementBuilder builder = new ElementBuilder(holder); |
7445 ClassElementImpl classB = ElementFactory.classElement2('B', []); | 7451 ClassElementImpl classB = ElementFactory.classElement2('B', []); |
7446 ConstructorElementImpl constructorB = | 7452 ConstructorElementImpl constructorB = |
7447 ElementFactory.constructorElement2(classB, '', []); | 7453 ElementFactory.constructorElement2(classB, '', []); |
7448 constructorB.setModifier(Modifier.SYNTHETIC, true); | 7454 constructorB.setModifier(Modifier.SYNTHETIC, true); |
7449 classB.constructors = [constructorB]; | 7455 classB.constructors = [constructorB]; |
7450 ClassElementImpl classM = ElementFactory.classElement2('M', []); | 7456 ClassElementImpl classM = ElementFactory.classElement2('M', []); |
7451 WithClause withClause = | 7457 WithClause withClause = |
7452 AstFactory.withClause([AstFactory.typeName(classM, [])]); | 7458 AstFactory.withClause([AstFactory.typeName(classM, [])]); |
7453 ClassTypeAlias classCAst = AstFactory.classTypeAlias('C', | 7459 ClassTypeAlias classCAst = AstFactory.classTypeAlias( |
7454 AstFactory.typeParameterList(['T']), null, | 7460 'C', |
7455 AstFactory.typeName(classB, []), withClause, null); | 7461 AstFactory.typeParameterList(['T']), |
| 7462 null, |
| 7463 AstFactory.typeName(classB, []), |
| 7464 withClause, |
| 7465 null); |
7456 classCAst.accept(builder); | 7466 classCAst.accept(builder); |
7457 List<ClassElement> types = holder.types; | 7467 List<ClassElement> types = holder.types; |
7458 expect(types, hasLength(1)); | 7468 expect(types, hasLength(1)); |
7459 ClassElement type = types[0]; | 7469 ClassElement type = types[0]; |
7460 expect(type.typeParameters, hasLength(1)); | 7470 expect(type.typeParameters, hasLength(1)); |
7461 expect(type.typeParameters[0].name, equals('T')); | 7471 expect(type.typeParameters[0].name, equals('T')); |
7462 } | 7472 } |
7463 | 7473 |
7464 void test_visitConstructorDeclaration_factory() { | 7474 void test_visitConstructorDeclaration_factory() { |
7465 ElementHolder holder = new ElementHolder(); | 7475 ElementHolder holder = new ElementHolder(); |
(...skipping 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8150 String labelName = "l"; | 8160 String labelName = "l"; |
8151 String exceptionParameterName = "e"; | 8161 String exceptionParameterName = "e"; |
8152 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( | 8162 MethodDeclaration methodDeclaration = AstFactory.methodDeclaration2( |
8153 null, | 8163 null, |
8154 null, | 8164 null, |
8155 null, | 8165 null, |
8156 null, | 8166 null, |
8157 AstFactory.identifier3(methodName), | 8167 AstFactory.identifier3(methodName), |
8158 AstFactory.formalParameterList( | 8168 AstFactory.formalParameterList( |
8159 [AstFactory.simpleFormalParameter3(parameterName)]), | 8169 [AstFactory.simpleFormalParameter3(parameterName)]), |
8160 AstFactory.blockFunctionBody2([ | 8170 AstFactory.blockFunctionBody2( |
8161 AstFactory.variableDeclarationStatement2( | 8171 [ |
8162 Keyword.VAR, | 8172 AstFactory.variableDeclarationStatement2( |
8163 [AstFactory.variableDeclaration(localVariableName)]), | 8173 Keyword.VAR, |
8164 AstFactory.tryStatement2( | 8174 [AstFactory.variableDeclaration(localVariableName)]), |
8165 AstFactory.block([AstFactory.labeledStatement( | 8175 AstFactory.tryStatement2( |
8166 [AstFactory.label2(labelName)], | 8176 AstFactory.block( |
8167 AstFactory.returnStatement())]), | 8177 [ |
8168 [AstFactory.catchClause(exceptionParameterName)])])); | 8178 AstFactory.labeledStatement( |
| 8179 [AstFactory.label2(labelName)], |
| 8180 AstFactory.returnStatement())]), |
| 8181 [AstFactory.catchClause(exceptionParameterName)])])); |
8169 methodDeclaration.accept(builder); | 8182 methodDeclaration.accept(builder); |
8170 List<MethodElement> methods = holder.methods; | 8183 List<MethodElement> methods = holder.methods; |
8171 expect(methods, hasLength(1)); | 8184 expect(methods, hasLength(1)); |
8172 MethodElement method = methods[0]; | 8185 MethodElement method = methods[0]; |
8173 expect(method, isNotNull); | 8186 expect(method, isNotNull); |
8174 expect(method.name, methodName); | 8187 expect(method.name, methodName); |
8175 expect(method.isAbstract, isFalse); | 8188 expect(method.isAbstract, isFalse); |
8176 expect(method.isStatic, isFalse); | 8189 expect(method.isStatic, isFalse); |
8177 expect(method.isSynthetic, isFalse); | 8190 expect(method.isSynthetic, isFalse); |
8178 List<VariableElement> parameters = method.parameters; | 8191 List<VariableElement> parameters = method.parameters; |
8179 expect(parameters, hasLength(1)); | 8192 expect(parameters, hasLength(1)); |
8180 VariableElement parameter = parameters[0]; | 8193 VariableElement parameter = parameters[0]; |
8181 expect(parameter, isNotNull); | 8194 expect(parameter, isNotNull); |
8182 expect(parameter.name, parameterName); | 8195 expect(parameter.name, parameterName); |
8183 List<VariableElement> localVariables = method.localVariables; | 8196 List<VariableElement> localVariables = method.localVariables; |
8184 expect(localVariables, hasLength(2)); | 8197 expect(localVariables, hasLength(2)); |
8185 VariableElement firstVariable = localVariables[0]; | 8198 VariableElement firstVariable = localVariables[0]; |
8186 VariableElement secondVariable = localVariables[1]; | 8199 VariableElement secondVariable = localVariables[1]; |
8187 expect(firstVariable, isNotNull); | 8200 expect(firstVariable, isNotNull); |
8188 expect(secondVariable, isNotNull); | 8201 expect(secondVariable, isNotNull); |
8189 expect((firstVariable.name == localVariableName && | 8202 expect( |
| 8203 (firstVariable.name == localVariableName && |
8190 secondVariable.name == exceptionParameterName) || | 8204 secondVariable.name == exceptionParameterName) || |
8191 (firstVariable.name == exceptionParameterName && | 8205 (firstVariable.name == exceptionParameterName && |
8192 secondVariable.name == localVariableName), isTrue); | 8206 secondVariable.name == localVariableName), |
| 8207 isTrue); |
8193 List<LabelElement> labels = method.labels; | 8208 List<LabelElement> labels = method.labels; |
8194 expect(labels, hasLength(1)); | 8209 expect(labels, hasLength(1)); |
8195 LabelElement label = labels[0]; | 8210 LabelElement label = labels[0]; |
8196 expect(label, isNotNull); | 8211 expect(label, isNotNull); |
8197 expect(label.name, labelName); | 8212 expect(label.name, labelName); |
8198 } | 8213 } |
8199 | 8214 |
8200 void test_visitNamedFormalParameter() { | 8215 void test_visitNamedFormalParameter() { |
8201 ElementHolder holder = new ElementHolder(); | 8216 ElementHolder holder = new ElementHolder(); |
8202 ElementBuilder builder = new ElementBuilder(holder); | 8217 ElementBuilder builder = new ElementBuilder(holder); |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8501 fail("Test this case"); | 8516 fail("Test this case"); |
8502 } | 8517 } |
8503 | 8518 |
8504 @override | 8519 @override |
8505 void reset() { | 8520 void reset() { |
8506 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); | 8521 AnalysisOptionsImpl analysisOptions = new AnalysisOptionsImpl(); |
8507 analysisOptions.hint = false; | 8522 analysisOptions.hint = false; |
8508 resetWithOptions(analysisOptions); | 8523 resetWithOptions(analysisOptions); |
8509 } | 8524 } |
8510 | 8525 |
8511 void test_locateWithOffset_BinaryExpression() { | |
8512 AstNode id = _findNodeIn("+", "var x = 3 + 4;"); | |
8513 Element element = ElementLocator.locateWithOffset(id, 0); | |
8514 EngineTestCase.assertInstanceOf( | |
8515 (obj) => obj is MethodElement, | |
8516 MethodElement, | |
8517 element); | |
8518 } | |
8519 | |
8520 void test_locateWithOffset_StringLiteral() { | |
8521 AstNode id = _findNodeIn("abc", "var x = 'abc';"); | |
8522 Element element = ElementLocator.locateWithOffset(id, 1); | |
8523 expect(element, isNull); | |
8524 } | |
8525 | |
8526 void test_locate_AssignmentExpression() { | 8526 void test_locate_AssignmentExpression() { |
8527 AstNode id = | 8527 AstNode id = _findNodeIn("+=", r''' |
8528 _findNodeIn("+=", r''' | |
8529 int x = 0; | 8528 int x = 0; |
8530 void main() { | 8529 void main() { |
8531 x += 1; | 8530 x += 1; |
8532 }'''); | 8531 }'''); |
8533 Element element = ElementLocator.locate(id); | 8532 Element element = ElementLocator.locate(id); |
8534 EngineTestCase.assertInstanceOf( | 8533 EngineTestCase.assertInstanceOf( |
8535 (obj) => obj is MethodElement, | 8534 (obj) => obj is MethodElement, |
8536 MethodElement, | 8535 MethodElement, |
8537 element); | 8536 element); |
8538 } | 8537 } |
(...skipping 17 matching lines...) Expand all Loading... |
8556 } | 8555 } |
8557 | 8556 |
8558 void test_locate_CompilationUnit() { | 8557 void test_locate_CompilationUnit() { |
8559 CompilationUnit cu = _resolveContents("// only comment"); | 8558 CompilationUnit cu = _resolveContents("// only comment"); |
8560 expect(cu.element, isNotNull); | 8559 expect(cu.element, isNotNull); |
8561 Element element = ElementLocator.locate(cu); | 8560 Element element = ElementLocator.locate(cu); |
8562 expect(element, same(cu.element)); | 8561 expect(element, same(cu.element)); |
8563 } | 8562 } |
8564 | 8563 |
8565 void test_locate_ConstructorDeclaration() { | 8564 void test_locate_ConstructorDeclaration() { |
8566 AstNode id = | 8565 AstNode id = _findNodeIndexedIn("bar", 0, r''' |
8567 _findNodeIndexedIn("bar", 0, r''' | |
8568 class A { | 8566 class A { |
8569 A.bar() {} | 8567 A.bar() {} |
8570 }'''); | 8568 }'''); |
8571 ConstructorDeclaration declaration = | 8569 ConstructorDeclaration declaration = |
8572 id.getAncestor((node) => node is ConstructorDeclaration); | 8570 id.getAncestor((node) => node is ConstructorDeclaration); |
8573 Element element = ElementLocator.locate(declaration); | 8571 Element element = ElementLocator.locate(declaration); |
8574 EngineTestCase.assertInstanceOf( | 8572 EngineTestCase.assertInstanceOf( |
8575 (obj) => obj is ConstructorElement, | 8573 (obj) => obj is ConstructorElement, |
8576 ConstructorElement, | 8574 ConstructorElement, |
8577 element); | 8575 element); |
8578 } | 8576 } |
8579 | 8577 |
8580 void test_locate_FunctionDeclaration() { | 8578 void test_locate_FunctionDeclaration() { |
8581 AstNode id = _findNodeIn("f", "int f() => 3;"); | 8579 AstNode id = _findNodeIn("f", "int f() => 3;"); |
8582 FunctionDeclaration declaration = | 8580 FunctionDeclaration declaration = |
8583 id.getAncestor((node) => node is FunctionDeclaration); | 8581 id.getAncestor((node) => node is FunctionDeclaration); |
8584 Element element = ElementLocator.locate(declaration); | 8582 Element element = ElementLocator.locate(declaration); |
8585 EngineTestCase.assertInstanceOf( | 8583 EngineTestCase.assertInstanceOf( |
8586 (obj) => obj is FunctionElement, | 8584 (obj) => obj is FunctionElement, |
8587 FunctionElement, | 8585 FunctionElement, |
8588 element); | 8586 element); |
8589 } | 8587 } |
8590 | 8588 |
8591 void | 8589 void |
8592 test_locate_Identifier_annotationClass_namedConstructor_forSimpleFormalPar
ameter() { | 8590 test_locate_Identifier_annotationClass_namedConstructor_forSimpleFormalPar
ameter() { |
8593 AstNode id = _findNodeIndexedIn( | 8591 AstNode id = _findNodeIndexedIn("Class", 2, r''' |
8594 "Class", | |
8595 2, | |
8596 r''' | |
8597 class Class { | 8592 class Class { |
8598 const Class.name(); | 8593 const Class.name(); |
8599 } | 8594 } |
8600 void main(@Class.name() parameter) { | 8595 void main(@Class.name() parameter) { |
8601 }'''); | 8596 }'''); |
8602 Element element = ElementLocator.locate(id); | 8597 Element element = ElementLocator.locate(id); |
8603 EngineTestCase.assertInstanceOf( | 8598 EngineTestCase.assertInstanceOf( |
8604 (obj) => obj is ClassElement, | 8599 (obj) => obj is ClassElement, |
8605 ClassElement, | 8600 ClassElement, |
8606 element); | 8601 element); |
8607 } | 8602 } |
8608 | 8603 |
8609 void | 8604 void |
8610 test_locate_Identifier_annotationClass_unnamedConstructor_forSimpleFormalP
arameter() { | 8605 test_locate_Identifier_annotationClass_unnamedConstructor_forSimpleFormalP
arameter() { |
8611 AstNode id = _findNodeIndexedIn( | 8606 AstNode id = _findNodeIndexedIn("Class", 2, r''' |
8612 "Class", | |
8613 2, | |
8614 r''' | |
8615 class Class { | 8607 class Class { |
8616 const Class(); | 8608 const Class(); |
8617 } | 8609 } |
8618 void main(@Class() parameter) { | 8610 void main(@Class() parameter) { |
8619 }'''); | 8611 }'''); |
8620 Element element = ElementLocator.locate(id); | 8612 Element element = ElementLocator.locate(id); |
8621 EngineTestCase.assertInstanceOf( | 8613 EngineTestCase.assertInstanceOf( |
8622 (obj) => obj is ConstructorElement, | 8614 (obj) => obj is ConstructorElement, |
8623 ConstructorElement, | 8615 ConstructorElement, |
8624 element); | 8616 element); |
8625 } | 8617 } |
8626 | 8618 |
8627 void test_locate_Identifier_className() { | 8619 void test_locate_Identifier_className() { |
8628 AstNode id = _findNodeIn("A", "class A { }"); | 8620 AstNode id = _findNodeIn("A", "class A { }"); |
8629 Element element = ElementLocator.locate(id); | 8621 Element element = ElementLocator.locate(id); |
8630 EngineTestCase.assertInstanceOf( | 8622 EngineTestCase.assertInstanceOf( |
8631 (obj) => obj is ClassElement, | 8623 (obj) => obj is ClassElement, |
8632 ClassElement, | 8624 ClassElement, |
8633 element); | 8625 element); |
8634 } | 8626 } |
8635 | 8627 |
8636 void test_locate_Identifier_constructor_named() { | 8628 void test_locate_Identifier_constructor_named() { |
8637 AstNode id = | 8629 AstNode id = _findNodeIndexedIn("bar", 0, r''' |
8638 _findNodeIndexedIn("bar", 0, r''' | |
8639 class A { | 8630 class A { |
8640 A.bar() {} | 8631 A.bar() {} |
8641 }'''); | 8632 }'''); |
8642 Element element = ElementLocator.locate(id); | 8633 Element element = ElementLocator.locate(id); |
8643 EngineTestCase.assertInstanceOf( | 8634 EngineTestCase.assertInstanceOf( |
8644 (obj) => obj is ConstructorElement, | 8635 (obj) => obj is ConstructorElement, |
8645 ConstructorElement, | 8636 ConstructorElement, |
8646 element); | 8637 element); |
8647 } | 8638 } |
8648 | 8639 |
(...skipping 12 matching lines...) Expand all Loading... |
8661 void test_locate_Identifier_fieldName() { | 8652 void test_locate_Identifier_fieldName() { |
8662 AstNode id = _findNodeIn("x", "class A { var x; }"); | 8653 AstNode id = _findNodeIn("x", "class A { var x; }"); |
8663 Element element = ElementLocator.locate(id); | 8654 Element element = ElementLocator.locate(id); |
8664 EngineTestCase.assertInstanceOf( | 8655 EngineTestCase.assertInstanceOf( |
8665 (obj) => obj is FieldElement, | 8656 (obj) => obj is FieldElement, |
8666 FieldElement, | 8657 FieldElement, |
8667 element); | 8658 element); |
8668 } | 8659 } |
8669 | 8660 |
8670 void test_locate_Identifier_propertAccess() { | 8661 void test_locate_Identifier_propertAccess() { |
8671 AstNode id = | 8662 AstNode id = _findNodeIn("length", r''' |
8672 _findNodeIn("length", r''' | |
8673 void main() { | 8663 void main() { |
8674 int x = 'foo'.length; | 8664 int x = 'foo'.length; |
8675 }'''); | 8665 }'''); |
8676 Element element = ElementLocator.locate(id); | 8666 Element element = ElementLocator.locate(id); |
8677 EngineTestCase.assertInstanceOf( | 8667 EngineTestCase.assertInstanceOf( |
8678 (obj) => obj is PropertyAccessorElement, | 8668 (obj) => obj is PropertyAccessorElement, |
8679 PropertyAccessorElement, | 8669 PropertyAccessorElement, |
8680 element); | 8670 element); |
8681 } | 8671 } |
8682 | 8672 |
8683 void test_locate_ImportDirective() { | 8673 void test_locate_ImportDirective() { |
8684 AstNode id = _findNodeIn("import", "import 'dart:core';"); | 8674 AstNode id = _findNodeIn("import", "import 'dart:core';"); |
8685 Element element = ElementLocator.locate(id); | 8675 Element element = ElementLocator.locate(id); |
8686 EngineTestCase.assertInstanceOf( | 8676 EngineTestCase.assertInstanceOf( |
8687 (obj) => obj is ImportElement, | 8677 (obj) => obj is ImportElement, |
8688 ImportElement, | 8678 ImportElement, |
8689 element); | 8679 element); |
8690 } | 8680 } |
8691 | 8681 |
8692 void test_locate_IndexExpression() { | 8682 void test_locate_IndexExpression() { |
8693 AstNode id = _findNodeIndexedIn( | 8683 AstNode id = _findNodeIndexedIn("\\[", 1, r''' |
8694 "\\[", | |
8695 1, | |
8696 r''' | |
8697 void main() { | 8684 void main() { |
8698 List x = [1, 2]; | 8685 List x = [1, 2]; |
8699 var y = x[0]; | 8686 var y = x[0]; |
8700 }'''); | 8687 }'''); |
8701 Element element = ElementLocator.locate(id); | 8688 Element element = ElementLocator.locate(id); |
8702 EngineTestCase.assertInstanceOf( | 8689 EngineTestCase.assertInstanceOf( |
8703 (obj) => obj is MethodElement, | 8690 (obj) => obj is MethodElement, |
8704 MethodElement, | 8691 MethodElement, |
8705 element); | 8692 element); |
8706 } | 8693 } |
8707 | 8694 |
8708 void test_locate_InstanceCreationExpression() { | 8695 void test_locate_InstanceCreationExpression() { |
8709 AstNode node = | 8696 AstNode node = _findNodeIndexedIn("A(", 0, r''' |
8710 _findNodeIndexedIn("A(", 0, r''' | |
8711 class A {} | 8697 class A {} |
8712 void main() { | 8698 void main() { |
8713 new A(); | 8699 new A(); |
8714 }'''); | 8700 }'''); |
8715 Element element = ElementLocator.locate(node); | 8701 Element element = ElementLocator.locate(node); |
8716 EngineTestCase.assertInstanceOf( | 8702 EngineTestCase.assertInstanceOf( |
8717 (obj) => obj is ConstructorElement, | 8703 (obj) => obj is ConstructorElement, |
8718 ConstructorElement, | 8704 ConstructorElement, |
8719 element); | 8705 element); |
8720 } | 8706 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8776 MethodDeclaration declaration = | 8762 MethodDeclaration declaration = |
8777 id.getAncestor((node) => node is MethodDeclaration); | 8763 id.getAncestor((node) => node is MethodDeclaration); |
8778 Element element = ElementLocator.locate(declaration); | 8764 Element element = ElementLocator.locate(declaration); |
8779 EngineTestCase.assertInstanceOf( | 8765 EngineTestCase.assertInstanceOf( |
8780 (obj) => obj is MethodElement, | 8766 (obj) => obj is MethodElement, |
8781 MethodElement, | 8767 MethodElement, |
8782 element); | 8768 element); |
8783 } | 8769 } |
8784 | 8770 |
8785 void test_locate_MethodInvocation_method() { | 8771 void test_locate_MethodInvocation_method() { |
8786 AstNode id = _findNodeIndexedIn( | 8772 AstNode id = _findNodeIndexedIn("bar", 1, r''' |
8787 "bar", | |
8788 1, | |
8789 r''' | |
8790 class A { | 8773 class A { |
8791 int bar() => 42; | 8774 int bar() => 42; |
8792 } | 8775 } |
8793 void main() { | 8776 void main() { |
8794 var f = new A().bar(); | 8777 var f = new A().bar(); |
8795 }'''); | 8778 }'''); |
8796 Element element = ElementLocator.locate(id); | 8779 Element element = ElementLocator.locate(id); |
8797 EngineTestCase.assertInstanceOf( | 8780 EngineTestCase.assertInstanceOf( |
8798 (obj) => obj is MethodElement, | 8781 (obj) => obj is MethodElement, |
8799 MethodElement, | 8782 MethodElement, |
8800 element); | 8783 element); |
8801 } | 8784 } |
8802 | 8785 |
8803 void test_locate_MethodInvocation_topLevel() { | 8786 void test_locate_MethodInvocation_topLevel() { |
8804 String code = | 8787 String code = r''' |
8805 r''' | |
8806 foo(x) {} | 8788 foo(x) {} |
8807 void main() { | 8789 void main() { |
8808 foo(0); | 8790 foo(0); |
8809 }'''; | 8791 }'''; |
8810 CompilationUnit cu = _resolveContents(code); | 8792 CompilationUnit cu = _resolveContents(code); |
8811 int offset = code.indexOf('foo(0)'); | 8793 int offset = code.indexOf('foo(0)'); |
8812 AstNode node = new NodeLocator.con1(offset).searchWithin(cu); | 8794 AstNode node = new NodeLocator.con1(offset).searchWithin(cu); |
8813 MethodInvocation invocation = | 8795 MethodInvocation invocation = |
8814 node.getAncestor((n) => n is MethodInvocation); | 8796 node.getAncestor((n) => n is MethodInvocation); |
8815 Element element = ElementLocator.locate(invocation); | 8797 Element element = ElementLocator.locate(invocation); |
8816 EngineTestCase.assertInstanceOf( | 8798 EngineTestCase.assertInstanceOf( |
8817 (obj) => obj is FunctionElement, | 8799 (obj) => obj is FunctionElement, |
8818 FunctionElement, | 8800 FunctionElement, |
8819 element); | 8801 element); |
8820 } | 8802 } |
8821 | 8803 |
8822 void test_locate_PostfixExpression() { | 8804 void test_locate_PostfixExpression() { |
8823 AstNode id = _findNodeIn("++", "int addOne(int x) => x++;"); | 8805 AstNode id = _findNodeIn("++", "int addOne(int x) => x++;"); |
8824 Element element = ElementLocator.locate(id); | 8806 Element element = ElementLocator.locate(id); |
8825 EngineTestCase.assertInstanceOf( | 8807 EngineTestCase.assertInstanceOf( |
8826 (obj) => obj is MethodElement, | 8808 (obj) => obj is MethodElement, |
8827 MethodElement, | 8809 MethodElement, |
8828 element); | 8810 element); |
8829 } | 8811 } |
8830 | 8812 |
8831 void test_locate_PrefixExpression() { | |
8832 AstNode id = _findNodeIn("++", "int addOne(int x) => ++x;"); | |
8833 Element element = ElementLocator.locate(id); | |
8834 EngineTestCase.assertInstanceOf( | |
8835 (obj) => obj is MethodElement, | |
8836 MethodElement, | |
8837 element); | |
8838 } | |
8839 | |
8840 void test_locate_PrefixedIdentifier() { | 8813 void test_locate_PrefixedIdentifier() { |
8841 AstNode id = | 8814 AstNode id = _findNodeIn("int", r''' |
8842 _findNodeIn("int", r''' | |
8843 import 'dart:core' as core; | 8815 import 'dart:core' as core; |
8844 core.int value;'''); | 8816 core.int value;'''); |
8845 PrefixedIdentifier identifier = | 8817 PrefixedIdentifier identifier = |
8846 id.getAncestor((node) => node is PrefixedIdentifier); | 8818 id.getAncestor((node) => node is PrefixedIdentifier); |
8847 Element element = ElementLocator.locate(identifier); | 8819 Element element = ElementLocator.locate(identifier); |
8848 EngineTestCase.assertInstanceOf( | 8820 EngineTestCase.assertInstanceOf( |
8849 (obj) => obj is ClassElement, | 8821 (obj) => obj is ClassElement, |
8850 ClassElement, | 8822 ClassElement, |
8851 element); | 8823 element); |
8852 } | 8824 } |
8853 | 8825 |
| 8826 void test_locate_PrefixExpression() { |
| 8827 AstNode id = _findNodeIn("++", "int addOne(int x) => ++x;"); |
| 8828 Element element = ElementLocator.locate(id); |
| 8829 EngineTestCase.assertInstanceOf( |
| 8830 (obj) => obj is MethodElement, |
| 8831 MethodElement, |
| 8832 element); |
| 8833 } |
| 8834 |
8854 void test_locate_StringLiteral_exportUri() { | 8835 void test_locate_StringLiteral_exportUri() { |
8855 addNamedSource("/foo.dart", "library foo;"); | 8836 addNamedSource("/foo.dart", "library foo;"); |
8856 AstNode id = _findNodeIn("'foo.dart'", "export 'foo.dart';"); | 8837 AstNode id = _findNodeIn("'foo.dart'", "export 'foo.dart';"); |
8857 Element element = ElementLocator.locate(id); | 8838 Element element = ElementLocator.locate(id); |
8858 EngineTestCase.assertInstanceOf( | 8839 EngineTestCase.assertInstanceOf( |
8859 (obj) => obj is LibraryElement, | 8840 (obj) => obj is LibraryElement, |
8860 LibraryElement, | 8841 LibraryElement, |
8861 element); | 8842 element); |
8862 } | 8843 } |
8863 | 8844 |
(...skipping 28 matching lines...) Expand all Loading... |
8892 AstNode id = _findNodeIn("x", "var x = 'abc';"); | 8873 AstNode id = _findNodeIn("x", "var x = 'abc';"); |
8893 VariableDeclaration declaration = | 8874 VariableDeclaration declaration = |
8894 id.getAncestor((node) => node is VariableDeclaration); | 8875 id.getAncestor((node) => node is VariableDeclaration); |
8895 Element element = ElementLocator.locate(declaration); | 8876 Element element = ElementLocator.locate(declaration); |
8896 EngineTestCase.assertInstanceOf( | 8877 EngineTestCase.assertInstanceOf( |
8897 (obj) => obj is TopLevelVariableElement, | 8878 (obj) => obj is TopLevelVariableElement, |
8898 TopLevelVariableElement, | 8879 TopLevelVariableElement, |
8899 element); | 8880 element); |
8900 } | 8881 } |
8901 | 8882 |
| 8883 void test_locateWithOffset_BinaryExpression() { |
| 8884 AstNode id = _findNodeIn("+", "var x = 3 + 4;"); |
| 8885 Element element = ElementLocator.locateWithOffset(id, 0); |
| 8886 EngineTestCase.assertInstanceOf( |
| 8887 (obj) => obj is MethodElement, |
| 8888 MethodElement, |
| 8889 element); |
| 8890 } |
| 8891 |
| 8892 void test_locateWithOffset_StringLiteral() { |
| 8893 AstNode id = _findNodeIn("abc", "var x = 'abc';"); |
| 8894 Element element = ElementLocator.locateWithOffset(id, 1); |
| 8895 expect(element, isNull); |
| 8896 } |
| 8897 |
8902 /** | 8898 /** |
8903 * Find the first AST node matching a pattern in the resolved AST for the give
n source. | 8899 * Find the first AST node matching a pattern in the resolved AST for the give
n source. |
8904 * | 8900 * |
8905 * [nodePattern] the (unique) pattern used to identify the node of interest. | 8901 * [nodePattern] the (unique) pattern used to identify the node of interest. |
8906 * [code] the code to resolve. | 8902 * [code] the code to resolve. |
8907 * Returns the matched node in the resolved AST for the given source lines. | 8903 * Returns the matched node in the resolved AST for the given source lines. |
8908 */ | 8904 */ |
8909 AstNode _findNodeIn(String nodePattern, String code) { | 8905 AstNode _findNodeIn(String nodePattern, String code) { |
8910 return _findNodeIndexedIn(nodePattern, 0, code); | 8906 return _findNodeIndexedIn(nodePattern, 0, code); |
8911 } | 8907 } |
8912 | 8908 |
8913 /** | 8909 /** |
8914 * Find the AST node matching the given indexed occurrence of a pattern in the
resolved AST for | 8910 * Find the AST node matching the given indexed occurrence of a pattern in the
resolved AST for |
8915 * the given source. | 8911 * the given source. |
8916 * | 8912 * |
8917 * [nodePattern] the pattern used to identify the node of interest. | 8913 * [nodePattern] the pattern used to identify the node of interest. |
8918 * [index] the index of the pattern match of interest. | 8914 * [index] the index of the pattern match of interest. |
8919 * [code] the code to resolve. | 8915 * [code] the code to resolve. |
8920 * Returns the matched node in the resolved AST for the given source lines | 8916 * Returns the matched node in the resolved AST for the given source lines |
8921 */ | 8917 */ |
8922 AstNode _findNodeIndexedIn(String nodePattern, int index, | 8918 AstNode _findNodeIndexedIn(String nodePattern, int index, String code) { |
8923 String code) { | |
8924 CompilationUnit cu = _resolveContents(code); | 8919 CompilationUnit cu = _resolveContents(code); |
8925 int start = _getOffsetOfMatch(code, nodePattern, index); | 8920 int start = _getOffsetOfMatch(code, nodePattern, index); |
8926 int end = start + nodePattern.length; | 8921 int end = start + nodePattern.length; |
8927 return new NodeLocator.con2(start, end).searchWithin(cu); | 8922 return new NodeLocator.con2(start, end).searchWithin(cu); |
8928 } | 8923 } |
8929 | 8924 |
8930 int _getOffsetOfMatch(String contents, String pattern, int matchIndex) { | 8925 int _getOffsetOfMatch(String contents, String pattern, int matchIndex) { |
8931 if (matchIndex == 0) { | 8926 if (matchIndex == 0) { |
8932 return contents.indexOf(pattern); | 8927 return contents.indexOf(pattern); |
8933 } | 8928 } |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9093 AstFactory.identifier3("x"), | 9088 AstFactory.identifier3("x"), |
9094 [firstType, secondType]); | 9089 [firstType, secondType]); |
9095 AnalysisError error = listener.errors[0]; | 9090 AnalysisError error = listener.errors[0]; |
9096 expect(error.message.indexOf("(") >= 0, isTrue); | 9091 expect(error.message.indexOf("(") >= 0, isTrue); |
9097 } | 9092 } |
9098 } | 9093 } |
9099 | 9094 |
9100 | 9095 |
9101 class ErrorSeverityTest extends EngineTestCase { | 9096 class ErrorSeverityTest extends EngineTestCase { |
9102 void test_max_error_error() { | 9097 void test_max_error_error() { |
9103 expect(ErrorSeverity.ERROR.max(ErrorSeverity.ERROR), same(ErrorSeverity.ERRO
R)); | 9098 expect( |
| 9099 ErrorSeverity.ERROR.max(ErrorSeverity.ERROR), |
| 9100 same(ErrorSeverity.ERROR)); |
9104 } | 9101 } |
9105 | 9102 |
9106 void test_max_error_none() { | 9103 void test_max_error_none() { |
9107 expect(ErrorSeverity.ERROR.max(ErrorSeverity.NONE), same(ErrorSeverity.ERROR
)); | 9104 expect( |
| 9105 ErrorSeverity.ERROR.max(ErrorSeverity.NONE), |
| 9106 same(ErrorSeverity.ERROR)); |
9108 } | 9107 } |
9109 | 9108 |
9110 void test_max_error_warning() { | 9109 void test_max_error_warning() { |
9111 expect(ErrorSeverity.ERROR.max(ErrorSeverity.WARNING), same(ErrorSeverity.ER
ROR)); | 9110 expect( |
| 9111 ErrorSeverity.ERROR.max(ErrorSeverity.WARNING), |
| 9112 same(ErrorSeverity.ERROR)); |
9112 } | 9113 } |
9113 | 9114 |
9114 void test_max_none_error() { | 9115 void test_max_none_error() { |
9115 expect(ErrorSeverity.NONE.max(ErrorSeverity.ERROR), same(ErrorSeverity.ERROR
)); | 9116 expect( |
| 9117 ErrorSeverity.NONE.max(ErrorSeverity.ERROR), |
| 9118 same(ErrorSeverity.ERROR)); |
9116 } | 9119 } |
9117 | 9120 |
9118 void test_max_none_none() { | 9121 void test_max_none_none() { |
9119 expect(ErrorSeverity.NONE.max(ErrorSeverity.NONE), same(ErrorSeverity.NONE))
; | 9122 expect( |
| 9123 ErrorSeverity.NONE.max(ErrorSeverity.NONE), |
| 9124 same(ErrorSeverity.NONE)); |
9120 } | 9125 } |
9121 | 9126 |
9122 void test_max_none_warning() { | 9127 void test_max_none_warning() { |
9123 expect(ErrorSeverity.NONE.max(ErrorSeverity.WARNING), same(ErrorSeverity.WAR
NING)); | 9128 expect( |
| 9129 ErrorSeverity.NONE.max(ErrorSeverity.WARNING), |
| 9130 same(ErrorSeverity.WARNING)); |
9124 } | 9131 } |
9125 | 9132 |
9126 void test_max_warning_error() { | 9133 void test_max_warning_error() { |
9127 expect(ErrorSeverity.WARNING.max(ErrorSeverity.ERROR), same(ErrorSeverity.ER
ROR)); | 9134 expect( |
| 9135 ErrorSeverity.WARNING.max(ErrorSeverity.ERROR), |
| 9136 same(ErrorSeverity.ERROR)); |
9128 } | 9137 } |
9129 | 9138 |
9130 void test_max_warning_none() { | 9139 void test_max_warning_none() { |
9131 expect(ErrorSeverity.WARNING.max(ErrorSeverity.NONE), same(ErrorSeverity.WAR
NING)); | 9140 expect( |
| 9141 ErrorSeverity.WARNING.max(ErrorSeverity.NONE), |
| 9142 same(ErrorSeverity.WARNING)); |
9132 } | 9143 } |
9133 | 9144 |
9134 void test_max_warning_warning() { | 9145 void test_max_warning_warning() { |
9135 expect(ErrorSeverity.WARNING.max(ErrorSeverity.WARNING), same(ErrorSeverity.
WARNING)); | 9146 expect( |
| 9147 ErrorSeverity.WARNING.max(ErrorSeverity.WARNING), |
| 9148 same(ErrorSeverity.WARNING)); |
9136 } | 9149 } |
9137 } | 9150 } |
9138 | 9151 |
9139 | 9152 |
9140 class ExitDetectorTest extends ParserTestCase { | 9153 class ExitDetectorTest extends ParserTestCase { |
9141 void fail_doStatement_continue_with_label() { | 9154 void fail_doStatement_continue_with_label() { |
9142 _assertFalse("{ x: do { continue x; } while(true); }"); | 9155 _assertFalse("{ x: do { continue x; } while(true); }"); |
9143 } | 9156 } |
9144 | 9157 |
9145 void fail_whileStatement_continue_with_label() { | 9158 void fail_whileStatement_continue_with_label() { |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9347 } | 9360 } |
9348 | 9361 |
9349 void test_forStatement_variableDeclaration() { | 9362 void test_forStatement_variableDeclaration() { |
9350 _assertTrue("for (int i = throw 0;;) {}"); | 9363 _assertTrue("for (int i = throw 0;;) {}"); |
9351 } | 9364 } |
9352 | 9365 |
9353 void test_functionExpression() { | 9366 void test_functionExpression() { |
9354 _assertFalse("(){};"); | 9367 _assertFalse("(){};"); |
9355 } | 9368 } |
9356 | 9369 |
| 9370 void test_functionExpression_bodyThrows() { |
| 9371 _assertFalse("(int i) => throw '';"); |
| 9372 } |
| 9373 |
9357 void test_functionExpressionInvocation() { | 9374 void test_functionExpressionInvocation() { |
9358 _assertFalse("f(g);"); | 9375 _assertFalse("f(g);"); |
9359 } | 9376 } |
9360 | 9377 |
9361 void test_functionExpressionInvocation_argumentThrows() { | 9378 void test_functionExpressionInvocation_argumentThrows() { |
9362 _assertTrue("f(throw '');"); | 9379 _assertTrue("f(throw '');"); |
9363 } | 9380 } |
9364 | 9381 |
9365 void test_functionExpressionInvocation_targetThrows() { | 9382 void test_functionExpressionInvocation_targetThrows() { |
9366 _assertTrue("throw ''(g);"); | 9383 _assertTrue("throw ''(g);"); |
9367 } | 9384 } |
9368 | 9385 |
9369 void test_functionExpression_bodyThrows() { | |
9370 _assertFalse("(int i) => throw '';"); | |
9371 } | |
9372 | |
9373 void test_identifier_prefixedIdentifier() { | 9386 void test_identifier_prefixedIdentifier() { |
9374 _assertFalse("a.b;"); | 9387 _assertFalse("a.b;"); |
9375 } | 9388 } |
9376 | 9389 |
9377 void test_identifier_simpleIdentifier() { | 9390 void test_identifier_simpleIdentifier() { |
9378 _assertFalse("a;"); | 9391 _assertFalse("a;"); |
9379 } | 9392 } |
9380 | 9393 |
9381 void test_ifElse_bothReturn() { | |
9382 _assertTrue("if (c) return 0; else return 1;"); | |
9383 } | |
9384 | |
9385 void test_ifElse_elseReturn() { | |
9386 _assertFalse("if (c) i++; else return 1;"); | |
9387 } | |
9388 | |
9389 void test_ifElse_noReturn() { | |
9390 _assertFalse("if (c) i++; else j++;"); | |
9391 } | |
9392 | |
9393 void test_ifElse_thenReturn() { | |
9394 _assertFalse("if (c) return 0; else j++;"); | |
9395 } | |
9396 | |
9397 void test_if_false_else_return() { | 9394 void test_if_false_else_return() { |
9398 _assertTrue("if (false) {} else { return 0; }"); | 9395 _assertTrue("if (false) {} else { return 0; }"); |
9399 } | 9396 } |
9400 | 9397 |
9401 void test_if_false_noReturn() { | 9398 void test_if_false_noReturn() { |
9402 _assertFalse("if (false) {}"); | 9399 _assertFalse("if (false) {}"); |
9403 } | 9400 } |
9404 | 9401 |
9405 void test_if_false_return() { | 9402 void test_if_false_return() { |
9406 _assertFalse("if (false) { return 0; }"); | 9403 _assertFalse("if (false) { return 0; }"); |
9407 } | 9404 } |
9408 | 9405 |
9409 void test_if_noReturn() { | 9406 void test_if_noReturn() { |
9410 _assertFalse("if (c) i++;"); | 9407 _assertFalse("if (c) i++;"); |
9411 } | 9408 } |
9412 | 9409 |
9413 void test_if_return() { | 9410 void test_if_return() { |
9414 _assertFalse("if (c) return 0;"); | 9411 _assertFalse("if (c) return 0;"); |
9415 } | 9412 } |
9416 | 9413 |
9417 void test_if_true_noReturn() { | 9414 void test_if_true_noReturn() { |
9418 _assertFalse("if (true) {}"); | 9415 _assertFalse("if (true) {}"); |
9419 } | 9416 } |
9420 | 9417 |
9421 void test_if_true_return() { | 9418 void test_if_true_return() { |
9422 _assertTrue("if (true) { return 0; }"); | 9419 _assertTrue("if (true) { return 0; }"); |
9423 } | 9420 } |
9424 | 9421 |
| 9422 void test_ifElse_bothReturn() { |
| 9423 _assertTrue("if (c) return 0; else return 1;"); |
| 9424 } |
| 9425 |
| 9426 void test_ifElse_elseReturn() { |
| 9427 _assertFalse("if (c) i++; else return 1;"); |
| 9428 } |
| 9429 |
| 9430 void test_ifElse_noReturn() { |
| 9431 _assertFalse("if (c) i++; else j++;"); |
| 9432 } |
| 9433 |
| 9434 void test_ifElse_thenReturn() { |
| 9435 _assertFalse("if (c) return 0; else j++;"); |
| 9436 } |
| 9437 |
9425 void test_indexExpression() { | 9438 void test_indexExpression() { |
9426 _assertFalse("a[b];"); | 9439 _assertFalse("a[b];"); |
9427 } | 9440 } |
9428 | 9441 |
9429 void test_indexExpression_index() { | 9442 void test_indexExpression_index() { |
9430 _assertTrue("a[throw ''];"); | 9443 _assertTrue("a[throw ''];"); |
9431 } | 9444 } |
9432 | 9445 |
9433 void test_indexExpression_target() { | 9446 void test_indexExpression_target() { |
9434 _assertTrue("throw ''[b];"); | 9447 _assertTrue("throw ''[b];"); |
(...skipping 16 matching lines...) Expand all Loading... |
9451 } | 9464 } |
9452 | 9465 |
9453 void test_labeledStatement() { | 9466 void test_labeledStatement() { |
9454 _assertFalse("label: a;"); | 9467 _assertFalse("label: a;"); |
9455 } | 9468 } |
9456 | 9469 |
9457 void test_labeledStatement_throws() { | 9470 void test_labeledStatement_throws() { |
9458 _assertTrue("label: throw '';"); | 9471 _assertTrue("label: throw '';"); |
9459 } | 9472 } |
9460 | 9473 |
9461 void test_literal_String() { | |
9462 _assertFalse("'str';"); | |
9463 } | |
9464 | |
9465 void test_literal_boolean() { | 9474 void test_literal_boolean() { |
9466 _assertFalse("true;"); | 9475 _assertFalse("true;"); |
9467 } | 9476 } |
9468 | 9477 |
9469 void test_literal_double() { | 9478 void test_literal_double() { |
9470 _assertFalse("1.1;"); | 9479 _assertFalse("1.1;"); |
9471 } | 9480 } |
9472 | 9481 |
9473 void test_literal_integer() { | 9482 void test_literal_integer() { |
9474 _assertFalse("1;"); | 9483 _assertFalse("1;"); |
9475 } | 9484 } |
9476 | 9485 |
9477 void test_literal_null() { | 9486 void test_literal_null() { |
9478 _assertFalse("null;"); | 9487 _assertFalse("null;"); |
9479 } | 9488 } |
9480 | 9489 |
| 9490 void test_literal_String() { |
| 9491 _assertFalse("'str';"); |
| 9492 } |
| 9493 |
9481 void test_methodInvocation() { | 9494 void test_methodInvocation() { |
9482 _assertFalse("a.b(c);"); | 9495 _assertFalse("a.b(c);"); |
9483 } | 9496 } |
9484 | 9497 |
9485 void test_methodInvocation_argument() { | 9498 void test_methodInvocation_argument() { |
9486 _assertTrue("a.b(throw '');"); | 9499 _assertTrue("a.b(throw '');"); |
9487 } | 9500 } |
9488 | 9501 |
9489 void test_methodInvocation_target() { | 9502 void test_methodInvocation_target() { |
9490 _assertTrue("throw ''.b(c);"); | 9503 _assertTrue("throw ''.b(c);"); |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9857 class FileUriResolverTest { | 9870 class FileUriResolverTest { |
9858 void test_creation() { | 9871 void test_creation() { |
9859 expect(new FileUriResolver(), isNotNull); | 9872 expect(new FileUriResolver(), isNotNull); |
9860 } | 9873 } |
9861 | 9874 |
9862 void test_resolve_file() { | 9875 void test_resolve_file() { |
9863 UriResolver resolver = new FileUriResolver(); | 9876 UriResolver resolver = new FileUriResolver(); |
9864 Source result = | 9877 Source result = |
9865 resolver.resolveAbsolute(parseUriWithException("file:/does/not/exist.dar
t")); | 9878 resolver.resolveAbsolute(parseUriWithException("file:/does/not/exist.dar
t")); |
9866 expect(result, isNotNull); | 9879 expect(result, isNotNull); |
9867 expect(result.fullName, FileUtilities2.createFile("/does/not/exist.dart").ge
tAbsolutePath()); | 9880 expect( |
| 9881 result.fullName, |
| 9882 FileUtilities2.createFile("/does/not/exist.dart").getAbsolutePath()); |
9868 } | 9883 } |
9869 | 9884 |
9870 void test_resolve_nonFile() { | 9885 void test_resolve_nonFile() { |
9871 UriResolver resolver = new FileUriResolver(); | 9886 UriResolver resolver = new FileUriResolver(); |
9872 Source result = | 9887 Source result = |
9873 resolver.resolveAbsolute(parseUriWithException("dart:core")); | 9888 resolver.resolveAbsolute(parseUriWithException("dart:core")); |
9874 expect(result, isNull); | 9889 expect(result, isNull); |
9875 } | 9890 } |
9876 } | 9891 } |
9877 | 9892 |
(...skipping 17 matching lines...) Expand all Loading... |
9895 $scriptBody | 9910 $scriptBody |
9896 </script> | 9911 </script> |
9897 </body> | 9912 </body> |
9898 </html>"""); | 9913 </html>"""); |
9899 _validate( | 9914 _validate( |
9900 htmlUnit, | 9915 htmlUnit, |
9901 [ | 9916 [ |
9902 _t4( | 9917 _t4( |
9903 "html", | 9918 "html", |
9904 [ | 9919 [ |
9905 _t4( | 9920 _t4("body", [_t("script", _a(["type", "'application/dart'"])
, scriptBody)])])]); |
9906 "body", | |
9907 [_t("script", _a(["type", "'application/dart'"]), script
Body)])])]); | |
9908 } | 9921 } |
9909 ht.HtmlUnit parse(String contents) { | 9922 ht.HtmlUnit parse(String contents) { |
9910 // TestSource source = | 9923 // TestSource source = |
9911 // new TestSource.con1(FileUtilities2.createFile("/test.dart"), contents)
; | 9924 // new TestSource.con1(FileUtilities2.createFile("/test.dart"), contents)
; |
9912 ht.AbstractScanner scanner = new ht.StringScanner(null, contents); | 9925 ht.AbstractScanner scanner = new ht.StringScanner(null, contents); |
9913 scanner.passThroughElements = <String>[_TAG_SCRIPT]; | 9926 scanner.passThroughElements = <String>[_TAG_SCRIPT]; |
9914 ht.Token token = scanner.tokenize(); | 9927 ht.Token token = scanner.tokenize(); |
9915 LineInfo lineInfo = new LineInfo(scanner.lineStarts); | 9928 LineInfo lineInfo = new LineInfo(scanner.lineStarts); |
9916 GatheringErrorListener errorListener = new GatheringErrorListener(); | 9929 GatheringErrorListener errorListener = new GatheringErrorListener(); |
9917 ht.HtmlUnit unit = | 9930 ht.HtmlUnit unit = |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10036 ht.HtmlUnit htmlUnit = parse("<html>foo<br>bar</html>"); | 10049 ht.HtmlUnit htmlUnit = parse("<html>foo<br>bar</html>"); |
10037 _validate(htmlUnit, [_t3("html", "foo<br>bar", [_t3("br", "")])]); | 10050 _validate(htmlUnit, [_t3("html", "foo<br>bar", [_t3("br", "")])]); |
10038 } | 10051 } |
10039 void test_parse_self_closing_declaration() { | 10052 void test_parse_self_closing_declaration() { |
10040 ht.HtmlUnit htmlUnit = parse("<!DOCTYPE html><html>foo</html>"); | 10053 ht.HtmlUnit htmlUnit = parse("<!DOCTYPE html><html>foo</html>"); |
10041 _validate(htmlUnit, [_t3("html", "foo")]); | 10054 _validate(htmlUnit, [_t3("html", "foo")]); |
10042 } | 10055 } |
10043 XmlValidator_Attributes _a(List<String> keyValuePairs) => | 10056 XmlValidator_Attributes _a(List<String> keyValuePairs) => |
10044 new XmlValidator_Attributes(keyValuePairs); | 10057 new XmlValidator_Attributes(keyValuePairs); |
10045 XmlValidator_Tag _t(String tag, XmlValidator_Attributes attributes, | 10058 XmlValidator_Tag _t(String tag, XmlValidator_Attributes attributes, |
10046 String content, [List<XmlValidator_Tag> children = XmlValidator_Tag.EMPTY_
LIST]) => | 10059 String content, [List<XmlValidator_Tag> children = |
| 10060 XmlValidator_Tag.EMPTY_LIST]) => |
10047 new XmlValidator_Tag(tag, attributes, content, children); | 10061 new XmlValidator_Tag(tag, attributes, content, children); |
10048 XmlValidator_Tag _t3(String tag, String content, | 10062 XmlValidator_Tag _t3(String tag, String content, |
10049 [List<XmlValidator_Tag> children = XmlValidator_Tag.EMPTY_LIST]) => | 10063 [List<XmlValidator_Tag> children = XmlValidator_Tag.EMPTY_LIST]) => |
10050 new XmlValidator_Tag(tag, new XmlValidator_Attributes(), content, children
); | 10064 new XmlValidator_Tag(tag, new XmlValidator_Attributes(), content, children
); |
10051 XmlValidator_Tag _t4(String tag, [List<XmlValidator_Tag> children = XmlValidat
or_Tag.EMPTY_LIST]) => | 10065 XmlValidator_Tag _t4(String tag, [List<XmlValidator_Tag> children = |
| 10066 XmlValidator_Tag.EMPTY_LIST]) => |
10052 new XmlValidator_Tag(tag, new XmlValidator_Attributes(), null, children); | 10067 new XmlValidator_Tag(tag, new XmlValidator_Attributes(), null, children); |
10053 void _validate(ht.HtmlUnit htmlUnit, List<XmlValidator_Tag> expectedTags) { | 10068 void _validate(ht.HtmlUnit htmlUnit, List<XmlValidator_Tag> expectedTags) { |
10054 XmlValidator validator = new XmlValidator(); | 10069 XmlValidator validator = new XmlValidator(); |
10055 validator.expectTags(expectedTags); | 10070 validator.expectTags(expectedTags); |
10056 htmlUnit.accept(validator); | 10071 htmlUnit.accept(validator); |
10057 validator.assertValid(); | 10072 validator.assertValid(); |
10058 } | 10073 } |
10059 } | 10074 } |
10060 | 10075 |
10061 | 10076 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10147 TestSource source = new TestSource( | 10162 TestSource source = new TestSource( |
10148 FileUtilities2.createFile("/test.html").getAbsolutePath(), | 10163 FileUtilities2.createFile("/test.html").getAbsolutePath(), |
10149 contents); | 10164 contents); |
10150 ChangeSet changeSet = new ChangeSet(); | 10165 ChangeSet changeSet = new ChangeSet(); |
10151 changeSet.addedSource(source); | 10166 changeSet.addedSource(source); |
10152 _context.applyChanges(changeSet); | 10167 _context.applyChanges(changeSet); |
10153 HtmlUnitBuilder builder = new HtmlUnitBuilder(_context); | 10168 HtmlUnitBuilder builder = new HtmlUnitBuilder(_context); |
10154 return builder.buildHtmlElement(source, _context.parseHtmlUnit(source)); | 10169 return builder.buildHtmlElement(source, _context.parseHtmlUnit(source)); |
10155 } | 10170 } |
10156 HtmlUnitBuilderTest_ExpectedLibrary | 10171 HtmlUnitBuilderTest_ExpectedLibrary |
10157 _l([List<HtmlUnitBuilderTest_ExpectedVariable> expectedVariables = HtmlUni
tBuilderTest_ExpectedVariable.EMPTY_LIST]) => | 10172 _l([List<HtmlUnitBuilderTest_ExpectedVariable> expectedVariables = |
| 10173 HtmlUnitBuilderTest_ExpectedVariable.EMPTY_LIST]) => |
10158 new HtmlUnitBuilderTest_ExpectedLibrary(this, expectedVariables); | 10174 new HtmlUnitBuilderTest_ExpectedLibrary(this, expectedVariables); |
10159 _ExpectedScript _s(HtmlUnitBuilderTest_ExpectedLibrary expectedLibrary) => | 10175 _ExpectedScript _s(HtmlUnitBuilderTest_ExpectedLibrary expectedLibrary) => |
10160 new _ExpectedScript.con1(expectedLibrary); | 10176 new _ExpectedScript.con1(expectedLibrary); |
10161 _ExpectedScript _s2(String scriptSourcePath) => | 10177 _ExpectedScript _s2(String scriptSourcePath) => |
10162 new _ExpectedScript.con2(scriptSourcePath); | 10178 new _ExpectedScript.con2(scriptSourcePath); |
10163 HtmlUnitBuilderTest_ExpectedVariable _v(String varName) => | 10179 HtmlUnitBuilderTest_ExpectedVariable _v(String varName) => |
10164 new HtmlUnitBuilderTest_ExpectedVariable(varName); | 10180 new HtmlUnitBuilderTest_ExpectedVariable(varName); |
10165 void _validate(HtmlElementImpl element, | 10181 void _validate(HtmlElementImpl element, |
10166 List<_ExpectedScript> expectedScripts) { | 10182 List<_ExpectedScript> expectedScripts) { |
10167 expect(element.context, same(_context)); | 10183 expect(element.context, same(_context)); |
10168 List<HtmlScriptElement> scripts = element.scripts; | 10184 List<HtmlScriptElement> scripts = element.scripts; |
10169 expect(scripts, isNotNull); | 10185 expect(scripts, isNotNull); |
10170 expect(scripts, hasLength(expectedScripts.length)); | 10186 expect(scripts, hasLength(expectedScripts.length)); |
10171 for (int scriptIndex = 0; scriptIndex < scripts.length; scriptIndex++) { | 10187 for (int scriptIndex = 0; scriptIndex < scripts.length; scriptIndex++) { |
10172 expectedScripts[scriptIndex]._validate(scriptIndex, scripts[scriptIndex]); | 10188 expectedScripts[scriptIndex]._validate(scriptIndex, scripts[scriptIndex]); |
10173 } | 10189 } |
10174 } | 10190 } |
10175 } | 10191 } |
10176 | 10192 |
10177 | 10193 |
10178 class HtmlUnitBuilderTest_ExpectedLibrary { | 10194 class HtmlUnitBuilderTest_ExpectedLibrary { |
10179 final HtmlUnitBuilderTest HtmlUnitBuilderTest_this; | 10195 final HtmlUnitBuilderTest HtmlUnitBuilderTest_this; |
10180 final List<HtmlUnitBuilderTest_ExpectedVariable> _expectedVariables; | 10196 final List<HtmlUnitBuilderTest_ExpectedVariable> _expectedVariables; |
10181 HtmlUnitBuilderTest_ExpectedLibrary(this.HtmlUnitBuilderTest_this, | 10197 HtmlUnitBuilderTest_ExpectedLibrary(this.HtmlUnitBuilderTest_this, |
10182 [this._expectedVariables = HtmlUnitBuilderTest_ExpectedVariable.EMPTY_LIST
]); | 10198 [this._expectedVariables = HtmlUnitBuilderTest_ExpectedVariable.EMPTY_LIST
]); |
10183 void _validate(int scriptIndex, EmbeddedHtmlScriptElementImpl script) { | 10199 void _validate(int scriptIndex, EmbeddedHtmlScriptElementImpl script) { |
10184 LibraryElement library = script.scriptLibrary; | 10200 LibraryElement library = script.scriptLibrary; |
10185 expect(library, isNotNull, reason: "script $scriptIndex"); | 10201 expect(library, isNotNull, reason: "script $scriptIndex"); |
10186 expect(script.context, same(HtmlUnitBuilderTest_this._context), reason: "scr
ipt $scriptIndex"); | 10202 expect( |
| 10203 script.context, |
| 10204 same(HtmlUnitBuilderTest_this._context), |
| 10205 reason: "script $scriptIndex"); |
10187 CompilationUnitElement unit = library.definingCompilationUnit; | 10206 CompilationUnitElement unit = library.definingCompilationUnit; |
10188 expect(unit, isNotNull, reason: "script $scriptIndex"); | 10207 expect(unit, isNotNull, reason: "script $scriptIndex"); |
10189 List<TopLevelVariableElement> variables = unit.topLevelVariables; | 10208 List<TopLevelVariableElement> variables = unit.topLevelVariables; |
10190 expect(variables, hasLength(_expectedVariables.length)); | 10209 expect(variables, hasLength(_expectedVariables.length)); |
10191 for (int index = 0; index < variables.length; index++) { | 10210 for (int index = 0; index < variables.length; index++) { |
10192 _expectedVariables[index].validate(scriptIndex, variables[index]); | 10211 _expectedVariables[index].validate(scriptIndex, variables[index]); |
10193 } | 10212 } |
10194 expect(library.enclosingElement, same(script), reason: "script $scriptIndex"
); | 10213 expect( |
| 10214 library.enclosingElement, |
| 10215 same(script), |
| 10216 reason: "script $scriptIndex"); |
10195 } | 10217 } |
10196 } | 10218 } |
10197 | 10219 |
10198 | 10220 |
10199 class HtmlUnitBuilderTest_ExpectedVariable { | 10221 class HtmlUnitBuilderTest_ExpectedVariable { |
| 10222 static const List<HtmlUnitBuilderTest_ExpectedVariable> EMPTY_LIST = const |
| 10223 <HtmlUnitBuilderTest_ExpectedVariable>[ |
| 10224 ]; |
10200 final String _expectedName; | 10225 final String _expectedName; |
10201 static const List<HtmlUnitBuilderTest_ExpectedVariable> EMPTY_LIST | |
10202 = const <HtmlUnitBuilderTest_ExpectedVariable>[]; | |
10203 HtmlUnitBuilderTest_ExpectedVariable(this._expectedName); | 10226 HtmlUnitBuilderTest_ExpectedVariable(this._expectedName); |
10204 void validate(int scriptIndex, TopLevelVariableElement variable) { | 10227 void validate(int scriptIndex, TopLevelVariableElement variable) { |
10205 expect(variable, isNotNull, reason: "script $scriptIndex"); | 10228 expect(variable, isNotNull, reason: "script $scriptIndex"); |
10206 expect(variable.name, _expectedName, reason: "script $scriptIndex"); | 10229 expect(variable.name, _expectedName, reason: "script $scriptIndex"); |
10207 } | 10230 } |
10208 } | 10231 } |
10209 | 10232 |
10210 | 10233 |
10211 /** | 10234 /** |
10212 * Instances of the class `HtmlWarningCodeTest` test the generation of HTML warn
ing codes. | 10235 * Instances of the class `HtmlWarningCodeTest` test the generation of HTML warn
ing codes. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10244 _context = null; | 10267 _context = null; |
10245 _contents = null; | 10268 _contents = null; |
10246 _errors = null; | 10269 _errors = null; |
10247 super.tearDown(); | 10270 super.tearDown(); |
10248 } | 10271 } |
10249 | 10272 |
10250 void test_invalidUri() { | 10273 void test_invalidUri() { |
10251 _verify(r''' | 10274 _verify(r''' |
10252 <html> | 10275 <html> |
10253 <script type='application/dart' src='ht:'/> | 10276 <script type='application/dart' src='ht:'/> |
10254 </html>''', | 10277 </html>''', [HtmlWarningCode.INVALID_URI]); |
10255 [HtmlWarningCode.INVALID_URI]); | |
10256 _assertErrorLocation2(_errors[0], "ht:"); | 10278 _assertErrorLocation2(_errors[0], "ht:"); |
10257 } | 10279 } |
10258 | 10280 |
10259 void test_uriDoesNotExist() { | 10281 void test_uriDoesNotExist() { |
10260 _verify(r''' | 10282 _verify(r''' |
10261 <html> | 10283 <html> |
10262 <script type='application/dart' src='other.dart'/> | 10284 <script type='application/dart' src='other.dart'/> |
10263 </html>''', | 10285 </html>''', [HtmlWarningCode.URI_DOES_NOT_EXIST]); |
10264 [HtmlWarningCode.URI_DOES_NOT_EXIST]); | |
10265 _assertErrorLocation2(_errors[0], "other.dart"); | 10286 _assertErrorLocation2(_errors[0], "other.dart"); |
10266 } | 10287 } |
10267 | 10288 |
10268 void _assertErrorLocation(AnalysisError error, int expectedOffset, | 10289 void _assertErrorLocation(AnalysisError error, int expectedOffset, |
10269 int expectedLength) { | 10290 int expectedLength) { |
10270 expect(error.offset, expectedOffset, reason: error.toString()); | 10291 expect(error.offset, expectedOffset, reason: error.toString()); |
10271 expect(error.length, expectedLength, reason: error.toString()); | 10292 expect(error.length, expectedLength, reason: error.toString()); |
10272 } | 10293 } |
10273 | 10294 |
10274 void _assertErrorLocation2(AnalysisError error, String expectedString) { | 10295 void _assertErrorLocation2(AnalysisError error, String expectedString) { |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10481 } | 10502 } |
10482 void _visitNode(AstNode node) { | 10503 void _visitNode(AstNode node) { |
10483 node.accept(_createReferenceFinder(_head)); | 10504 node.accept(_createReferenceFinder(_head)); |
10484 } | 10505 } |
10485 } | 10506 } |
10486 | 10507 |
10487 | 10508 |
10488 class SDKLibrariesReaderTest extends EngineTestCase { | 10509 class SDKLibrariesReaderTest extends EngineTestCase { |
10489 void test_readFrom_dart2js() { | 10510 void test_readFrom_dart2js() { |
10490 LibraryMap libraryMap = new SdkLibrariesReader( | 10511 LibraryMap libraryMap = new SdkLibrariesReader( |
10491 true).readFromFile( | 10512 true).readFromFile(FileUtilities2.createFile("/libs.dart"), r''' |
10492 FileUtilities2.createFile("/libs.dart"), | |
10493 r''' | |
10494 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> { | 10513 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> { |
10495 'first' : const LibraryInfo( | 10514 'first' : const LibraryInfo( |
10496 'first/first.dart', | 10515 'first/first.dart', |
10497 category: 'First', | 10516 category: 'First', |
10498 documented: true, | 10517 documented: true, |
10499 platforms: VM_PLATFORM, | 10518 platforms: VM_PLATFORM, |
10500 dart2jsPath: 'first/first_dart2js.dart'), | 10519 dart2jsPath: 'first/first_dart2js.dart'), |
10501 };'''); | 10520 };'''); |
10502 expect(libraryMap, isNotNull); | 10521 expect(libraryMap, isNotNull); |
10503 expect(libraryMap.size(), 1); | 10522 expect(libraryMap.size(), 1); |
10504 SdkLibrary first = libraryMap.getLibrary("dart:first"); | 10523 SdkLibrary first = libraryMap.getLibrary("dart:first"); |
10505 expect(first, isNotNull); | 10524 expect(first, isNotNull); |
10506 expect(first.category, "First"); | 10525 expect(first.category, "First"); |
10507 expect(first.path, "first/first_dart2js.dart"); | 10526 expect(first.path, "first/first_dart2js.dart"); |
10508 expect(first.shortName, "dart:first"); | 10527 expect(first.shortName, "dart:first"); |
10509 expect(first.isDart2JsLibrary, false); | 10528 expect(first.isDart2JsLibrary, false); |
10510 expect(first.isDocumented, true); | 10529 expect(first.isDocumented, true); |
10511 expect(first.isImplementation, false); | 10530 expect(first.isImplementation, false); |
10512 expect(first.isVmLibrary, true); | 10531 expect(first.isVmLibrary, true); |
10513 } | 10532 } |
10514 void test_readFrom_empty() { | 10533 void test_readFrom_empty() { |
10515 LibraryMap libraryMap = new SdkLibrariesReader( | 10534 LibraryMap libraryMap = new SdkLibrariesReader( |
10516 false).readFromFile(FileUtilities2.createFile("/libs.dart"), ""); | 10535 false).readFromFile(FileUtilities2.createFile("/libs.dart"), ""); |
10517 expect(libraryMap, isNotNull); | 10536 expect(libraryMap, isNotNull); |
10518 expect(libraryMap.size(), 0); | 10537 expect(libraryMap.size(), 0); |
10519 } | 10538 } |
10520 void test_readFrom_normal() { | 10539 void test_readFrom_normal() { |
10521 LibraryMap libraryMap = new SdkLibrariesReader( | 10540 LibraryMap libraryMap = new SdkLibrariesReader( |
10522 false).readFromFile( | 10541 false).readFromFile(FileUtilities2.createFile("/libs.dart"), r''' |
10523 FileUtilities2.createFile("/libs.dart"), | |
10524 r''' | |
10525 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> { | 10542 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> { |
10526 'first' : const LibraryInfo( | 10543 'first' : const LibraryInfo( |
10527 'first/first.dart', | 10544 'first/first.dart', |
10528 category: 'First', | 10545 category: 'First', |
10529 documented: true, | 10546 documented: true, |
10530 platforms: VM_PLATFORM), | 10547 platforms: VM_PLATFORM), |
10531 | 10548 |
10532 'second' : const LibraryInfo( | 10549 'second' : const LibraryInfo( |
10533 'second/second.dart', | 10550 'second/second.dart', |
10534 category: 'Second', | 10551 category: 'Second', |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10581 } | 10598 } |
10582 } | 10599 } |
10583 void test_fromEncoding_valid() { | 10600 void test_fromEncoding_valid() { |
10584 String encoding = "file:///does/not/exist.dart"; | 10601 String encoding = "file:///does/not/exist.dart"; |
10585 SourceFactory factory = new SourceFactory( | 10602 SourceFactory factory = new SourceFactory( |
10586 [new UriResolver_SourceFactoryTest_test_fromEncoding_valid(encoding)]); | 10603 [new UriResolver_SourceFactoryTest_test_fromEncoding_valid(encoding)]); |
10587 expect(factory.fromEncoding(encoding), isNotNull); | 10604 expect(factory.fromEncoding(encoding), isNotNull); |
10588 } | 10605 } |
10589 void test_resolveUri_absolute() { | 10606 void test_resolveUri_absolute() { |
10590 UriResolver_absolute resolver = new UriResolver_absolute(); | 10607 UriResolver_absolute resolver = new UriResolver_absolute(); |
10591 SourceFactory factory = | 10608 SourceFactory factory = new SourceFactory([resolver]); |
10592 new SourceFactory([resolver]); | |
10593 factory.resolveUri(null, "dart:core"); | 10609 factory.resolveUri(null, "dart:core"); |
10594 expect(resolver.invoked, isTrue); | 10610 expect(resolver.invoked, isTrue); |
10595 } | 10611 } |
10596 void test_resolveUri_nonAbsolute_absolute() { | 10612 void test_resolveUri_nonAbsolute_absolute() { |
10597 SourceFactory factory = | 10613 SourceFactory factory = |
10598 new SourceFactory([new UriResolver_nonAbsolute_absolute()]); | 10614 new SourceFactory([new UriResolver_nonAbsolute_absolute()]); |
10599 String absolutePath = "/does/not/matter.dart"; | 10615 String absolutePath = "/does/not/matter.dart"; |
10600 Source containingSource = | 10616 Source containingSource = |
10601 new FileBasedSource.con1(FileUtilities2.createFile("/does/not/exist.dart
")); | 10617 new FileBasedSource.con1(FileUtilities2.createFile("/does/not/exist.dart
")); |
10602 Source result = factory.resolveUri(containingSource, absolutePath); | 10618 Source result = factory.resolveUri(containingSource, absolutePath); |
10603 expect(result.fullName, FileUtilities2.createFile(absolutePath).getAbsoluteP
ath()); | 10619 expect( |
| 10620 result.fullName, |
| 10621 FileUtilities2.createFile(absolutePath).getAbsolutePath()); |
10604 } | 10622 } |
10605 void test_resolveUri_nonAbsolute_relative() { | 10623 void test_resolveUri_nonAbsolute_relative() { |
10606 SourceFactory factory = | 10624 SourceFactory factory = |
10607 new SourceFactory([new UriResolver_nonAbsolute_relative()]); | 10625 new SourceFactory([new UriResolver_nonAbsolute_relative()]); |
10608 Source containingSource = | 10626 Source containingSource = |
10609 new FileBasedSource.con1(FileUtilities2.createFile("/does/not/have.dart"
)); | 10627 new FileBasedSource.con1(FileUtilities2.createFile("/does/not/have.dart"
)); |
10610 Source result = factory.resolveUri(containingSource, "exist.dart"); | 10628 Source result = factory.resolveUri(containingSource, "exist.dart"); |
10611 expect(result.fullName, FileUtilities2.createFile("/does/not/exist.dart").ge
tAbsolutePath()); | 10629 expect( |
| 10630 result.fullName, |
| 10631 FileUtilities2.createFile("/does/not/exist.dart").getAbsolutePath()); |
10612 } | 10632 } |
10613 void test_restoreUri() { | 10633 void test_restoreUri() { |
10614 JavaFile file1 = FileUtilities2.createFile("/some/file1.dart"); | 10634 JavaFile file1 = FileUtilities2.createFile("/some/file1.dart"); |
10615 JavaFile file2 = FileUtilities2.createFile("/some/file2.dart"); | 10635 JavaFile file2 = FileUtilities2.createFile("/some/file2.dart"); |
10616 Source source1 = new FileBasedSource.con1(file1); | 10636 Source source1 = new FileBasedSource.con1(file1); |
10617 Source source2 = new FileBasedSource.con1(file2); | 10637 Source source2 = new FileBasedSource.con1(file2); |
10618 Uri expected1 = parseUriWithException("file:///my_file.dart"); | 10638 Uri expected1 = parseUriWithException("file:///my_file.dart"); |
10619 SourceFactory factory = | 10639 SourceFactory factory = |
10620 new SourceFactory([new UriResolver_restoreUri(source1, expected1)]); | 10640 new SourceFactory([new UriResolver_restoreUri(source1, expected1)]); |
10621 expect(factory.restoreUri(source1), same(expected1)); | 10641 expect(factory.restoreUri(source1), same(expected1)); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10698 } | 10718 } |
10699 | 10719 |
10700 void test_getEncoding() { | 10720 void test_getEncoding() { |
10701 expect(UriKind.DART_URI.encoding, 0x64); | 10721 expect(UriKind.DART_URI.encoding, 0x64); |
10702 expect(UriKind.FILE_URI.encoding, 0x66); | 10722 expect(UriKind.FILE_URI.encoding, 0x66); |
10703 expect(UriKind.PACKAGE_URI.encoding, 0x70); | 10723 expect(UriKind.PACKAGE_URI.encoding, 0x70); |
10704 } | 10724 } |
10705 } | 10725 } |
10706 | 10726 |
10707 | 10727 |
10708 class UriResolver_SourceFactoryTest_test_fromEncoding_valid extends UriResolver | |
10709 { | |
10710 String encoding; | |
10711 | |
10712 UriResolver_SourceFactoryTest_test_fromEncoding_valid(this.encoding); | |
10713 | |
10714 @override | |
10715 Source resolveAbsolute(Uri uri) { | |
10716 if (uri.toString() == encoding) { | |
10717 return new TestSource(); | |
10718 } | |
10719 return null; | |
10720 } | |
10721 } | |
10722 | |
10723 | |
10724 class UriResolver_absolute extends UriResolver { | 10728 class UriResolver_absolute extends UriResolver { |
10725 bool invoked = false; | 10729 bool invoked = false; |
10726 | 10730 |
10727 UriResolver_absolute(); | 10731 UriResolver_absolute(); |
10728 | 10732 |
10729 @override | 10733 @override |
10730 Source resolveAbsolute(Uri uri) { | 10734 Source resolveAbsolute(Uri uri) { |
10731 invoked = true; | 10735 invoked = true; |
10732 return null; | 10736 return null; |
10733 } | 10737 } |
(...skipping 29 matching lines...) Expand all Loading... |
10763 @override | 10767 @override |
10764 Uri restoreAbsolute(Source source) { | 10768 Uri restoreAbsolute(Source source) { |
10765 if (identical(source, source1)) { | 10769 if (identical(source, source1)) { |
10766 return expected1; | 10770 return expected1; |
10767 } | 10771 } |
10768 return null; | 10772 return null; |
10769 } | 10773 } |
10770 } | 10774 } |
10771 | 10775 |
10772 | 10776 |
| 10777 class UriResolver_SourceFactoryTest_test_fromEncoding_valid extends UriResolver |
| 10778 { |
| 10779 String encoding; |
| 10780 |
| 10781 UriResolver_SourceFactoryTest_test_fromEncoding_valid(this.encoding); |
| 10782 |
| 10783 @override |
| 10784 Source resolveAbsolute(Uri uri) { |
| 10785 if (uri.toString() == encoding) { |
| 10786 return new TestSource(); |
| 10787 } |
| 10788 return null; |
| 10789 } |
| 10790 } |
| 10791 |
| 10792 |
10773 class ValidatingConstantValueComputer extends ConstantValueComputer { | 10793 class ValidatingConstantValueComputer extends ConstantValueComputer { |
10774 AstNode _nodeBeingEvaluated; | 10794 AstNode _nodeBeingEvaluated; |
10775 ValidatingConstantValueComputer(TypeProvider typeProvider, | 10795 ValidatingConstantValueComputer(TypeProvider typeProvider, |
10776 DeclaredVariables declaredVariables) | 10796 DeclaredVariables declaredVariables) |
10777 : super(typeProvider, declaredVariables); | 10797 : super(typeProvider, declaredVariables); |
10778 | 10798 |
10779 @override | 10799 @override |
10780 void beforeComputeValue(AstNode constNode) { | 10800 void beforeComputeValue(AstNode constNode) { |
10781 super.beforeComputeValue(constNode); | 10801 super.beforeComputeValue(constNode); |
10782 _nodeBeingEvaluated = constNode; | 10802 _nodeBeingEvaluated = constNode; |
(...skipping 27 matching lines...) Expand all Loading... |
10810 } | 10830 } |
10811 expect(parameterIndex < numParameters, isTrue); | 10831 expect(parameterIndex < numParameters, isTrue); |
10812 // If we are getting the default parameter for a constructor in the graph, | 10832 // If we are getting the default parameter for a constructor in the graph, |
10813 // make sure we properly recorded the dependency on the parameter. | 10833 // make sure we properly recorded the dependency on the parameter. |
10814 ConstructorDeclaration constructorNode = | 10834 ConstructorDeclaration constructorNode = |
10815 constructorDeclarationMap[constructor]; | 10835 constructorDeclarationMap[constructor]; |
10816 if (constructorNode != null) { | 10836 if (constructorNode != null) { |
10817 FormalParameter parameterNode = | 10837 FormalParameter parameterNode = |
10818 constructorNode.parameters.parameters[parameterIndex]; | 10838 constructorNode.parameters.parameters[parameterIndex]; |
10819 expect(referenceGraph.nodes.contains(parameterNode), isTrue); | 10839 expect(referenceGraph.nodes.contains(parameterNode), isTrue); |
10820 expect(referenceGraph.containsPath(_nodeBeingEvaluated, parameterNode), is
True); | 10840 expect( |
| 10841 referenceGraph.containsPath(_nodeBeingEvaluated, parameterNode), |
| 10842 isTrue); |
10821 } | 10843 } |
10822 } | 10844 } |
10823 | 10845 |
10824 @override | 10846 @override |
10825 ConstantVisitor createConstantVisitor(ErrorReporter errorReporter) { | 10847 ConstantVisitor createConstantVisitor(ErrorReporter errorReporter) { |
10826 return new ConstantValueComputerTest_ValidatingConstantVisitor( | 10848 return new ConstantValueComputerTest_ValidatingConstantVisitor( |
10827 typeProvider, | 10849 typeProvider, |
10828 referenceGraph, | 10850 referenceGraph, |
10829 _nodeBeingEvaluated, | 10851 _nodeBeingEvaluated, |
10830 errorReporter); | 10852 errorReporter); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10957 _expectedAttributeIndex = 0; | 10979 _expectedAttributeIndex = 0; |
10958 _expectedTagsIndex++; | 10980 _expectedTagsIndex++; |
10959 expect(actual.attributeEnd, isNotNull); | 10981 expect(actual.attributeEnd, isNotNull); |
10960 expect(actual.contentEnd, isNotNull); | 10982 expect(actual.contentEnd, isNotNull); |
10961 int count = 0; | 10983 int count = 0; |
10962 ht.Token token = actual.attributeEnd.next; | 10984 ht.Token token = actual.attributeEnd.next; |
10963 ht.Token lastToken = actual.contentEnd; | 10985 ht.Token lastToken = actual.contentEnd; |
10964 while (!identical(token, lastToken)) { | 10986 while (!identical(token, lastToken)) { |
10965 token = token.next; | 10987 token = token.next; |
10966 if (++count > 1000) { | 10988 if (++count > 1000) { |
10967 fail("Expected $_expectedTagsIndex tag: ${expected._tag} to have a s
equence of tokens from getAttributeEnd() to getContentEnd()"); | 10989 fail( |
| 10990 "Expected $_expectedTagsIndex tag: ${expected._tag} to have a se
quence of tokens from getAttributeEnd() to getContentEnd()"); |
10968 break; | 10991 break; |
10969 } | 10992 } |
10970 } | 10993 } |
10971 if (actual.attributeEnd.type == ht.TokenType.GT) { | 10994 if (actual.attributeEnd.type == ht.TokenType.GT) { |
10972 if (ht.HtmlParser.SELF_CLOSING.contains(actual.tag)) { | 10995 if (ht.HtmlParser.SELF_CLOSING.contains(actual.tag)) { |
10973 expect(actual.closingTag, isNull); | 10996 expect(actual.closingTag, isNull); |
10974 } else { | 10997 } else { |
10975 expect(actual.closingTag, isNotNull); | 10998 expect(actual.closingTag, isNotNull); |
10976 } | 10999 } |
10977 } else if (actual.attributeEnd.type == ht.TokenType.SLASH_GT) { | 11000 } else if (actual.attributeEnd.type == ht.TokenType.SLASH_GT) { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11046 } | 11069 } |
11047 | 11070 |
11048 | 11071 |
11049 class XmlValidator_Attributes { | 11072 class XmlValidator_Attributes { |
11050 final List<String> _keyValuePairs; | 11073 final List<String> _keyValuePairs; |
11051 XmlValidator_Attributes([this._keyValuePairs = StringUtilities.EMPTY_ARRAY]); | 11074 XmlValidator_Attributes([this._keyValuePairs = StringUtilities.EMPTY_ARRAY]); |
11052 } | 11075 } |
11053 | 11076 |
11054 | 11077 |
11055 class XmlValidator_Tag { | 11078 class XmlValidator_Tag { |
| 11079 static const List<XmlValidator_Tag> EMPTY_LIST = const <XmlValidator_Tag>[]; |
11056 final String _tag; | 11080 final String _tag; |
11057 final XmlValidator_Attributes _attributes; | 11081 final XmlValidator_Attributes _attributes; |
11058 final String _content; | 11082 final String _content; |
11059 final List<XmlValidator_Tag> _children; | 11083 final List<XmlValidator_Tag> _children; |
11060 static const List<XmlValidator_Tag> EMPTY_LIST = const <XmlValidator_Tag>[]; | 11084 XmlValidator_Tag(this._tag, this._attributes, this._content, [this._children = |
11061 XmlValidator_Tag(this._tag, this._attributes, this._content, [this._children =
EMPTY_LIST]); | 11085 EMPTY_LIST]); |
11062 } | 11086 } |
11063 | 11087 |
11064 | 11088 |
11065 class _AngularTest_findElement extends GeneralizingElementVisitor<Object> { | 11089 class _AngularTest_findElement extends GeneralizingElementVisitor<Object> { |
11066 final ElementKind kind; | 11090 final ElementKind kind; |
11067 | 11091 |
11068 final String name; | 11092 final String name; |
11069 | 11093 |
11070 Element result; | 11094 Element result; |
11071 | 11095 |
(...skipping 22 matching lines...) Expand all Loading... |
11094 } | 11118 } |
11095 void _validate(int scriptIndex, HtmlScriptElement script) { | 11119 void _validate(int scriptIndex, HtmlScriptElement script) { |
11096 if (_expectedLibrary != null) { | 11120 if (_expectedLibrary != null) { |
11097 _validateEmbedded(scriptIndex, script); | 11121 _validateEmbedded(scriptIndex, script); |
11098 } else { | 11122 } else { |
11099 _validateExternal(scriptIndex, script); | 11123 _validateExternal(scriptIndex, script); |
11100 } | 11124 } |
11101 } | 11125 } |
11102 void _validateEmbedded(int scriptIndex, HtmlScriptElement script) { | 11126 void _validateEmbedded(int scriptIndex, HtmlScriptElement script) { |
11103 if (script is! EmbeddedHtmlScriptElementImpl) { | 11127 if (script is! EmbeddedHtmlScriptElementImpl) { |
11104 fail("Expected script $scriptIndex to be embedded, but found ${script != n
ull ? script.runtimeType : "null"}"); | 11128 fail( |
| 11129 "Expected script $scriptIndex to be embedded, but found ${script != nu
ll ? script.runtimeType : "null"}"); |
11105 } | 11130 } |
11106 EmbeddedHtmlScriptElementImpl embeddedScript = | 11131 EmbeddedHtmlScriptElementImpl embeddedScript = |
11107 script as EmbeddedHtmlScriptElementImpl; | 11132 script as EmbeddedHtmlScriptElementImpl; |
11108 _expectedLibrary._validate(scriptIndex, embeddedScript); | 11133 _expectedLibrary._validate(scriptIndex, embeddedScript); |
11109 } | 11134 } |
11110 void _validateExternal(int scriptIndex, HtmlScriptElement script) { | 11135 void _validateExternal(int scriptIndex, HtmlScriptElement script) { |
11111 if (script is! ExternalHtmlScriptElementImpl) { | 11136 if (script is! ExternalHtmlScriptElementImpl) { |
11112 fail("Expected script $scriptIndex to be external with src=$_expectedExter
nalScriptName but found ${script != null ? script.runtimeType : "null"}"); | 11137 fail( |
| 11138 "Expected script $scriptIndex to be external with src=$_expectedExtern
alScriptName but found ${script != null ? script.runtimeType : "null"}"); |
11113 } | 11139 } |
11114 ExternalHtmlScriptElementImpl externalScript = | 11140 ExternalHtmlScriptElementImpl externalScript = |
11115 script as ExternalHtmlScriptElementImpl; | 11141 script as ExternalHtmlScriptElementImpl; |
11116 Source scriptSource = externalScript.scriptSource; | 11142 Source scriptSource = externalScript.scriptSource; |
11117 if (_expectedExternalScriptName == null) { | 11143 if (_expectedExternalScriptName == null) { |
11118 expect(scriptSource, isNull, reason: "script $scriptIndex"); | 11144 expect(scriptSource, isNull, reason: "script $scriptIndex"); |
11119 } else { | 11145 } else { |
11120 expect(scriptSource, isNotNull, reason: "script $scriptIndex"); | 11146 expect(scriptSource, isNotNull, reason: "script $scriptIndex"); |
11121 String actualExternalScriptName = scriptSource.shortName; | 11147 String actualExternalScriptName = scriptSource.shortName; |
11122 expect(actualExternalScriptName, _expectedExternalScriptName, reason: "scr
ipt $scriptIndex"); | 11148 expect( |
| 11149 actualExternalScriptName, |
| 11150 _expectedExternalScriptName, |
| 11151 reason: "script $scriptIndex"); |
11123 } | 11152 } |
11124 } | 11153 } |
11125 } | 11154 } |
OLD | NEW |