OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
7 | 7 |
8 library engine.element_test; | 8 library engine.element_test; |
9 | 9 |
10 import 'package:analyzer/src/generated/ast.dart'; | 10 import 'package:analyzer/src/generated/ast.dart'; |
(...skipping 1240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1251 } | 1251 } |
1252 | 1252 |
1253 @reflectiveTest | 1253 @reflectiveTest |
1254 class FunctionTypeImplTest extends EngineTestCase { | 1254 class FunctionTypeImplTest extends EngineTestCase { |
1255 void test_creation() { | 1255 void test_creation() { |
1256 expect(new FunctionTypeImpl( | 1256 expect(new FunctionTypeImpl( |
1257 new FunctionElementImpl.forNode(AstFactory.identifier3("f"))), | 1257 new FunctionElementImpl.forNode(AstFactory.identifier3("f"))), |
1258 isNotNull); | 1258 isNotNull); |
1259 } | 1259 } |
1260 | 1260 |
| 1261 void test_equality_recursive() { |
| 1262 FunctionTypeAliasElementImpl s = |
| 1263 ElementFactory.functionTypeAliasElement('s'); |
| 1264 FunctionTypeAliasElementImpl t = |
| 1265 ElementFactory.functionTypeAliasElement('t'); |
| 1266 FunctionTypeAliasElementImpl u = |
| 1267 ElementFactory.functionTypeAliasElement('u'); |
| 1268 FunctionTypeAliasElementImpl v = |
| 1269 ElementFactory.functionTypeAliasElement('v'); |
| 1270 s.returnType = t.type; |
| 1271 t.returnType = s.type; |
| 1272 u.returnType = v.type; |
| 1273 v.returnType = u.type; |
| 1274 // We don't care whether the types compare equal or not. We just need the |
| 1275 // computation to terminate. |
| 1276 expect(s.type == u.type, new isInstanceOf<bool>()); |
| 1277 } |
| 1278 |
1261 void test_getElement() { | 1279 void test_getElement() { |
1262 FunctionElementImpl typeElement = | 1280 FunctionElementImpl typeElement = |
1263 new FunctionElementImpl.forNode(AstFactory.identifier3("f")); | 1281 new FunctionElementImpl.forNode(AstFactory.identifier3("f")); |
1264 FunctionTypeImpl type = new FunctionTypeImpl(typeElement); | 1282 FunctionTypeImpl type = new FunctionTypeImpl(typeElement); |
1265 expect(type.element, typeElement); | 1283 expect(type.element, typeElement); |
1266 } | 1284 } |
1267 | 1285 |
1268 void test_getNamedParameterTypes() { | 1286 void test_getNamedParameterTypes() { |
1269 FunctionTypeImpl type = new FunctionTypeImpl( | 1287 FunctionTypeImpl type = new FunctionTypeImpl( |
1270 new FunctionElementImpl.forNode(AstFactory.identifier3("f"))); | 1288 new FunctionElementImpl.forNode(AstFactory.identifier3("f"))); |
(...skipping 29 matching lines...) Expand all Loading... |
1300 FunctionTypeImpl type = new FunctionTypeImpl( | 1318 FunctionTypeImpl type = new FunctionTypeImpl( |
1301 new FunctionElementImpl.forNode(AstFactory.identifier3("f"))); | 1319 new FunctionElementImpl.forNode(AstFactory.identifier3("f"))); |
1302 type.hashCode; | 1320 type.hashCode; |
1303 } | 1321 } |
1304 | 1322 |
1305 void test_hashCode_noElement() { | 1323 void test_hashCode_noElement() { |
1306 FunctionTypeImpl type = new FunctionTypeImpl(null); | 1324 FunctionTypeImpl type = new FunctionTypeImpl(null); |
1307 type.hashCode; | 1325 type.hashCode; |
1308 } | 1326 } |
1309 | 1327 |
| 1328 void test_hashCode_recursive() { |
| 1329 FunctionTypeAliasElementImpl s = |
| 1330 ElementFactory.functionTypeAliasElement('s'); |
| 1331 FunctionTypeAliasElementImpl t = |
| 1332 ElementFactory.functionTypeAliasElement('t'); |
| 1333 s.returnType = t.type; |
| 1334 t.returnType = s.type; |
| 1335 // We don't care what the hash code is. We just need its computation to |
| 1336 // terminate. |
| 1337 expect(t.type.hashCode, new isInstanceOf<int>()); |
| 1338 } |
| 1339 |
1310 void test_isAssignableTo_normalAndPositionalArgs() { | 1340 void test_isAssignableTo_normalAndPositionalArgs() { |
1311 // ([a]) -> void <: (a) -> void | 1341 // ([a]) -> void <: (a) -> void |
1312 ClassElement a = ElementFactory.classElement2("A"); | 1342 ClassElement a = ElementFactory.classElement2("A"); |
1313 FunctionType t = | 1343 FunctionType t = |
1314 ElementFactory.functionElement6("t", null, <ClassElement>[a]).type; | 1344 ElementFactory.functionElement6("t", null, <ClassElement>[a]).type; |
1315 FunctionType s = | 1345 FunctionType s = |
1316 ElementFactory.functionElement5("s", <ClassElement>[a]).type; | 1346 ElementFactory.functionElement5("s", <ClassElement>[a]).type; |
1317 expect(t.isSubtypeOf(s), isTrue); | 1347 expect(t.isSubtypeOf(s), isTrue); |
1318 expect(s.isSubtypeOf(t), isFalse); | 1348 expect(s.isSubtypeOf(t), isFalse); |
1319 // assignable iff subtype | 1349 // assignable iff subtype |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1684 // ! ({name: A}) -> void <: ([a]) -> void | 1714 // ! ({name: A}) -> void <: ([a]) -> void |
1685 ClassElement a = ElementFactory.classElement2("A"); | 1715 ClassElement a = ElementFactory.classElement2("A"); |
1686 FunctionType t = | 1716 FunctionType t = |
1687 ElementFactory.functionElement6("t", null, <ClassElement>[a]).type; | 1717 ElementFactory.functionElement6("t", null, <ClassElement>[a]).type; |
1688 FunctionType s = ElementFactory.functionElement7( | 1718 FunctionType s = ElementFactory.functionElement7( |
1689 "s", null, <String>["name"], <ClassElement>[a]).type; | 1719 "s", null, <String>["name"], <ClassElement>[a]).type; |
1690 expect(t.isSubtypeOf(s), isFalse); | 1720 expect(t.isSubtypeOf(s), isFalse); |
1691 expect(s.isSubtypeOf(t), isFalse); | 1721 expect(s.isSubtypeOf(t), isFalse); |
1692 } | 1722 } |
1693 | 1723 |
| 1724 void test_namedParameterTypes_pruned_no_type_arguments() { |
| 1725 FunctionTypeAliasElementImpl f = |
| 1726 ElementFactory.functionTypeAliasElement('f'); |
| 1727 FunctionTypeAliasElementImpl g = |
| 1728 ElementFactory.functionTypeAliasElement('g'); |
| 1729 f.parameters = [ElementFactory.namedParameter2('x', g.type)]; |
| 1730 FunctionTypeImpl paramType = f.type.namedParameterTypes['x']; |
| 1731 expect(paramType.prunedTypedefs, hasLength(1)); |
| 1732 expect(paramType.prunedTypedefs[0], same(f)); |
| 1733 } |
| 1734 |
| 1735 void test_namedParameterTypes_pruned_with_type_arguments() { |
| 1736 FunctionTypeAliasElementImpl f = |
| 1737 ElementFactory.functionTypeAliasElement('f'); |
| 1738 FunctionTypeAliasElementImpl g = |
| 1739 ElementFactory.functionTypeAliasElement('g'); |
| 1740 f.typeParameters = [ElementFactory.typeParameterElement('T')]; |
| 1741 f.parameters = [ElementFactory.namedParameter2('x', g.type)]; |
| 1742 FunctionTypeImpl paramType = f.type.namedParameterTypes['x']; |
| 1743 expect(paramType.prunedTypedefs, hasLength(1)); |
| 1744 expect(paramType.prunedTypedefs[0], same(f)); |
| 1745 } |
| 1746 |
| 1747 void test_newPrune_no_previous_prune() { |
| 1748 FunctionTypeAliasElementImpl f = |
| 1749 ElementFactory.functionTypeAliasElement('f'); |
| 1750 FunctionTypeImpl type = f.type; |
| 1751 List<FunctionTypeAliasElement> pruneList = type.newPrune; |
| 1752 expect(pruneList, hasLength(1)); |
| 1753 expect(pruneList[0], same(f)); |
| 1754 } |
| 1755 |
| 1756 void test_newPrune_non_typedef() { |
| 1757 // No pruning needs to be done for function types that aren't associated |
| 1758 // with typedefs because those types can't be directly referred to by the |
| 1759 // user (and hence can't participate in circularities). |
| 1760 FunctionElementImpl f = ElementFactory.functionElement('f'); |
| 1761 FunctionTypeImpl type = f.type; |
| 1762 expect(type.newPrune, isNull); |
| 1763 } |
| 1764 |
| 1765 void test_newPrune_synthetic_typedef() { |
| 1766 // No pruning needs to be done for function types that are associated with |
| 1767 // synthetic typedefs because those types are only created for |
| 1768 // function-typed formal parameters, which can't be directly referred to by |
| 1769 // the user (and hence can't participate in circularities). |
| 1770 FunctionTypeAliasElementImpl f = |
| 1771 ElementFactory.functionTypeAliasElement('f'); |
| 1772 f.synthetic = true; |
| 1773 FunctionTypeImpl type = f.type; |
| 1774 expect(type.newPrune, isNull); |
| 1775 } |
| 1776 |
| 1777 void test_newPrune_with_previous_prune() { |
| 1778 FunctionTypeAliasElementImpl f = |
| 1779 ElementFactory.functionTypeAliasElement('f'); |
| 1780 FunctionTypeAliasElementImpl g = |
| 1781 ElementFactory.functionTypeAliasElement('g'); |
| 1782 FunctionTypeImpl type = f.type; |
| 1783 FunctionTypeImpl prunedType = type.pruned([g]); |
| 1784 List<FunctionTypeAliasElement> pruneList = prunedType.newPrune; |
| 1785 expect(pruneList, hasLength(2)); |
| 1786 expect(pruneList, contains(f)); |
| 1787 expect(pruneList, contains(g)); |
| 1788 } |
| 1789 |
| 1790 void test_normalParameterTypes_pruned_no_type_arguments() { |
| 1791 FunctionTypeAliasElementImpl f = |
| 1792 ElementFactory.functionTypeAliasElement('f'); |
| 1793 FunctionTypeAliasElementImpl g = |
| 1794 ElementFactory.functionTypeAliasElement('g'); |
| 1795 f.parameters = [ElementFactory.requiredParameter2('x', g.type)]; |
| 1796 FunctionTypeImpl paramType = f.type.normalParameterTypes[0]; |
| 1797 expect(paramType.prunedTypedefs, hasLength(1)); |
| 1798 expect(paramType.prunedTypedefs[0], same(f)); |
| 1799 } |
| 1800 |
| 1801 void test_normalParameterTypes_pruned_with_type_arguments() { |
| 1802 FunctionTypeAliasElementImpl f = |
| 1803 ElementFactory.functionTypeAliasElement('f'); |
| 1804 FunctionTypeAliasElementImpl g = |
| 1805 ElementFactory.functionTypeAliasElement('g'); |
| 1806 f.typeParameters = [ElementFactory.typeParameterElement('T')]; |
| 1807 f.parameters = [ElementFactory.requiredParameter2('x', g.type)]; |
| 1808 FunctionTypeImpl paramType = f.type.normalParameterTypes[0]; |
| 1809 expect(paramType.prunedTypedefs, hasLength(1)); |
| 1810 expect(paramType.prunedTypedefs[0], same(f)); |
| 1811 } |
| 1812 |
| 1813 void test_optionalParameterTypes_pruned_no_type_arguments() { |
| 1814 FunctionTypeAliasElementImpl f = |
| 1815 ElementFactory.functionTypeAliasElement('f'); |
| 1816 FunctionTypeAliasElementImpl g = |
| 1817 ElementFactory.functionTypeAliasElement('g'); |
| 1818 f.parameters = [ElementFactory.positionalParameter2('x', g.type)]; |
| 1819 FunctionTypeImpl paramType = f.type.optionalParameterTypes[0]; |
| 1820 expect(paramType.prunedTypedefs, hasLength(1)); |
| 1821 expect(paramType.prunedTypedefs[0], same(f)); |
| 1822 } |
| 1823 |
| 1824 void test_optionalParameterTypes_pruned_with_type_arguments() { |
| 1825 FunctionTypeAliasElementImpl f = |
| 1826 ElementFactory.functionTypeAliasElement('f'); |
| 1827 FunctionTypeAliasElementImpl g = |
| 1828 ElementFactory.functionTypeAliasElement('g'); |
| 1829 f.typeParameters = [ElementFactory.typeParameterElement('T')]; |
| 1830 f.parameters = [ElementFactory.positionalParameter2('x', g.type)]; |
| 1831 FunctionTypeImpl paramType = f.type.optionalParameterTypes[0]; |
| 1832 expect(paramType.prunedTypedefs, hasLength(1)); |
| 1833 expect(paramType.prunedTypedefs[0], same(f)); |
| 1834 } |
| 1835 |
| 1836 void test_returnType_pruned_no_type_arguments() { |
| 1837 FunctionTypeAliasElementImpl f = |
| 1838 ElementFactory.functionTypeAliasElement('f'); |
| 1839 FunctionTypeAliasElementImpl g = |
| 1840 ElementFactory.functionTypeAliasElement('g'); |
| 1841 f.returnType = g.type; |
| 1842 FunctionTypeImpl paramType = f.type.returnType; |
| 1843 expect(paramType.prunedTypedefs, hasLength(1)); |
| 1844 expect(paramType.prunedTypedefs[0], same(f)); |
| 1845 } |
| 1846 |
| 1847 void test_returnType_pruned_with_type_arguments() { |
| 1848 FunctionTypeAliasElementImpl f = |
| 1849 ElementFactory.functionTypeAliasElement('f'); |
| 1850 FunctionTypeAliasElementImpl g = |
| 1851 ElementFactory.functionTypeAliasElement('g'); |
| 1852 f.typeParameters = [ElementFactory.typeParameterElement('T')]; |
| 1853 f.returnType = g.type; |
| 1854 FunctionTypeImpl paramType = f.type.returnType; |
| 1855 expect(paramType.prunedTypedefs, hasLength(1)); |
| 1856 expect(paramType.prunedTypedefs[0], same(f)); |
| 1857 } |
| 1858 |
1694 void test_setTypeArguments() { | 1859 void test_setTypeArguments() { |
1695 ClassElementImpl enclosingClass = ElementFactory.classElement2("C", ["E"]); | 1860 ClassElementImpl enclosingClass = ElementFactory.classElement2("C", ["E"]); |
1696 MethodElementImpl methodElement = | 1861 MethodElementImpl methodElement = |
1697 new MethodElementImpl.forNode(AstFactory.identifier3("m")); | 1862 new MethodElementImpl.forNode(AstFactory.identifier3("m")); |
1698 enclosingClass.methods = <MethodElement>[methodElement]; | 1863 enclosingClass.methods = <MethodElement>[methodElement]; |
1699 FunctionTypeImpl type = new FunctionTypeImpl(methodElement); | 1864 FunctionTypeImpl type = new FunctionTypeImpl(methodElement); |
1700 DartType expectedType = enclosingClass.typeParameters[0].type; | 1865 DartType expectedType = enclosingClass.typeParameters[0].type; |
1701 type.typeArguments = <DartType>[expectedType]; | 1866 type.typeArguments = <DartType>[expectedType]; |
1702 List<DartType> arguments = type.typeArguments; | 1867 List<DartType> arguments = type.typeArguments; |
1703 expect(arguments, hasLength(1)); | 1868 expect(arguments, hasLength(1)); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1766 expect(normalParameters[0], normalParameterType); | 1931 expect(normalParameters[0], normalParameterType); |
1767 List<DartType> optionalParameters = result.optionalParameterTypes; | 1932 List<DartType> optionalParameters = result.optionalParameterTypes; |
1768 expect(optionalParameters, hasLength(1)); | 1933 expect(optionalParameters, hasLength(1)); |
1769 expect(optionalParameters[0], optionalParameterType); | 1934 expect(optionalParameters[0], optionalParameterType); |
1770 Map<String, DartType> namedParameters = result.namedParameterTypes; | 1935 Map<String, DartType> namedParameters = result.namedParameterTypes; |
1771 expect(namedParameters, hasLength(1)); | 1936 expect(namedParameters, hasLength(1)); |
1772 expect(namedParameters[namedParameterName], namedParameterType); | 1937 expect(namedParameters[namedParameterName], namedParameterType); |
1773 } | 1938 } |
1774 | 1939 |
1775 void test_toString_recursive() { | 1940 void test_toString_recursive() { |
1776 FunctionElementImpl t = ElementFactory.functionElement("t"); | 1941 FunctionTypeAliasElementImpl t = |
1777 FunctionElementImpl s = ElementFactory.functionElement("s"); | 1942 ElementFactory.functionTypeAliasElement("t"); |
| 1943 FunctionTypeAliasElementImpl s = |
| 1944 ElementFactory.functionTypeAliasElement("s"); |
1778 t.returnType = s.type; | 1945 t.returnType = s.type; |
1779 s.returnType = t.type; | 1946 s.returnType = t.type; |
1780 expect(t.type.toString(), '() \u2192 () \u2192 ...'); | 1947 expect(t.type.toString(), '() \u2192 () \u2192 ...'); |
1781 } | 1948 } |
| 1949 |
| 1950 void test_toString_recursive_via_interface_type() { |
| 1951 FunctionTypeAliasElementImpl f = |
| 1952 ElementFactory.functionTypeAliasElement('f'); |
| 1953 ClassElementImpl c = ElementFactory.classElement2('C', ['T']); |
| 1954 f.returnType = c.type.substitute4([f.type]); |
| 1955 expect(f.type.toString(), '() \u2192 C<...>'); |
| 1956 } |
1782 } | 1957 } |
1783 | 1958 |
1784 @reflectiveTest | 1959 @reflectiveTest |
1785 class HtmlElementImplTest extends EngineTestCase { | 1960 class HtmlElementImplTest extends EngineTestCase { |
1786 void test_equals_differentSource() { | 1961 void test_equals_differentSource() { |
1787 AnalysisContextImpl context = createAnalysisContext(); | 1962 AnalysisContextImpl context = createAnalysisContext(); |
1788 HtmlElementImpl elementA = ElementFactory.htmlUnit(context, "indexA.html"); | 1963 HtmlElementImpl elementA = ElementFactory.htmlUnit(context, "indexA.html"); |
1789 HtmlElementImpl elementB = ElementFactory.htmlUnit(context, "indexB.html"); | 1964 HtmlElementImpl elementB = ElementFactory.htmlUnit(context, "indexB.html"); |
1790 expect(elementA == elementB, isFalse); | 1965 expect(elementA == elementB, isFalse); |
1791 } | 1966 } |
(...skipping 2187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3979 } | 4154 } |
3980 | 4155 |
3981 class _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction | 4156 class _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction |
3982 extends InterfaceTypeImpl { | 4157 extends InterfaceTypeImpl { |
3983 _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction(ClassElement arg0) | 4158 _FunctionTypeImplTest_isSubtypeOf_baseCase_classFunction(ClassElement arg0) |
3984 : super(arg0); | 4159 : super(arg0); |
3985 | 4160 |
3986 @override | 4161 @override |
3987 bool get isDartCoreFunction => true; | 4162 bool get isDartCoreFunction => true; |
3988 } | 4163 } |
OLD | NEW |