Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Side by Side Diff: pkg/analyzer/test/generated/all_the_rest.dart

Issue 682553002: Convert most of the EngineTestCase.createSource invocations into multi-line String literals. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/ast_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 742 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 JUnitTestCase.assertEquals(null, component.templateSource); 753 JUnitTestCase.assertEquals(null, component.templateSource);
754 JUnitTestCase.assertEquals(-1, component.templateUriOffset); 754 JUnitTestCase.assertEquals(-1, component.templateUriOffset);
755 } 755 }
756 756
757 /** 757 /**
758 * https://code.google.com/p/dart/issues/detail?id=19023 758 * https://code.google.com/p/dart/issues/detail?id=19023
759 */ 759 */
760 void test_NgComponent_notAngular() { 760 void test_NgComponent_notAngular() {
761 contextHelper.addSource("/my_template.html", ""); 761 contextHelper.addSource("/my_template.html", "");
762 contextHelper.addSource("/my_styles.css", ""); 762 contextHelper.addSource("/my_styles.css", "");
763 String mainContent = EngineTestCase.createSource( 763 String mainContent = r'''
764 [ 764 class Component {
765 "class Component {", 765 const Component(a, b);
766 " const Component(a, b);", 766 }
767 "}", 767
768 "", 768 @Component('foo', 42)
769 "@Component('foo', 42)", 769 class MyComponent {
770 "class MyComponent {", 770 }''';
771 "}"]);
772 resolveMainSource(mainContent); 771 resolveMainSource(mainContent);
773 assertNoMainErrors(); 772 assertNoMainErrors();
774 } 773 }
775 774
776 void test_NgComponent_properties_fieldFromSuper() { 775 void test_NgComponent_properties_fieldFromSuper() {
777 contextHelper.addSource("/my_template.html", ""); 776 contextHelper.addSource("/my_template.html", "");
778 contextHelper.addSource("/my_styles.css", ""); 777 contextHelper.addSource("/my_styles.css", "");
779 resolveMainSourceNoErrors( 778 resolveMainSourceNoErrors(
780 _createAngularSource( 779 _createAngularSource(
781 [ 780 [
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 assertMainErrors([AngularCode.MISSING_SELECTOR]); 1080 assertMainErrors([AngularCode.MISSING_SELECTOR]);
1082 } 1081 }
1083 1082
1084 void test_NgController_noAnnotationArguments() { 1083 void test_NgController_noAnnotationArguments() {
1085 String mainContent = 1084 String mainContent =
1086 _createAngularSource(["@NgController", "class MyController {", "}"]); 1085 _createAngularSource(["@NgController", "class MyController {", "}"]);
1087 resolveMainSource(mainContent); 1086 resolveMainSource(mainContent);
1088 } 1087 }
1089 1088
1090 void test_bad_notConstructorAnnotation() { 1089 void test_bad_notConstructorAnnotation() {
1091 String mainContent = EngineTestCase.createSource( 1090 String mainContent = r'''
1092 ["const MY_ANNOTATION = null;", "@MY_ANNOTATION()", "class MyFilter {", "}"]); 1091 const MY_ANNOTATION = null;
1092 @MY_ANNOTATION()
1093 class MyFilter {
1094 }''';
1093 resolveMainSource(mainContent); 1095 resolveMainSource(mainContent);
1094 // prepare AngularFilterElement 1096 // prepare AngularFilterElement
1095 ClassElement classElement = mainUnitElement.getType("MyFilter"); 1097 ClassElement classElement = mainUnitElement.getType("MyFilter");
1096 AngularFormatterElement filter = 1098 AngularFormatterElement filter =
1097 getAngularElement(classElement, (e) => e is AngularFormatterElement); 1099 getAngularElement(classElement, (e) => e is AngularFormatterElement);
1098 JUnitTestCase.assertNull(filter); 1100 JUnitTestCase.assertNull(filter);
1099 } 1101 }
1100 1102
1101 void test_getElement_SimpleStringLiteral_withToolkitElement() { 1103 void test_getElement_SimpleStringLiteral_withToolkitElement() {
1102 SimpleStringLiteral literal = AstFactory.string2("foo"); 1104 SimpleStringLiteral literal = AstFactory.string2("foo");
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 1282
1281 void test_getElement_noClassDeclaration() { 1283 void test_getElement_noClassDeclaration() {
1282 resolveMainSource("var foo = 'bar';"); 1284 resolveMainSource("var foo = 'bar';");
1283 SimpleStringLiteral node = 1285 SimpleStringLiteral node =
1284 _findMainNode("bar'", (n) => n is SimpleStringLiteral); 1286 _findMainNode("bar'", (n) => n is SimpleStringLiteral);
1285 Element element = AngularCompilationUnitBuilder.getElement(node, 0); 1287 Element element = AngularCompilationUnitBuilder.getElement(node, 0);
1286 JUnitTestCase.assertNull(element); 1288 JUnitTestCase.assertNull(element);
1287 } 1289 }
1288 1290
1289 void test_getElement_noClassElement() { 1291 void test_getElement_noClassElement() {
1290 resolveMainSource( 1292 resolveMainSource(r'''
1291 EngineTestCase.createSource( 1293 class A {
1292 ["class A {", " const A(p);", "}", "", "@A('bar')", "class B {}"])) ; 1294 const A(p);
1295 }
1296
1297 @A('bar')
1298 class B {}''');
1293 SimpleStringLiteral node = 1299 SimpleStringLiteral node =
1294 _findMainNode("bar'", (n) => n is SimpleStringLiteral); 1300 _findMainNode("bar'", (n) => n is SimpleStringLiteral);
1295 // reset B element 1301 // reset B element
1296 ClassDeclaration classDeclaration = 1302 ClassDeclaration classDeclaration =
1297 node.getAncestor((node) => node is ClassDeclaration); 1303 node.getAncestor((node) => node is ClassDeclaration);
1298 classDeclaration.name.staticElement = null; 1304 classDeclaration.name.staticElement = null;
1299 // class is not resolved - no element 1305 // class is not resolved - no element
1300 Element element = AngularCompilationUnitBuilder.getElement(node, 0); 1306 Element element = AngularCompilationUnitBuilder.getElement(node, 0);
1301 JUnitTestCase.assertNull(element); 1307 JUnitTestCase.assertNull(element);
1302 } 1308 }
1303 1309
1304 void test_getElement_noNode() { 1310 void test_getElement_noNode() {
1305 Element element = AngularCompilationUnitBuilder.getElement(null, 0); 1311 Element element = AngularCompilationUnitBuilder.getElement(null, 0);
1306 JUnitTestCase.assertNull(element); 1312 JUnitTestCase.assertNull(element);
1307 } 1313 }
1308 1314
1309 void test_getElement_notFound() { 1315 void test_getElement_notFound() {
1310 resolveMainSource( 1316 resolveMainSource(r'''
1311 EngineTestCase.createSource( 1317 class MyComponent {
1312 ["class MyComponent {", " var str = 'some string';", "}"])); 1318 var str = 'some string';
1319 }''');
1313 // prepare node 1320 // prepare node
1314 SimpleStringLiteral node = 1321 SimpleStringLiteral node =
1315 _findMainNode("some string'", (n) => n is SimpleStringLiteral); 1322 _findMainNode("some string'", (n) => n is SimpleStringLiteral);
1316 int offset = node.offset; 1323 int offset = node.offset;
1317 // no Element 1324 // no Element
1318 Element element = AngularCompilationUnitBuilder.getElement(node, offset); 1325 Element element = AngularCompilationUnitBuilder.getElement(node, offset);
1319 JUnitTestCase.assertNull(element); 1326 JUnitTestCase.assertNull(element);
1320 } 1327 }
1321 1328
1322 void test_parseSelector_hasAttribute() { 1329 void test_parseSelector_hasAttribute() {
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1482 static String _createAngularSource(List<String> lines) { 1489 static String _createAngularSource(List<String> lines) {
1483 String source = "import 'angular.dart';\n"; 1490 String source = "import 'angular.dart';\n";
1484 source += EngineTestCase.createSource(lines); 1491 source += EngineTestCase.createSource(lines);
1485 return source; 1492 return source;
1486 } 1493 }
1487 } 1494 }
1488 1495
1489 1496
1490 class AngularHtmlUnitResolverTest extends AngularTest { 1497 class AngularHtmlUnitResolverTest extends AngularTest {
1491 void test_NgComponent_resolveTemplateFile() { 1498 void test_NgComponent_resolveTemplateFile() {
1492 addMainSource( 1499 addMainSource(r'''
1493 EngineTestCase.createSource( 1500 import 'angular.dart';
1494 [ 1501
1495 "", 1502 @Component(
1496 "import 'angular.dart';", 1503 templateUrl: 'my_template.html', cssUrl: 'my_styles.css',
1497 "", 1504 publishAs: 'ctrl',
1498 "@Component(", 1505 selector: 'myComponent')
1499 " templateUrl: 'my_template.html', cssUrl: 'my_styles.css',", 1506 class MyComponent {
1500 " publishAs: 'ctrl',", 1507 String field;
1501 " selector: 'myComponent')", 1508 }''');
1502 "class MyComponent {",
1503 " String field;",
1504 "}"]));
1505 contextHelper.addSource( 1509 contextHelper.addSource(
1506 "/entry-point.html", 1510 "/entry-point.html",
1507 AngularTest.createHtmlWithAngular([])); 1511 AngularTest.createHtmlWithAngular([]));
1508 addIndexSource2( 1512 addIndexSource2(
1509 "/my_template.html", 1513 "/my_template.html",
1510 EngineTestCase.createSource( 1514 r'''
1511 [" <div>", " {{ctrl.field}}", " </div>"])); 1515 <div>
1516 {{ctrl.field}}
1517 </div>''');
1512 contextHelper.addSource("/my_styles.css", ""); 1518 contextHelper.addSource("/my_styles.css", "");
1513 contextHelper.runTasks(); 1519 contextHelper.runTasks();
1514 resolveIndex(); 1520 resolveIndex();
1515 assertNoErrors(); 1521 assertNoErrors();
1516 assertResolvedIdentifier2("ctrl.", "MyComponent"); 1522 assertResolvedIdentifier2("ctrl.", "MyComponent");
1517 assertResolvedIdentifier2("field}}", "String"); 1523 assertResolvedIdentifier2("field}}", "String");
1518 } 1524 }
1519 1525
1520 void test_NgComponent_updateDartFile() { 1526 void test_NgComponent_updateDartFile() {
1521 Source componentSource = contextHelper.addSource( 1527 Source componentSource = contextHelper.addSource(
1522 "/my_component.dart", 1528 "/my_component.dart",
1523 EngineTestCase.createSource( 1529 r'''
1524 [ 1530 library my.component;
1525 "library my.component;", 1531 import 'angular.dart';
1526 "import 'angular.dart';", 1532 @Component(selector: 'myComponent')
1527 "@Component(selector: 'myComponent')", 1533 class MyComponent {
1528 "class MyComponent {", 1534 }''');
1529 "}"]));
1530 contextHelper.addSource( 1535 contextHelper.addSource(
1531 "/my_module.dart", 1536 "/my_module.dart",
1532 EngineTestCase.createSource( 1537 r'''
1533 ["library my.module;", "import 'my_component.dart';"])); 1538 library my.module;
1534 addMainSource( 1539 import 'my_component.dart';''');
1535 EngineTestCase.createSource(["library main;", "import 'my_module.dart';" ])); 1540 addMainSource(r'''
1541 library main;
1542 import 'my_module.dart';''');
1536 _resolveIndexNoErrors( 1543 _resolveIndexNoErrors(
1537 AngularTest.createHtmlWithMyController(["<myComponent/>"])); 1544 AngularTest.createHtmlWithMyController(["<myComponent/>"]));
1538 // "myComponent" tag was resolved 1545 // "myComponent" tag was resolved
1539 { 1546 {
1540 ht.XmlTagNode tagNode = 1547 ht.XmlTagNode tagNode =
1541 ht.HtmlUnitUtils.getTagNode(indexUnit, findOffset2("myComponent")); 1548 ht.HtmlUnitUtils.getTagNode(indexUnit, findOffset2("myComponent"));
1542 AngularSelectorElement tagElement = 1549 AngularSelectorElement tagElement =
1543 tagNode.element as AngularSelectorElement; 1550 tagNode.element as AngularSelectorElement;
1544 JUnitTestCase.assertNotNull(tagElement); 1551 JUnitTestCase.assertNotNull(tagElement);
1545 JUnitTestCase.assertEquals("myComponent", tagElement.name); 1552 JUnitTestCase.assertEquals("myComponent", tagElement.name);
(...skipping 17 matching lines...) Expand all
1563 AngularSelectorElement tagElement = 1570 AngularSelectorElement tagElement =
1564 tagNode.element as AngularSelectorElement; 1571 tagNode.element as AngularSelectorElement;
1565 JUnitTestCase.assertNotNull(tagElement); 1572 JUnitTestCase.assertNotNull(tagElement);
1566 JUnitTestCase.assertEquals("myComponent2", tagElement.name); 1573 JUnitTestCase.assertEquals("myComponent2", tagElement.name);
1567 } 1574 }
1568 } 1575 }
1569 1576
1570 void test_NgComponent_use_resolveAttributes() { 1577 void test_NgComponent_use_resolveAttributes() {
1571 contextHelper.addSource( 1578 contextHelper.addSource(
1572 "/my_template.html", 1579 "/my_template.html",
1573 EngineTestCase.createSource( 1580 r'''
1574 [" <div>", " {{ctrl.field}}", " </div>"])); 1581 <div>
1575 addMainSource( 1582 {{ctrl.field}}
1576 EngineTestCase.createSource( 1583 </div>''');
1577 [ 1584 addMainSource(r'''
1578 "", 1585
1579 "import 'angular.dart';", 1586 import 'angular.dart';
1580 "", 1587
1581 "@Component(", 1588 @Component(
1582 " templateUrl: 'my_template.html', cssUrl: 'my_styles.css',", 1589 templateUrl: 'my_template.html', cssUrl: 'my_styles.css',
1583 " publishAs: 'ctrl',", 1590 publishAs: 'ctrl',
1584 " selector: 'myComponent', // selector", 1591 selector: 'myComponent', // selector
1585 " map: const {'attrA' : '=>setA', 'attrB' : '@setB'})", 1592 map: const {'attrA' : '=>setA', 'attrB' : '@setB'})
1586 "class MyComponent {", 1593 class MyComponent {
1587 " set setA(value) {}", 1594 set setA(value) {}
1588 " set setB(value) {}", 1595 set setB(value) {}
1589 "}"])); 1596 }''');
1590 _resolveIndexNoErrors( 1597 _resolveIndexNoErrors(
1591 AngularTest.createHtmlWithMyController( 1598 AngularTest.createHtmlWithMyController(
1592 [ 1599 [
1593 "<input type='text' ng-model='someModel'/>", 1600 "<input type='text' ng-model='someModel'/>",
1594 "<myComponent attrA='someModel' attrB='bbb'/>"])); 1601 "<myComponent attrA='someModel' attrB='bbb'/>"]));
1595 // "attrA" attribute expression was resolved 1602 // "attrA" attribute expression was resolved
1596 JUnitTestCase.assertNotNull(findIdentifier("someModel")); 1603 JUnitTestCase.assertNotNull(findIdentifier("someModel"));
1597 // "myComponent" tag was resolved 1604 // "myComponent" tag was resolved
1598 ht.XmlTagNode tagNode = 1605 ht.XmlTagNode tagNode =
1599 ht.HtmlUnitUtils.getTagNode(indexUnit, findOffset2("myComponent")); 1606 ht.HtmlUnitUtils.getTagNode(indexUnit, findOffset2("myComponent"));
(...skipping 18 matching lines...) Expand all
1618 ht.XmlAttributeNode node = 1625 ht.XmlAttributeNode node =
1619 ht.HtmlUnitUtils.getAttributeNode(indexUnit, findOffset2("attrB='")); 1626 ht.HtmlUnitUtils.getAttributeNode(indexUnit, findOffset2("attrB='"));
1620 AngularPropertyElement element = node.element as AngularPropertyElement; 1627 AngularPropertyElement element = node.element as AngularPropertyElement;
1621 JUnitTestCase.assertNotNull(element); 1628 JUnitTestCase.assertNotNull(element);
1622 JUnitTestCase.assertEquals("attrB", element.name); 1629 JUnitTestCase.assertEquals("attrB", element.name);
1623 JUnitTestCase.assertEquals("setB", element.field.name); 1630 JUnitTestCase.assertEquals("setB", element.field.name);
1624 } 1631 }
1625 } 1632 }
1626 1633
1627 void test_NgDirective_noAttribute() { 1634 void test_NgDirective_noAttribute() {
1628 addMainSource( 1635 addMainSource(r'''
1629 EngineTestCase.createSource( 1636
1630 [ 1637 import 'angular.dart';
1631 "", 1638
1632 "import 'angular.dart';", 1639 @NgDirective(selector: '[my-directive]', map: const {'foo': '=>input'})
1633 "", 1640 class MyDirective {
1634 "@NgDirective(selector: '[my-directive]', map: const {'foo': '=> input'})", 1641 set input(value) {}
1635 "class MyDirective {", 1642 }''');
1636 " set input(value) {}",
1637 "}"]));
1638 _resolveIndexNoErrors( 1643 _resolveIndexNoErrors(
1639 AngularTest.createHtmlWithMyController(["<div my-directive>", "</div>"]) ); 1644 AngularTest.createHtmlWithMyController(["<div my-directive>", "</div>"]) );
1640 } 1645 }
1641 1646
1642 void test_NgDirective_noExpression() { 1647 void test_NgDirective_noExpression() {
1643 addMainSource( 1648 addMainSource(r'''
1644 EngineTestCase.createSource( 1649
1645 [ 1650 import 'angular.dart';
1646 "", 1651
1647 "import 'angular.dart';", 1652 @NgDirective(selector: '[my-directive]', map: const {'.': '=>input'})
1648 "", 1653 class MyDirective {
1649 "@NgDirective(selector: '[my-directive]', map: const {'.': '=>in put'})", 1654 set input(value) {}
1650 "class MyDirective {", 1655 }''');
1651 " set input(value) {}",
1652 "}"]));
1653 _resolveIndexNoErrors( 1656 _resolveIndexNoErrors(
1654 AngularTest.createHtmlWithMyController(["<div my-directive>", "</div>"]) ); 1657 AngularTest.createHtmlWithMyController(["<div my-directive>", "</div>"]) );
1655 } 1658 }
1656 1659
1657 void test_NgDirective_resolvedExpression() { 1660 void test_NgDirective_resolvedExpression() {
1658 addMainSource( 1661 addMainSource(r'''
1659 EngineTestCase.createSource( 1662
1660 [ 1663 import 'angular.dart';
1661 "", 1664
1662 "import 'angular.dart';", 1665 @Decorator(selector: '[my-directive]')
1663 "", 1666 class MyDirective {
1664 "@Decorator(selector: '[my-directive]')", 1667 @NgOneWay('my-property')
1665 "class MyDirective {", 1668 String condition;
1666 " @NgOneWay('my-property')", 1669 }''');
1667 " String condition;",
1668 "}"]));
1669 _resolveIndexNoErrors( 1670 _resolveIndexNoErrors(
1670 AngularTest.createHtmlWithMyController( 1671 AngularTest.createHtmlWithMyController(
1671 [ 1672 [
1672 "<input type='text' ng-model='name'>", 1673 "<input type='text' ng-model='name'>",
1673 "<div my-directive my-property='name != null'>", 1674 "<div my-directive my-property='name != null'>",
1674 "</div>"])); 1675 "</div>"]));
1675 resolveMainNoErrors(); 1676 resolveMainNoErrors();
1676 // "my-directive" attribute was resolved 1677 // "my-directive" attribute was resolved
1677 { 1678 {
1678 AngularSelectorElement selector = 1679 AngularSelectorElement selector =
(...skipping 13 matching lines...) Expand all
1692 JUnitTestCase.assertSame( 1693 JUnitTestCase.assertSame(
1693 AngularPropertyKind.ONE_WAY, 1694 AngularPropertyKind.ONE_WAY,
1694 propertyElement.propertyKind); 1695 propertyElement.propertyKind);
1695 JUnitTestCase.assertEquals("condition", propertyElement.field.name); 1696 JUnitTestCase.assertEquals("condition", propertyElement.field.name);
1696 } 1697 }
1697 // "name" expression was resolved 1698 // "name" expression was resolved
1698 JUnitTestCase.assertNotNull(findIdentifier("name != null")); 1699 JUnitTestCase.assertNotNull(findIdentifier("name != null"));
1699 } 1700 }
1700 1701
1701 void test_NgDirective_resolvedExpression_attrString() { 1702 void test_NgDirective_resolvedExpression_attrString() {
1702 addMainSource( 1703 addMainSource(r'''
1703 EngineTestCase.createSource( 1704
1704 [ 1705 import 'angular.dart';
1705 "", 1706
1706 "import 'angular.dart';", 1707 @NgDirective(selector: '[my-directive])
1707 "", 1708 class MyDirective {
1708 "@NgDirective(selector: '[my-directive])", 1709 @NgAttr('my-property')
1709 "class MyDirective {", 1710 String property;
1710 " @NgAttr('my-property')", 1711 }''');
1711 " String property;",
1712 "}"]));
1713 _resolveIndexNoErrors( 1712 _resolveIndexNoErrors(
1714 AngularTest.createHtmlWithMyController( 1713 AngularTest.createHtmlWithMyController(
1715 [ 1714 [
1716 "<input type='text' ng-model='name'>", 1715 "<input type='text' ng-model='name'>",
1717 "<div my-directive my-property='name != null'>", 1716 "<div my-directive my-property='name != null'>",
1718 "</div>"])); 1717 "</div>"]));
1719 resolveMain(); 1718 resolveMain();
1720 // @NgAttr means "string attribute", which we don't parse 1719 // @NgAttr means "string attribute", which we don't parse
1721 JUnitTestCase.assertNull(findIdentifierMaybe("name != null")); 1720 JUnitTestCase.assertNull(findIdentifierMaybe("name != null"));
1722 } 1721 }
1723 1722
1724 void test_NgDirective_resolvedExpression_dotAsName() { 1723 void test_NgDirective_resolvedExpression_dotAsName() {
1725 addMainSource( 1724 addMainSource(r'''
1726 EngineTestCase.createSource( 1725
1727 [ 1726 import 'angular.dart';
1728 "", 1727
1729 "import 'angular.dart';", 1728 @Decorator(
1730 "", 1729 selector: '[my-directive]',
1731 "@Decorator(", 1730 map: const {'.' : '=>condition'})
1732 " selector: '[my-directive]',", 1731 class MyDirective {
1733 " map: const {'.' : '=>condition'})", 1732 set condition(value) {}
1734 "class MyDirective {", 1733 }''');
1735 " set condition(value) {}",
1736 "}"]));
1737 _resolveIndexNoErrors( 1734 _resolveIndexNoErrors(
1738 AngularTest.createHtmlWithMyController( 1735 AngularTest.createHtmlWithMyController(
1739 [ 1736 [
1740 "<input type='text' ng-model='name'>", 1737 "<input type='text' ng-model='name'>",
1741 "<div my-directive='name != null'>", 1738 "<div my-directive='name != null'>",
1742 "</div>"])); 1739 "</div>"]));
1743 // "name" attribute was resolved 1740 // "name" attribute was resolved
1744 JUnitTestCase.assertNotNull(findIdentifier("name != null")); 1741 JUnitTestCase.assertNotNull(findIdentifier("name != null"));
1745 } 1742 }
1746 1743
1747 void fail_analysisContext_changeDart_invalidateApplication() { 1744 void fail_analysisContext_changeDart_invalidateApplication() {
1748 addMainSource( 1745 addMainSource(r'''
1749 EngineTestCase.createSource( 1746
1750 [ 1747 import 'angular.dart';
1751 "", 1748
1752 "import 'angular.dart';", 1749 @Component(
1753 "", 1750 templateUrl: 'my_template.html', cssUrl: 'my_styles.css',
1754 "@Component(", 1751 publishAs: 'ctrl',
1755 " templateUrl: 'my_template.html', cssUrl: 'my_styles.css',", 1752 selector: 'myComponent')
1756 " publishAs: 'ctrl',", 1753 class MyComponent {
1757 " selector: 'myComponent')", 1754 }''');
1758 "class MyComponent {",
1759 "}"]));
1760 contextHelper.addSource( 1755 contextHelper.addSource(
1761 "/entry-point.html", 1756 "/entry-point.html",
1762 AngularTest.createHtmlWithAngular([])); 1757 AngularTest.createHtmlWithAngular([]));
1763 addIndexSource2( 1758 addIndexSource2(
1764 "/my_template.html", 1759 "/my_template.html",
1765 EngineTestCase.createSource( 1760 r'''
1766 [" <div>", " {{ctrl.noMethod()}}", " </div>"])); 1761 <div>
1762 {{ctrl.noMethod()}}
1763 </div>''');
1767 contextHelper.addSource("/my_styles.css", ""); 1764 contextHelper.addSource("/my_styles.css", "");
1768 contextHelper.runTasks(); 1765 contextHelper.runTasks();
1769 // there are some errors in my_template.html 1766 // there are some errors in my_template.html
1770 { 1767 {
1771 List<AnalysisError> errors = context.getErrors(indexSource).errors; 1768 List<AnalysisError> errors = context.getErrors(indexSource).errors;
1772 JUnitTestCase.assertTrue(errors.length != 0); 1769 JUnitTestCase.assertTrue(errors.length != 0);
1773 } 1770 }
1774 // change main.dart, there are no MyComponent anymore 1771 // change main.dart, there are no MyComponent anymore
1775 context.setContents(mainSource, ""); 1772 context.setContents(mainSource, "");
1776 // ...errors in my_template.html should be removed 1773 // ...errors in my_template.html should be removed
1777 { 1774 {
1778 List<AnalysisError> errors = context.getErrors(indexSource).errors; 1775 List<AnalysisError> errors = context.getErrors(indexSource).errors;
1779 _ut.expect(errors, _ut.isEmpty); 1776 _ut.expect(errors, _ut.isEmpty);
1780 JUnitTestCase.assertTrue(errors.length == 0); 1777 JUnitTestCase.assertTrue(errors.length == 0);
1781 } 1778 }
1782 } 1779 }
1783 1780
1784 void test_analysisContext_changeEntryPoint_clearAngularErrors_inDart() { 1781 void test_analysisContext_changeEntryPoint_clearAngularErrors_inDart() {
1785 addMainSource( 1782 addMainSource(r'''
1786 EngineTestCase.createSource( 1783
1787 [ 1784 import 'angular.dart';
1788 "", 1785
1789 "import 'angular.dart';", 1786 @Component(
1790 "", 1787 templateUrl: 'no-such-template.html', cssUrl: 'my_styles.css',
1791 "@Component(", 1788 publishAs: 'ctrl',
1792 " templateUrl: 'no-such-template.html', cssUrl: 'my_styles.cs s',", 1789 selector: 'myComponent')
1793 " publishAs: 'ctrl',", 1790 class MyComponent {
1794 " selector: 'myComponent')", 1791 }''');
1795 "class MyComponent {",
1796 "}"]));
1797 Source entrySource = contextHelper.addSource( 1792 Source entrySource = contextHelper.addSource(
1798 "/entry-point.html", 1793 "/entry-point.html",
1799 AngularTest.createHtmlWithAngular([])); 1794 AngularTest.createHtmlWithAngular([]));
1800 contextHelper.addSource("/my_styles.css", ""); 1795 contextHelper.addSource("/my_styles.css", "");
1801 contextHelper.runTasks(); 1796 contextHelper.runTasks();
1802 // there are some errors in MyComponent 1797 // there are some errors in MyComponent
1803 { 1798 {
1804 List<AnalysisError> errors = context.getErrors(mainSource).errors; 1799 List<AnalysisError> errors = context.getErrors(mainSource).errors;
1805 JUnitTestCase.assertTrue(errors.length != 0); 1800 JUnitTestCase.assertTrue(errors.length != 0);
1806 } 1801 }
1807 // make entry-point.html non-Angular 1802 // make entry-point.html non-Angular
1808 context.setContents(entrySource, "<html/>"); 1803 context.setContents(entrySource, "<html/>");
1809 // ...errors in MyComponent should be removed 1804 // ...errors in MyComponent should be removed
1810 { 1805 {
1811 List<AnalysisError> errors = context.getErrors(mainSource).errors; 1806 List<AnalysisError> errors = context.getErrors(mainSource).errors;
1812 JUnitTestCase.assertTrue(errors.length == 0); 1807 JUnitTestCase.assertTrue(errors.length == 0);
1813 } 1808 }
1814 } 1809 }
1815 1810
1816 void test_analysisContext_changeEntryPoint_clearAngularErrors_inTemplate() { 1811 void test_analysisContext_changeEntryPoint_clearAngularErrors_inTemplate() {
1817 addMainSource( 1812 addMainSource(r'''
1818 EngineTestCase.createSource( 1813
1819 [ 1814 import 'angular.dart';
1820 "", 1815
1821 "import 'angular.dart';", 1816 @Component(
1822 "", 1817 templateUrl: 'my_template.html', cssUrl: 'my_styles.css',
1823 "@Component(", 1818 publishAs: 'ctrl',
1824 " templateUrl: 'my_template.html', cssUrl: 'my_styles.css',", 1819 selector: 'myComponent')
1825 " publishAs: 'ctrl',", 1820 class MyComponent {
1826 " selector: 'myComponent')", 1821 }''');
1827 "class MyComponent {",
1828 "}"]));
1829 Source entrySource = contextHelper.addSource( 1822 Source entrySource = contextHelper.addSource(
1830 "/entry-point.html", 1823 "/entry-point.html",
1831 AngularTest.createHtmlWithAngular([])); 1824 AngularTest.createHtmlWithAngular([]));
1832 addIndexSource2( 1825 addIndexSource2(
1833 "/my_template.html", 1826 "/my_template.html",
1834 EngineTestCase.createSource( 1827 r'''
1835 [" <div>", " {{ctrl.noMethod()}}", " </div>"])); 1828 <div>
1829 {{ctrl.noMethod()}}
1830 </div>''');
1836 contextHelper.addSource("/my_styles.css", ""); 1831 contextHelper.addSource("/my_styles.css", "");
1837 contextHelper.runTasks(); 1832 contextHelper.runTasks();
1838 // there are some errors in my_template.html 1833 // there are some errors in my_template.html
1839 { 1834 {
1840 List<AnalysisError> errors = context.getErrors(indexSource).errors; 1835 List<AnalysisError> errors = context.getErrors(indexSource).errors;
1841 JUnitTestCase.assertTrue(errors.length != 0); 1836 JUnitTestCase.assertTrue(errors.length != 0);
1842 } 1837 }
1843 // make entry-point.html non-Angular 1838 // make entry-point.html non-Angular
1844 context.setContents(entrySource, "<html/>"); 1839 context.setContents(entrySource, "<html/>");
1845 // ...errors in my_template.html should be removed 1840 // ...errors in my_template.html should be removed
1846 { 1841 {
1847 List<AnalysisError> errors = context.getErrors(indexSource).errors; 1842 List<AnalysisError> errors = context.getErrors(indexSource).errors;
1848 JUnitTestCase.assertTrue(errors.length == 0); 1843 JUnitTestCase.assertTrue(errors.length == 0);
1849 } 1844 }
1850 } 1845 }
1851 1846
1852 void test_analysisContext_removeEntryPoint_clearAngularErrors_inDart() { 1847 void test_analysisContext_removeEntryPoint_clearAngularErrors_inDart() {
1853 addMainSource( 1848 addMainSource(r'''
1854 EngineTestCase.createSource( 1849
1855 [ 1850 import 'angular.dart';
1856 "", 1851
1857 "import 'angular.dart';", 1852 @Component(
1858 "", 1853 templateUrl: 'no-such-template.html', cssUrl: 'my_styles.css',
1859 "@Component(", 1854 publishAs: 'ctrl',
1860 " templateUrl: 'no-such-template.html', cssUrl: 'my_styles.cs s',", 1855 selector: 'myComponent')
1861 " publishAs: 'ctrl',", 1856 class MyComponent {
1862 " selector: 'myComponent')", 1857 }''');
1863 "class MyComponent {",
1864 "}"]));
1865 Source entrySource = contextHelper.addSource( 1858 Source entrySource = contextHelper.addSource(
1866 "/entry-point.html", 1859 "/entry-point.html",
1867 AngularTest.createHtmlWithAngular([])); 1860 AngularTest.createHtmlWithAngular([]));
1868 contextHelper.addSource("/my_styles.css", ""); 1861 contextHelper.addSource("/my_styles.css", "");
1869 contextHelper.runTasks(); 1862 contextHelper.runTasks();
1870 // there are some errors in MyComponent 1863 // there are some errors in MyComponent
1871 { 1864 {
1872 List<AnalysisError> errors = context.getErrors(mainSource).errors; 1865 List<AnalysisError> errors = context.getErrors(mainSource).errors;
1873 JUnitTestCase.assertTrue(errors.length != 0); 1866 JUnitTestCase.assertTrue(errors.length != 0);
1874 } 1867 }
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
2158 */ 2151 */
2159 void test_ngShow() { 2152 void test_ngShow() {
2160 addMyController(); 2153 addMyController();
2161 _resolveIndexNoErrors( 2154 _resolveIndexNoErrors(
2162 AngularTest.createHtmlWithMyController( 2155 AngularTest.createHtmlWithMyController(
2163 ["<div ng-show='ctrl.field != null'/>"])); 2156 ["<div ng-show='ctrl.field != null'/>"]));
2164 assertResolvedIdentifier("field"); 2157 assertResolvedIdentifier("field");
2165 } 2158 }
2166 2159
2167 void test_notResolved_noDartScript() { 2160 void test_notResolved_noDartScript() {
2168 resolveIndex2( 2161 resolveIndex2(r'''
2169 EngineTestCase.createSource( 2162 <html ng-app>
2170 [ 2163 <body>
2171 "<html ng-app>", 2164 <div my-marker>
2172 " <body>", 2165 {{ctrl.field}}
2173 " <div my-marker>", 2166 </div>
2174 " {{ctrl.field}}", 2167 </body>
2175 " </div>", 2168 </html>''');
2176 " </body>",
2177 "</html>"]));
2178 assertNoErrors(); 2169 assertNoErrors();
2179 // Angular is not initialized, so "ctrl" is not parsed 2170 // Angular is not initialized, so "ctrl" is not parsed
2180 Expression expression = 2171 Expression expression =
2181 ht.HtmlUnitUtils.getExpression(indexUnit, findOffset2("ctrl")); 2172 ht.HtmlUnitUtils.getExpression(indexUnit, findOffset2("ctrl"));
2182 JUnitTestCase.assertNull(expression); 2173 JUnitTestCase.assertNull(expression);
2183 } 2174 }
2184 2175
2185 void test_notResolved_notAngular() { 2176 void test_notResolved_notAngular() {
2186 resolveIndex2( 2177 resolveIndex2(r'''
2187 EngineTestCase.createSource( 2178 <html no-ng-app>
2188 [ 2179 <body>
2189 "<html no-ng-app>", 2180 <div my-marker>
2190 " <body>", 2181 {{ctrl.field}}
2191 " <div my-marker>", 2182 </div>
2192 " {{ctrl.field}}", 2183 </body>
2193 " </div>", 2184 </html>''');
2194 " </body>",
2195 "</html>"]));
2196 assertNoErrors(); 2185 assertNoErrors();
2197 // Angular is not initialized, so "ctrl" is not parsed 2186 // Angular is not initialized, so "ctrl" is not parsed
2198 Expression expression = 2187 Expression expression =
2199 ht.HtmlUnitUtils.getExpression(indexUnit, findOffset2("ctrl")); 2188 ht.HtmlUnitUtils.getExpression(indexUnit, findOffset2("ctrl"));
2200 JUnitTestCase.assertNull(expression); 2189 JUnitTestCase.assertNull(expression);
2201 } 2190 }
2202 2191
2203 void test_notResolved_wrongControllerMarker() { 2192 void test_notResolved_wrongControllerMarker() {
2204 addMyController(); 2193 addMyController();
2205 addIndexSource( 2194 addIndexSource(r'''
2206 EngineTestCase.createSource( 2195 <html ng-app>
2207 [ 2196 <body>
2208 "<html ng-app>", 2197 <div not-my-marker>
2209 " <body>", 2198 {{ctrl.field}}
2210 " <div not-my-marker>", 2199 </div>
2211 " {{ctrl.field}}", 2200 <script type='application/dart' src='main.dart'></script>
2212 " </div>", 2201 </body>
2213 " <script type='application/dart' src='main.dart'></script>", 2202 </html>''');
2214 " </body>",
2215 "</html>"]));
2216 contextHelper.runTasks(); 2203 contextHelper.runTasks();
2217 resolveIndex(); 2204 resolveIndex();
2218 // no errors, because we decided to ignore them at the moment 2205 // no errors, because we decided to ignore them at the moment
2219 assertNoErrors(); 2206 assertNoErrors();
2220 // "ctrl" is not resolved 2207 // "ctrl" is not resolved
2221 SimpleIdentifier identifier = findIdentifier("ctrl"); 2208 SimpleIdentifier identifier = findIdentifier("ctrl");
2222 JUnitTestCase.assertNull(identifier.bestElement); 2209 JUnitTestCase.assertNull(identifier.bestElement);
2223 } 2210 }
2224 2211
2225 void test_resolveExpression_evenWithout_ngBootstrap() { 2212 void test_resolveExpression_evenWithout_ngBootstrap() {
2226 resolveMainSource( 2213 resolveMainSource(r'''
2227 EngineTestCase.createSource( 2214
2228 [ 2215 import 'angular.dart';
2229 "", 2216
2230 "import 'angular.dart';", 2217 @Controller(
2231 "", 2218 selector: '[my-controller]',
2232 "@Controller(", 2219 publishAs: 'ctrl')
2233 " selector: '[my-controller]',", 2220 class MyController {
2234 " publishAs: 'ctrl')", 2221 String field;
2235 "class MyController {", 2222 }''');
2236 " String field;", 2223 _resolveIndexNoErrors(r'''
2237 "}"])); 2224 <html ng-app>
2238 _resolveIndexNoErrors( 2225 <body>
2239 EngineTestCase.createSource( 2226 <div my-controller>
2240 [ 2227 {{ctrl.field}}
2241 "<html ng-app>", 2228 </div>
2242 " <body>", 2229 <script type='application/dart' src='main.dart'></script>
2243 " <div my-controller>", 2230 </body>
2244 " {{ctrl.field}}", 2231 </html>''');
2245 " </div>",
2246 " <script type='application/dart' src='main.dart'></script>",
2247 " </body>",
2248 "</html>"]));
2249 assertResolvedIdentifier2("ctrl.", "MyController"); 2232 assertResolvedIdentifier2("ctrl.", "MyController");
2250 } 2233 }
2251 2234
2252 void test_resolveExpression_ignoreUnresolved() { 2235 void test_resolveExpression_ignoreUnresolved() {
2253 resolveMainSource( 2236 resolveMainSource(r'''
2254 EngineTestCase.createSource( 2237
2255 [ 2238 import 'angular.dart';
2256 "", 2239
2257 "import 'angular.dart';", 2240 @Controller(
2258 "", 2241 selector: '[my-controller]',
2259 "@Controller(", 2242 publishAs: 'ctrl')
2260 " selector: '[my-controller]',", 2243 class MyController {
2261 " publishAs: 'ctrl')", 2244 Map map;
2262 "class MyController {", 2245 Object obj;
2263 " Map map;", 2246 }''');
2264 " Object obj;", 2247 resolveIndex2(r'''
2265 "}"])); 2248 <html ng-app>
2266 resolveIndex2( 2249 <body>
2267 EngineTestCase.createSource( 2250 <div my-controller>
2268 [ 2251 {{ctrl.map.property}}
2269 "<html ng-app>", 2252 {{ctrl.obj.property}}
2270 " <body>", 2253 {{invisibleScopeProperty}}
2271 " <div my-controller>", 2254 </div>
2272 " {{ctrl.map.property}}", 2255 <script type='application/dart' src='main.dart'></script>
2273 " {{ctrl.obj.property}}", 2256 </body>
2274 " {{invisibleScopeProperty}}", 2257 </html>''');
2275 " </div>",
2276 " <script type='application/dart' src='main.dart'></script>",
2277 " </body>",
2278 "</html>"]));
2279 assertNoErrors(); 2258 assertNoErrors();
2280 // "ctrl.map" and "ctrl.obj" are resolved 2259 // "ctrl.map" and "ctrl.obj" are resolved
2281 assertResolvedIdentifier2("map", "Map<dynamic, dynamic>"); 2260 assertResolvedIdentifier2("map", "Map<dynamic, dynamic>");
2282 assertResolvedIdentifier2("obj", "Object"); 2261 assertResolvedIdentifier2("obj", "Object");
2283 // ...but not "invisibleScopeProperty" 2262 // ...but not "invisibleScopeProperty"
2284 { 2263 {
2285 SimpleIdentifier identifier = findIdentifier("invisibleScopeProperty"); 2264 SimpleIdentifier identifier = findIdentifier("invisibleScopeProperty");
2286 JUnitTestCase.assertNull(identifier.bestElement); 2265 JUnitTestCase.assertNull(identifier.bestElement);
2287 } 2266 }
2288 } 2267 }
2289 2268
2290 void test_resolveExpression_inAttribute() { 2269 void test_resolveExpression_inAttribute() {
2291 addMyController(); 2270 addMyController();
2292 _resolveIndexNoErrors( 2271 _resolveIndexNoErrors(
2293 AngularTest.createHtmlWithMyController( 2272 AngularTest.createHtmlWithMyController(
2294 ["<button title='{{ctrl.field}}'></button>"])); 2273 ["<button title='{{ctrl.field}}'></button>"]));
2295 assertResolvedIdentifier2("ctrl", "MyController"); 2274 assertResolvedIdentifier2("ctrl", "MyController");
2296 } 2275 }
2297 2276
2298 void test_resolveExpression_ngApp_onBody() { 2277 void test_resolveExpression_ngApp_onBody() {
2299 addMyController(); 2278 addMyController();
2300 _resolveIndexNoErrors( 2279 _resolveIndexNoErrors(r'''
2301 EngineTestCase.createSource( 2280 <html>
2302 [ 2281 <body ng-app>
2303 "<html>", 2282 <div my-controller>
2304 " <body ng-app>", 2283 {{ctrl.field}}
2305 " <div my-controller>", 2284 </div>
2306 " {{ctrl.field}}", 2285 <script type='application/dart' src='main.dart'></script>
2307 " </div>", 2286 </body>
2308 " <script type='application/dart' src='main.dart'></script>", 2287 </html>''');
2309 " </body>",
2310 "</html>"]));
2311 assertResolvedIdentifier2("ctrl", "MyController"); 2288 assertResolvedIdentifier2("ctrl", "MyController");
2312 } 2289 }
2313 2290
2314 void test_resolveExpression_withFilter() { 2291 void test_resolveExpression_withFilter() {
2315 addMyController(); 2292 addMyController();
2316 _resolveIndexNoErrors( 2293 _resolveIndexNoErrors(
2317 AngularTest.createHtmlWithMyController(["{{ctrl.field | uppercase}}"])); 2294 AngularTest.createHtmlWithMyController(["{{ctrl.field | uppercase}}"]));
2318 assertResolvedIdentifier2("ctrl", "MyController"); 2295 assertResolvedIdentifier2("ctrl", "MyController");
2319 assertResolvedIdentifier("uppercase"); 2296 assertResolvedIdentifier("uppercase");
2320 } 2297 }
2321 2298
2322 void test_resolveExpression_withFilter_notSimpleIdentifier() { 2299 void test_resolveExpression_withFilter_notSimpleIdentifier() {
2323 addMyController(); 2300 addMyController();
2324 resolveIndex2( 2301 resolveIndex2(
2325 AngularTest.createHtmlWithMyController(["{{ctrl.field | not.supported}}" ])); 2302 AngularTest.createHtmlWithMyController(["{{ctrl.field | not.supported}}" ]));
2326 assertErrors(indexSource, [AngularCode.INVALID_FORMATTER_NAME]); 2303 assertErrors(indexSource, [AngularCode.INVALID_FORMATTER_NAME]);
2327 } 2304 }
2328 2305
2329 void test_scopeProperties() { 2306 void test_scopeProperties() {
2330 addMainSource( 2307 addMainSource(r'''
2331 EngineTestCase.createSource( 2308
2332 [ 2309 import 'angular.dart';
2333 "", 2310
2334 "import 'angular.dart';", 2311 @Component(
2335 "", 2312 templateUrl: 'my_template.html', cssUrl: 'my_styles.css',
2336 "@Component(", 2313 publishAs: 'ctrl',
2337 " templateUrl: 'my_template.html', cssUrl: 'my_styles.css',", 2314 selector: 'myComponent')
2338 " publishAs: 'ctrl',", 2315 class MyComponent {
2339 " selector: 'myComponent')", 2316 String field;
2340 "class MyComponent {", 2317 MyComponent(Scope scope) {
2341 " String field;", 2318 scope.context['scopeProperty'] = 'abc';
2342 " MyComponent(Scope scope) {", 2319 }
2343 " scope.context['scopeProperty'] = 'abc';", 2320 }
2344 " }", 2321 ''');
2345 "}",
2346 ""]));
2347 contextHelper.addSource( 2322 contextHelper.addSource(
2348 "/entry-point.html", 2323 "/entry-point.html",
2349 AngularTest.createHtmlWithAngular([])); 2324 AngularTest.createHtmlWithAngular([]));
2350 addIndexSource2( 2325 addIndexSource2(
2351 "/my_template.html", 2326 "/my_template.html",
2352 EngineTestCase.createSource( 2327 r'''
2353 [" <div>", " {{scopeProperty}}", " </div>"])); 2328 <div>
2329 {{scopeProperty}}
2330 </div>''');
2354 contextHelper.addSource("/my_styles.css", ""); 2331 contextHelper.addSource("/my_styles.css", "");
2355 contextHelper.runTasks(); 2332 contextHelper.runTasks();
2356 resolveIndex(); 2333 resolveIndex();
2357 assertNoErrors(); 2334 assertNoErrors();
2358 // "scopeProperty" is resolved 2335 // "scopeProperty" is resolved
2359 Element element = assertResolvedIdentifier2("scopeProperty}}", "String"); 2336 Element element = assertResolvedIdentifier2("scopeProperty}}", "String");
2360 EngineTestCase.assertInstanceOf( 2337 EngineTestCase.assertInstanceOf(
2361 (obj) => obj is AngularScopePropertyElement, 2338 (obj) => obj is AngularScopePropertyElement,
2362 AngularScopePropertyElement, 2339 AngularScopePropertyElement,
2363 AngularHtmlUnitResolver.getAngularElement(element)); 2340 AngularHtmlUnitResolver.getAngularElement(element));
2364 } 2341 }
2365 2342
2366 void test_scopeProperties_hideWithComponent() { 2343 void test_scopeProperties_hideWithComponent() {
2367 addMainSource( 2344 addMainSource(r'''
2368 EngineTestCase.createSource( 2345
2369 [ 2346 import 'angular.dart';
2370 "", 2347
2371 "import 'angular.dart';", 2348 @Component(
2372 "", 2349 templateUrl: 'my_template.html', cssUrl: 'my_styles.css',
2373 "@Component(", 2350 publishAs: 'ctrl',
2374 " templateUrl: 'my_template.html', cssUrl: 'my_styles.css',", 2351 selector: 'myComponent')
2375 " publishAs: 'ctrl',", 2352 class MyComponent {
2376 " selector: 'myComponent')", 2353 }
2377 "class MyComponent {", 2354
2378 "}", 2355 void setScopeProperties(Scope scope) {
2379 "", 2356 scope.context['ctrl'] = 1;
2380 "void setScopeProperties(Scope scope) {", 2357 }
2381 " scope.context['ctrl'] = 1;", 2358 ''');
2382 "}",
2383 ""]));
2384 contextHelper.addSource( 2359 contextHelper.addSource(
2385 "/entry-point.html", 2360 "/entry-point.html",
2386 AngularTest.createHtmlWithAngular([])); 2361 AngularTest.createHtmlWithAngular([]));
2387 addIndexSource2( 2362 addIndexSource2(
2388 "/my_template.html", 2363 "/my_template.html",
2389 EngineTestCase.createSource([" <div>", " {{ctrl}}", " </div>" ])); 2364 r'''
2365 <div>
2366 {{ctrl}}
2367 </div>''');
2390 contextHelper.addSource("/my_styles.css", ""); 2368 contextHelper.addSource("/my_styles.css", "");
2391 contextHelper.runTasks(); 2369 contextHelper.runTasks();
2392 resolveIndex(); 2370 resolveIndex();
2393 assertNoErrors(); 2371 assertNoErrors();
2394 // "ctrl" is resolved 2372 // "ctrl" is resolved
2395 LocalVariableElement element = 2373 LocalVariableElement element =
2396 assertResolvedIdentifier("ctrl}}") as LocalVariableElement; 2374 assertResolvedIdentifier("ctrl}}") as LocalVariableElement;
2397 List<ToolkitObjectElement> toolkitObjects = element.toolkitObjects; 2375 List<ToolkitObjectElement> toolkitObjects = element.toolkitObjects;
2398 EngineTestCase.assertInstanceOf( 2376 EngineTestCase.assertInstanceOf(
2399 (obj) => obj is AngularComponentElement, 2377 (obj) => obj is AngularComponentElement,
2400 AngularComponentElement, 2378 AngularComponentElement,
2401 toolkitObjects[0]); 2379 toolkitObjects[0]);
2402 } 2380 }
2403 2381
2404 void test_view_resolveTemplateFile() { 2382 void test_view_resolveTemplateFile() {
2405 addMainSource( 2383 addMainSource(r'''
2406 EngineTestCase.createSource( 2384
2407 [ 2385 import 'angular.dart';
2408 "", 2386
2409 "import 'angular.dart';", 2387 @Controller(
2410 "", 2388 selector: '[my-controller]',
2411 "@Controller(", 2389 publishAs: 'ctrl')
2412 " selector: '[my-controller]',", 2390 class MyController {
2413 " publishAs: 'ctrl')", 2391 String field;
2414 "class MyController {", 2392 }
2415 " String field;", 2393
2416 "}", 2394 class MyRouteInitializer {
2417 "", 2395 init(ViewFactory view) {
2418 "class MyRouteInitializer {", 2396 view('my_template.html');
2419 " init(ViewFactory view) {", 2397 }
2420 " view('my_template.html');", 2398 }''');
2421 " }",
2422 "}"]));
2423 contextHelper.addSource( 2399 contextHelper.addSource(
2424 "/entry-point.html", 2400 "/entry-point.html",
2425 AngularTest.createHtmlWithAngular([])); 2401 AngularTest.createHtmlWithAngular([]));
2426 addIndexSource2( 2402 addIndexSource2(
2427 "/my_template.html", 2403 "/my_template.html",
2428 EngineTestCase.createSource( 2404 r'''
2429 [" <div my-controller>", " {{ctrl.field}}", " </div>"])); 2405 <div my-controller>
2406 {{ctrl.field}}
2407 </div>''');
2430 contextHelper.addSource("/my_styles.css", ""); 2408 contextHelper.addSource("/my_styles.css", "");
2431 contextHelper.runTasks(); 2409 contextHelper.runTasks();
2432 resolveIndex(); 2410 resolveIndex();
2433 assertNoErrors(); 2411 assertNoErrors();
2434 assertResolvedIdentifier2("ctrl.", "MyController"); 2412 assertResolvedIdentifier2("ctrl.", "MyController");
2435 assertResolvedIdentifier2("field}}", "String"); 2413 assertResolvedIdentifier2("field}}", "String");
2436 } 2414 }
2437 2415
2438 String _getSourceContent(Source source) { 2416 String _getSourceContent(Source source) {
2439 return context.getContents(source).data.toString(); 2417 return context.getContents(source).data.toString();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
2515 Element element = ht.HtmlUnitUtils.getElementAtOffset(indexUnit, offset); 2493 Element element = ht.HtmlUnitUtils.getElementAtOffset(indexUnit, offset);
2516 EngineTestCase.assertInstanceOf( 2494 EngineTestCase.assertInstanceOf(
2517 (obj) => obj is PropertyAccessorElement, 2495 (obj) => obj is PropertyAccessorElement,
2518 PropertyAccessorElement, 2496 PropertyAccessorElement,
2519 element); 2497 element);
2520 JUnitTestCase.assertEquals("field", element.name); 2498 JUnitTestCase.assertEquals("field", element.name);
2521 } 2499 }
2522 } 2500 }
2523 2501
2524 void test_getEnclosingTagNode() { 2502 void test_getEnclosingTagNode() {
2525 resolveIndex2( 2503 resolveIndex2(r'''
2526 EngineTestCase.createSource( 2504 <html>
2527 [ 2505 <body ng-app>
2528 "<html>", 2506 <badge name='abc'> 123 </badge>
2529 " <body ng-app>", 2507 </body>
2530 " <badge name='abc'> 123 </badge>", 2508 </html>''');
2531 " </body>",
2532 "</html>"]));
2533 // no unit 2509 // no unit
2534 JUnitTestCase.assertNull(ht.HtmlUnitUtils.getEnclosingTagNode(null, 0)); 2510 JUnitTestCase.assertNull(ht.HtmlUnitUtils.getEnclosingTagNode(null, 0));
2535 // wrong offset 2511 // wrong offset
2536 JUnitTestCase.assertNull( 2512 JUnitTestCase.assertNull(
2537 ht.HtmlUnitUtils.getEnclosingTagNode(indexUnit, -1)); 2513 ht.HtmlUnitUtils.getEnclosingTagNode(indexUnit, -1));
2538 // valid offset 2514 // valid offset
2539 ht.XmlTagNode expected = _getEnclosingTagNode("<badge"); 2515 ht.XmlTagNode expected = _getEnclosingTagNode("<badge");
2540 JUnitTestCase.assertNotNull(expected); 2516 JUnitTestCase.assertNotNull(expected);
2541 JUnitTestCase.assertEquals("badge", expected.tag); 2517 JUnitTestCase.assertEquals("badge", expected.tag);
2542 JUnitTestCase.assertSame(expected, _getEnclosingTagNode("badge")); 2518 JUnitTestCase.assertSame(expected, _getEnclosingTagNode("badge"));
(...skipping 15 matching lines...) Expand all
2558 ht.HtmlUnitUtils.getExpression(indexUnit, offset + 1)); 2534 ht.HtmlUnitUtils.getExpression(indexUnit, offset + 1));
2559 JUnitTestCase.assertNotNull( 2535 JUnitTestCase.assertNotNull(
2560 ht.HtmlUnitUtils.getExpression(indexUnit, offset + 2)); 2536 ht.HtmlUnitUtils.getExpression(indexUnit, offset + 2));
2561 JUnitTestCase.assertNotNull( 2537 JUnitTestCase.assertNotNull(
2562 ht.HtmlUnitUtils.getExpression(indexUnit, offset + "ctrl.field".length)) ; 2538 ht.HtmlUnitUtils.getExpression(indexUnit, offset + "ctrl.field".length)) ;
2563 // try without unit 2539 // try without unit
2564 JUnitTestCase.assertNull(ht.HtmlUnitUtils.getExpression(null, offset)); 2540 JUnitTestCase.assertNull(ht.HtmlUnitUtils.getExpression(null, offset));
2565 } 2541 }
2566 2542
2567 void test_getTagNode() { 2543 void test_getTagNode() {
2568 resolveIndex2( 2544 resolveIndex2(r'''
2569 EngineTestCase.createSource( 2545 <html>
2570 [ 2546 <body ng-app>
2571 "<html>", 2547 <badge name='abc'> 123 </badge> done
2572 " <body ng-app>", 2548 </body>
2573 " <badge name='abc'> 123 </badge> done", 2549 </html>''');
2574 " </body>",
2575 "</html>"]));
2576 // no unit 2550 // no unit
2577 JUnitTestCase.assertNull(ht.HtmlUnitUtils.getTagNode(null, 0)); 2551 JUnitTestCase.assertNull(ht.HtmlUnitUtils.getTagNode(null, 0));
2578 // wrong offset 2552 // wrong offset
2579 JUnitTestCase.assertNull(ht.HtmlUnitUtils.getTagNode(indexUnit, -1)); 2553 JUnitTestCase.assertNull(ht.HtmlUnitUtils.getTagNode(indexUnit, -1));
2580 // on tag name 2554 // on tag name
2581 ht.XmlTagNode expected = _getTagNode("badge name="); 2555 ht.XmlTagNode expected = _getTagNode("badge name=");
2582 JUnitTestCase.assertNotNull(expected); 2556 JUnitTestCase.assertNotNull(expected);
2583 JUnitTestCase.assertEquals("badge", expected.tag); 2557 JUnitTestCase.assertEquals("badge", expected.tag);
2584 JUnitTestCase.assertSame(expected, _getTagNode("badge")); 2558 JUnitTestCase.assertSame(expected, _getTagNode("badge"));
2585 JUnitTestCase.assertSame(expected, _getTagNode(" name=")); 2559 JUnitTestCase.assertSame(expected, _getTagNode(" name="));
(...skipping 10 matching lines...) Expand all
2596 return ht.HtmlUnitUtils.getEnclosingTagNode( 2570 return ht.HtmlUnitUtils.getEnclosingTagNode(
2597 indexUnit, 2571 indexUnit,
2598 indexContent.indexOf(search)); 2572 indexContent.indexOf(search));
2599 } 2573 }
2600 2574
2601 ht.XmlTagNode _getTagNode(String search) { 2575 ht.XmlTagNode _getTagNode(String search) {
2602 return ht.HtmlUnitUtils.getTagNode(indexUnit, indexContent.indexOf(search)); 2576 return ht.HtmlUnitUtils.getTagNode(indexUnit, indexContent.indexOf(search));
2603 } 2577 }
2604 2578
2605 void _resolveSimpleCtrlFieldHtml() { 2579 void _resolveSimpleCtrlFieldHtml() {
2606 resolveIndex2( 2580 resolveIndex2(r'''
2607 EngineTestCase.createSource( 2581 <html>
2608 [ 2582 <body ng-app>
2609 "<html>", 2583 <div my-controller>
2610 " <body ng-app>", 2584 {{ctrl.field}}
2611 " <div my-controller>", 2585 </div>
2612 " {{ctrl.field}}", 2586 <script type='application/dart' src='main.dart'></script>
2613 " </div>", 2587 </body>
2614 " <script type='application/dart' src='main.dart'></script>", 2588 </html>''');
2615 " </body>",
2616 "</html>"]));
2617 } 2589 }
2618 } 2590 }
2619 2591
2620 2592
2621 abstract class AngularTest extends EngineTestCase { 2593 abstract class AngularTest extends EngineTestCase {
2622 AnalysisContextHelper contextHelper = new AnalysisContextHelper(); 2594 AnalysisContextHelper contextHelper = new AnalysisContextHelper();
2623 2595
2624 AnalysisContext context; 2596 AnalysisContext context;
2625 2597
2626 String mainContent; 2598 String mainContent;
(...skipping 22 matching lines...) Expand all
2649 indexSource = contextHelper.addSource(name, indexContent); 2621 indexSource = contextHelper.addSource(name, indexContent);
2650 } 2622 }
2651 /** 2623 /**
2652 * Fills [mainContent] and [mainSource]. 2624 * Fills [mainContent] and [mainSource].
2653 */ 2625 */
2654 void addMainSource(String content) { 2626 void addMainSource(String content) {
2655 mainContent = content; 2627 mainContent = content;
2656 mainSource = contextHelper.addSource("/main.dart", content); 2628 mainSource = contextHelper.addSource("/main.dart", content);
2657 } 2629 }
2658 void addMyController() { 2630 void addMyController() {
2659 resolveMainSource( 2631 resolveMainSource(r'''
2660 EngineTestCase.createSource( 2632
2661 [ 2633 import 'angular.dart';
2662 "", 2634
2663 "import 'angular.dart';", 2635 class Item {
2664 "", 2636 String name;
2665 "class Item {", 2637 bool done;
2666 " String name;", 2638 }
2667 " bool done;", 2639
2668 "}", 2640 @Controller(
2669 "", 2641 selector: '[my-controller]',
2670 "@Controller(", 2642 publishAs: 'ctrl')
2671 " selector: '[my-controller]',", 2643 class MyController {
2672 " publishAs: 'ctrl')", 2644 String field;
2673 "class MyController {", 2645 List<String> names;
2674 " String field;", 2646 List<Item> items;
2675 " List<String> names;", 2647 var untypedItems;
2676 " List<Item> items;", 2648 doSomething(event) {}
2677 " var untypedItems;", 2649 }''');
2678 " doSomething(event) {}",
2679 "}"]));
2680 } 2650 }
2681 /** 2651 /**
2682 * Assert that the number of errors reported against the given source matches the number of errors 2652 * Assert that the number of errors reported against the given source matches the number of errors
2683 * that are given and that they have the expected error codes. The order in wh ich the errors were 2653 * that are given and that they have the expected error codes. The order in wh ich the errors were
2684 * gathered is ignored. 2654 * gathered is ignored.
2685 * 2655 *
2686 * @param source the source against which the errors should have been reported 2656 * @param source the source against which the errors should have been reported
2687 * @param expectedErrorCodes the error codes of the errors that should have be en reported 2657 * @param expectedErrorCodes the error codes of the errors that should have be en reported
2688 * @throws AnalysisException if the reported errors could not be computed 2658 * @throws AnalysisException if the reported errors could not be computed
2689 * @throws AssertionFailedError if a different number of errors have been repo rted than were 2659 * @throws AssertionFailedError if a different number of errors have been repo rted than were
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
2890 for (Source source in sources) { 2860 for (Source source in sources) {
2891 ht.HtmlUnit htmlUnit = context.getResolvedHtmlUnit(source); 2861 ht.HtmlUnit htmlUnit = context.getResolvedHtmlUnit(source);
2892 htmlUnit.accept(new ExpressionVisitor_AngularTest_verify(verifier)); 2862 htmlUnit.accept(new ExpressionVisitor_AngularTest_verify(verifier));
2893 } 2863 }
2894 verifier.assertResolved(); 2864 verifier.assertResolved();
2895 } 2865 }
2896 2866
2897 void _configureForAngular(AnalysisContextHelper contextHelper) { 2867 void _configureForAngular(AnalysisContextHelper contextHelper) {
2898 contextHelper.addSource( 2868 contextHelper.addSource(
2899 "/angular.dart", 2869 "/angular.dart",
2900 EngineTestCase.createSource( 2870 r'''
2901 [ 2871 library angular;
2902 "library angular;", 2872
2903 "", 2873 class Scope {
2904 "class Scope {", 2874 Map context;
2905 " Map context;", 2875 }
2906 "}", 2876
2907 "", 2877 class Formatter {
2908 "class Formatter {", 2878 final String name;
2909 " final String name;", 2879 const Formatter({this.name});
2910 " const Formatter({this.name});", 2880 }
2911 "}", 2881
2912 "", 2882 class Directive {
2913 "class Directive {", 2883 const Directive({
2914 " const Directive({", 2884 selector,
2915 " selector,", 2885 children,
2916 " children,", 2886 visibility,
2917 " visibility,", 2887 module,
2918 " module,", 2888 map,
2919 " map,", 2889 exportedExpressions,
2920 " exportedExpressions,", 2890 exportedExpressionAttrs
2921 " exportedExpressionAttrs", 2891 });
2922 " });", 2892 }
2923 "}", 2893
2924 "", 2894 class Decorator {
2925 "class Decorator {", 2895 const Decorator({
2926 " const Decorator({", 2896 children/*: Directive.COMPILE_CHILDREN*/,
2927 " children/*: Directive.COMPILE_CHILDREN*/,", 2897 map,
2928 " map,", 2898 selector,
2929 " selector,", 2899 module,
2930 " module,", 2900 visibility,
2931 " visibility,", 2901 exportedExpressions,
2932 " exportedExpressions,", 2902 exportedExpressionAttrs
2933 " exportedExpressionAttrs", 2903 });
2934 " });", 2904 }
2935 "}", 2905
2936 "", 2906 class Controller {
2937 "class Controller {", 2907 const Controller({
2938 " const Controller({", 2908 children,
2939 " children,", 2909 publishAs,
2940 " publishAs,", 2910 map,
2941 " map,", 2911 selector,
2942 " selector,", 2912 visibility,
2943 " visibility,", 2913 publishTypes,
2944 " publishTypes,", 2914 exportedExpressions,
2945 " exportedExpressions,", 2915 exportedExpressionAttrs
2946 " exportedExpressionAttrs", 2916 });
2947 " });", 2917 }
2948 "}", 2918
2949 "", 2919 class NgAttr {
2950 "class NgAttr {", 2920 const NgAttr(String name);
2951 " const NgAttr(String name);", 2921 }
2952 "}", 2922 class NgCallback {
2953 "class NgCallback {", 2923 const NgCallback(String name);
2954 " const NgCallback(String name);", 2924 }
2955 "}", 2925 class NgOneWay {
2956 "class NgOneWay {", 2926 const NgOneWay(String name);
2957 " const NgOneWay(String name);", 2927 }
2958 "}", 2928 class NgOneWayOneTime {
2959 "class NgOneWayOneTime {", 2929 const NgOneWayOneTime(String name);
2960 " const NgOneWayOneTime(String name);", 2930 }
2961 "}", 2931 class NgTwoWay {
2962 "class NgTwoWay {", 2932 const NgTwoWay(String name);
2963 " const NgTwoWay(String name);", 2933 }
2964 "}", 2934
2965 "", 2935 class Component extends Directive {
2966 "class Component extends Directive {", 2936 const Component({
2967 " const Component({", 2937 this.template,
2968 " this.template,", 2938 this.templateUrl,
2969 " this.templateUrl,", 2939 this.cssUrl,
2970 " this.cssUrl,", 2940 this.applyAuthorStyles,
2971 " this.applyAuthorStyles,", 2941 this.resetStyleInheritance,
2972 " this.resetStyleInheritance,", 2942 publishAs,
2973 " publishAs,", 2943 module,
2974 " module,", 2944 map,
2975 " map,", 2945 selector,
2976 " selector,", 2946 visibility,
2977 " visibility,", 2947 exportExpressions,
2978 " exportExpressions,", 2948 exportExpressionAttrs
2979 " exportExpressionAttrs", 2949 }) : super(selector: selector,
2980 " }) : super(selector: selector,", 2950 children: null/*NgAnnotation.COMPILE_CHILDREN*/,
2981 " children: null/*NgAnnotation.COMPILE_CHILDREN*/,", 2951 visibility: visibility,
2982 " visibility: visibility,", 2952 map: map,
2983 " map: map,", 2953 module: module,
2984 " module: module,", 2954 exportExpressions: exportExpressions,
2985 " exportExpressions: exportExpressions,", 2955 exportExpressionAttrs: exportExpressionAttrs);
2986 " exportExpressionAttrs: exportExpressionAttrs);", 2956 }
2987 "}", 2957
2988 "", 2958 @Decorator(selector: '[ng-click]', map: const {'ng-click': '&onEvent'})
2989 "@Decorator(selector: '[ng-click]', map: const {'ng-click': '&on Event'})", 2959 @Decorator(selector: '[ng-mouseout]', map: const {'ng-mouseout': '&onEvent'})
2990 "@Decorator(selector: '[ng-mouseout]', map: const {'ng-mouseout' : '&onEvent'})", 2960 class NgEventDirective {
2991 "class NgEventDirective {", 2961 set onEvent(value) {}
2992 " set onEvent(value) {}", 2962 }
2993 "}", 2963
2994 "", 2964 @Decorator(selector: '[ng-if]', map: const {'ng-if': '=>condition'})
2995 "@Decorator(selector: '[ng-if]', map: const {'ng-if': '=>conditi on'})", 2965 class NgIfDirective {
2996 "class NgIfDirective {", 2966 set condition(value) {}
2997 " set condition(value) {}", 2967 }
2998 "}", 2968
2999 "", 2969 @Decorator(selector: '[ng-show]', map: const {'ng-show': '=>show'})
3000 "@Decorator(selector: '[ng-show]', map: const {'ng-show': '=>sho w'})", 2970 class NgShowDirective {
3001 "class NgShowDirective {", 2971 set show(value) {}
3002 " set show(value) {}", 2972 }
3003 "}", 2973
3004 "", 2974 @Formatter(name: 'filter')
3005 "@Formatter(name: 'filter')", 2975 class FilterFormatter {}
3006 "class FilterFormatter {}", 2976
3007 "", 2977 @Formatter(name: 'orderBy')
3008 "@Formatter(name: 'orderBy')", 2978 class OrderByFilter {}
3009 "class OrderByFilter {}", 2979
3010 "", 2980 @Formatter(name: 'uppercase')
3011 "@Formatter(name: 'uppercase')", 2981 class UppercaseFilter {}
3012 "class UppercaseFilter {}", 2982
3013 "", 2983 class ViewFactory {
3014 "class ViewFactory {", 2984 call(String templateUrl) => null;
3015 " call(String templateUrl) => null;", 2985 }
3016 "}", 2986
3017 "", 2987 class Module {
3018 "class Module {", 2988 install(Module m) {}
3019 " install(Module m) {}", 2989 type(Type t) {}
3020 " type(Type t) {}", 2990 value(Type t, value) {}
3021 " value(Type t, value) {}", 2991 }
3022 "}", 2992
3023 "", 2993 class Injector {}
3024 "class Injector {}", 2994
3025 "", 2995 Injector ngBootstrap({
3026 "Injector ngBootstrap({", 2996 Module module: null,
3027 " Module module: null,", 2997 List<Module> modules: null,
3028 " List<Module> modules: null,", 2998 /*dom.Element*/ element: null,
3029 " /*dom.Element*/ element: null,", 2999 String selector: '[ng-app]',
3030 " String selector: '[ng-app]',", 3000 /*Injector*/ injectorFactory/*(List<Module> modules): _defaultInjectorFa ctory*/}) {}
3031 " /*Injector*/ injectorFactory/*(List<Module> modules): _ defaultInjectorFactory*/}) {}", 3001 ''');
3032 ""]));
3033 } 3002 }
3034 3003
3035 /** 3004 /**
3036 * Creates an HTML content that has Angular marker and script with "main.dart" reference. 3005 * Creates an HTML content that has Angular marker and script with "main.dart" reference.
3037 */ 3006 */
3038 static String createHtmlWithAngular(List<String> lines) { 3007 static String createHtmlWithAngular(List<String> lines) {
3039 String source = EngineTestCase.createSource(["<html ng-app>", " <body>"]); 3008 String source = r'''
3009 <html ng-app>
3010 <body>''';
3040 source += EngineTestCase.createSource(lines); 3011 source += EngineTestCase.createSource(lines);
3041 source += EngineTestCase.createSource( 3012 source += r'''
3042 [ 3013 <script type='application/dart' src='main.dart'></script>
3043 " <script type='application/dart' src='main.dart'></script>", 3014 </body>
3044 " </body>", 3015 </html>''';
3045 "</html>"]);
3046 return source; 3016 return source;
3047 } 3017 }
3048 3018
3049 /** 3019 /**
3050 * Creates an HTML content that has Angular marker, script with "main.dart" re ference and 3020 * Creates an HTML content that has Angular marker, script with "main.dart" re ference and
3051 * "MyController" injected. 3021 * "MyController" injected.
3052 */ 3022 */
3053 static String createHtmlWithMyController(List<String> lines) { 3023 static String createHtmlWithMyController(List<String> lines) {
3054 String source = EngineTestCase.createSource( 3024 String source = r'''
3055 ["<html ng-app>", " <body>", " <div my-controller>"]); 3025 <html ng-app>
3026 <body>
3027 <div my-controller>''';
3056 source += EngineTestCase.createSource(lines); 3028 source += EngineTestCase.createSource(lines);
3057 source += EngineTestCase.createSource( 3029 source += r'''
3058 [ 3030 </div>
3059 " </div>", 3031 <script type='application/dart' src='main.dart'></script>
3060 " <script type='application/dart' src='main.dart'></script>", 3032 </body>
3061 " </body>", 3033 </html>''';
3062 "</html>"]);
3063 return source; 3034 return source;
3064 } 3035 }
3065 3036
3066 /** 3037 /**
3067 * Finds an [Element] with the given names inside of the given root [Element]. 3038 * Finds an [Element] with the given names inside of the given root [Element].
3068 * 3039 *
3069 * TODO(scheglov) maybe move this method to Element 3040 * TODO(scheglov) maybe move this method to Element
3070 * 3041 *
3071 * @param root the root [Element] to start searching from 3042 * @param root the root [Element] to start searching from
3072 * @param kind the kind of the [Element] to find, if `null` then any kind 3043 * @param kind the kind of the [Element] to find, if `null` then any kind
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
3590 _node = variableDeclaration; 3561 _node = variableDeclaration;
3591 return element; 3562 return element;
3592 } 3563 }
3593 } 3564 }
3594 3565
3595 3566
3596 class ConstantValueComputerTest extends ResolverTestCase { 3567 class ConstantValueComputerTest extends ResolverTestCase {
3597 void test_computeValues_cycle() { 3568 void test_computeValues_cycle() {
3598 TestLogger logger = new TestLogger(); 3569 TestLogger logger = new TestLogger();
3599 AnalysisEngine.instance.logger = logger; 3570 AnalysisEngine.instance.logger = logger;
3600 Source librarySource = addSource( 3571 Source librarySource = addSource(r'''
3601 EngineTestCase.createSource( 3572 const int a = c;
3602 ["const int a = c;", "const int b = a;", "const int c = b;"])); 3573 const int b = a;
3574 const int c = b;''');
3603 LibraryElement libraryElement = resolve(librarySource); 3575 LibraryElement libraryElement = resolve(librarySource);
3604 CompilationUnit unit = 3576 CompilationUnit unit =
3605 analysisContext.resolveCompilationUnit(librarySource, libraryElement); 3577 analysisContext.resolveCompilationUnit(librarySource, libraryElement);
3606 analysisContext.computeErrors(librarySource); 3578 analysisContext.computeErrors(librarySource);
3607 JUnitTestCase.assertNotNull(unit); 3579 JUnitTestCase.assertNotNull(unit);
3608 ConstantValueComputer computer = _makeConstantValueComputer(); 3580 ConstantValueComputer computer = _makeConstantValueComputer();
3609 computer.add(unit); 3581 computer.add(unit);
3610 computer.computeValues(); 3582 computer.computeValues();
3611 NodeList<CompilationUnitMember> members = unit.declarations; 3583 NodeList<CompilationUnitMember> members = unit.declarations;
3612 EngineTestCase.assertSizeOfList(3, members); 3584 EngineTestCase.assertSizeOfList(3, members);
3613 _validate(false, (members[0] as TopLevelVariableDeclaration).variables); 3585 _validate(false, (members[0] as TopLevelVariableDeclaration).variables);
3614 _validate(false, (members[1] as TopLevelVariableDeclaration).variables); 3586 _validate(false, (members[1] as TopLevelVariableDeclaration).variables);
3615 _validate(false, (members[2] as TopLevelVariableDeclaration).variables); 3587 _validate(false, (members[2] as TopLevelVariableDeclaration).variables);
3616 } 3588 }
3617 3589
3618 void test_computeValues_dependentVariables() { 3590 void test_computeValues_dependentVariables() {
3619 Source librarySource = addSource( 3591 Source librarySource = addSource(r'''
3620 EngineTestCase.createSource(["const int b = a;", "const int a = 0;"])); 3592 const int b = a;
3593 const int a = 0;''');
3621 LibraryElement libraryElement = resolve(librarySource); 3594 LibraryElement libraryElement = resolve(librarySource);
3622 CompilationUnit unit = 3595 CompilationUnit unit =
3623 analysisContext.resolveCompilationUnit(librarySource, libraryElement); 3596 analysisContext.resolveCompilationUnit(librarySource, libraryElement);
3624 JUnitTestCase.assertNotNull(unit); 3597 JUnitTestCase.assertNotNull(unit);
3625 ConstantValueComputer computer = _makeConstantValueComputer(); 3598 ConstantValueComputer computer = _makeConstantValueComputer();
3626 computer.add(unit); 3599 computer.add(unit);
3627 computer.computeValues(); 3600 computer.computeValues();
3628 NodeList<CompilationUnitMember> members = unit.declarations; 3601 NodeList<CompilationUnitMember> members = unit.declarations;
3629 EngineTestCase.assertSizeOfList(2, members); 3602 EngineTestCase.assertSizeOfList(2, members);
3630 _validate(true, (members[0] as TopLevelVariableDeclaration).variables); 3603 _validate(true, (members[0] as TopLevelVariableDeclaration).variables);
3631 _validate(true, (members[1] as TopLevelVariableDeclaration).variables); 3604 _validate(true, (members[1] as TopLevelVariableDeclaration).variables);
3632 } 3605 }
3633 3606
3634 void test_computeValues_empty() { 3607 void test_computeValues_empty() {
3635 ConstantValueComputer computer = _makeConstantValueComputer(); 3608 ConstantValueComputer computer = _makeConstantValueComputer();
3636 computer.computeValues(); 3609 computer.computeValues();
3637 } 3610 }
3638 3611
3639 void test_computeValues_multipleSources() { 3612 void test_computeValues_multipleSources() {
3640 Source librarySource = addNamedSource( 3613 Source librarySource = addNamedSource(
3641 "/lib.dart", 3614 "/lib.dart",
3642 EngineTestCase.createSource( 3615 r'''
3643 ["library lib;", "part 'part.dart';", "const int c = b;", "const int a = 0;"])); 3616 library lib;
3617 part 'part.dart';
3618 const int c = b;
3619 const int a = 0;''');
3644 Source partSource = addNamedSource( 3620 Source partSource = addNamedSource(
3645 "/part.dart", 3621 "/part.dart",
3646 EngineTestCase.createSource( 3622 r'''
3647 ["part of lib;", "const int b = a;", "const int d = c;"])); 3623 part of lib;
3624 const int b = a;
3625 const int d = c;''');
3648 LibraryElement libraryElement = resolve(librarySource); 3626 LibraryElement libraryElement = resolve(librarySource);
3649 CompilationUnit libraryUnit = 3627 CompilationUnit libraryUnit =
3650 analysisContext.resolveCompilationUnit(librarySource, libraryElement); 3628 analysisContext.resolveCompilationUnit(librarySource, libraryElement);
3651 JUnitTestCase.assertNotNull(libraryUnit); 3629 JUnitTestCase.assertNotNull(libraryUnit);
3652 CompilationUnit partUnit = 3630 CompilationUnit partUnit =
3653 analysisContext.resolveCompilationUnit(partSource, libraryElement); 3631 analysisContext.resolveCompilationUnit(partSource, libraryElement);
3654 JUnitTestCase.assertNotNull(partUnit); 3632 JUnitTestCase.assertNotNull(partUnit);
3655 ConstantValueComputer computer = _makeConstantValueComputer(); 3633 ConstantValueComputer computer = _makeConstantValueComputer();
3656 computer.add(libraryUnit); 3634 computer.add(libraryUnit);
3657 computer.add(partUnit); 3635 computer.add(partUnit);
(...skipping 21 matching lines...) Expand all
3679 ConstantValueComputer computer = _makeConstantValueComputer(); 3657 ConstantValueComputer computer = _makeConstantValueComputer();
3680 computer.add(unit); 3658 computer.add(unit);
3681 computer.computeValues(); 3659 computer.computeValues();
3682 NodeList<CompilationUnitMember> members = unit.declarations; 3660 NodeList<CompilationUnitMember> members = unit.declarations;
3683 EngineTestCase.assertSizeOfList(1, members); 3661 EngineTestCase.assertSizeOfList(1, members);
3684 _validate(true, (members[0] as TopLevelVariableDeclaration).variables); 3662 _validate(true, (members[0] as TopLevelVariableDeclaration).variables);
3685 } 3663 }
3686 3664
3687 void test_dependencyOnConstructor() { 3665 void test_dependencyOnConstructor() {
3688 // x depends on "const A()" 3666 // x depends on "const A()"
3689 _assertProperDependencies( 3667 _assertProperDependencies(r'''
3690 EngineTestCase.createSource( 3668 class A {
3691 ["class A {", " const A();", "}", "const x = const A();"]), 3669 const A();
3670 }
3671 const x = const A();''',
3692 []); 3672 []);
3693 } 3673 }
3694 3674
3695 void test_dependencyOnConstructorArgument() { 3675 void test_dependencyOnConstructorArgument() {
3696 // "const A(x)" depends on x 3676 // "const A(x)" depends on x
3697 _assertProperDependencies( 3677 _assertProperDependencies(r'''
3698 EngineTestCase.createSource( 3678 class A {
3699 [ 3679 const A(this.next);
3700 "class A {", 3680 final A next;
3701 " const A(this.next);", 3681 }
3702 " final A next;", 3682 const A x = const A(null);
3703 "}", 3683 const A y = const A(x);''',
3704 "const A x = const A(null);",
3705 "const A y = const A(x);"]),
3706 []); 3684 []);
3707 } 3685 }
3708 3686
3709 void test_dependencyOnConstructorArgument_unresolvedConstructor() { 3687 void test_dependencyOnConstructorArgument_unresolvedConstructor() {
3710 // "const A.a(x)" depends on x even if the constructor A.a can't be found. 3688 // "const A.a(x)" depends on x even if the constructor A.a can't be found.
3711 _assertProperDependencies( 3689 _assertProperDependencies(r'''
3712 EngineTestCase.createSource( 3690 class A {
3713 ["class A {", "}", "const int x = 1;", "const A y = const A.a(x);"]) , 3691 }
3692 const int x = 1;
3693 const A y = const A.a(x);''',
3714 [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR]); 3694 [CompileTimeErrorCode.CONST_WITH_UNDEFINED_CONSTRUCTOR]);
3715 } 3695 }
3716 3696
3717 void test_dependencyOnConstructorInitializer() { 3697 void test_dependencyOnConstructorInitializer() {
3718 // "const A()" depends on x 3698 // "const A()" depends on x
3719 _assertProperDependencies( 3699 _assertProperDependencies(r'''
3720 EngineTestCase.createSource( 3700 const int x = 1;
3721 [ 3701 class A {
3722 "const int x = 1;", 3702 const A() : v = x;
3723 "class A {", 3703 final int v;
3724 " const A() : v = x;", 3704 }''',
3725 " final int v;",
3726 "}"]),
3727 []); 3705 []);
3728 } 3706 }
3729 3707
3730 void test_dependencyOnExplicitSuperConstructor() { 3708 void test_dependencyOnExplicitSuperConstructor() {
3731 // b depends on B() depends on A() 3709 // b depends on B() depends on A()
3732 _assertProperDependencies( 3710 _assertProperDependencies(r'''
3733 EngineTestCase.createSource( 3711 class A {
3734 [ 3712 const A(this.x);
3735 "class A {", 3713 final int x;
3736 " const A(this.x);", 3714 }
3737 " final int x;", 3715 class B extends A {
3738 "}", 3716 const B() : super(5);
3739 "class B extends A {", 3717 }
3740 " const B() : super(5);", 3718 const B b = const B();''',
3741 "}",
3742 "const B b = const B();"]),
3743 []); 3719 []);
3744 } 3720 }
3745 3721
3746 void test_dependencyOnExplicitSuperConstructorParameters() { 3722 void test_dependencyOnExplicitSuperConstructorParameters() {
3747 // b depends on B() depends on i 3723 // b depends on B() depends on i
3748 _assertProperDependencies( 3724 _assertProperDependencies(r'''
3749 EngineTestCase.createSource( 3725 class A {
3750 [ 3726 const A(this.x);
3751 "class A {", 3727 final int x;
3752 " const A(this.x);", 3728 }
3753 " final int x;", 3729 class B extends A {
3754 "}", 3730 const B() : super(i);
3755 "class B extends A {", 3731 }
3756 " const B() : super(i);", 3732 const B b = const B();
3757 "}", 3733 const int i = 5;''',
3758 "const B b = const B();",
3759 "const int i = 5;"]),
3760 []); 3734 []);
3761 } 3735 }
3762 3736
3763 void test_dependencyOnFactoryRedirect() { 3737 void test_dependencyOnFactoryRedirect() {
3764 // a depends on A.foo() depends on A.bar() 3738 // a depends on A.foo() depends on A.bar()
3765 _assertProperDependencies( 3739 _assertProperDependencies(r'''
3766 EngineTestCase.createSource( 3740 const A a = const A.foo();
3767 [ 3741 class A {
3768 "const A a = const A.foo();", 3742 factory const A.foo() = A.bar;
3769 "class A {", 3743 const A.bar();
3770 " factory const A.foo() = A.bar;", 3744 }''',
3771 " const A.bar();",
3772 "}"]),
3773 []); 3745 []);
3774 } 3746 }
3775 3747
3776 void test_dependencyOnFactoryRedirectWithTypeParams() { 3748 void test_dependencyOnFactoryRedirectWithTypeParams() {
3777 _assertProperDependencies( 3749 _assertProperDependencies(r'''
3778 EngineTestCase.createSource( 3750 class A {
3779 [ 3751 const factory A(var a) = B<int>;
3780 "class A {", 3752 }
3781 " const factory A(var a) = B<int>;", 3753
3782 "}", 3754 class B<T> implements A {
3783 "", 3755 final T x;
3784 "class B<T> implements A {", 3756 const B(this.x);
3785 " final T x;", 3757 }
3786 " const B(this.x);", 3758
3787 "}", 3759 const A a = const A(10);''',
3788 "",
3789 "const A a = const A(10);"]),
3790 []); 3760 []);
3791 } 3761 }
3792 3762
3793 void test_dependencyOnImplicitSuperConstructor() { 3763 void test_dependencyOnImplicitSuperConstructor() {
3794 // b depends on B() depends on A() 3764 // b depends on B() depends on A()
3795 _assertProperDependencies( 3765 _assertProperDependencies(r'''
3796 EngineTestCase.createSource( 3766 class A {
3797 [ 3767 const A() : x = 5;
3798 "class A {", 3768 final int x;
3799 " const A() : x = 5;", 3769 }
3800 " final int x;", 3770 class B extends A {
3801 "}", 3771 const B();
3802 "class B extends A {", 3772 }
3803 " const B();", 3773 const B b = const B();''',
3804 "}",
3805 "const B b = const B();"]),
3806 []); 3774 []);
3807 } 3775 }
3808 3776
3809 void test_dependencyOnNonFactoryRedirect() { 3777 void test_dependencyOnNonFactoryRedirect() {
3810 // a depends on A.foo() depends on A.bar() 3778 // a depends on A.foo() depends on A.bar()
3811 _assertProperDependencies( 3779 _assertProperDependencies(r'''
3812 EngineTestCase.createSource( 3780 const A a = const A.foo();
3813 [ 3781 class A {
3814 "const A a = const A.foo();", 3782 const A.foo() : this.bar();
3815 "class A {", 3783 const A.bar();
3816 " const A.foo() : this.bar();", 3784 }''',
3817 " const A.bar();",
3818 "}"]),
3819 []); 3785 []);
3820 } 3786 }
3821 3787
3822 void test_dependencyOnNonFactoryRedirect_arg() { 3788 void test_dependencyOnNonFactoryRedirect_arg() {
3823 // a depends on A.foo() depends on b 3789 // a depends on A.foo() depends on b
3824 _assertProperDependencies( 3790 _assertProperDependencies(r'''
3825 EngineTestCase.createSource( 3791 const A a = const A.foo();
3826 [ 3792 const int b = 1;
3827 "const A a = const A.foo();", 3793 class A {
3828 "const int b = 1;", 3794 const A.foo() : this.bar(b);
3829 "class A {", 3795 const A.bar(x) : y = x;
3830 " const A.foo() : this.bar(b);", 3796 final int y;
3831 " const A.bar(x) : y = x;", 3797 }''',
3832 " final int y;"
3833 "}"]),
3834 []); 3798 []);
3835 } 3799 }
3836 3800
3837 void test_dependencyOnNonFactoryRedirect_defaultValue() { 3801 void test_dependencyOnNonFactoryRedirect_defaultValue() {
3838 // a depends on A.foo() depends on A.bar() depends on b 3802 // a depends on A.foo() depends on A.bar() depends on b
3839 _assertProperDependencies( 3803 _assertProperDependencies(r'''
3840 EngineTestCase.createSource( 3804 const A a = const A.foo();
3841 [ 3805 const int b = 1;
3842 "const A a = const A.foo();", 3806 class A {
3843 "const int b = 1;", 3807 const A.foo() : this.bar();
3844 "class A {", 3808 const A.bar([x = b]) : y = x;
3845 " const A.foo() : this.bar();", 3809 final int y;
3846 " const A.bar([x = b]) : y = x;", 3810 }''',
3847 " final int y;",
3848 "}"]),
3849 []); 3811 []);
3850 } 3812 }
3851 3813
3852 void test_dependencyOnNonFactoryRedirect_toMissing() { 3814 void test_dependencyOnNonFactoryRedirect_toMissing() {
3853 // a depends on A.foo() which depends on nothing, since A.bar() is 3815 // a depends on A.foo() which depends on nothing, since A.bar() is
3854 // missing. 3816 // missing.
3855 _assertProperDependencies( 3817 _assertProperDependencies(r'''
3856 EngineTestCase.createSource( 3818 const A a = const A.foo();
3857 [ 3819 class A {
3858 "const A a = const A.foo();", 3820 const A.foo() : this.bar();
3859 "class A {", 3821 }''',
3860 " const A.foo() : this.bar();",
3861 "}"]),
3862 [CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_MISSING_CONSTRUCTOR]); 3822 [CompileTimeErrorCode.REDIRECT_GENERATIVE_TO_MISSING_CONSTRUCTOR]);
3863 } 3823 }
3864 3824
3865 void test_dependencyOnNonFactoryRedirect_toNonConst() { 3825 void test_dependencyOnNonFactoryRedirect_toNonConst() {
3866 // a depends on A.foo() which depends on nothing, since A.bar() is 3826 // a depends on A.foo() which depends on nothing, since A.bar() is
3867 // non-const. 3827 // non-const.
3868 _assertProperDependencies( 3828 _assertProperDependencies(r'''
3869 EngineTestCase.createSource( 3829 const A a = const A.foo();
3870 [ 3830 class A {
3871 "const A a = const A.foo();", 3831 const A.foo() : this.bar();
3872 "class A {", 3832 A.bar();
3873 " const A.foo() : this.bar();", 3833 }''',
3874 " A.bar();",
3875 "}"]),
3876 []); 3834 []);
3877 } 3835 }
3878 3836
3879 void test_dependencyOnNonFactoryRedirect_unnamed() { 3837 void test_dependencyOnNonFactoryRedirect_unnamed() {
3880 // a depends on A.foo() depends on A() 3838 // a depends on A.foo() depends on A()
3881 _assertProperDependencies( 3839 _assertProperDependencies(r'''
3882 EngineTestCase.createSource( 3840 const A a = const A.foo();
3883 [ 3841 class A {
3884 "const A a = const A.foo();", 3842 const A.foo() : this();
3885 "class A {", 3843 const A();
3886 " const A.foo() : this();", 3844 }''',
3887 " const A();",
3888 "}"]),
3889 []); 3845 []);
3890 } 3846 }
3891 3847
3892 void test_dependencyOnOptionalParameterDefault() { 3848 void test_dependencyOnOptionalParameterDefault() {
3893 // a depends on A() depends on B() 3849 // a depends on A() depends on B()
3894 _assertProperDependencies( 3850 _assertProperDependencies(r'''
3895 EngineTestCase.createSource( 3851 class A {
3896 [ 3852 const A([x = const B()]) : b = x;
3897 "class A {", 3853 final B b;
3898 " const A([x = const B()]) : b = x;", 3854 }
3899 " final B b;", 3855 class B {
3900 "}", 3856 const B();
3901 "class B {", 3857 }
3902 " const B();", 3858 const A a = const A();''',
3903 "}",
3904 "const A a = const A();"]),
3905 []); 3859 []);
3906 } 3860 }
3907 3861
3908 void test_dependencyOnVariable() { 3862 void test_dependencyOnVariable() {
3909 // x depends on y 3863 // x depends on y
3910 _assertProperDependencies( 3864 _assertProperDependencies(r'''
3911 EngineTestCase.createSource(["const x = y + 1;", "const y = 2;"]), 3865 const x = y + 1;
3912 []); 3866 const y = 2;''',
3913 } 3867 []);
3914 3868 }
3869
3915 void test_fromEnvironment_bool_default_false() { 3870 void test_fromEnvironment_bool_default_false() {
3916 JUnitTestCase.assertEquals( 3871 JUnitTestCase.assertEquals(
3917 false, 3872 false,
3918 _assertValidBool(_check_fromEnvironment_bool(null, "false"))); 3873 _assertValidBool(_check_fromEnvironment_bool(null, "false")));
3919 } 3874 }
3920 3875
3921 void test_fromEnvironment_bool_default_overridden() { 3876 void test_fromEnvironment_bool_default_overridden() {
3922 JUnitTestCase.assertEquals( 3877 JUnitTestCase.assertEquals(
3923 false, 3878 false,
3924 _assertValidBool(_check_fromEnvironment_bool("false", "true"))); 3879 _assertValidBool(_check_fromEnvironment_bool("false", "true")));
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
4024 3979
4025 void test_fromEnvironment_string_undeclared() { 3980 void test_fromEnvironment_string_undeclared() {
4026 _assertValidUnknown(_check_fromEnvironment_string(null, null)); 3981 _assertValidUnknown(_check_fromEnvironment_string(null, null));
4027 } 3982 }
4028 3983
4029 void test_fromEnvironment_string_undeclared_nullDefault() { 3984 void test_fromEnvironment_string_undeclared_nullDefault() {
4030 _assertValidNull(_check_fromEnvironment_string(null, "null")); 3985 _assertValidNull(_check_fromEnvironment_string(null, "null"));
4031 } 3986 }
4032 3987
4033 void test_instanceCreationExpression_computedField() { 3988 void test_instanceCreationExpression_computedField() {
4034 CompilationUnit compilationUnit = resolveSource( 3989 CompilationUnit compilationUnit = resolveSource(r'''
4035 EngineTestCase.createSource( 3990 const foo = const A(4, 5);
4036 [ 3991 class A {
4037 "const foo = const A(4, 5);", 3992 const A(int i, int j) : k = 2 * i + j;
4038 "class A {", 3993 final int k;
4039 " const A(int i, int j) : k = 2 * i + j;", 3994 }''');
4040 " final int k;",
4041 "}"]));
4042 EvaluationResultImpl result = 3995 EvaluationResultImpl result =
4043 _evaluateInstanceCreationExpression(compilationUnit, "foo"); 3996 _evaluateInstanceCreationExpression(compilationUnit, "foo");
4044 Map<String, DartObjectImpl> fields = _assertType(result, "A"); 3997 Map<String, DartObjectImpl> fields = _assertType(result, "A");
4045 EngineTestCase.assertSizeOfMap(1, fields); 3998 EngineTestCase.assertSizeOfMap(1, fields);
4046 _assertIntField(fields, "k", 13); 3999 _assertIntField(fields, "k", 13);
4047 } 4000 }
4048 4001
4049 void 4002 void
4050 test_instanceCreationExpression_computedField_namedOptionalWithDefault() { 4003 test_instanceCreationExpression_computedField_namedOptionalWithDefault() {
4051 _checkInstanceCreationOptionalParams(false, true, true); 4004 _checkInstanceCreationOptionalParams(false, true, true);
4052 } 4005 }
4053 4006
4054 void 4007 void
4055 test_instanceCreationExpression_computedField_namedOptionalWithoutDefault( ) { 4008 test_instanceCreationExpression_computedField_namedOptionalWithoutDefault( ) {
4056 _checkInstanceCreationOptionalParams(false, true, false); 4009 _checkInstanceCreationOptionalParams(false, true, false);
4057 } 4010 }
4058 4011
4059 void 4012 void
4060 test_instanceCreationExpression_computedField_unnamedOptionalWithDefault() { 4013 test_instanceCreationExpression_computedField_unnamedOptionalWithDefault() {
4061 _checkInstanceCreationOptionalParams(false, false, true); 4014 _checkInstanceCreationOptionalParams(false, false, true);
4062 } 4015 }
4063 4016
4064 void 4017 void
4065 test_instanceCreationExpression_computedField_unnamedOptionalWithoutDefaul t() { 4018 test_instanceCreationExpression_computedField_unnamedOptionalWithoutDefaul t() {
4066 _checkInstanceCreationOptionalParams(false, false, false); 4019 _checkInstanceCreationOptionalParams(false, false, false);
4067 } 4020 }
4068 4021
4069 void test_instanceCreationExpression_computedField_usesConstConstructor() { 4022 void test_instanceCreationExpression_computedField_usesConstConstructor() {
4070 CompilationUnit compilationUnit = resolveSource( 4023 CompilationUnit compilationUnit = resolveSource(r'''
4071 EngineTestCase.createSource( 4024 const foo = const A(3);
4072 [ 4025 class A {
4073 "const foo = const A(3);", 4026 const A(int i) : b = const B(4);
4074 "class A {", 4027 final int b;
4075 " const A(int i) : b = const B(4);", 4028 }
4076 " final int b;", 4029 class B {
4077 "}", 4030 const B(this.k);
4078 "class B {", 4031 final int k;
4079 " const B(this.k);", 4032 }''');
4080 " final int k;",
4081 "}"]));
4082 EvaluationResultImpl result = 4033 EvaluationResultImpl result =
4083 _evaluateInstanceCreationExpression(compilationUnit, "foo"); 4034 _evaluateInstanceCreationExpression(compilationUnit, "foo");
4084 Map<String, DartObjectImpl> fieldsOfA = _assertType(result, "A"); 4035 Map<String, DartObjectImpl> fieldsOfA = _assertType(result, "A");
4085 EngineTestCase.assertSizeOfMap(1, fieldsOfA); 4036 EngineTestCase.assertSizeOfMap(1, fieldsOfA);
4086 Map<String, DartObjectImpl> fieldsOfB = 4037 Map<String, DartObjectImpl> fieldsOfB =
4087 _assertFieldType(fieldsOfA, "b", "B"); 4038 _assertFieldType(fieldsOfA, "b", "B");
4088 EngineTestCase.assertSizeOfMap(1, fieldsOfB); 4039 EngineTestCase.assertSizeOfMap(1, fieldsOfB);
4089 _assertIntField(fieldsOfB, "k", 4); 4040 _assertIntField(fieldsOfB, "k", 4);
4090 } 4041 }
4091 4042
4092 void test_instanceCreationExpression_computedField_usesStaticConst() { 4043 void test_instanceCreationExpression_computedField_usesStaticConst() {
4093 CompilationUnit compilationUnit = resolveSource( 4044 CompilationUnit compilationUnit = resolveSource(r'''
4094 EngineTestCase.createSource( 4045 const foo = const A(3);
4095 [ 4046 class A {
4096 "const foo = const A(3);", 4047 const A(int i) : k = i + B.bar;
4097 "class A {", 4048 final int k;
4098 " const A(int i) : k = i + B.bar;", 4049 }
4099 " final int k;", 4050 class B {
4100 "}", 4051 static const bar = 4;
4101 "class B {", 4052 }''');
4102 " static const bar = 4;",
4103 "}"]));
4104 EvaluationResultImpl result = 4053 EvaluationResultImpl result =
4105 _evaluateInstanceCreationExpression(compilationUnit, "foo"); 4054 _evaluateInstanceCreationExpression(compilationUnit, "foo");
4106 Map<String, DartObjectImpl> fields = _assertType(result, "A"); 4055 Map<String, DartObjectImpl> fields = _assertType(result, "A");
4107 EngineTestCase.assertSizeOfMap(1, fields); 4056 EngineTestCase.assertSizeOfMap(1, fields);
4108 _assertIntField(fields, "k", 7); 4057 _assertIntField(fields, "k", 7);
4109 } 4058 }
4110 4059
4111 void test_instanceCreationExpression_computedField_usesToplevelConst() { 4060 void test_instanceCreationExpression_computedField_usesToplevelConst() {
4112 CompilationUnit compilationUnit = resolveSource( 4061 CompilationUnit compilationUnit = resolveSource(r'''
4113 EngineTestCase.createSource( 4062 const foo = const A(3);
4114 [ 4063 const bar = 4;
4115 "const foo = const A(3);", 4064 class A {
4116 "const bar = 4;", 4065 const A(int i) : k = i + bar;
4117 "class A {", 4066 final int k;
4118 " const A(int i) : k = i + bar;", 4067 }''');
4119 " final int k;",
4120 "}"]));
4121 EvaluationResultImpl result = 4068 EvaluationResultImpl result =
4122 _evaluateInstanceCreationExpression(compilationUnit, "foo"); 4069 _evaluateInstanceCreationExpression(compilationUnit, "foo");
4123 Map<String, DartObjectImpl> fields = _assertType(result, "A"); 4070 Map<String, DartObjectImpl> fields = _assertType(result, "A");
4124 EngineTestCase.assertSizeOfMap(1, fields); 4071 EngineTestCase.assertSizeOfMap(1, fields);
4125 _assertIntField(fields, "k", 7); 4072 _assertIntField(fields, "k", 7);
4126 } 4073 }
4127 4074
4128 void test_instanceCreationExpression_explicitSuper() { 4075 void test_instanceCreationExpression_explicitSuper() {
4129 CompilationUnit compilationUnit = resolveSource( 4076 CompilationUnit compilationUnit = resolveSource(r'''
4130 EngineTestCase.createSource( 4077 const foo = const B(4, 5);
4131 [ 4078 class A {
4132 "const foo = const B(4, 5);", 4079 const A(this.x);
4133 "class A {", 4080 final int x;
4134 " const A(this.x);", 4081 }
4135 " final int x;", 4082 class B extends A {
4136 "}", 4083 const B(int x, this.y) : super(x * 2);
4137 "class B extends A {", 4084 final int y;
4138 " const B(int x, this.y) : super(x * 2);", 4085 }''');
4139 " final int y;",
4140 "}"]));
4141 EvaluationResultImpl result = 4086 EvaluationResultImpl result =
4142 _evaluateInstanceCreationExpression(compilationUnit, "foo"); 4087 _evaluateInstanceCreationExpression(compilationUnit, "foo");
4143 Map<String, DartObjectImpl> fields = _assertType(result, "B"); 4088 Map<String, DartObjectImpl> fields = _assertType(result, "B");
4144 EngineTestCase.assertSizeOfMap(2, fields); 4089 EngineTestCase.assertSizeOfMap(2, fields);
4145 _assertIntField(fields, "y", 5); 4090 _assertIntField(fields, "y", 5);
4146 Map<String, DartObjectImpl> superclassFields = 4091 Map<String, DartObjectImpl> superclassFields =
4147 _assertFieldType(fields, GenericState.SUPERCLASS_FIELD, "A"); 4092 _assertFieldType(fields, GenericState.SUPERCLASS_FIELD, "A");
4148 EngineTestCase.assertSizeOfMap(1, superclassFields); 4093 EngineTestCase.assertSizeOfMap(1, superclassFields);
4149 _assertIntField(superclassFields, "x", 8); 4094 _assertIntField(superclassFields, "x", 8);
4150 } 4095 }
4151 4096
4152 void test_instanceCreationExpression_fieldFormalParameter() { 4097 void test_instanceCreationExpression_fieldFormalParameter() {
4153 CompilationUnit compilationUnit = resolveSource( 4098 CompilationUnit compilationUnit = resolveSource(r'''
4154 EngineTestCase.createSource( 4099 const foo = const A(42);
4155 [ 4100 class A {
4156 "const foo = const A(42);", 4101 int x;
4157 "class A {", 4102 const A(this.x)
4158 " int x;", 4103 }''');
4159 " const A(this.x)",
4160 "}"]));
4161 EvaluationResultImpl result = 4104 EvaluationResultImpl result =
4162 _evaluateInstanceCreationExpression(compilationUnit, "foo"); 4105 _evaluateInstanceCreationExpression(compilationUnit, "foo");
4163 Map<String, DartObjectImpl> fields = _assertType(result, "A"); 4106 Map<String, DartObjectImpl> fields = _assertType(result, "A");
4164 EngineTestCase.assertSizeOfMap(1, fields); 4107 EngineTestCase.assertSizeOfMap(1, fields);
4165 _assertIntField(fields, "x", 42); 4108 _assertIntField(fields, "x", 42);
4166 } 4109 }
4167 4110
4168 void 4111 void
4169 test_instanceCreationExpression_fieldFormalParameter_namedOptionalWithDefa ult() { 4112 test_instanceCreationExpression_fieldFormalParameter_namedOptionalWithDefa ult() {
4170 _checkInstanceCreationOptionalParams(true, true, true); 4113 _checkInstanceCreationOptionalParams(true, true, true);
4171 } 4114 }
4172 4115
4173 void 4116 void
4174 test_instanceCreationExpression_fieldFormalParameter_namedOptionalWithoutD efault() { 4117 test_instanceCreationExpression_fieldFormalParameter_namedOptionalWithoutD efault() {
4175 _checkInstanceCreationOptionalParams(true, true, false); 4118 _checkInstanceCreationOptionalParams(true, true, false);
4176 } 4119 }
4177 4120
4178 void 4121 void
4179 test_instanceCreationExpression_fieldFormalParameter_unnamedOptionalWithDe fault() { 4122 test_instanceCreationExpression_fieldFormalParameter_unnamedOptionalWithDe fault() {
4180 _checkInstanceCreationOptionalParams(true, false, true); 4123 _checkInstanceCreationOptionalParams(true, false, true);
4181 } 4124 }
4182 4125
4183 void 4126 void
4184 test_instanceCreationExpression_fieldFormalParameter_unnamedOptionalWithou tDefault() { 4127 test_instanceCreationExpression_fieldFormalParameter_unnamedOptionalWithou tDefault() {
4185 _checkInstanceCreationOptionalParams(true, false, false); 4128 _checkInstanceCreationOptionalParams(true, false, false);
4186 } 4129 }
4187 4130
4188 void test_instanceCreationExpression_implicitSuper() { 4131 void test_instanceCreationExpression_implicitSuper() {
4189 CompilationUnit compilationUnit = resolveSource( 4132 CompilationUnit compilationUnit = resolveSource(r'''
4190 EngineTestCase.createSource( 4133 const foo = const B(4);
4191 [ 4134 class A {
4192 "const foo = const B(4);", 4135 const A() : x(3);
4193 "class A {", 4136 final int x;
4194 " const A() : x(3);", 4137 }
4195 " final int x;", 4138 class B extends A {
4196 "}", 4139 const B(this.y);
4197 "class B extends A {", 4140 final int y;
4198 " const B(this.y);", 4141 }''');
4199 " final int y;",
4200 "}"]));
4201 EvaluationResultImpl result = 4142 EvaluationResultImpl result =
4202 _evaluateInstanceCreationExpression(compilationUnit, "foo"); 4143 _evaluateInstanceCreationExpression(compilationUnit, "foo");
4203 Map<String, DartObjectImpl> fields = _assertType(result, "B"); 4144 Map<String, DartObjectImpl> fields = _assertType(result, "B");
4204 EngineTestCase.assertSizeOfMap(2, fields); 4145 EngineTestCase.assertSizeOfMap(2, fields);
4205 _assertIntField(fields, "y", 4); 4146 _assertIntField(fields, "y", 4);
4206 Map<String, DartObjectImpl> superclassFields = 4147 Map<String, DartObjectImpl> superclassFields =
4207 _assertFieldType(fields, GenericState.SUPERCLASS_FIELD, "A"); 4148 _assertFieldType(fields, GenericState.SUPERCLASS_FIELD, "A");
4208 EngineTestCase.assertSizeOfMap(1, superclassFields); 4149 EngineTestCase.assertSizeOfMap(1, superclassFields);
4209 _assertIntField(superclassFields, "x", 3); 4150 _assertIntField(superclassFields, "x", 3);
4210 } 4151 }
4211 4152
4212 void test_instanceCreationExpression_nonFactoryRedirect() { 4153 void test_instanceCreationExpression_nonFactoryRedirect() {
4213 CompilationUnit compilationUnit = resolveSource( 4154 CompilationUnit compilationUnit = resolveSource(r'''
4214 EngineTestCase.createSource( 4155 const foo = const A.a1();
4215 [ 4156 class A {
4216 "const foo = const A.a1();", 4157 const A.a1() : this.a2();
4217 "class A {", 4158 const A.a2() : x = 5;
4218 " const A.a1() : this.a2();", 4159 final int x;
4219 " const A.a2() : x = 5;", 4160 }''');
4220 " final int x;",
4221 "}"]));
4222 Map<String, DartObjectImpl> aFields = _assertType( 4161 Map<String, DartObjectImpl> aFields = _assertType(
4223 _evaluateInstanceCreationExpression(compilationUnit, "foo"), 4162 _evaluateInstanceCreationExpression(compilationUnit, "foo"),
4224 "A"); 4163 "A");
4225 _assertIntField(aFields, 'x', 5); 4164 _assertIntField(aFields, 'x', 5);
4226 } 4165 }
4227 4166
4228 void test_instanceCreationExpression_nonFactoryRedirect_arg() { 4167 void test_instanceCreationExpression_nonFactoryRedirect_arg() {
4229 CompilationUnit compilationUnit = resolveSource( 4168 CompilationUnit compilationUnit = resolveSource(r'''
4230 EngineTestCase.createSource( 4169 const foo = const A.a1(1);
4231 [ 4170 class A {
4232 "const foo = const A.a1(1);", 4171 const A.a1(x) : this.a2(x + 100);
4233 "class A {", 4172 const A.a2(x) : y = x + 10;
4234 " const A.a1(x) : this.a2(x + 100);", 4173 final int y;
4235 " const A.a2(x) : y = x + 10;", 4174 }''');
4236 " final int y;",
4237 "}"]));
4238 Map<String, DartObjectImpl> aFields = _assertType( 4175 Map<String, DartObjectImpl> aFields = _assertType(
4239 _evaluateInstanceCreationExpression(compilationUnit, "foo"), 4176 _evaluateInstanceCreationExpression(compilationUnit, "foo"),
4240 "A"); 4177 "A");
4241 _assertIntField(aFields, 'y', 111); 4178 _assertIntField(aFields, 'y', 111);
4242 } 4179 }
4243 4180
4244 void test_instanceCreationExpression_nonFactoryRedirect_cycle() { 4181 void test_instanceCreationExpression_nonFactoryRedirect_cycle() {
4245 // It is an error to have a cycle in non-factory redirects; however, we 4182 // It is an error to have a cycle in non-factory redirects; however, we
4246 // need to make sure that even if the error occurs, attempting to evaluate 4183 // need to make sure that even if the error occurs, attempting to evaluate
4247 // the constant will terminate. 4184 // the constant will terminate.
4248 CompilationUnit compilationUnit = resolveSource( 4185 CompilationUnit compilationUnit = resolveSource(r'''
4249 EngineTestCase.createSource( 4186 const foo = const A();
4250 [ 4187 class A {
4251 "const foo = const A();", 4188 const A() : this.b();
4252 "class A {", 4189 const A.b() : this();
4253 " const A() : this.b();", 4190 }''');
4254 " const A.b() : this();",
4255 "}"]));
4256 _assertValidUnknown( 4191 _assertValidUnknown(
4257 _evaluateInstanceCreationExpression(compilationUnit, "foo")); 4192 _evaluateInstanceCreationExpression(compilationUnit, "foo"));
4258 } 4193 }
4259 4194
4260 void test_instanceCreationExpression_nonFactoryRedirect_defaultArg() { 4195 void test_instanceCreationExpression_nonFactoryRedirect_defaultArg() {
4261 CompilationUnit compilationUnit = resolveSource( 4196 CompilationUnit compilationUnit = resolveSource(r'''
4262 EngineTestCase.createSource( 4197 const foo = const A.a1();
4263 [ 4198 class A {
4264 "const foo = const A.a1();", 4199 const A.a1() : this.a2();
4265 "class A {", 4200 const A.a2([x = 100]) : y = x + 10;
4266 " const A.a1() : this.a2();", 4201 final int y;
4267 " const A.a2([x = 100]) : y = x + 10;", 4202 }''');
4268 " final int y;",
4269 "}"]));
4270 Map<String, DartObjectImpl> aFields = _assertType( 4203 Map<String, DartObjectImpl> aFields = _assertType(
4271 _evaluateInstanceCreationExpression(compilationUnit, "foo"), 4204 _evaluateInstanceCreationExpression(compilationUnit, "foo"),
4272 "A"); 4205 "A");
4273 _assertIntField(aFields, 'y', 110); 4206 _assertIntField(aFields, 'y', 110);
4274 } 4207 }
4275 4208
4276 void test_instanceCreationExpression_nonFactoryRedirect_toMissing() { 4209 void test_instanceCreationExpression_nonFactoryRedirect_toMissing() {
4277 CompilationUnit compilationUnit = resolveSource( 4210 CompilationUnit compilationUnit = resolveSource(r'''
4278 EngineTestCase.createSource( 4211 const foo = const A.a1();
4279 [ 4212 class A {
4280 "const foo = const A.a1();", 4213 const A.a1() : this.a2();
4281 "class A {", 4214 }''');
4282 " const A.a1() : this.a2();",
4283 "}"]));
4284 // We don't care what value foo evaluates to (since there is a compile 4215 // We don't care what value foo evaluates to (since there is a compile
4285 // error), but we shouldn't crash, and we should figure 4216 // error), but we shouldn't crash, and we should figure
4286 // out that it evaluates to an instance of class A. 4217 // out that it evaluates to an instance of class A.
4287 _assertType( 4218 _assertType(
4288 _evaluateInstanceCreationExpression(compilationUnit, "foo"), 4219 _evaluateInstanceCreationExpression(compilationUnit, "foo"),
4289 "A"); 4220 "A");
4290 } 4221 }
4291 4222
4292 void test_instanceCreationExpression_nonFactoryRedirect_toNonConst() { 4223 void test_instanceCreationExpression_nonFactoryRedirect_toNonConst() {
4293 CompilationUnit compilationUnit = resolveSource( 4224 CompilationUnit compilationUnit = resolveSource(r'''
4294 EngineTestCase.createSource( 4225 const foo = const A.a1();
4295 [ 4226 class A {
4296 "const foo = const A.a1();", 4227 const A.a1() : this.a2();
4297 "class A {", 4228 A.a2();
4298 " const A.a1() : this.a2();", 4229 }''');
4299 " A.a2();",
4300 "}"]));
4301 // We don't care what value foo evaluates to (since there is a compile 4230 // We don't care what value foo evaluates to (since there is a compile
4302 // error), but we shouldn't crash, and we should figure 4231 // error), but we shouldn't crash, and we should figure
4303 // out that it evaluates to an instance of class A. 4232 // out that it evaluates to an instance of class A.
4304 _assertType( 4233 _assertType(
4305 _evaluateInstanceCreationExpression(compilationUnit, "foo"), 4234 _evaluateInstanceCreationExpression(compilationUnit, "foo"),
4306 "A"); 4235 "A");
4307 } 4236 }
4308 4237
4309 void test_instanceCreationExpression_nonFactoryRedirect_unnamed() { 4238 void test_instanceCreationExpression_nonFactoryRedirect_unnamed() {
4310 CompilationUnit compilationUnit = resolveSource( 4239 CompilationUnit compilationUnit = resolveSource(r'''
4311 EngineTestCase.createSource( 4240 const foo = const A.a1();
4312 [ 4241 class A {
4313 "const foo = const A.a1();", 4242 const A.a1() : this();
4314 "class A {", 4243 const A() : x = 5;
4315 " const A.a1() : this();", 4244 final int x;
4316 " const A() : x = 5;", 4245 }''');
4317 " final int x;",
4318 "}"]));
4319 Map<String, DartObjectImpl> aFields = _assertType( 4246 Map<String, DartObjectImpl> aFields = _assertType(
4320 _evaluateInstanceCreationExpression(compilationUnit, "foo"), 4247 _evaluateInstanceCreationExpression(compilationUnit, "foo"),
4321 "A"); 4248 "A");
4322 _assertIntField(aFields, 'x', 5); 4249 _assertIntField(aFields, 'x', 5);
4323 } 4250 }
4324 4251
4325 void test_instanceCreationExpression_redirect() { 4252 void test_instanceCreationExpression_redirect() {
4326 CompilationUnit compilationUnit = resolveSource( 4253 CompilationUnit compilationUnit = resolveSource(r'''
4327 EngineTestCase.createSource( 4254 const foo = const A();
4328 [ 4255 class A {
4329 "const foo = const A();", 4256 const factory A() = B;
4330 "class A {", 4257 }
4331 " const factory A() = B;", 4258 class B implements A {
4332 "}", 4259 const B();
4333 "class B implements A {", 4260 }''');
4334 " const B();",
4335 "}"]));
4336 _assertType( 4261 _assertType(
4337 _evaluateInstanceCreationExpression(compilationUnit, "foo"), 4262 _evaluateInstanceCreationExpression(compilationUnit, "foo"),
4338 "B"); 4263 "B");
4339 } 4264 }
4340 4265
4341 void test_instanceCreationExpression_redirectWithTypeParams() { 4266 void test_instanceCreationExpression_redirectWithTypeParams() {
4342 CompilationUnit compilationUnit = resolveSource( 4267 CompilationUnit compilationUnit = resolveSource(r'''
4343 EngineTestCase.createSource( 4268 class A {
4344 [ 4269 const factory A(var a) = B<int>;
4345 "class A {", 4270 }
4346 " const factory A(var a) = B<int>;", 4271
4347 "}", 4272 class B<T> implements A {
4348 "", 4273 final T x;
4349 "class B<T> implements A {", 4274 const B(this.x);
4350 " final T x;", 4275 }
4351 " const B(this.x);", 4276
4352 "}", 4277 const A a = const A(10);''');
4353 "",
4354 "const A a = const A(10);"]));
4355 EvaluationResultImpl result = 4278 EvaluationResultImpl result =
4356 _evaluateInstanceCreationExpression(compilationUnit, "a"); 4279 _evaluateInstanceCreationExpression(compilationUnit, "a");
4357 Map<String, DartObjectImpl> fields = _assertType(result, "B<int>"); 4280 Map<String, DartObjectImpl> fields = _assertType(result, "B<int>");
4358 EngineTestCase.assertSizeOfMap(1, fields); 4281 EngineTestCase.assertSizeOfMap(1, fields);
4359 _assertIntField(fields, "x", 10); 4282 _assertIntField(fields, "x", 10);
4360 } 4283 }
4361 4284
4362 void test_instanceCreationExpression_redirectWithTypeSubstitution() { 4285 void test_instanceCreationExpression_redirectWithTypeSubstitution() {
4363 // To evaluate the redirection of A<int>, 4286 // To evaluate the redirection of A<int>,
4364 // A's template argument (T=int) must be substituted 4287 // A's template argument (T=int) must be substituted
4365 // into B's template argument (B<U> where U=T) to get B<int>. 4288 // into B's template argument (B<U> where U=T) to get B<int>.
4366 CompilationUnit compilationUnit = resolveSource( 4289 CompilationUnit compilationUnit = resolveSource(r'''
4367 EngineTestCase.createSource( 4290 class A<T> {
4368 [ 4291 const factory A(var a) = B<T>;
4369 "class A<T> {", 4292 }
4370 " const factory A(var a) = B<T>;", 4293
4371 "}", 4294 class B<U> implements A {
4372 "", 4295 final U x;
4373 "class B<U> implements A {", 4296 const B(this.x);
4374 " final U x;", 4297 }
4375 " const B(this.x);", 4298
4376 "}", 4299 const A<int> a = const A<int>(10);''');
4377 "",
4378 "const A<int> a = const A<int>(10);"]));
4379 EvaluationResultImpl result = 4300 EvaluationResultImpl result =
4380 _evaluateInstanceCreationExpression(compilationUnit, "a"); 4301 _evaluateInstanceCreationExpression(compilationUnit, "a");
4381 Map<String, DartObjectImpl> fields = _assertType(result, "B<int>"); 4302 Map<String, DartObjectImpl> fields = _assertType(result, "B<int>");
4382 EngineTestCase.assertSizeOfMap(1, fields); 4303 EngineTestCase.assertSizeOfMap(1, fields);
4383 _assertIntField(fields, "x", 10); 4304 _assertIntField(fields, "x", 10);
4384 } 4305 }
4385 4306
4386 void test_instanceCreationExpression_redirect_cycle() { 4307 void test_instanceCreationExpression_redirect_cycle() {
4387 // It is an error to have a cycle in factory redirects; however, we need 4308 // It is an error to have a cycle in factory redirects; however, we need
4388 // to make sure that even if the error occurs, attempting to evaluate the 4309 // to make sure that even if the error occurs, attempting to evaluate the
4389 // constant will terminate. 4310 // constant will terminate.
4390 CompilationUnit compilationUnit = resolveSource( 4311 CompilationUnit compilationUnit = resolveSource(r'''
4391 EngineTestCase.createSource( 4312 const foo = const A();
4392 [ 4313 class A {
4393 "const foo = const A();", 4314 const factory A() = A.b;
4394 "class A {", 4315 const factory A.b() = A;
4395 " const factory A() = A.b;", 4316 }''');
4396 " const factory A.b() = A;",
4397 "}"]));
4398 _assertValidUnknown( 4317 _assertValidUnknown(
4399 _evaluateInstanceCreationExpression(compilationUnit, "foo")); 4318 _evaluateInstanceCreationExpression(compilationUnit, "foo"));
4400 } 4319 }
4401 4320
4402 void test_instanceCreationExpression_redirect_extern() { 4321 void test_instanceCreationExpression_redirect_extern() {
4403 CompilationUnit compilationUnit = resolveSource( 4322 CompilationUnit compilationUnit = resolveSource(r'''
4404 EngineTestCase.createSource( 4323 const foo = const A();
4405 ["const foo = const A();", "class A {", " external const factory A( );", "}"])); 4324 class A {
4325 external const factory A();
4326 }''');
4406 _assertValidUnknown( 4327 _assertValidUnknown(
4407 _evaluateInstanceCreationExpression(compilationUnit, "foo")); 4328 _evaluateInstanceCreationExpression(compilationUnit, "foo"));
4408 } 4329 }
4409 4330
4410 void test_instanceCreationExpression_redirect_nonConst() { 4331 void test_instanceCreationExpression_redirect_nonConst() {
4411 // It is an error for a const factory constructor redirect to a non-const 4332 // It is an error for a const factory constructor redirect to a non-const
4412 // constructor; however, we need to make sure that even if the error 4333 // constructor; however, we need to make sure that even if the error
4413 // attempting to evaluate the constant won't cause a crash. 4334 // attempting to evaluate the constant won't cause a crash.
4414 CompilationUnit compilationUnit = resolveSource( 4335 CompilationUnit compilationUnit = resolveSource(r'''
4415 EngineTestCase.createSource( 4336 const foo = const A();
4416 [ 4337 class A {
4417 "const foo = const A();", 4338 const factory A() = A.b;
4418 "class A {", 4339 A.b();
4419 " const factory A() = A.b;", 4340 }''');
4420 " A.b();",
4421 "}"]));
4422 _assertValidUnknown( 4341 _assertValidUnknown(
4423 _evaluateInstanceCreationExpression(compilationUnit, "foo")); 4342 _evaluateInstanceCreationExpression(compilationUnit, "foo"));
4424 } 4343 }
4425 4344
4426 void test_instanceCreationExpression_symbol() { 4345 void test_instanceCreationExpression_symbol() {
4427 CompilationUnit compilationUnit = 4346 CompilationUnit compilationUnit =
4428 resolveSource(EngineTestCase.createSource(["const foo = const Symbol('a' );"])); 4347 resolveSource("const foo = const Symbol('a');");
4429 EvaluationResultImpl evaluationResult = 4348 EvaluationResultImpl evaluationResult =
4430 _evaluateInstanceCreationExpression(compilationUnit, "foo"); 4349 _evaluateInstanceCreationExpression(compilationUnit, "foo");
4431 JUnitTestCase.assertNotNull(evaluationResult.value); 4350 JUnitTestCase.assertNotNull(evaluationResult.value);
4432 DartObjectImpl value = evaluationResult.value; 4351 DartObjectImpl value = evaluationResult.value;
4433 JUnitTestCase.assertEquals(typeProvider.symbolType, value.type); 4352 JUnitTestCase.assertEquals(typeProvider.symbolType, value.type);
4434 JUnitTestCase.assertEquals("a", value.value); 4353 JUnitTestCase.assertEquals("a", value.value);
4435 } 4354 }
4436 4355
4437 void test_instanceCreationExpression_withSupertypeParams_explicit() { 4356 void test_instanceCreationExpression_withSupertypeParams_explicit() {
4438 _checkInstanceCreation_withSupertypeParams(true); 4357 _checkInstanceCreation_withSupertypeParams(true);
4439 } 4358 }
4440 4359
4441 void test_instanceCreationExpression_withSupertypeParams_implicit() { 4360 void test_instanceCreationExpression_withSupertypeParams_implicit() {
4442 _checkInstanceCreation_withSupertypeParams(false); 4361 _checkInstanceCreation_withSupertypeParams(false);
4443 } 4362 }
4444 4363
4445 void test_instanceCreationExpression_withTypeParams() { 4364 void test_instanceCreationExpression_withTypeParams() {
4446 CompilationUnit compilationUnit = resolveSource( 4365 CompilationUnit compilationUnit = resolveSource(r'''
4447 EngineTestCase.createSource( 4366 class C<E> {
4448 [ 4367 const C();
4449 "class C<E> {", 4368 }
4450 " const C();", 4369 const c_int = const C<int>();
4451 "}", 4370 const c_num = const C<num>();''');
4452 "const c_int = const C<int>();",
4453 "const c_num = const C<num>();"]));
4454 EvaluationResultImpl c_int = 4371 EvaluationResultImpl c_int =
4455 _evaluateInstanceCreationExpression(compilationUnit, "c_int"); 4372 _evaluateInstanceCreationExpression(compilationUnit, "c_int");
4456 _assertType(c_int, "C<int>"); 4373 _assertType(c_int, "C<int>");
4457 DartObjectImpl c_int_value = c_int.value; 4374 DartObjectImpl c_int_value = c_int.value;
4458 EvaluationResultImpl c_num = 4375 EvaluationResultImpl c_num =
4459 _evaluateInstanceCreationExpression(compilationUnit, "c_num"); 4376 _evaluateInstanceCreationExpression(compilationUnit, "c_num");
4460 _assertType(c_num, "C<num>"); 4377 _assertType(c_num, "C<num>");
4461 DartObjectImpl c_num_value = c_num.value; 4378 DartObjectImpl c_num_value = c_num.value;
4462 JUnitTestCase.assertFalse(c_int_value == c_num_value); 4379 JUnitTestCase.assertFalse(c_int_value == c_num_value);
4463 } 4380 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
4499 JUnitTestCase.assertFalse( 4416 JUnitTestCase.assertFalse(
4500 ConstantValueComputer.isValidPublicSymbol("+.foo")); 4417 ConstantValueComputer.isValidPublicSymbol("+.foo"));
4501 JUnitTestCase.assertFalse( 4418 JUnitTestCase.assertFalse(
4502 ConstantValueComputer.isValidPublicSymbol("void.foo")); 4419 ConstantValueComputer.isValidPublicSymbol("void.foo"));
4503 JUnitTestCase.assertFalse( 4420 JUnitTestCase.assertFalse(
4504 ConstantValueComputer.isValidPublicSymbol("foo.void")); 4421 ConstantValueComputer.isValidPublicSymbol("foo.void"));
4505 } 4422 }
4506 4423
4507 void test_symbolLiteral_void() { 4424 void test_symbolLiteral_void() {
4508 CompilationUnit compilationUnit = 4425 CompilationUnit compilationUnit =
4509 resolveSource(EngineTestCase.createSource(["const voidSymbol = #void;"]) ); 4426 resolveSource("const voidSymbol = #void;");
4510 VariableDeclaration voidSymbol = 4427 VariableDeclaration voidSymbol =
4511 findTopLevelDeclaration(compilationUnit, "voidSymbol"); 4428 findTopLevelDeclaration(compilationUnit, "voidSymbol");
4512 EvaluationResultImpl voidSymbolResult = 4429 EvaluationResultImpl voidSymbolResult =
4513 (voidSymbol.element as VariableElementImpl).evaluationResult; 4430 (voidSymbol.element as VariableElementImpl).evaluationResult;
4514 DartObjectImpl value = voidSymbolResult.value; 4431 DartObjectImpl value = voidSymbolResult.value;
4515 JUnitTestCase.assertEquals(typeProvider.symbolType, value.type); 4432 JUnitTestCase.assertEquals(typeProvider.symbolType, value.type);
4516 JUnitTestCase.assertEquals("void", value.value); 4433 JUnitTestCase.assertEquals("void", value.value);
4517 } 4434 }
4518 4435
4519 Map<String, DartObjectImpl> _assertFieldType(Map<String, 4436 Map<String, DartObjectImpl> _assertFieldType(Map<String,
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
4590 DartObjectImpl value = result.value; 4507 DartObjectImpl value = result.value;
4591 JUnitTestCase.assertTrue(value.isUnknown); 4508 JUnitTestCase.assertTrue(value.isUnknown);
4592 } 4509 }
4593 4510
4594 void _checkInstanceCreationOptionalParams(bool isFieldFormal, bool isNamed, 4511 void _checkInstanceCreationOptionalParams(bool isFieldFormal, bool isNamed,
4595 bool hasDefault) { 4512 bool hasDefault) {
4596 String fieldName = "j"; 4513 String fieldName = "j";
4597 String paramName = isFieldFormal ? fieldName : "i"; 4514 String paramName = isFieldFormal ? fieldName : "i";
4598 String formalParam = 4515 String formalParam =
4599 "${(isFieldFormal ? "this." : "int ")}${paramName}${(hasDefault ? " = 3" : "")}"; 4516 "${(isFieldFormal ? "this." : "int ")}${paramName}${(hasDefault ? " = 3" : "")}";
4600 CompilationUnit compilationUnit = resolveSource( 4517 CompilationUnit compilationUnit = resolveSource("""
4601 EngineTestCase.createSource( 4518 const x = const A();
4602 [ 4519 const y = const A(${isNamed ? '$paramName: ' : ''}10);
4603 "const x = const A();", 4520 class A {
4604 "const y = const A(${(isNamed ? "${paramName}: " : "")}10);", 4521 const A(${isNamed ? "{${formalParam}}" : "[${formalParam}]"})${isFieldFormal ? "" : " : ${fieldName} = ${paramName}"};
4605 "class A {", 4522 final int ${fieldName};
4606 " const A(${(isNamed ? "{${formalParam}}" : "[${formalParam}]") })${(isFieldFormal ? "" : " : ${fieldName} = ${paramName}")};", 4523 }""");
4607 " final int ${fieldName};",
4608 "}"]));
4609 EvaluationResultImpl x = 4524 EvaluationResultImpl x =
4610 _evaluateInstanceCreationExpression(compilationUnit, "x"); 4525 _evaluateInstanceCreationExpression(compilationUnit, "x");
4611 Map<String, DartObjectImpl> fieldsOfX = _assertType(x, "A"); 4526 Map<String, DartObjectImpl> fieldsOfX = _assertType(x, "A");
4612 EngineTestCase.assertSizeOfMap(1, fieldsOfX); 4527 EngineTestCase.assertSizeOfMap(1, fieldsOfX);
4613 if (hasDefault) { 4528 if (hasDefault) {
4614 _assertIntField(fieldsOfX, fieldName, 3); 4529 _assertIntField(fieldsOfX, fieldName, 3);
4615 } else { 4530 } else {
4616 _assertNullField(fieldsOfX, fieldName); 4531 _assertNullField(fieldsOfX, fieldName);
4617 } 4532 }
4618 EvaluationResultImpl y = 4533 EvaluationResultImpl y =
4619 _evaluateInstanceCreationExpression(compilationUnit, "y"); 4534 _evaluateInstanceCreationExpression(compilationUnit, "y");
4620 Map<String, DartObjectImpl> fieldsOfY = _assertType(y, "A"); 4535 Map<String, DartObjectImpl> fieldsOfY = _assertType(y, "A");
4621 EngineTestCase.assertSizeOfMap(1, fieldsOfY); 4536 EngineTestCase.assertSizeOfMap(1, fieldsOfY);
4622 _assertIntField(fieldsOfY, fieldName, 10); 4537 _assertIntField(fieldsOfY, fieldName, 10);
4623 } 4538 }
4624 4539
4625 void _checkInstanceCreation_withSupertypeParams(bool isExplicit) { 4540 void _checkInstanceCreation_withSupertypeParams(bool isExplicit) {
4626 String superCall = isExplicit ? " : super()" : ""; 4541 String superCall = isExplicit ? " : super()" : "";
4627 CompilationUnit compilationUnit = resolveSource( 4542 CompilationUnit compilationUnit = resolveSource("""
4628 EngineTestCase.createSource( 4543 class A<T> {
4629 [ 4544 const A();
4630 "class A<T> {", 4545 }
4631 " const A();", 4546 class B<T, U> extends A<T> {
4632 "}", 4547 const B()$superCall;
4633 "class B<T, U> extends A<T> {", 4548 }
4634 " const B()${superCall};", 4549 class C<T, U> extends A<U> {
4635 "}", 4550 const C()${superCall};
4636 "class C<T, U> extends A<U> {", 4551 }
4637 " const C()${superCall};", 4552 const b_int_num = const B<int, num>();
4638 "}", 4553 const c_int_num = const C<int, num>();""");
4639 "const b_int_num = const B<int, num>();",
4640 "const c_int_num = const C<int, num>();"]));
4641 EvaluationResultImpl b_int_num = 4554 EvaluationResultImpl b_int_num =
4642 _evaluateInstanceCreationExpression(compilationUnit, "b_int_num"); 4555 _evaluateInstanceCreationExpression(compilationUnit, "b_int_num");
4643 Map<String, DartObjectImpl> b_int_num_fields = 4556 Map<String, DartObjectImpl> b_int_num_fields =
4644 _assertType(b_int_num, "B<int, num>"); 4557 _assertType(b_int_num, "B<int, num>");
4645 _assertFieldType(b_int_num_fields, GenericState.SUPERCLASS_FIELD, "A<int>"); 4558 _assertFieldType(b_int_num_fields, GenericState.SUPERCLASS_FIELD, "A<int>");
4646 EvaluationResultImpl c_int_num = 4559 EvaluationResultImpl c_int_num =
4647 _evaluateInstanceCreationExpression(compilationUnit, "c_int_num"); 4560 _evaluateInstanceCreationExpression(compilationUnit, "c_int_num");
4648 Map<String, DartObjectImpl> c_int_num_fields = 4561 Map<String, DartObjectImpl> c_int_num_fields =
4649 _assertType(c_int_num, "C<int, num>"); 4562 _assertType(c_int_num, "C<int, num>");
4650 _assertFieldType(c_int_num_fields, GenericState.SUPERCLASS_FIELD, "A<num>"); 4563 _assertFieldType(c_int_num_fields, GenericState.SUPERCLASS_FIELD, "A<num>");
4651 } 4564 }
4652 4565
4653 EvaluationResultImpl _check_fromEnvironment_bool(String valueInEnvironment, 4566 EvaluationResultImpl _check_fromEnvironment_bool(String valueInEnvironment,
4654 String defaultExpr) { 4567 String defaultExpr) {
4655 String envVarName = "x"; 4568 String envVarName = "x";
4656 String varName = "foo"; 4569 String varName = "foo";
4657 if (valueInEnvironment != null) { 4570 if (valueInEnvironment != null) {
4658 analysisContext2.declaredVariables.define(envVarName, valueInEnvironment); 4571 analysisContext2.declaredVariables.define(envVarName, valueInEnvironment);
4659 } 4572 }
4660 String defaultArg = 4573 String defaultArg =
4661 defaultExpr == null ? "" : ", defaultValue: ${defaultExpr}"; 4574 defaultExpr == null ? "" : ", defaultValue: ${defaultExpr}";
4662 CompilationUnit compilationUnit = resolveSource( 4575 CompilationUnit compilationUnit = resolveSource(
4663 EngineTestCase.createSource( 4576 "const ${varName} = const bool.fromEnvironment('${envVarName}'${ defaultArg});");
4664 [
4665 "const ${varName} = const bool.fromEnvironment('${envVarName}'${ defaultArg});"]));
4666 return _evaluateInstanceCreationExpression(compilationUnit, varName); 4577 return _evaluateInstanceCreationExpression(compilationUnit, varName);
4667 } 4578 }
4668 4579
4669 EvaluationResultImpl _check_fromEnvironment_int(String valueInEnvironment, 4580 EvaluationResultImpl _check_fromEnvironment_int(String valueInEnvironment,
4670 String defaultExpr) { 4581 String defaultExpr) {
4671 String envVarName = "x"; 4582 String envVarName = "x";
4672 String varName = "foo"; 4583 String varName = "foo";
4673 if (valueInEnvironment != null) { 4584 if (valueInEnvironment != null) {
4674 analysisContext2.declaredVariables.define(envVarName, valueInEnvironment); 4585 analysisContext2.declaredVariables.define(envVarName, valueInEnvironment);
4675 } 4586 }
4676 String defaultArg = 4587 String defaultArg =
4677 defaultExpr == null ? "" : ", defaultValue: ${defaultExpr}"; 4588 defaultExpr == null ? "" : ", defaultValue: ${defaultExpr}";
4678 CompilationUnit compilationUnit = resolveSource( 4589 CompilationUnit compilationUnit = resolveSource(
4679 EngineTestCase.createSource( 4590 "const ${varName} = const int.fromEnvironment('${envVarName}'${d efaultArg});");
4680 [
4681 "const ${varName} = const int.fromEnvironment('${envVarName}'${d efaultArg});"]));
4682 return _evaluateInstanceCreationExpression(compilationUnit, varName); 4591 return _evaluateInstanceCreationExpression(compilationUnit, varName);
4683 } 4592 }
4684 4593
4685 EvaluationResultImpl _check_fromEnvironment_string(String valueInEnvironment, 4594 EvaluationResultImpl _check_fromEnvironment_string(String valueInEnvironment,
4686 String defaultExpr) { 4595 String defaultExpr) {
4687 String envVarName = "x"; 4596 String envVarName = "x";
4688 String varName = "foo"; 4597 String varName = "foo";
4689 if (valueInEnvironment != null) { 4598 if (valueInEnvironment != null) {
4690 analysisContext2.declaredVariables.define(envVarName, valueInEnvironment); 4599 analysisContext2.declaredVariables.define(envVarName, valueInEnvironment);
4691 } 4600 }
4692 String defaultArg = 4601 String defaultArg =
4693 defaultExpr == null ? "" : ", defaultValue: ${defaultExpr}"; 4602 defaultExpr == null ? "" : ", defaultValue: ${defaultExpr}";
4694 CompilationUnit compilationUnit = resolveSource( 4603 CompilationUnit compilationUnit = resolveSource(
4695 EngineTestCase.createSource( 4604 "const ${varName} = const String.fromEnvironment('${envVarName}' ${defaultArg});");
4696 [
4697 "const ${varName} = const String.fromEnvironment('${envVarName}' ${defaultArg});"]));
4698 return _evaluateInstanceCreationExpression(compilationUnit, varName); 4605 return _evaluateInstanceCreationExpression(compilationUnit, varName);
4699 } 4606 }
4700 4607
4701 EvaluationResultImpl 4608 EvaluationResultImpl
4702 _evaluateInstanceCreationExpression(CompilationUnit compilationUnit, 4609 _evaluateInstanceCreationExpression(CompilationUnit compilationUnit,
4703 String name) { 4610 String name) {
4704 Expression expression = 4611 Expression expression =
4705 findTopLevelConstantExpression(compilationUnit, name); 4612 findTopLevelConstantExpression(compilationUnit, name);
4706 return (expression as InstanceCreationExpression).evaluationResult; 4613 return (expression as InstanceCreationExpression).evaluationResult;
4707 } 4614 }
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
4861 new ErrorReporter(errorListener, _dummySource()); 4768 new ErrorReporter(errorListener, _dummySource());
4862 _assertValue( 4769 _assertValue(
4863 1, 4770 1,
4864 expression.accept( 4771 expression.accept(
4865 new ConstantVisitor.con1(new TestTypeProvider(), errorReporter))); 4772 new ConstantVisitor.con1(new TestTypeProvider(), errorReporter)));
4866 errorListener.assertNoErrors(); 4773 errorListener.assertNoErrors();
4867 } 4774 }
4868 4775
4869 void test_visitSimpleIdentifier_inEnvironment() { 4776 void test_visitSimpleIdentifier_inEnvironment() {
4870 CompilationUnit compilationUnit = 4777 CompilationUnit compilationUnit =
4871 resolveSource(EngineTestCase.createSource(["const a = b;", "const b = 3; "])); 4778 resolveSource(r'''
4779 const a = b;
4780 const b = 3;''');
4872 Map<String, DartObjectImpl> environment = new Map<String, DartObjectImpl>(); 4781 Map<String, DartObjectImpl> environment = new Map<String, DartObjectImpl>();
4873 DartObjectImpl six = 4782 DartObjectImpl six =
4874 new DartObjectImpl(typeProvider.intType, new IntState(6)); 4783 new DartObjectImpl(typeProvider.intType, new IntState(6));
4875 environment["b"] = six; 4784 environment["b"] = six;
4876 _assertValue(6, _evaluateConstant(compilationUnit, "a", environment)); 4785 _assertValue(6, _evaluateConstant(compilationUnit, "a", environment));
4877 } 4786 }
4878 4787
4879 void test_visitSimpleIdentifier_notInEnvironment() { 4788 void test_visitSimpleIdentifier_notInEnvironment() {
4880 CompilationUnit compilationUnit = 4789 CompilationUnit compilationUnit =
4881 resolveSource(EngineTestCase.createSource(["const a = b;", "const b = 3; "])); 4790 resolveSource(r'''
4791 const a = b;
4792 const b = 3;''');
4882 Map<String, DartObjectImpl> environment = new Map<String, DartObjectImpl>(); 4793 Map<String, DartObjectImpl> environment = new Map<String, DartObjectImpl>();
4883 DartObjectImpl six = 4794 DartObjectImpl six =
4884 new DartObjectImpl(typeProvider.intType, new IntState(6)); 4795 new DartObjectImpl(typeProvider.intType, new IntState(6));
4885 environment["c"] = six; 4796 environment["c"] = six;
4886 _assertValue(3, _evaluateConstant(compilationUnit, "a", environment)); 4797 _assertValue(3, _evaluateConstant(compilationUnit, "a", environment));
4887 } 4798 }
4888 4799
4889 void test_visitSimpleIdentifier_withoutEnvironment() { 4800 void test_visitSimpleIdentifier_withoutEnvironment() {
4890 CompilationUnit compilationUnit = 4801 CompilationUnit compilationUnit =
4891 resolveSource(EngineTestCase.createSource(["const a = b;", "const b = 3; "])); 4802 resolveSource(r'''
4803 const a = b;
4804 const b = 3;''');
4892 _assertValue(3, _evaluateConstant(compilationUnit, "a", null)); 4805 _assertValue(3, _evaluateConstant(compilationUnit, "a", null));
4893 } 4806 }
4894 4807
4895 void _assertValue(int expectedValue, DartObjectImpl result) { 4808 void _assertValue(int expectedValue, DartObjectImpl result) {
4896 JUnitTestCase.assertNotNull(result); 4809 JUnitTestCase.assertNotNull(result);
4897 JUnitTestCase.assertEquals("int", result.type.name); 4810 JUnitTestCase.assertEquals("int", result.type.name);
4898 JUnitTestCase.assertEquals(expectedValue, result.intValue); 4811 JUnitTestCase.assertEquals(expectedValue, result.intValue);
4899 } 4812 }
4900 4813
4901 NonExistingSource _dummySource() { 4814 NonExistingSource _dummySource() {
(...skipping 3917 matching lines...) Expand 10 before | Expand all | Expand 10 after
8819 "}"]); 8732 "}"]);
8820 Element element = ElementLocator.locate(id); 8733 Element element = ElementLocator.locate(id);
8821 EngineTestCase.assertInstanceOf( 8734 EngineTestCase.assertInstanceOf(
8822 (obj) => obj is MethodElement, 8735 (obj) => obj is MethodElement,
8823 MethodElement, 8736 MethodElement,
8824 element); 8737 element);
8825 } 8738 }
8826 8739
8827 void test_locate_MethodInvocation_topLevel() { 8740 void test_locate_MethodInvocation_topLevel() {
8828 String contents = 8741 String contents =
8829 EngineTestCase.createSource(["foo(x) {}", "void main() {", " foo(0);", " }"]); 8742 r'''
8743 foo(x) {}
8744 void main() {
8745 foo(0);
8746 }''';
8830 CompilationUnit cu = _resolveContents([contents]); 8747 CompilationUnit cu = _resolveContents([contents]);
8831 int offset = contents.indexOf('foo(0)'); 8748 int offset = contents.indexOf('foo(0)');
8832 AstNode node = new NodeLocator.con1(offset).searchWithin(cu); 8749 AstNode node = new NodeLocator.con1(offset).searchWithin(cu);
8833 MethodInvocation invocation = 8750 MethodInvocation invocation =
8834 node.getAncestor((n) => n is MethodInvocation); 8751 node.getAncestor((n) => n is MethodInvocation);
8835 Element element = ElementLocator.locate(invocation); 8752 Element element = ElementLocator.locate(invocation);
8836 EngineTestCase.assertInstanceOf( 8753 EngineTestCase.assertInstanceOf(
8837 (obj) => obj is FunctionElement, 8754 (obj) => obj is FunctionElement,
8838 FunctionElement, 8755 FunctionElement,
8839 element); 8756 element);
(...skipping 1051 matching lines...) Expand 10 before | Expand all | Expand 10 after
9891 } 9808 }
9892 } 9809 }
9893 9810
9894 9811
9895 class HtmlParserTest extends EngineTestCase { 9812 class HtmlParserTest extends EngineTestCase {
9896 /** 9813 /**
9897 * The name of the 'script' tag in an HTML file. 9814 * The name of the 'script' tag in an HTML file.
9898 */ 9815 */
9899 static String _TAG_SCRIPT = "script"; 9816 static String _TAG_SCRIPT = "script";
9900 void fail_parse_scriptWithComment() { 9817 void fail_parse_scriptWithComment() {
9901 String scriptBody = EngineTestCase.createSource( 9818 String scriptBody = r'''
9902 [ 9819 /**
9903 " /**", 9820 * <editable-label bind-value="dartAsignableValue">
9904 " * <editable-label bind-value=\"dartAsignableValue\">", 9821 * </editable-label>
9905 " * </editable-label>", 9822 */
9906 " */", 9823 class Foo {}''';
9907 " class Foo {}"]); 9824 ht.HtmlUnit htmlUnit = parse("""
9908 ht.HtmlUnit htmlUnit = parse( 9825 <html>
9909 EngineTestCase.createSource( 9826 <body>
9910 [ 9827 <script type='application/dart'>
9911 " <html>", 9828 $scriptBody
9912 " <body>", 9829 </script>
9913 " <script type=\"application/dart\">", 9830 </body>
9914 scriptBody, 9831 </html>""");
9915 " </script>",
9916 " </body>",
9917 " </html>"]));
9918 _validate( 9832 _validate(
9919 htmlUnit, 9833 htmlUnit,
9920 [ 9834 [
9921 _t4( 9835 _t4(
9922 "html", 9836 "html",
9923 [ 9837 [
9924 _t4( 9838 _t4(
9925 "body", 9839 "body",
9926 [_t("script", _a(["type", "\"application/dart\""]), scri ptBody, [])])])]); 9840 [_t("script", _a(["type", "'application/dart'"]), script Body, [])])])]);
9927 } 9841 }
9928 ht.HtmlUnit parse(String contents) { 9842 ht.HtmlUnit parse(String contents) {
9929 // TestSource source = 9843 // TestSource source =
9930 // new TestSource.con1(FileUtilities2.createFile("/test.dart"), contents) ; 9844 // new TestSource.con1(FileUtilities2.createFile("/test.dart"), contents) ;
9931 ht.AbstractScanner scanner = new ht.StringScanner(null, contents); 9845 ht.AbstractScanner scanner = new ht.StringScanner(null, contents);
9932 scanner.passThroughElements = <String>[_TAG_SCRIPT]; 9846 scanner.passThroughElements = <String>[_TAG_SCRIPT];
9933 ht.Token token = scanner.tokenize(); 9847 ht.Token token = scanner.tokenize();
9934 LineInfo lineInfo = new LineInfo(scanner.lineStarts); 9848 LineInfo lineInfo = new LineInfo(scanner.lineStarts);
9935 GatheringErrorListener errorListener = new GatheringErrorListener(); 9849 GatheringErrorListener errorListener = new GatheringErrorListener();
9936 ht.HtmlUnit unit = 9850 ht.HtmlUnit unit =
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
10025 } 9939 }
10026 void test_parse_getAttributeText() { 9940 void test_parse_getAttributeText() {
10027 ht.HtmlUnit htmlUnit = parse("<html><body foo=\"sdfsdf\"></body></html>"); 9941 ht.HtmlUnit htmlUnit = parse("<html><body foo=\"sdfsdf\"></body></html>");
10028 ht.XmlTagNode htmlNode = htmlUnit.tagNodes[0]; 9942 ht.XmlTagNode htmlNode = htmlUnit.tagNodes[0];
10029 ht.XmlTagNode bodyNode = htmlNode.tagNodes[0]; 9943 ht.XmlTagNode bodyNode = htmlNode.tagNodes[0];
10030 JUnitTestCase.assertEquals("sdfsdf", bodyNode.getAttributeText("foo")); 9944 JUnitTestCase.assertEquals("sdfsdf", bodyNode.getAttributeText("foo"));
10031 JUnitTestCase.assertEquals(null, bodyNode.getAttributeText("bar")); 9945 JUnitTestCase.assertEquals(null, bodyNode.getAttributeText("bar"));
10032 JUnitTestCase.assertEquals(null, bodyNode.getAttributeText(null)); 9946 JUnitTestCase.assertEquals(null, bodyNode.getAttributeText(null));
10033 } 9947 }
10034 void test_parse_headers() { 9948 void test_parse_headers() {
10035 String code = EngineTestCase.createSource( 9949 String code = r'''
10036 [ 9950 <html>
10037 "<html>", 9951 <body>
10038 " <body>", 9952 <h2>000</h2>
10039 " <h2>000</h2>", 9953 <div>
10040 " <div>", 9954 111
10041 " 111", 9955 </div>
10042 " </div>", 9956 </body>
10043 " </body>", 9957 </html>''';
10044 "</html>"]);
10045 ht.HtmlUnit htmlUnit = parse(code); 9958 ht.HtmlUnit htmlUnit = parse(code);
10046 _validate( 9959 _validate(
10047 htmlUnit, 9960 htmlUnit,
10048 [_t4("html", [_t4("body", [_t3("h2", "000", []), _t4("div", [])])])]); 9961 [_t4("html", [_t4("body", [_t3("h2", "000", []), _t4("div", [])])])]);
10049 } 9962 }
10050 void test_parse_script() { 9963 void test_parse_script() {
10051 ht.HtmlUnit htmlUnit = 9964 ht.HtmlUnit htmlUnit =
10052 parse("<html><script >here is <p> some</script></html>"); 9965 parse("<html><script >here is <p> some</script></html>");
10053 _validate(htmlUnit, [_t4("html", [_t3("script", "here is <p> some", [])])]); 9966 _validate(htmlUnit, [_t4("html", [_t3("script", "here is <p> some", [])])]);
10054 } 9967 }
(...skipping 23 matching lines...) Expand all
10078 validator.expectTags(expectedTags); 9991 validator.expectTags(expectedTags);
10079 htmlUnit.accept(validator); 9992 htmlUnit.accept(validator);
10080 validator.assertValid(); 9993 validator.assertValid();
10081 } 9994 }
10082 } 9995 }
10083 9996
10084 9997
10085 class HtmlTagInfoBuilderTest extends HtmlParserTest { 9998 class HtmlTagInfoBuilderTest extends HtmlParserTest {
10086 void test_builder() { 9999 void test_builder() {
10087 HtmlTagInfoBuilder builder = new HtmlTagInfoBuilder(); 10000 HtmlTagInfoBuilder builder = new HtmlTagInfoBuilder();
10088 ht.HtmlUnit unit = parse( 10001 ht.HtmlUnit unit = parse(r'''
10089 EngineTestCase.createSource( 10002 <html>
10090 [ 10003 <body>
10091 "<html>", 10004 <div id="x"></div>
10092 " <body>", 10005 <p class='c'></p>
10093 " <div id=\"x\"></div>", 10006 <div class='c'></div>
10094 " <p class='c'></p>", 10007 </body>
10095 " <div class='c'></div>", 10008 </html>''');
10096 " </body>",
10097 "</html>"]));
10098 unit.accept(builder); 10009 unit.accept(builder);
10099 HtmlTagInfo info = builder.getTagInfo(); 10010 HtmlTagInfo info = builder.getTagInfo();
10100 JUnitTestCase.assertNotNull(info); 10011 JUnitTestCase.assertNotNull(info);
10101 List<String> allTags = info.allTags; 10012 List<String> allTags = info.allTags;
10102 EngineTestCase.assertLength(4, allTags); 10013 EngineTestCase.assertLength(4, allTags);
10103 JUnitTestCase.assertEquals("div", info.getTagWithId("x")); 10014 JUnitTestCase.assertEquals("div", info.getTagWithId("x"));
10104 List<String> tagsWithClass = info.getTagsWithClass("c"); 10015 List<String> tagsWithClass = info.getTagsWithClass("c");
10105 EngineTestCase.assertLength(2, tagsWithClass); 10016 EngineTestCase.assertLength(2, tagsWithClass);
10106 } 10017 }
10107 } 10018 }
10108 10019
10109 10020
10110 class HtmlUnitBuilderTest extends EngineTestCase { 10021 class HtmlUnitBuilderTest extends EngineTestCase {
10111 AnalysisContextImpl _context; 10022 AnalysisContextImpl _context;
10112 @override 10023 @override
10113 void setUp() { 10024 void setUp() {
10114 _context = AnalysisContextFactory.contextWithCore(); 10025 _context = AnalysisContextFactory.contextWithCore();
10115 } 10026 }
10116 @override 10027 @override
10117 void tearDown() { 10028 void tearDown() {
10118 _context = null; 10029 _context = null;
10119 super.tearDown(); 10030 super.tearDown();
10120 } 10031 }
10121 void test_embedded_script() { 10032 void test_embedded_script() {
10122 HtmlElementImpl element = _build( 10033 HtmlElementImpl element = _build(r'''
10123 EngineTestCase.createSource( 10034 <html>
10124 ["<html>", "<script type=\"application/dart\">foo=2;</script>", "</h tml>"])); 10035 <script type="application/dart">foo=2;</script>
10036 </html>''');
10125 _validate(element, [_s(_l([_v("foo")]))]); 10037 _validate(element, [_s(_l([_v("foo")]))]);
10126 } 10038 }
10127 void test_embedded_script_no_content() { 10039 void test_embedded_script_no_content() {
10128 HtmlElementImpl element = _build( 10040 HtmlElementImpl element = _build(r'''
10129 EngineTestCase.createSource( 10041 <html>
10130 ["<html>", "<script type=\"application/dart\"></script>", "</html>"] )); 10042 <script type="application/dart"></script>
10043 </html>''');
10131 _validate(element, [_s(_l([]))]); 10044 _validate(element, [_s(_l([]))]);
10132 } 10045 }
10133 void test_external_script() { 10046 void test_external_script() {
10134 HtmlElementImpl element = _build( 10047 HtmlElementImpl element = _build(r'''
10135 EngineTestCase.createSource( 10048 <html>
10136 [ 10049 <script type="application/dart" src="other.dart"/>
10137 "<html>", 10050 </html>''');
10138 "<script type=\"application/dart\" src=\"other.dart\"/>",
10139 "</html>"]));
10140 _validate(element, [_s2("other.dart")]); 10051 _validate(element, [_s2("other.dart")]);
10141 } 10052 }
10142 void test_external_script_no_source() { 10053 void test_external_script_no_source() {
10143 HtmlElementImpl element = _build( 10054 HtmlElementImpl element = _build(r'''
10144 EngineTestCase.createSource( 10055 <html>
10145 ["<html>", "<script type=\"application/dart\"/>", "</html>"])); 10056 <script type="application/dart"/>
10057 </html>''');
10146 _validate(element, [_s2(null)]); 10058 _validate(element, [_s2(null)]);
10147 } 10059 }
10148 void test_external_script_with_content() { 10060 void test_external_script_with_content() {
10149 HtmlElementImpl element = _build( 10061 HtmlElementImpl element = _build(r'''
10150 EngineTestCase.createSource( 10062 <html>
10151 [ 10063 <script type="application/dart" src="other.dart">blat=2;</script>
10152 "<html>", 10064 </html>''');
10153 "<script type=\"application/dart\" src=\"other.dart\">blat=2;</s cript>",
10154 "</html>"]));
10155 _validate(element, [_s2("other.dart")]); 10065 _validate(element, [_s2("other.dart")]);
10156 } 10066 }
10157 void test_no_scripts() { 10067 void test_no_scripts() {
10158 HtmlElementImpl element = _build( 10068 HtmlElementImpl element = _build(r'''
10159 EngineTestCase.createSource(["<!DOCTYPE html>", "<html><p></p></html>"]) ); 10069 <!DOCTYPE html>
10070 <html><p></p></html>''');
10160 _validate(element, []); 10071 _validate(element, []);
10161 } 10072 }
10162 void test_two_dart_scripts() { 10073 void test_two_dart_scripts() {
10163 HtmlElementImpl element = _build( 10074 HtmlElementImpl element = _build(r'''
10164 EngineTestCase.createSource( 10075 <html>
10165 [ 10076 <script type="application/dart">bar=2;</script>
10166 "<html>", 10077 <script type="application/dart" src="other.dart"/>
10167 "<script type=\"application/dart\">bar=2;</script>", 10078 <script src="dart.js"/>
10168 "<script type=\"application/dart\" src=\"other.dart\"/>", 10079 </html>''');
10169 "<script src=\"dart.js\"/>",
10170 "</html>"]));
10171 _validate(element, [_s(_l([_v("bar")])), _s2("other.dart")]); 10080 _validate(element, [_s(_l([_v("bar")])), _s2("other.dart")]);
10172 } 10081 }
10173 HtmlElementImpl _build(String contents) { 10082 HtmlElementImpl _build(String contents) {
10174 TestSource source = new TestSource( 10083 TestSource source = new TestSource(
10175 FileUtilities2.createFile("/test.html").getAbsolutePath(), 10084 FileUtilities2.createFile("/test.html").getAbsolutePath(),
10176 contents); 10085 contents);
10177 ChangeSet changeSet = new ChangeSet(); 10086 ChangeSet changeSet = new ChangeSet();
10178 changeSet.addedSource(source); 10087 changeSet.addedSource(source);
10179 _context.applyChanges(changeSet); 10088 _context.applyChanges(changeSet);
10180 HtmlUnitBuilder builder = new HtmlUnitBuilder(_context); 10089 HtmlUnitBuilder builder = new HtmlUnitBuilder(_context);
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
10278 @override 10187 @override
10279 void tearDown() { 10188 void tearDown() {
10280 _sourceFactory = null; 10189 _sourceFactory = null;
10281 _context = null; 10190 _context = null;
10282 _contents = null; 10191 _contents = null;
10283 _errors = null; 10192 _errors = null;
10284 super.tearDown(); 10193 super.tearDown();
10285 } 10194 }
10286 10195
10287 void test_invalidUri() { 10196 void test_invalidUri() {
10288 _verify( 10197 _verify(r'''
10289 EngineTestCase.createSource( 10198 <html>
10290 ["<html>", "<script type='application/dart' src='ht:'/>", "</html>"] ), 10199 <script type='application/dart' src='ht:'/>
10200 </html>''',
10291 [HtmlWarningCode.INVALID_URI]); 10201 [HtmlWarningCode.INVALID_URI]);
10292 _assertErrorLocation2(_errors[0], "ht:"); 10202 _assertErrorLocation2(_errors[0], "ht:");
10293 } 10203 }
10294 10204
10295 void test_uriDoesNotExist() { 10205 void test_uriDoesNotExist() {
10296 _verify( 10206 _verify(r'''
10297 EngineTestCase.createSource( 10207 <html>
10298 ["<html>", "<script type='application/dart' src='other.dart'/>", "</ html>"]), 10208 <script type='application/dart' src='other.dart'/>
10209 </html>''',
10299 [HtmlWarningCode.URI_DOES_NOT_EXIST]); 10210 [HtmlWarningCode.URI_DOES_NOT_EXIST]);
10300 _assertErrorLocation2(_errors[0], "other.dart"); 10211 _assertErrorLocation2(_errors[0], "other.dart");
10301 } 10212 }
10302 10213
10303 void _assertErrorLocation(AnalysisError error, int expectedOffset, 10214 void _assertErrorLocation(AnalysisError error, int expectedOffset,
10304 int expectedLength) { 10215 int expectedLength) {
10305 JUnitTestCase.assertEqualsMsg( 10216 JUnitTestCase.assertEqualsMsg(
10306 error.toString(), 10217 error.toString(),
10307 expectedOffset, 10218 expectedOffset,
10308 error.offset); 10219 error.offset);
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
10528 node.accept(_createReferenceFinder(_head)); 10439 node.accept(_createReferenceFinder(_head));
10529 } 10440 }
10530 } 10441 }
10531 10442
10532 10443
10533 class SDKLibrariesReaderTest extends EngineTestCase { 10444 class SDKLibrariesReaderTest extends EngineTestCase {
10534 void test_readFrom_dart2js() { 10445 void test_readFrom_dart2js() {
10535 LibraryMap libraryMap = new SdkLibrariesReader( 10446 LibraryMap libraryMap = new SdkLibrariesReader(
10536 true).readFromFile( 10447 true).readFromFile(
10537 FileUtilities2.createFile("/libs.dart"), 10448 FileUtilities2.createFile("/libs.dart"),
10538 EngineTestCase.createSource( 10449 r'''
10539 [ 10450 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> {
10540 "final Map<String, LibraryInfo> LIBRARIES = const <String, L ibraryInfo> {", 10451 'first' : const LibraryInfo(
10541 " 'first' : const LibraryInfo(", 10452 'first/first.dart',
10542 " 'first/first.dart',", 10453 category: 'First',
10543 " category: 'First',", 10454 documented: true,
10544 " documented: true,", 10455 platforms: VM_PLATFORM,
10545 " platforms: VM_PLATFORM,", 10456 dart2jsPath: 'first/first_dart2js.dart'),
10546 " dart2jsPath: 'first/first_dart2js.dart'),", 10457 };''');
10547 "};"]));
10548 JUnitTestCase.assertNotNull(libraryMap); 10458 JUnitTestCase.assertNotNull(libraryMap);
10549 JUnitTestCase.assertEquals(1, libraryMap.size()); 10459 JUnitTestCase.assertEquals(1, libraryMap.size());
10550 SdkLibrary first = libraryMap.getLibrary("dart:first"); 10460 SdkLibrary first = libraryMap.getLibrary("dart:first");
10551 JUnitTestCase.assertNotNull(first); 10461 JUnitTestCase.assertNotNull(first);
10552 JUnitTestCase.assertEquals("First", first.category); 10462 JUnitTestCase.assertEquals("First", first.category);
10553 JUnitTestCase.assertEquals("first/first_dart2js.dart", first.path); 10463 JUnitTestCase.assertEquals("first/first_dart2js.dart", first.path);
10554 JUnitTestCase.assertEquals("dart:first", first.shortName); 10464 JUnitTestCase.assertEquals("dart:first", first.shortName);
10555 JUnitTestCase.assertEquals(false, first.isDart2JsLibrary); 10465 JUnitTestCase.assertEquals(false, first.isDart2JsLibrary);
10556 JUnitTestCase.assertEquals(true, first.isDocumented); 10466 JUnitTestCase.assertEquals(true, first.isDocumented);
10557 JUnitTestCase.assertEquals(false, first.isImplementation); 10467 JUnitTestCase.assertEquals(false, first.isImplementation);
10558 JUnitTestCase.assertEquals(true, first.isVmLibrary); 10468 JUnitTestCase.assertEquals(true, first.isVmLibrary);
10559 } 10469 }
10560 void test_readFrom_empty() { 10470 void test_readFrom_empty() {
10561 LibraryMap libraryMap = new SdkLibrariesReader( 10471 LibraryMap libraryMap = new SdkLibrariesReader(
10562 false).readFromFile(FileUtilities2.createFile("/libs.dart"), ""); 10472 false).readFromFile(FileUtilities2.createFile("/libs.dart"), "");
10563 JUnitTestCase.assertNotNull(libraryMap); 10473 JUnitTestCase.assertNotNull(libraryMap);
10564 JUnitTestCase.assertEquals(0, libraryMap.size()); 10474 JUnitTestCase.assertEquals(0, libraryMap.size());
10565 } 10475 }
10566 void test_readFrom_normal() { 10476 void test_readFrom_normal() {
10567 LibraryMap libraryMap = new SdkLibrariesReader( 10477 LibraryMap libraryMap = new SdkLibrariesReader(
10568 false).readFromFile( 10478 false).readFromFile(
10569 FileUtilities2.createFile("/libs.dart"), 10479 FileUtilities2.createFile("/libs.dart"),
10570 EngineTestCase.createSource( 10480 r'''
10571 [ 10481 final Map<String, LibraryInfo> LIBRARIES = const <String, LibraryInfo> {
10572 "final Map<String, LibraryInfo> LIBRARIES = const <String, L ibraryInfo> {", 10482 'first' : const LibraryInfo(
10573 " 'first' : const LibraryInfo(", 10483 'first/first.dart',
10574 " 'first/first.dart',", 10484 category: 'First',
10575 " category: 'First',", 10485 documented: true,
10576 " documented: true,", 10486 platforms: VM_PLATFORM),
10577 " platforms: VM_PLATFORM),", 10487
10578 "", 10488 'second' : const LibraryInfo(
10579 " 'second' : const LibraryInfo(", 10489 'second/second.dart',
10580 " 'second/second.dart',", 10490 category: 'Second',
10581 " category: 'Second',", 10491 documented: false,
10582 " documented: false,", 10492 implementation: true,
10583 " implementation: true,", 10493 platforms: 0),
10584 " platforms: 0),", 10494 };''');
10585 "};"]));
10586 JUnitTestCase.assertNotNull(libraryMap); 10495 JUnitTestCase.assertNotNull(libraryMap);
10587 JUnitTestCase.assertEquals(2, libraryMap.size()); 10496 JUnitTestCase.assertEquals(2, libraryMap.size());
10588 SdkLibrary first = libraryMap.getLibrary("dart:first"); 10497 SdkLibrary first = libraryMap.getLibrary("dart:first");
10589 JUnitTestCase.assertNotNull(first); 10498 JUnitTestCase.assertNotNull(first);
10590 JUnitTestCase.assertEquals("First", first.category); 10499 JUnitTestCase.assertEquals("First", first.category);
10591 JUnitTestCase.assertEquals("first/first.dart", first.path); 10500 JUnitTestCase.assertEquals("first/first.dart", first.path);
10592 JUnitTestCase.assertEquals("dart:first", first.shortName); 10501 JUnitTestCase.assertEquals("dart:first", first.shortName);
10593 JUnitTestCase.assertEquals(false, first.isDart2JsLibrary); 10502 JUnitTestCase.assertEquals(false, first.isDart2JsLibrary);
10594 JUnitTestCase.assertEquals(true, first.isDocumented); 10503 JUnitTestCase.assertEquals(true, first.isDocumented);
10595 JUnitTestCase.assertEquals(false, first.isImplementation); 10504 JUnitTestCase.assertEquals(false, first.isImplementation);
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
11175 } else { 11084 } else {
11176 JUnitTestCase.assertNotNullMsg("script ${scriptIndex}", scriptSource); 11085 JUnitTestCase.assertNotNullMsg("script ${scriptIndex}", scriptSource);
11177 String actualExternalScriptName = scriptSource.shortName; 11086 String actualExternalScriptName = scriptSource.shortName;
11178 JUnitTestCase.assertEqualsMsg( 11087 JUnitTestCase.assertEqualsMsg(
11179 "script ${scriptIndex}", 11088 "script ${scriptIndex}",
11180 _expectedExternalScriptName, 11089 _expectedExternalScriptName,
11181 actualExternalScriptName); 11090 actualExternalScriptName);
11182 } 11091 }
11183 } 11092 }
11184 } 11093 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/ast_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698