| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library analyzer.test.src.summary.summary_test; | 5 library analyzer.test.src.summary.summary_test; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/element/element.dart'; | 7 import 'package:analyzer/dart/element/element.dart'; |
| 8 import 'package:analyzer/src/generated/ast.dart'; | 8 import 'package:analyzer/src/generated/ast.dart'; |
| 9 import 'package:analyzer/src/generated/engine.dart'; | 9 import 'package:analyzer/src/generated/engine.dart'; |
| 10 import 'package:analyzer/src/generated/error.dart'; | 10 import 'package:analyzer/src/generated/error.dart'; |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 } | 408 } |
| 409 | 409 |
| 410 /** | 410 /** |
| 411 * Verify that the given [typeRef] represents the type `dynamic`. | 411 * Verify that the given [typeRef] represents the type `dynamic`. |
| 412 */ | 412 */ |
| 413 void checkDynamicTypeRef(UnlinkedTypeRef typeRef) { | 413 void checkDynamicTypeRef(UnlinkedTypeRef typeRef) { |
| 414 checkTypeRef(typeRef, null, null, null); | 414 checkTypeRef(typeRef, null, null, null); |
| 415 } | 415 } |
| 416 | 416 |
| 417 /** | 417 /** |
| 418 * Verify that the given [exportName] represents a reference to an entity |
| 419 * declared in a file reachable via [absoluteUri] and [relativeUri], having |
| 420 * name [expectedName]. [expectedKind] is the kind of object referenced. |
| 421 * [expectedTargetUnit] is the index of the compilation unit in which the |
| 422 * target of the [exportName] is expected to appear; if not specified it is |
| 423 * assumed to be the defining compilation unit. |
| 424 */ |
| 425 void checkExportName( |
| 426 PrelinkedExportName exportName, |
| 427 String absoluteUri, |
| 428 String relativeUri, |
| 429 String expectedName, |
| 430 PrelinkedReferenceKind expectedKind, |
| 431 {int expectedTargetUnit: 0}) { |
| 432 expect(exportName, new isInstanceOf<PrelinkedExportName>()); |
| 433 // Exported names must come from other libraries. |
| 434 expect(exportName.dependency, isNot(0)); |
| 435 checkDependency(exportName.dependency, absoluteUri, relativeUri); |
| 436 expect(exportName.name, expectedName); |
| 437 expect(exportName.kind, expectedKind); |
| 438 expect(exportName.unit, expectedTargetUnit); |
| 439 } |
| 440 |
| 441 /** |
| 418 * Verify that the dependency table contains an entry for a file reachable | 442 * Verify that the dependency table contains an entry for a file reachable |
| 419 * via the given [absoluteUri] and [relativeUri]. | 443 * via the given [absoluteUri] and [relativeUri]. |
| 420 * | 444 * |
| 421 * The [PrelinkedDependency] is returned. | 445 * The [PrelinkedDependency] is returned. |
| 422 */ | 446 */ |
| 423 PrelinkedDependency checkHasDependency( | 447 PrelinkedDependency checkHasDependency( |
| 424 String absoluteUri, String relativeUri) { | 448 String absoluteUri, String relativeUri) { |
| 425 if (expectAbsoluteUrisInDependencies) { | 449 if (expectAbsoluteUrisInDependencies) { |
| 426 // The element model doesn't (yet) store enough information to recover | 450 // The element model doesn't (yet) store enough information to recover |
| 427 // relative URIs, so we have to use the absolute URI. | 451 // relative URIs, so we have to use the absolute URI. |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 */ | 575 */ |
| 552 void checkUnresolvedTypeRef( | 576 void checkUnresolvedTypeRef( |
| 553 UnlinkedTypeRef typeRef, String expectedPrefix, String expectedName) { | 577 UnlinkedTypeRef typeRef, String expectedPrefix, String expectedName) { |
| 554 // When serializing from the element model, unresolved type refs lose their | 578 // When serializing from the element model, unresolved type refs lose their |
| 555 // name. | 579 // name. |
| 556 checkTypeRef(typeRef, null, null, checkAstDerivedData ? expectedName : null, | 580 checkTypeRef(typeRef, null, null, checkAstDerivedData ? expectedName : null, |
| 557 expectedPrefix: expectedPrefix, | 581 expectedPrefix: expectedPrefix, |
| 558 expectedKind: PrelinkedReferenceKind.unresolved); | 582 expectedKind: PrelinkedReferenceKind.unresolved); |
| 559 } | 583 } |
| 560 | 584 |
| 561 fail_dependencies_export_to_export_unused() { | 585 test_dependencies_export_to_export_unused() { |
| 562 // TODO(paulberry): fix this test. | 586 // TODO(paulberry): fix this test. |
| 563 addNamedSource('/a.dart', 'export "b.dart";'); | 587 addNamedSource('/a.dart', 'export "b.dart";'); |
| 564 addNamedSource('/b.dart', ''); | 588 addNamedSource('/b.dart', ''); |
| 565 serializeLibraryText('export "a.dart";'); | 589 serializeLibraryText('export "a.dart";'); |
| 566 // The main test library depends on b.dart, even though it doesn't | 590 // The main test library depends on b.dart, even though it doesn't |
| 567 // re-export any names defined in b.dart, because a change to b.dart might | 591 // re-export any names defined in b.dart, because a change to b.dart might |
| 568 // cause it to start exporting a name that the main test library *does* | 592 // cause it to start exporting a name that the main test library *does* |
| 569 // use. | 593 // use. |
| 570 checkHasDependency(absUri('/b.dart'), 'b.dart'); | 594 checkHasDependency(absUri('/b.dart'), 'b.dart'); |
| 571 } | 595 } |
| 572 | 596 |
| 573 fail_dependencies_export_unused() { | 597 test_dependencies_export_unused() { |
| 574 // TODO(paulberry): fix this test. | 598 // TODO(paulberry): fix this test. |
| 575 addNamedSource('/a.dart', ''); | 599 addNamedSource('/a.dart', ''); |
| 576 serializeLibraryText('export "a.dart";'); | 600 serializeLibraryText('export "a.dart";'); |
| 577 // The main test library depends on a.dart, even though it doesn't | 601 // The main test library depends on a.dart, even though it doesn't |
| 578 // re-export any names defined in a.dart, because a change to a.dart might | 602 // re-export any names defined in a.dart, because a change to a.dart might |
| 579 // cause it to start exporting a name that the main test library *will* | 603 // cause it to start exporting a name that the main test library *will* |
| 580 // re-export. | 604 // re-export. |
| 581 checkHasDependency(absUri('/a.dart'), 'a.dart'); | 605 checkHasDependency(absUri('/a.dart'), 'a.dart'); |
| 582 } | 606 } |
| 583 | 607 |
| (...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1471 executables: serializeClassText('class C { C(); }').executables); | 1495 executables: serializeClassText('class C { C(); }').executables); |
| 1472 expect(executable.returnType, isNull); | 1496 expect(executable.returnType, isNull); |
| 1473 } | 1497 } |
| 1474 | 1498 |
| 1475 test_constructor_return_type_parameterized() { | 1499 test_constructor_return_type_parameterized() { |
| 1476 UnlinkedExecutable executable = findExecutable('', | 1500 UnlinkedExecutable executable = findExecutable('', |
| 1477 executables: serializeClassText('class C<T, U> { C(); }').executables); | 1501 executables: serializeClassText('class C<T, U> { C(); }').executables); |
| 1478 expect(executable.returnType, isNull); | 1502 expect(executable.returnType, isNull); |
| 1479 } | 1503 } |
| 1480 | 1504 |
| 1481 test_dependencies_export_none() { | |
| 1482 // Exports are not listed as dependencies since no change to the exported | |
| 1483 // file can change the summary of the exporting file. | |
| 1484 // TODO(paulberry): this needs to change since the element model for a | |
| 1485 // library includes its export namespace. | |
| 1486 addNamedSource('/a.dart', 'library a; export "b.dart";'); | |
| 1487 addNamedSource('/b.dart', 'library b;'); | |
| 1488 serializeLibraryText('export "a.dart";'); | |
| 1489 checkLacksDependency(absUri('/a.dart'), 'a.dart'); | |
| 1490 checkLacksDependency(absUri('/b.dart'), 'b.dart'); | |
| 1491 } | |
| 1492 | |
| 1493 test_dependencies_import_to_export() { | 1505 test_dependencies_import_to_export() { |
| 1494 addNamedSource('/a.dart', 'library a; export "b.dart"; class A {}'); | 1506 addNamedSource('/a.dart', 'library a; export "b.dart"; class A {}'); |
| 1495 addNamedSource('/b.dart', 'library b;'); | 1507 addNamedSource('/b.dart', 'library b;'); |
| 1496 serializeLibraryText('import "a.dart"; A a;'); | 1508 serializeLibraryText('import "a.dart"; A a;'); |
| 1497 checkHasDependency(absUri('/a.dart'), 'a.dart'); | 1509 checkHasDependency(absUri('/a.dart'), 'a.dart'); |
| 1498 // The main test library depends on b.dart, because names defined in | 1510 // The main test library depends on b.dart, because names defined in |
| 1499 // b.dart are exported by a.dart. | 1511 // b.dart are exported by a.dart. |
| 1500 checkHasDependency(absUri('/b.dart'), 'b.dart'); | 1512 checkHasDependency(absUri('/b.dart'), 'b.dart'); |
| 1501 } | 1513 } |
| 1502 | 1514 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1683 test_executable_function() { | 1695 test_executable_function() { |
| 1684 String text = ' f() {}'; | 1696 String text = ' f() {}'; |
| 1685 UnlinkedExecutable executable = serializeExecutableText(text); | 1697 UnlinkedExecutable executable = serializeExecutableText(text); |
| 1686 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod); | 1698 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod); |
| 1687 expect(executable.hasImplicitReturnType, isTrue); | 1699 expect(executable.hasImplicitReturnType, isTrue); |
| 1688 checkDynamicTypeRef(executable.returnType); | 1700 checkDynamicTypeRef(executable.returnType); |
| 1689 expect(executable.isExternal, isFalse); | 1701 expect(executable.isExternal, isFalse); |
| 1690 expect(executable.nameOffset, text.indexOf('f')); | 1702 expect(executable.nameOffset, text.indexOf('f')); |
| 1691 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); | 1703 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); |
| 1692 expect(unlinkedUnits[0].publicNamespace.names[0].kind, | 1704 expect(unlinkedUnits[0].publicNamespace.names[0].kind, |
| 1693 PrelinkedReferenceKind.other); | 1705 PrelinkedReferenceKind.topLevelFunction); |
| 1694 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'f'); | 1706 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'f'); |
| 1695 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 0); | 1707 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 0); |
| 1696 } | 1708 } |
| 1697 | 1709 |
| 1698 test_executable_function_explicit_return() { | 1710 test_executable_function_explicit_return() { |
| 1699 UnlinkedExecutable executable = | 1711 UnlinkedExecutable executable = |
| 1700 serializeExecutableText('dynamic f() => null;'); | 1712 serializeExecutableText('dynamic f() => null;'); |
| 1701 expect(executable.hasImplicitReturnType, isFalse); | 1713 expect(executable.hasImplicitReturnType, isFalse); |
| 1702 checkDynamicTypeRef(executable.returnType); | 1714 checkDynamicTypeRef(executable.returnType); |
| 1703 } | 1715 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1716 String text = 'int get f => 1;'; | 1728 String text = 'int get f => 1;'; |
| 1717 UnlinkedExecutable executable = serializeExecutableText(text); | 1729 UnlinkedExecutable executable = serializeExecutableText(text); |
| 1718 expect(executable.kind, UnlinkedExecutableKind.getter); | 1730 expect(executable.kind, UnlinkedExecutableKind.getter); |
| 1719 expect(executable.hasImplicitReturnType, isFalse); | 1731 expect(executable.hasImplicitReturnType, isFalse); |
| 1720 expect(executable.isExternal, isFalse); | 1732 expect(executable.isExternal, isFalse); |
| 1721 expect(executable.nameOffset, text.indexOf('f')); | 1733 expect(executable.nameOffset, text.indexOf('f')); |
| 1722 expect(findVariable('f'), isNull); | 1734 expect(findVariable('f'), isNull); |
| 1723 expect(findExecutable('f='), isNull); | 1735 expect(findExecutable('f='), isNull); |
| 1724 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); | 1736 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); |
| 1725 expect(unlinkedUnits[0].publicNamespace.names[0].kind, | 1737 expect(unlinkedUnits[0].publicNamespace.names[0].kind, |
| 1726 PrelinkedReferenceKind.other); | 1738 PrelinkedReferenceKind.topLevelPropertyAccessor); |
| 1727 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'f'); | 1739 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'f'); |
| 1728 } | 1740 } |
| 1729 | 1741 |
| 1730 test_executable_getter_external() { | 1742 test_executable_getter_external() { |
| 1731 UnlinkedExecutable executable = | 1743 UnlinkedExecutable executable = |
| 1732 serializeExecutableText('external int get f;'); | 1744 serializeExecutableText('external int get f;'); |
| 1733 expect(executable.isExternal, isTrue); | 1745 expect(executable.isExternal, isTrue); |
| 1734 } | 1746 } |
| 1735 | 1747 |
| 1736 test_executable_getter_private() { | 1748 test_executable_getter_private() { |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2046 String text = 'void set f(value) {}'; | 2058 String text = 'void set f(value) {}'; |
| 2047 UnlinkedExecutable executable = serializeExecutableText(text, 'f='); | 2059 UnlinkedExecutable executable = serializeExecutableText(text, 'f='); |
| 2048 expect(executable.kind, UnlinkedExecutableKind.setter); | 2060 expect(executable.kind, UnlinkedExecutableKind.setter); |
| 2049 expect(executable.hasImplicitReturnType, isFalse); | 2061 expect(executable.hasImplicitReturnType, isFalse); |
| 2050 expect(executable.isExternal, isFalse); | 2062 expect(executable.isExternal, isFalse); |
| 2051 expect(executable.nameOffset, text.indexOf('f')); | 2063 expect(executable.nameOffset, text.indexOf('f')); |
| 2052 expect(findVariable('f'), isNull); | 2064 expect(findVariable('f'), isNull); |
| 2053 expect(findExecutable('f'), isNull); | 2065 expect(findExecutable('f'), isNull); |
| 2054 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); | 2066 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); |
| 2055 expect(unlinkedUnits[0].publicNamespace.names[0].kind, | 2067 expect(unlinkedUnits[0].publicNamespace.names[0].kind, |
| 2056 PrelinkedReferenceKind.other); | 2068 PrelinkedReferenceKind.topLevelPropertyAccessor); |
| 2057 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'f='); | 2069 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'f='); |
| 2058 } | 2070 } |
| 2059 | 2071 |
| 2060 test_executable_setter_external() { | 2072 test_executable_setter_external() { |
| 2061 UnlinkedExecutable executable = | 2073 UnlinkedExecutable executable = |
| 2062 serializeExecutableText('external void set f(value);', 'f='); | 2074 serializeExecutableText('external void set f(value);', 'f='); |
| 2063 expect(executable.isExternal, isTrue); | 2075 expect(executable.isExternal, isTrue); |
| 2064 } | 2076 } |
| 2065 | 2077 |
| 2066 test_executable_setter_implicit_return() { | 2078 test_executable_setter_implicit_return() { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2133 test_executable_type_param_in_return_type_function() { | 2145 test_executable_type_param_in_return_type_function() { |
| 2134 UnlinkedExecutable ex = serializeExecutableText('T f<T>() => null;'); | 2146 UnlinkedExecutable ex = serializeExecutableText('T f<T>() => null;'); |
| 2135 checkParamTypeRef(ex.returnType, 1); | 2147 checkParamTypeRef(ex.returnType, 1); |
| 2136 } | 2148 } |
| 2137 | 2149 |
| 2138 test_executable_type_param_in_return_type_method() { | 2150 test_executable_type_param_in_return_type_method() { |
| 2139 UnlinkedExecutable ex = serializeMethodText('T f<T>() => null;'); | 2151 UnlinkedExecutable ex = serializeMethodText('T f<T>() => null;'); |
| 2140 checkParamTypeRef(ex.returnType, 1); | 2152 checkParamTypeRef(ex.returnType, 1); |
| 2141 } | 2153 } |
| 2142 | 2154 |
| 2155 test_export_class() { |
| 2156 addNamedSource('/a.dart', 'class C {}'); |
| 2157 serializeLibraryText('export "a.dart";'); |
| 2158 expect(prelinked.exportNames, hasLength(1)); |
| 2159 checkExportName(prelinked.exportNames[0], absUri('/a.dart'), 'a.dart', 'C', |
| 2160 PrelinkedReferenceKind.classOrEnum); |
| 2161 } |
| 2162 |
| 2163 test_export_class_alias() { |
| 2164 addNamedSource( |
| 2165 '/a.dart', 'class C extends _D with _E {} class _D {} class _E {}'); |
| 2166 serializeLibraryText('export "a.dart";'); |
| 2167 expect(prelinked.exportNames, hasLength(1)); |
| 2168 checkExportName(prelinked.exportNames[0], absUri('/a.dart'), 'a.dart', 'C', |
| 2169 PrelinkedReferenceKind.classOrEnum); |
| 2170 } |
| 2171 |
| 2172 test_export_enum() { |
| 2173 addNamedSource('/a.dart', 'enum E { v }'); |
| 2174 serializeLibraryText('export "a.dart";'); |
| 2175 expect(prelinked.exportNames, hasLength(1)); |
| 2176 checkExportName(prelinked.exportNames[0], absUri('/a.dart'), 'a.dart', 'E', |
| 2177 PrelinkedReferenceKind.classOrEnum); |
| 2178 } |
| 2179 |
| 2180 test_export_from_part() { |
| 2181 addNamedSource('/a.dart', 'library foo; part "b.dart";'); |
| 2182 addNamedSource('/b.dart', 'part of foo; f() {}'); |
| 2183 serializeLibraryText('export "a.dart";'); |
| 2184 expect(prelinked.exportNames, hasLength(1)); |
| 2185 checkExportName(prelinked.exportNames[0], absUri('/a.dart'), 'a.dart', 'f', |
| 2186 PrelinkedReferenceKind.topLevelFunction, |
| 2187 expectedTargetUnit: 1); |
| 2188 } |
| 2189 |
| 2190 test_export_function() { |
| 2191 addNamedSource('/a.dart', 'f() {}'); |
| 2192 serializeLibraryText('export "a.dart";'); |
| 2193 expect(prelinked.exportNames, hasLength(1)); |
| 2194 checkExportName(prelinked.exportNames[0], absUri('/a.dart'), 'a.dart', 'f', |
| 2195 PrelinkedReferenceKind.topLevelFunction); |
| 2196 } |
| 2197 |
| 2198 test_export_getter() { |
| 2199 addNamedSource('/a.dart', 'get f => null'); |
| 2200 serializeLibraryText('export "a.dart";'); |
| 2201 expect(prelinked.exportNames, hasLength(1)); |
| 2202 checkExportName(prelinked.exportNames[0], absUri('/a.dart'), 'a.dart', 'f', |
| 2203 PrelinkedReferenceKind.topLevelPropertyAccessor); |
| 2204 } |
| 2205 |
| 2206 test_export_hide() { |
| 2207 addNamedSource('/a.dart', 'f() {} g() {}'); |
| 2208 serializeLibraryText('export "a.dart" hide g;'); |
| 2209 expect(prelinked.exportNames, hasLength(1)); |
| 2210 checkExportName(prelinked.exportNames[0], absUri('/a.dart'), 'a.dart', 'f', |
| 2211 PrelinkedReferenceKind.topLevelFunction); |
| 2212 } |
| 2213 |
| 2143 test_export_hide_order() { | 2214 test_export_hide_order() { |
| 2144 serializeLibraryText('export "dart:async" hide Future, Stream;'); | 2215 serializeLibraryText('export "dart:async" hide Future, Stream;'); |
| 2145 expect(unlinkedUnits[0].publicNamespace.exports, hasLength(1)); | 2216 expect(unlinkedUnits[0].publicNamespace.exports, hasLength(1)); |
| 2146 expect( | 2217 expect( |
| 2147 unlinkedUnits[0].publicNamespace.exports[0].combinators, hasLength(1)); | 2218 unlinkedUnits[0].publicNamespace.exports[0].combinators, hasLength(1)); |
| 2148 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].shows, | 2219 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].shows, |
| 2149 isEmpty); | 2220 isEmpty); |
| 2150 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].hides, | 2221 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].hides, |
| 2151 hasLength(2)); | 2222 hasLength(2)); |
| 2152 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].hides[0], | 2223 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].hides[0], |
| 2153 'Future'); | 2224 'Future'); |
| 2154 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].hides[1], | 2225 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].hides[1], |
| 2155 'Stream'); | 2226 'Stream'); |
| 2227 expect(prelinked.exportNames, isNotEmpty); |
| 2228 } |
| 2229 |
| 2230 test_export_names_excludes_names_from_library() { |
| 2231 addNamedSource('/a.dart', 'part of my.lib; int y; int _y;'); |
| 2232 serializeLibraryText('library my.lib; part "a.dart"; int x; int _x;'); |
| 2233 expect(prelinked.exportNames, isEmpty); |
| 2156 } | 2234 } |
| 2157 | 2235 |
| 2158 test_export_no_combinators() { | 2236 test_export_no_combinators() { |
| 2159 serializeLibraryText('export "dart:async";'); | 2237 serializeLibraryText('export "dart:async";'); |
| 2160 expect(unlinkedUnits[0].publicNamespace.exports, hasLength(1)); | 2238 expect(unlinkedUnits[0].publicNamespace.exports, hasLength(1)); |
| 2161 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators, isEmpty); | 2239 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators, isEmpty); |
| 2162 } | 2240 } |
| 2163 | 2241 |
| 2242 test_export_not_shadowed_by_prefix() { |
| 2243 addNamedSource('/a.dart', 'f() {}'); |
| 2244 serializeLibraryText('export "a.dart"; import "dart:core" as f; f.int _x;'); |
| 2245 expect(prelinked.exportNames, hasLength(1)); |
| 2246 checkExportName(prelinked.exportNames[0], absUri('/a.dart'), 'a.dart', 'f', |
| 2247 PrelinkedReferenceKind.topLevelFunction); |
| 2248 } |
| 2249 |
| 2164 test_export_offset() { | 2250 test_export_offset() { |
| 2165 String libraryText = ' export "dart:async";'; | 2251 String libraryText = ' export "dart:async";'; |
| 2166 serializeLibraryText(libraryText); | 2252 serializeLibraryText(libraryText); |
| 2167 expect(unlinkedUnits[0].exports[0].uriOffset, | 2253 expect(unlinkedUnits[0].exports[0].uriOffset, |
| 2168 libraryText.indexOf('"dart:async"')); | 2254 libraryText.indexOf('"dart:async"')); |
| 2169 expect(unlinkedUnits[0].exports[0].uriEnd, libraryText.indexOf(';')); | 2255 expect(unlinkedUnits[0].exports[0].uriEnd, libraryText.indexOf(';')); |
| 2170 expect(unlinkedUnits[0].exports[0].offset, libraryText.indexOf('export')); | 2256 expect(unlinkedUnits[0].exports[0].offset, libraryText.indexOf('export')); |
| 2171 } | 2257 } |
| 2172 | 2258 |
| 2259 test_export_private() { |
| 2260 // Private names should not be exported. |
| 2261 addNamedSource('/a.dart', '_f() {}'); |
| 2262 serializeLibraryText('export "a.dart";'); |
| 2263 expect(prelinked.exportNames, isEmpty); |
| 2264 } |
| 2265 |
| 2266 test_export_setter() { |
| 2267 addNamedSource('/a.dart', 'void set f(value) {}'); |
| 2268 serializeLibraryText('export "a.dart";'); |
| 2269 expect(prelinked.exportNames, hasLength(1)); |
| 2270 checkExportName(prelinked.exportNames[0], absUri('/a.dart'), 'a.dart', 'f=', |
| 2271 PrelinkedReferenceKind.topLevelPropertyAccessor); |
| 2272 } |
| 2273 |
| 2274 test_export_shadowed() { |
| 2275 // f() is not shown in exportNames because it is already defined at top |
| 2276 // level in the library. |
| 2277 addNamedSource('/a.dart', 'f() {}'); |
| 2278 serializeLibraryText('export "a.dart"; f() {}'); |
| 2279 expect(prelinked.exportNames, isEmpty); |
| 2280 } |
| 2281 |
| 2282 test_export_shadowed_variable() { |
| 2283 // Neither `v` nor `v=` is shown in exportNames because both are defined at |
| 2284 // top level in the library by the declaration `var v;`. |
| 2285 addNamedSource('/a.dart', 'var v;'); |
| 2286 serializeLibraryText('export "a.dart"; var v;'); |
| 2287 expect(prelinked.exportNames, isEmpty); |
| 2288 } |
| 2289 |
| 2290 test_export_shadowed_variable_const() { |
| 2291 // `v=` is shown in exportNames because the top level declaration |
| 2292 // `const v = 0;` only shadows `v`, not `v=`. |
| 2293 addNamedSource('/a.dart', 'var v;'); |
| 2294 serializeLibraryText('export "a.dart"; const v = 0;'); |
| 2295 expect(prelinked.exportNames, hasLength(1)); |
| 2296 checkExportName(prelinked.exportNames[0], absUri('/a.dart'), 'a.dart', 'v=', |
| 2297 PrelinkedReferenceKind.topLevelPropertyAccessor); |
| 2298 } |
| 2299 |
| 2300 test_export_shadowed_variable_final() { |
| 2301 // `v=` is shown in exportNames because the top level declaration |
| 2302 // `final v = 0;` only shadows `v`, not `v=`. |
| 2303 addNamedSource('/a.dart', 'var v;'); |
| 2304 serializeLibraryText('export "a.dart"; final v = 0;'); |
| 2305 expect(prelinked.exportNames, hasLength(1)); |
| 2306 checkExportName(prelinked.exportNames[0], absUri('/a.dart'), 'a.dart', 'v=', |
| 2307 PrelinkedReferenceKind.topLevelPropertyAccessor); |
| 2308 } |
| 2309 |
| 2310 test_export_show() { |
| 2311 addNamedSource('/a.dart', 'f() {} g() {}'); |
| 2312 serializeLibraryText('export "a.dart" show f;'); |
| 2313 expect(prelinked.exportNames, hasLength(1)); |
| 2314 checkExportName(prelinked.exportNames[0], absUri('/a.dart'), 'a.dart', 'f', |
| 2315 PrelinkedReferenceKind.topLevelFunction); |
| 2316 } |
| 2317 |
| 2173 test_export_show_order() { | 2318 test_export_show_order() { |
| 2174 serializeLibraryText('export "dart:async" show Future, Stream;'); | 2319 serializeLibraryText('export "dart:async" show Future, Stream;'); |
| 2175 expect(unlinkedUnits[0].publicNamespace.exports, hasLength(1)); | 2320 expect(unlinkedUnits[0].publicNamespace.exports, hasLength(1)); |
| 2176 expect( | 2321 expect( |
| 2177 unlinkedUnits[0].publicNamespace.exports[0].combinators, hasLength(1)); | 2322 unlinkedUnits[0].publicNamespace.exports[0].combinators, hasLength(1)); |
| 2178 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].shows, | 2323 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].shows, |
| 2179 hasLength(2)); | 2324 hasLength(2)); |
| 2180 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].hides, | 2325 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].hides, |
| 2181 isEmpty); | 2326 isEmpty); |
| 2182 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].shows[0], | 2327 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].shows[0], |
| 2183 'Future'); | 2328 'Future'); |
| 2184 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].shows[1], | 2329 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].shows[1], |
| 2185 'Stream'); | 2330 'Stream'); |
| 2186 } | 2331 } |
| 2187 | 2332 |
| 2333 test_export_typedef() { |
| 2334 addNamedSource('/a.dart', 'typedef F();'); |
| 2335 serializeLibraryText('export "a.dart";'); |
| 2336 expect(prelinked.exportNames, hasLength(1)); |
| 2337 checkExportName(prelinked.exportNames[0], absUri('/a.dart'), 'a.dart', 'F', |
| 2338 PrelinkedReferenceKind.typedef); |
| 2339 } |
| 2340 |
| 2188 test_export_uri() { | 2341 test_export_uri() { |
| 2189 addNamedSource('/a.dart', 'library my.lib;'); | 2342 addNamedSource('/a.dart', 'library my.lib;'); |
| 2190 String uriString = '"a.dart"'; | 2343 String uriString = '"a.dart"'; |
| 2191 String libraryText = 'export $uriString;'; | 2344 String libraryText = 'export $uriString;'; |
| 2192 serializeLibraryText(libraryText); | 2345 serializeLibraryText(libraryText); |
| 2193 expect(unlinkedUnits[0].publicNamespace.exports, hasLength(1)); | 2346 expect(unlinkedUnits[0].publicNamespace.exports, hasLength(1)); |
| 2194 expect(unlinkedUnits[0].publicNamespace.exports[0].uri, 'a.dart'); | 2347 expect(unlinkedUnits[0].publicNamespace.exports[0].uri, 'a.dart'); |
| 2195 } | 2348 } |
| 2196 | 2349 |
| 2350 test_export_variable() { |
| 2351 addNamedSource('/a.dart', 'var v;'); |
| 2352 serializeLibraryText('export "a.dart";'); |
| 2353 expect(prelinked.exportNames, hasLength(2)); |
| 2354 PrelinkedExportName getter = |
| 2355 prelinked.exportNames.firstWhere((e) => e.name == 'v'); |
| 2356 expect(getter, isNotNull); |
| 2357 checkExportName(getter, absUri('/a.dart'), 'a.dart', 'v', |
| 2358 PrelinkedReferenceKind.topLevelPropertyAccessor); |
| 2359 PrelinkedExportName setter = |
| 2360 prelinked.exportNames.firstWhere((e) => e.name == 'v='); |
| 2361 expect(setter, isNotNull); |
| 2362 checkExportName(setter, absUri('/a.dart'), 'a.dart', 'v=', |
| 2363 PrelinkedReferenceKind.topLevelPropertyAccessor); |
| 2364 } |
| 2365 |
| 2197 test_field() { | 2366 test_field() { |
| 2198 UnlinkedClass cls = serializeClassText('class C { int i; }'); | 2367 UnlinkedClass cls = serializeClassText('class C { int i; }'); |
| 2199 UnlinkedVariable variable = findVariable('i', variables: cls.fields); | 2368 UnlinkedVariable variable = findVariable('i', variables: cls.fields); |
| 2200 expect(variable, isNotNull); | 2369 expect(variable, isNotNull); |
| 2201 expect(variable.isConst, isFalse); | 2370 expect(variable.isConst, isFalse); |
| 2202 expect(variable.isStatic, isFalse); | 2371 expect(variable.isStatic, isFalse); |
| 2203 expect(variable.isFinal, isFalse); | 2372 expect(variable.isFinal, isFalse); |
| 2204 expect(findExecutable('i', executables: cls.executables), isNull); | 2373 expect(findExecutable('i', executables: cls.executables), isNull); |
| 2205 expect(findExecutable('i=', executables: cls.executables), isNull); | 2374 expect(findExecutable('i=', executables: cls.executables), isNull); |
| 2206 } | 2375 } |
| (...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2898 } | 3067 } |
| 2899 | 3068 |
| 2900 test_variable() { | 3069 test_variable() { |
| 2901 String text = 'int i;'; | 3070 String text = 'int i;'; |
| 2902 UnlinkedVariable v = serializeVariableText(text, variableName: 'i'); | 3071 UnlinkedVariable v = serializeVariableText(text, variableName: 'i'); |
| 2903 expect(v.nameOffset, text.indexOf('i;')); | 3072 expect(v.nameOffset, text.indexOf('i;')); |
| 2904 expect(findExecutable('i'), isNull); | 3073 expect(findExecutable('i'), isNull); |
| 2905 expect(findExecutable('i='), isNull); | 3074 expect(findExecutable('i='), isNull); |
| 2906 expect(unlinkedUnits[0].publicNamespace.names, hasLength(2)); | 3075 expect(unlinkedUnits[0].publicNamespace.names, hasLength(2)); |
| 2907 expect(unlinkedUnits[0].publicNamespace.names[0].kind, | 3076 expect(unlinkedUnits[0].publicNamespace.names[0].kind, |
| 2908 PrelinkedReferenceKind.other); | 3077 PrelinkedReferenceKind.topLevelPropertyAccessor); |
| 2909 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'i'); | 3078 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'i'); |
| 2910 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 0); | 3079 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 0); |
| 2911 expect(unlinkedUnits[0].publicNamespace.names[1].kind, | 3080 expect(unlinkedUnits[0].publicNamespace.names[1].kind, |
| 2912 PrelinkedReferenceKind.other); | 3081 PrelinkedReferenceKind.topLevelPropertyAccessor); |
| 2913 expect(unlinkedUnits[0].publicNamespace.names[1].name, 'i='); | 3082 expect(unlinkedUnits[0].publicNamespace.names[1].name, 'i='); |
| 2914 expect(unlinkedUnits[0].publicNamespace.names[1].numTypeParameters, 0); | 3083 expect(unlinkedUnits[0].publicNamespace.names[1].numTypeParameters, 0); |
| 2915 } | 3084 } |
| 2916 | 3085 |
| 2917 test_variable_const() { | 3086 test_variable_const() { |
| 2918 UnlinkedVariable variable = | 3087 UnlinkedVariable variable = |
| 2919 serializeVariableText('const int i = 0;', variableName: 'i'); | 3088 serializeVariableText('const int i = 0;', variableName: 'i'); |
| 2920 expect(variable.isConst, isTrue); | 3089 expect(variable.isConst, isTrue); |
| 2921 } | 3090 } |
| 2922 | 3091 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2999 UnlinkedVariable variable = | 3168 UnlinkedVariable variable = |
| 3000 serializeVariableText('int i;', variableName: 'i'); | 3169 serializeVariableText('int i;', variableName: 'i'); |
| 3001 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int'); | 3170 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int'); |
| 3002 } | 3171 } |
| 3003 | 3172 |
| 3004 test_varible_private() { | 3173 test_varible_private() { |
| 3005 serializeVariableText('int _i;', variableName: '_i'); | 3174 serializeVariableText('int _i;', variableName: '_i'); |
| 3006 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); | 3175 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); |
| 3007 } | 3176 } |
| 3008 } | 3177 } |
| OLD | NEW |