| 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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 return FileUtilities2.createFile(path).toURI().toString(); | 203 return FileUtilities2.createFile(path).toURI().toString(); |
| 204 } | 204 } |
| 205 | 205 |
| 206 /** | 206 /** |
| 207 * Add the given source file so that it may be referenced by the file under | 207 * Add the given source file so that it may be referenced by the file under |
| 208 * test. | 208 * test. |
| 209 */ | 209 */ |
| 210 addNamedSource(String filePath, String contents); | 210 addNamedSource(String filePath, String contents); |
| 211 | 211 |
| 212 /** | 212 /** |
| 213 * Verify that the [combinatorName] correctly represents the given [expected] | |
| 214 * name. | |
| 215 */ | |
| 216 void checkCombinatorName( | |
| 217 UnlinkedCombinatorName combinatorName, String expected) { | |
| 218 expect(combinatorName, new isInstanceOf<UnlinkedCombinatorName>()); | |
| 219 expect(combinatorName.name, expected); | |
| 220 } | |
| 221 | |
| 222 /** | |
| 223 * Verify that the [dependency]th element of the dependency table represents | 213 * Verify that the [dependency]th element of the dependency table represents |
| 224 * a file reachable via the given [absoluteUri] and [relativeUri]. | 214 * a file reachable via the given [absoluteUri] and [relativeUri]. |
| 225 */ | 215 */ |
| 226 void checkDependency(int dependency, String absoluteUri, String relativeUri) { | 216 void checkDependency(int dependency, String absoluteUri, String relativeUri) { |
| 227 if (!checkAstDerivedData) { | 217 if (!checkAstDerivedData) { |
| 228 // The element model doesn't (yet) store enough information to recover | 218 // The element model doesn't (yet) store enough information to recover |
| 229 // relative URIs, so we have to use the absolute URI. | 219 // relative URIs, so we have to use the absolute URI. |
| 230 // TODO(paulberry): fix this. | 220 // TODO(paulberry): fix this. |
| 231 relativeUri = absoluteUri; | 221 relativeUri = absoluteUri; |
| 232 } | 222 } |
| (...skipping 1463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1696 | 1686 |
| 1697 test_export_hide_order() { | 1687 test_export_hide_order() { |
| 1698 serializeLibraryText('export "dart:async" hide Future, Stream;'); | 1688 serializeLibraryText('export "dart:async" hide Future, Stream;'); |
| 1699 expect(unlinkedUnits[0].publicNamespace.exports, hasLength(1)); | 1689 expect(unlinkedUnits[0].publicNamespace.exports, hasLength(1)); |
| 1700 expect( | 1690 expect( |
| 1701 unlinkedUnits[0].publicNamespace.exports[0].combinators, hasLength(1)); | 1691 unlinkedUnits[0].publicNamespace.exports[0].combinators, hasLength(1)); |
| 1702 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].shows, | 1692 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].shows, |
| 1703 isEmpty); | 1693 isEmpty); |
| 1704 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].hides, | 1694 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].hides, |
| 1705 hasLength(2)); | 1695 hasLength(2)); |
| 1706 checkCombinatorName( | 1696 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].hides[0], |
| 1707 unlinkedUnits[0].publicNamespace.exports[0].combinators[0].hides[0], | |
| 1708 'Future'); | 1697 'Future'); |
| 1709 checkCombinatorName( | 1698 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].hides[1], |
| 1710 unlinkedUnits[0].publicNamespace.exports[0].combinators[0].hides[1], | |
| 1711 'Stream'); | 1699 'Stream'); |
| 1712 } | 1700 } |
| 1713 | 1701 |
| 1714 test_export_no_combinators() { | 1702 test_export_no_combinators() { |
| 1715 serializeLibraryText('export "dart:async";'); | 1703 serializeLibraryText('export "dart:async";'); |
| 1716 expect(unlinkedUnits[0].publicNamespace.exports, hasLength(1)); | 1704 expect(unlinkedUnits[0].publicNamespace.exports, hasLength(1)); |
| 1717 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators, isEmpty); | 1705 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators, isEmpty); |
| 1718 } | 1706 } |
| 1719 | 1707 |
| 1720 test_export_show_order() { | 1708 test_export_show_order() { |
| 1721 serializeLibraryText('export "dart:async" show Future, Stream;'); | 1709 serializeLibraryText('export "dart:async" show Future, Stream;'); |
| 1722 expect(unlinkedUnits[0].publicNamespace.exports, hasLength(1)); | 1710 expect(unlinkedUnits[0].publicNamespace.exports, hasLength(1)); |
| 1723 expect( | 1711 expect( |
| 1724 unlinkedUnits[0].publicNamespace.exports[0].combinators, hasLength(1)); | 1712 unlinkedUnits[0].publicNamespace.exports[0].combinators, hasLength(1)); |
| 1725 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].shows, | 1713 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].shows, |
| 1726 hasLength(2)); | 1714 hasLength(2)); |
| 1727 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].hides, | 1715 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].hides, |
| 1728 isEmpty); | 1716 isEmpty); |
| 1729 checkCombinatorName( | 1717 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].shows[0], |
| 1730 unlinkedUnits[0].publicNamespace.exports[0].combinators[0].shows[0], | |
| 1731 'Future'); | 1718 'Future'); |
| 1732 checkCombinatorName( | 1719 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].shows[1], |
| 1733 unlinkedUnits[0].publicNamespace.exports[0].combinators[0].shows[1], | |
| 1734 'Stream'); | 1720 'Stream'); |
| 1735 } | 1721 } |
| 1736 | 1722 |
| 1737 test_export_uri() { | 1723 test_export_uri() { |
| 1738 addNamedSource('/a.dart', 'library my.lib;'); | 1724 addNamedSource('/a.dart', 'library my.lib;'); |
| 1739 String uriString = '"a.dart"'; | 1725 String uriString = '"a.dart"'; |
| 1740 String libraryText = 'export $uriString;'; | 1726 String libraryText = 'export $uriString;'; |
| 1741 serializeLibraryText(libraryText); | 1727 serializeLibraryText(libraryText); |
| 1742 expect(unlinkedUnits[0].publicNamespace.exports, hasLength(1)); | 1728 expect(unlinkedUnits[0].publicNamespace.exports, hasLength(1)); |
| 1743 expect(unlinkedUnits[0].publicNamespace.exports[0].uri, 'a.dart'); | 1729 expect(unlinkedUnits[0].publicNamespace.exports[0].uri, 'a.dart'); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1803 } | 1789 } |
| 1804 | 1790 |
| 1805 test_import_hide_order() { | 1791 test_import_hide_order() { |
| 1806 serializeLibraryText( | 1792 serializeLibraryText( |
| 1807 'import "dart:async" hide Future, Stream; Completer c;'); | 1793 'import "dart:async" hide Future, Stream; Completer c;'); |
| 1808 // Second import is the implicit import of dart:core | 1794 // Second import is the implicit import of dart:core |
| 1809 expect(unlinkedUnits[0].imports, hasLength(2)); | 1795 expect(unlinkedUnits[0].imports, hasLength(2)); |
| 1810 expect(unlinkedUnits[0].imports[0].combinators, hasLength(1)); | 1796 expect(unlinkedUnits[0].imports[0].combinators, hasLength(1)); |
| 1811 expect(unlinkedUnits[0].imports[0].combinators[0].shows, isEmpty); | 1797 expect(unlinkedUnits[0].imports[0].combinators[0].shows, isEmpty); |
| 1812 expect(unlinkedUnits[0].imports[0].combinators[0].hides, hasLength(2)); | 1798 expect(unlinkedUnits[0].imports[0].combinators[0].hides, hasLength(2)); |
| 1813 checkCombinatorName( | 1799 expect(unlinkedUnits[0].imports[0].combinators[0].hides[0], 'Future'); |
| 1814 unlinkedUnits[0].imports[0].combinators[0].hides[0], 'Future'); | 1800 expect(unlinkedUnits[0].imports[0].combinators[0].hides[1], 'Stream'); |
| 1815 checkCombinatorName( | |
| 1816 unlinkedUnits[0].imports[0].combinators[0].hides[1], 'Stream'); | |
| 1817 } | 1801 } |
| 1818 | 1802 |
| 1819 test_import_implicit() { | 1803 test_import_implicit() { |
| 1820 // The implicit import of dart:core is represented in the model. | 1804 // The implicit import of dart:core is represented in the model. |
| 1821 serializeLibraryText(''); | 1805 serializeLibraryText(''); |
| 1822 expect(unlinkedUnits[0].imports, hasLength(1)); | 1806 expect(unlinkedUnits[0].imports, hasLength(1)); |
| 1823 checkDependency(prelinked.importDependencies[0], 'dart:core', 'dart:core'); | 1807 checkDependency(prelinked.importDependencies[0], 'dart:core', 'dart:core'); |
| 1824 expect(unlinkedUnits[0].imports[0].uri, isEmpty); | 1808 expect(unlinkedUnits[0].imports[0].uri, isEmpty); |
| 1825 expect(unlinkedUnits[0].imports[0].prefixReference, 0); | 1809 expect(unlinkedUnits[0].imports[0].prefixReference, 0); |
| 1826 expect(unlinkedUnits[0].imports[0].combinators, isEmpty); | 1810 expect(unlinkedUnits[0].imports[0].combinators, isEmpty); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1931 | 1915 |
| 1932 test_import_show_order() { | 1916 test_import_show_order() { |
| 1933 String libraryText = | 1917 String libraryText = |
| 1934 'import "dart:async" show Future, Stream; Future x; Stream y;'; | 1918 'import "dart:async" show Future, Stream; Future x; Stream y;'; |
| 1935 serializeLibraryText(libraryText); | 1919 serializeLibraryText(libraryText); |
| 1936 // Second import is the implicit import of dart:core | 1920 // Second import is the implicit import of dart:core |
| 1937 expect(unlinkedUnits[0].imports, hasLength(2)); | 1921 expect(unlinkedUnits[0].imports, hasLength(2)); |
| 1938 expect(unlinkedUnits[0].imports[0].combinators, hasLength(1)); | 1922 expect(unlinkedUnits[0].imports[0].combinators, hasLength(1)); |
| 1939 expect(unlinkedUnits[0].imports[0].combinators[0].shows, hasLength(2)); | 1923 expect(unlinkedUnits[0].imports[0].combinators[0].shows, hasLength(2)); |
| 1940 expect(unlinkedUnits[0].imports[0].combinators[0].hides, isEmpty); | 1924 expect(unlinkedUnits[0].imports[0].combinators[0].hides, isEmpty); |
| 1941 checkCombinatorName( | 1925 expect(unlinkedUnits[0].imports[0].combinators[0].shows[0], 'Future'); |
| 1942 unlinkedUnits[0].imports[0].combinators[0].shows[0], 'Future'); | 1926 expect(unlinkedUnits[0].imports[0].combinators[0].shows[1], 'Stream'); |
| 1943 checkCombinatorName( | |
| 1944 unlinkedUnits[0].imports[0].combinators[0].shows[1], 'Stream'); | |
| 1945 } | 1927 } |
| 1946 | 1928 |
| 1947 test_import_uri() { | 1929 test_import_uri() { |
| 1948 String uriString = '"dart:async"'; | 1930 String uriString = '"dart:async"'; |
| 1949 String libraryText = 'import $uriString; Future x;'; | 1931 String libraryText = 'import $uriString; Future x;'; |
| 1950 serializeLibraryText(libraryText); | 1932 serializeLibraryText(libraryText); |
| 1951 // Second import is the implicit import of dart:core | 1933 // Second import is the implicit import of dart:core |
| 1952 expect(unlinkedUnits[0].imports, hasLength(2)); | 1934 expect(unlinkedUnits[0].imports, hasLength(2)); |
| 1953 expect(unlinkedUnits[0].imports[0].uri, 'dart:async'); | 1935 expect(unlinkedUnits[0].imports[0].uri, 'dart:async'); |
| 1954 } | 1936 } |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2328 UnlinkedVariable variable = | 2310 UnlinkedVariable variable = |
| 2329 serializeVariableText('int i;', variableName: 'i'); | 2311 serializeVariableText('int i;', variableName: 'i'); |
| 2330 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int'); | 2312 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int'); |
| 2331 } | 2313 } |
| 2332 | 2314 |
| 2333 test_varible_private() { | 2315 test_varible_private() { |
| 2334 serializeVariableText('int _i;', variableName: '_i'); | 2316 serializeVariableText('int _i;', variableName: '_i'); |
| 2335 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); | 2317 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); |
| 2336 } | 2318 } |
| 2337 } | 2319 } |
| OLD | NEW |