| 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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 // The element model doesn't (yet) store enough information to recover | 219 // The element model doesn't (yet) store enough information to recover |
| 220 // relative URIs, so we have to use the absolute URI. | 220 // relative URIs, so we have to use the absolute URI. |
| 221 // TODO(paulberry): fix this. | 221 // TODO(paulberry): fix this. |
| 222 relativeUri = absoluteUri; | 222 relativeUri = absoluteUri; |
| 223 } | 223 } |
| 224 expect(dependency, new isInstanceOf<int>()); | 224 expect(dependency, new isInstanceOf<int>()); |
| 225 expect(prelinked.dependencies[dependency].uri, relativeUri); | 225 expect(prelinked.dependencies[dependency].uri, relativeUri); |
| 226 } | 226 } |
| 227 | 227 |
| 228 /** | 228 /** |
| 229 * Check that the given [documentationComment] matches the first |
| 230 * Javadoc-style comment found in [text]. |
| 231 * |
| 232 * Note that the algorithm for finding the Javadoc-style comment in [text] is |
| 233 * a simple-minded text search; it is easily confused by corner cases such as |
| 234 * strings containing comments, nested comments, etc. |
| 235 */ |
| 236 void checkDocumentationComment( |
| 237 UnlinkedDocumentationComment documentationComment, String text) { |
| 238 expect(documentationComment, isNotNull); |
| 239 int commentStart = text.indexOf('/*'); |
| 240 expect(commentStart, isNot(-1)); |
| 241 int commentEnd = text.indexOf('*/'); |
| 242 expect(commentEnd, isNot(-1)); |
| 243 commentEnd += 2; |
| 244 String expectedCommentText = text.substring(commentStart, commentEnd); |
| 245 expect(documentationComment.text, expectedCommentText); |
| 246 } |
| 247 |
| 248 /** |
| 229 * Verify that the given [typeRef] represents the type `dynamic`. | 249 * Verify that the given [typeRef] represents the type `dynamic`. |
| 230 */ | 250 */ |
| 231 void checkDynamicTypeRef(UnlinkedTypeRef typeRef) { | 251 void checkDynamicTypeRef(UnlinkedTypeRef typeRef) { |
| 232 checkTypeRef(typeRef, null, null, null); | 252 checkTypeRef(typeRef, null, null, null); |
| 233 } | 253 } |
| 234 | 254 |
| 235 /** | 255 /** |
| 236 * Verify that the dependency table contains an entry for a file reachable | 256 * Verify that the dependency table contains an entry for a file reachable |
| 237 * via the given [absoluteUri] and [relativeUri]. | 257 * via the given [absoluteUri] and [relativeUri]. |
| 238 */ | 258 */ |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 */ | 381 */ |
| 362 void checkUnresolvedTypeRef( | 382 void checkUnresolvedTypeRef( |
| 363 UnlinkedTypeRef typeRef, String expectedPrefix, String expectedName) { | 383 UnlinkedTypeRef typeRef, String expectedPrefix, String expectedName) { |
| 364 // When serializing from the element model, unresolved type refs lose their | 384 // When serializing from the element model, unresolved type refs lose their |
| 365 // name. | 385 // name. |
| 366 checkTypeRef(typeRef, null, null, checkAstDerivedData ? expectedName : null, | 386 checkTypeRef(typeRef, null, null, checkAstDerivedData ? expectedName : null, |
| 367 expectedPrefix: expectedPrefix, | 387 expectedPrefix: expectedPrefix, |
| 368 expectedKind: PrelinkedReferenceKind.unresolved); | 388 expectedKind: PrelinkedReferenceKind.unresolved); |
| 369 } | 389 } |
| 370 | 390 |
| 391 fail_enum_value_documented() { |
| 392 // TODO(paulberry): currently broken because of dartbug.com/25385 |
| 393 String text = ''' |
| 394 enum E { |
| 395 /** |
| 396 * Docs |
| 397 */ |
| 398 v |
| 399 }'''; |
| 400 UnlinkedEnumValue value = serializeEnumText(text).values[0]; |
| 401 expect(value.documentationComment, isNotNull); |
| 402 checkDocumentationComment(value.documentationComment, text); |
| 403 } |
| 404 |
| 371 fail_test_import_missing() { | 405 fail_test_import_missing() { |
| 372 // TODO(paulberry): At the moment unresolved imports are not included in | 406 // TODO(paulberry): At the moment unresolved imports are not included in |
| 373 // the element model, so we can't pass this test. | 407 // the element model, so we can't pass this test. |
| 374 // Unresolved imports are included since this is necessary for proper | 408 // Unresolved imports are included since this is necessary for proper |
| 375 // dependency tracking. | 409 // dependency tracking. |
| 376 serializeLibraryText('import "foo.dart";', allowErrors: true); | 410 serializeLibraryText('import "foo.dart";', allowErrors: true); |
| 377 // Second import is the implicit import of dart:core | 411 // Second import is the implicit import of dart:core |
| 378 expect(unlinkedUnits[0].imports, hasLength(2)); | 412 expect(unlinkedUnits[0].imports, hasLength(2)); |
| 379 checkDependency( | 413 checkDependency( |
| 380 prelinked.importDependencies[0], absUri('/foo.dart'), 'foo.dart'); | 414 prelinked.importDependencies[0], absUri('/foo.dart'), 'foo.dart'); |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 UnlinkedClass cls = | 751 UnlinkedClass cls = |
| 718 serializeClassText('class C = _D with _E; class _D {} class _E {}'); | 752 serializeClassText('class C = _D with _E; class _D {} class _E {}'); |
| 719 expect(cls.isAbstract, false); | 753 expect(cls.isAbstract, false); |
| 720 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); | 754 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); |
| 721 expect(unlinkedUnits[0].publicNamespace.names[0].kind, | 755 expect(unlinkedUnits[0].publicNamespace.names[0].kind, |
| 722 PrelinkedReferenceKind.classOrEnum); | 756 PrelinkedReferenceKind.classOrEnum); |
| 723 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'C'); | 757 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'C'); |
| 724 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 0); | 758 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 0); |
| 725 } | 759 } |
| 726 | 760 |
| 761 test_class_alias_documented() { |
| 762 String text = ''' |
| 763 // Extra comment so doc comment offset != 0 |
| 764 /** |
| 765 * Docs |
| 766 */ |
| 767 class C = D with E; |
| 768 |
| 769 class D {} |
| 770 class E {}'''; |
| 771 UnlinkedClass cls = serializeClassText(text); |
| 772 expect(cls.documentationComment, isNotNull); |
| 773 checkDocumentationComment(cls.documentationComment, text); |
| 774 } |
| 775 |
| 727 test_class_alias_flag() { | 776 test_class_alias_flag() { |
| 728 UnlinkedClass cls = | 777 UnlinkedClass cls = |
| 729 serializeClassText('class C = D with E; class D {} class E {}'); | 778 serializeClassText('class C = D with E; class D {} class E {}'); |
| 730 expect(cls.isMixinApplication, true); | 779 expect(cls.isMixinApplication, true); |
| 731 } | 780 } |
| 732 | 781 |
| 733 test_class_alias_generic() { | 782 test_class_alias_generic() { |
| 734 serializeClassText('class C<A, B> = _D with _E; class _D {} class _E {}'); | 783 serializeClassText('class C<A, B> = _D with _E; class _D {} class _E {}'); |
| 735 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 2); | 784 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 2); |
| 736 } | 785 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 test_class_concrete() { | 838 test_class_concrete() { |
| 790 UnlinkedClass cls = serializeClassText('class C {}'); | 839 UnlinkedClass cls = serializeClassText('class C {}'); |
| 791 expect(cls.isAbstract, false); | 840 expect(cls.isAbstract, false); |
| 792 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); | 841 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); |
| 793 expect(unlinkedUnits[0].publicNamespace.names[0].kind, | 842 expect(unlinkedUnits[0].publicNamespace.names[0].kind, |
| 794 PrelinkedReferenceKind.classOrEnum); | 843 PrelinkedReferenceKind.classOrEnum); |
| 795 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'C'); | 844 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'C'); |
| 796 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 0); | 845 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 0); |
| 797 } | 846 } |
| 798 | 847 |
| 848 test_class_documented() { |
| 849 String text = ''' |
| 850 // Extra comment so doc comment offset != 0 |
| 851 /** |
| 852 * Docs |
| 853 */ |
| 854 class C {}'''; |
| 855 UnlinkedClass cls = serializeClassText(text); |
| 856 expect(cls.documentationComment, isNotNull); |
| 857 checkDocumentationComment(cls.documentationComment, text); |
| 858 } |
| 859 |
| 860 test_class_documented_with_references() { |
| 861 String text = ''' |
| 862 // Extra comment so doc comment offset != 0 |
| 863 /** |
| 864 * Docs referring to [D] and [E] |
| 865 */ |
| 866 class C {} |
| 867 |
| 868 class D {} |
| 869 class E {}'''; |
| 870 UnlinkedClass cls = serializeClassText(text); |
| 871 expect(cls.documentationComment, isNotNull); |
| 872 checkDocumentationComment(cls.documentationComment, text); |
| 873 } |
| 874 |
| 875 test_class_documented_with_with_windows_line_endings() { |
| 876 String text = '/**\r\n * Docs\r\n */\r\nclass C {}'; |
| 877 String convertedText = text.replaceAll('\r\n', '\n'); |
| 878 UnlinkedClass cls = serializeClassText(text); |
| 879 expect(cls.documentationComment, isNotNull); |
| 880 checkDocumentationComment(cls.documentationComment, convertedText); |
| 881 } |
| 882 |
| 799 test_class_interface() { | 883 test_class_interface() { |
| 800 UnlinkedClass cls = serializeClassText(''' | 884 UnlinkedClass cls = serializeClassText(''' |
| 801 class C implements D {} | 885 class C implements D {} |
| 802 class D {} | 886 class D {} |
| 803 '''); | 887 '''); |
| 804 expect(cls.interfaces, hasLength(1)); | 888 expect(cls.interfaces, hasLength(1)); |
| 805 checkTypeRef(cls.interfaces[0], null, null, 'D'); | 889 checkTypeRef(cls.interfaces[0], null, null, 'D'); |
| 806 } | 890 } |
| 807 | 891 |
| 808 test_class_interface_order() { | 892 test_class_interface_order() { |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 956 } | 1040 } |
| 957 | 1041 |
| 958 test_constructor_const_external() { | 1042 test_constructor_const_external() { |
| 959 UnlinkedExecutable executable = findExecutable('', | 1043 UnlinkedExecutable executable = findExecutable('', |
| 960 executables: | 1044 executables: |
| 961 serializeClassText('class C { external const C(); }').executables); | 1045 serializeClassText('class C { external const C(); }').executables); |
| 962 expect(executable.isConst, isTrue); | 1046 expect(executable.isConst, isTrue); |
| 963 expect(executable.isExternal, isTrue); | 1047 expect(executable.isExternal, isTrue); |
| 964 } | 1048 } |
| 965 | 1049 |
| 1050 test_constructor_documented() { |
| 1051 String text = ''' |
| 1052 class C { |
| 1053 /** |
| 1054 * Docs |
| 1055 */ |
| 1056 C(); |
| 1057 }'''; |
| 1058 UnlinkedExecutable executable = serializeClassText(text).executables[0]; |
| 1059 expect(executable.documentationComment, isNotNull); |
| 1060 checkDocumentationComment(executable.documentationComment, text); |
| 1061 } |
| 1062 |
| 966 test_constructor_external() { | 1063 test_constructor_external() { |
| 967 UnlinkedExecutable executable = findExecutable('', | 1064 UnlinkedExecutable executable = findExecutable('', |
| 968 executables: | 1065 executables: |
| 969 serializeClassText('class C { external C(); }').executables); | 1066 serializeClassText('class C { external C(); }').executables); |
| 970 expect(executable.isExternal, isTrue); | 1067 expect(executable.isExternal, isTrue); |
| 971 } | 1068 } |
| 972 | 1069 |
| 973 test_constructor_factory() { | 1070 test_constructor_factory() { |
| 974 UnlinkedExecutable executable = findExecutable('', | 1071 UnlinkedExecutable executable = findExecutable('', |
| 975 executables: | 1072 executables: |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1262 expect(e.values, hasLength(1)); | 1359 expect(e.values, hasLength(1)); |
| 1263 expect(e.values[0].name, 'v1'); | 1360 expect(e.values[0].name, 'v1'); |
| 1264 expect(e.values[0].nameOffset, text.indexOf('v1')); | 1361 expect(e.values[0].nameOffset, text.indexOf('v1')); |
| 1265 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); | 1362 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); |
| 1266 expect(unlinkedUnits[0].publicNamespace.names[0].kind, | 1363 expect(unlinkedUnits[0].publicNamespace.names[0].kind, |
| 1267 PrelinkedReferenceKind.classOrEnum); | 1364 PrelinkedReferenceKind.classOrEnum); |
| 1268 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'E'); | 1365 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'E'); |
| 1269 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 0); | 1366 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 0); |
| 1270 } | 1367 } |
| 1271 | 1368 |
| 1369 test_enum_documented() { |
| 1370 String text = ''' |
| 1371 // Extra comment so doc comment offset != 0 |
| 1372 /** |
| 1373 * Docs |
| 1374 */ |
| 1375 enum E { v }'''; |
| 1376 UnlinkedEnum enm = serializeEnumText(text); |
| 1377 expect(enm.documentationComment, isNotNull); |
| 1378 checkDocumentationComment(enm.documentationComment, text); |
| 1379 } |
| 1380 |
| 1272 test_enum_order() { | 1381 test_enum_order() { |
| 1273 UnlinkedEnum e = serializeEnumText('enum E { v1, v2 }'); | 1382 UnlinkedEnum e = serializeEnumText('enum E { v1, v2 }'); |
| 1274 expect(e.values, hasLength(2)); | 1383 expect(e.values, hasLength(2)); |
| 1275 expect(e.values[0].name, 'v1'); | 1384 expect(e.values[0].name, 'v1'); |
| 1276 expect(e.values[1].name, 'v2'); | 1385 expect(e.values[1].name, 'v2'); |
| 1277 } | 1386 } |
| 1278 | 1387 |
| 1279 test_enum_private() { | 1388 test_enum_private() { |
| 1280 serializeEnumText('enum _E { v1 }', '_E'); | 1389 serializeEnumText('enum _E { v1 }', '_E'); |
| 1281 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); | 1390 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); |
| (...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1819 expect(findExecutable('i', executables: cls.executables), isNull); | 1928 expect(findExecutable('i', executables: cls.executables), isNull); |
| 1820 expect(findExecutable('i=', executables: cls.executables), isNull); | 1929 expect(findExecutable('i=', executables: cls.executables), isNull); |
| 1821 } | 1930 } |
| 1822 | 1931 |
| 1823 test_field_const() { | 1932 test_field_const() { |
| 1824 UnlinkedVariable variable = | 1933 UnlinkedVariable variable = |
| 1825 serializeClassText('class C { static const int i = 0; }').fields[0]; | 1934 serializeClassText('class C { static const int i = 0; }').fields[0]; |
| 1826 expect(variable.isConst, isTrue); | 1935 expect(variable.isConst, isTrue); |
| 1827 } | 1936 } |
| 1828 | 1937 |
| 1938 test_field_documented() { |
| 1939 String text = ''' |
| 1940 class C { |
| 1941 /** |
| 1942 * Docs |
| 1943 */ |
| 1944 var v; |
| 1945 }'''; |
| 1946 UnlinkedVariable variable = serializeClassText(text).fields[0]; |
| 1947 expect(variable.documentationComment, isNotNull); |
| 1948 checkDocumentationComment(variable.documentationComment, text); |
| 1949 } |
| 1950 |
| 1829 test_field_final() { | 1951 test_field_final() { |
| 1830 UnlinkedVariable variable = | 1952 UnlinkedVariable variable = |
| 1831 serializeClassText('class C { final int i = 0; }').fields[0]; | 1953 serializeClassText('class C { final int i = 0; }').fields[0]; |
| 1832 expect(variable.isFinal, isTrue); | 1954 expect(variable.isFinal, isTrue); |
| 1833 } | 1955 } |
| 1834 | 1956 |
| 1835 test_field_static() { | 1957 test_field_static() { |
| 1836 UnlinkedVariable variable = | 1958 UnlinkedVariable variable = |
| 1837 serializeClassText('class C { static int i; }').fields[0]; | 1959 serializeClassText('class C { static int i; }').fields[0]; |
| 1838 expect(variable.isStatic, isTrue); | 1960 expect(variable.isStatic, isTrue); |
| 1839 } | 1961 } |
| 1840 | 1962 |
| 1963 test_function_documented() { |
| 1964 String text = ''' |
| 1965 // Extra comment so doc comment offset != 0 |
| 1966 /** |
| 1967 * Docs |
| 1968 */ |
| 1969 f() {}'''; |
| 1970 UnlinkedExecutable executable = serializeExecutableText(text); |
| 1971 expect(executable.documentationComment, isNotNull); |
| 1972 checkDocumentationComment(executable.documentationComment, text); |
| 1973 } |
| 1974 |
| 1841 test_generic_method_in_generic_class() { | 1975 test_generic_method_in_generic_class() { |
| 1842 UnlinkedClass cls = serializeClassText( | 1976 UnlinkedClass cls = serializeClassText( |
| 1843 'class C<T, U> { void m<V, W>(T t, U u, V v, W w) {} }'); | 1977 'class C<T, U> { void m<V, W>(T t, U u, V v, W w) {} }'); |
| 1844 List<UnlinkedParam> params = cls.executables[0].parameters; | 1978 List<UnlinkedParam> params = cls.executables[0].parameters; |
| 1845 checkParamTypeRef(params[0].type, 4); | 1979 checkParamTypeRef(params[0].type, 4); |
| 1846 checkParamTypeRef(params[1].type, 3); | 1980 checkParamTypeRef(params[1].type, 3); |
| 1847 checkParamTypeRef(params[2].type, 2); | 1981 checkParamTypeRef(params[2].type, 2); |
| 1848 checkParamTypeRef(params[3].type, 1); | 1982 checkParamTypeRef(params[3].type, 1); |
| 1849 } | 1983 } |
| 1850 | 1984 |
| 1985 test_getter_documented() { |
| 1986 String text = ''' |
| 1987 // Extra comment so doc comment offset != 0 |
| 1988 /** |
| 1989 * Docs |
| 1990 */ |
| 1991 get f => null;'''; |
| 1992 UnlinkedExecutable executable = serializeExecutableText(text); |
| 1993 expect(executable.documentationComment, isNotNull); |
| 1994 checkDocumentationComment(executable.documentationComment, text); |
| 1995 } |
| 1996 |
| 1851 test_import_deferred() { | 1997 test_import_deferred() { |
| 1852 serializeLibraryText( | 1998 serializeLibraryText( |
| 1853 'import "dart:async" deferred as a; main() { print(a.Future); }'); | 1999 'import "dart:async" deferred as a; main() { print(a.Future); }'); |
| 1854 expect(unlinkedUnits[0].imports[0].isDeferred, isTrue); | 2000 expect(unlinkedUnits[0].imports[0].isDeferred, isTrue); |
| 1855 } | 2001 } |
| 1856 | 2002 |
| 1857 test_import_dependency() { | 2003 test_import_dependency() { |
| 1858 serializeLibraryText('import "dart:async"; Future x;'); | 2004 serializeLibraryText('import "dart:async"; Future x;'); |
| 1859 // Second import is the implicit import of dart:core | 2005 // Second import is the implicit import of dart:core |
| 1860 expect(unlinkedUnits[0].imports, hasLength(2)); | 2006 expect(unlinkedUnits[0].imports, hasLength(2)); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2017 | 2163 |
| 2018 test_import_uri() { | 2164 test_import_uri() { |
| 2019 String uriString = '"dart:async"'; | 2165 String uriString = '"dart:async"'; |
| 2020 String libraryText = 'import $uriString; Future x;'; | 2166 String libraryText = 'import $uriString; Future x;'; |
| 2021 serializeLibraryText(libraryText); | 2167 serializeLibraryText(libraryText); |
| 2022 // Second import is the implicit import of dart:core | 2168 // Second import is the implicit import of dart:core |
| 2023 expect(unlinkedUnits[0].imports, hasLength(2)); | 2169 expect(unlinkedUnits[0].imports, hasLength(2)); |
| 2024 expect(unlinkedUnits[0].imports[0].uri, 'dart:async'); | 2170 expect(unlinkedUnits[0].imports[0].uri, 'dart:async'); |
| 2025 } | 2171 } |
| 2026 | 2172 |
| 2173 test_library_documented() { |
| 2174 String text = ''' |
| 2175 // Extra comment so doc comment offset != 0 |
| 2176 /** |
| 2177 * Docs |
| 2178 */ |
| 2179 library foo;'''; |
| 2180 serializeLibraryText(text); |
| 2181 expect(unlinkedUnits[0].libraryDocumentationComment, isNotNull); |
| 2182 checkDocumentationComment( |
| 2183 unlinkedUnits[0].libraryDocumentationComment, text); |
| 2184 } |
| 2185 |
| 2027 test_library_name_with_spaces() { | 2186 test_library_name_with_spaces() { |
| 2028 String text = 'library foo . bar ;'; | 2187 String text = 'library foo . bar ;'; |
| 2029 serializeLibraryText(text); | 2188 serializeLibraryText(text); |
| 2030 expect(unlinkedUnits[0].libraryName, 'foo.bar'); | 2189 expect(unlinkedUnits[0].libraryName, 'foo.bar'); |
| 2031 expect(unlinkedUnits[0].libraryNameOffset, text.indexOf('foo . bar')); | 2190 expect(unlinkedUnits[0].libraryNameOffset, text.indexOf('foo . bar')); |
| 2032 expect(unlinkedUnits[0].libraryNameLength, 'foo . bar'.length); | 2191 expect(unlinkedUnits[0].libraryNameLength, 'foo . bar'.length); |
| 2033 } | 2192 } |
| 2034 | 2193 |
| 2035 test_library_named() { | 2194 test_library_named() { |
| 2036 String text = 'library foo.bar;'; | 2195 String text = 'library foo.bar;'; |
| 2037 serializeLibraryText(text); | 2196 serializeLibraryText(text); |
| 2038 expect(unlinkedUnits[0].libraryName, 'foo.bar'); | 2197 expect(unlinkedUnits[0].libraryName, 'foo.bar'); |
| 2039 expect(unlinkedUnits[0].libraryNameOffset, text.indexOf('foo.bar')); | 2198 expect(unlinkedUnits[0].libraryNameOffset, text.indexOf('foo.bar')); |
| 2040 expect(unlinkedUnits[0].libraryNameLength, 'foo.bar'.length); | 2199 expect(unlinkedUnits[0].libraryNameLength, 'foo.bar'.length); |
| 2041 } | 2200 } |
| 2042 | 2201 |
| 2043 test_library_unnamed() { | 2202 test_library_unnamed() { |
| 2044 serializeLibraryText(''); | 2203 serializeLibraryText(''); |
| 2045 expect(unlinkedUnits[0].libraryName, isEmpty); | 2204 expect(unlinkedUnits[0].libraryName, isEmpty); |
| 2046 expect(unlinkedUnits[0].libraryNameOffset, 0); | 2205 expect(unlinkedUnits[0].libraryNameOffset, 0); |
| 2047 expect(unlinkedUnits[0].libraryNameLength, 0); | 2206 expect(unlinkedUnits[0].libraryNameLength, 0); |
| 2048 } | 2207 } |
| 2049 | 2208 |
| 2209 test_method_documented() { |
| 2210 String text = ''' |
| 2211 class C { |
| 2212 /** |
| 2213 * Docs |
| 2214 */ |
| 2215 f() {} |
| 2216 }'''; |
| 2217 UnlinkedExecutable executable = serializeClassText(text).executables[0]; |
| 2218 expect(executable.documentationComment, isNotNull); |
| 2219 checkDocumentationComment(executable.documentationComment, text); |
| 2220 } |
| 2221 |
| 2050 test_part_declaration() { | 2222 test_part_declaration() { |
| 2051 addNamedSource('/a.dart', 'part of my.lib;'); | 2223 addNamedSource('/a.dart', 'part of my.lib;'); |
| 2052 String text = 'library my.lib; part "a.dart"; // <-part'; | 2224 String text = 'library my.lib; part "a.dart"; // <-part'; |
| 2053 serializeLibraryText(text); | 2225 serializeLibraryText(text); |
| 2054 expect(unlinkedUnits[0].publicNamespace.parts, hasLength(1)); | 2226 expect(unlinkedUnits[0].publicNamespace.parts, hasLength(1)); |
| 2055 expect(unlinkedUnits[0].publicNamespace.parts[0], 'a.dart'); | 2227 expect(unlinkedUnits[0].publicNamespace.parts[0], 'a.dart'); |
| 2056 expect(unlinkedUnits[0].parts, hasLength(1)); | 2228 expect(unlinkedUnits[0].parts, hasLength(1)); |
| 2057 expect(unlinkedUnits[0].parts[0].uriOffset, text.indexOf('"a.dart"')); | 2229 expect(unlinkedUnits[0].parts[0].uriOffset, text.indexOf('"a.dart"')); |
| 2058 expect(unlinkedUnits[0].parts[0].uriEnd, text.indexOf('; // <-part')); | 2230 expect(unlinkedUnits[0].parts[0].uriEnd, text.indexOf('; // <-part')); |
| 2059 } | 2231 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2075 } | 2247 } |
| 2076 | 2248 |
| 2077 test_public_namespace_of_part() { | 2249 test_public_namespace_of_part() { |
| 2078 addNamedSource('/a.dart', 'part of foo; class C {}'); | 2250 addNamedSource('/a.dart', 'part of foo; class C {}'); |
| 2079 serializeLibraryText('library foo; part "a.dart";'); | 2251 serializeLibraryText('library foo; part "a.dart";'); |
| 2080 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); | 2252 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); |
| 2081 expect(unlinkedUnits[1].publicNamespace.names, hasLength(1)); | 2253 expect(unlinkedUnits[1].publicNamespace.names, hasLength(1)); |
| 2082 expect(unlinkedUnits[1].publicNamespace.names[0].name, 'C'); | 2254 expect(unlinkedUnits[1].publicNamespace.names[0].name, 'C'); |
| 2083 } | 2255 } |
| 2084 | 2256 |
| 2257 test_setter_documented() { |
| 2258 String text = ''' |
| 2259 // Extra comment so doc comment offset != 0 |
| 2260 /** |
| 2261 * Docs |
| 2262 */ |
| 2263 void set f(value) {}'''; |
| 2264 UnlinkedExecutable executable = serializeExecutableText(text, 'f='); |
| 2265 expect(executable.documentationComment, isNotNull); |
| 2266 checkDocumentationComment(executable.documentationComment, text); |
| 2267 } |
| 2268 |
| 2085 test_type_arguments_explicit() { | 2269 test_type_arguments_explicit() { |
| 2086 UnlinkedTypeRef typeRef = serializeTypeText('List<int>'); | 2270 UnlinkedTypeRef typeRef = serializeTypeText('List<int>'); |
| 2087 checkTypeRef(typeRef, 'dart:core', 'dart:core', 'List', | 2271 checkTypeRef(typeRef, 'dart:core', 'dart:core', 'List', |
| 2088 allowTypeParameters: true, numTypeParameters: 1); | 2272 allowTypeParameters: true, numTypeParameters: 1); |
| 2089 expect(typeRef.typeArguments, hasLength(1)); | 2273 expect(typeRef.typeArguments, hasLength(1)); |
| 2090 checkTypeRef(typeRef.typeArguments[0], 'dart:core', 'dart:core', 'int'); | 2274 checkTypeRef(typeRef.typeArguments[0], 'dart:core', 'dart:core', 'int'); |
| 2091 } | 2275 } |
| 2092 | 2276 |
| 2093 test_type_arguments_explicit_dynamic() { | 2277 test_type_arguments_explicit_dynamic() { |
| 2094 UnlinkedTypeRef typeRef = serializeTypeText('List<dynamic>'); | 2278 UnlinkedTypeRef typeRef = serializeTypeText('List<dynamic>'); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2276 // from them. | 2460 // from them. |
| 2277 checkTypeRef(typeRef, absUri('/a.dart'), 'a.dart', 'C', | 2461 checkTypeRef(typeRef, absUri('/a.dart'), 'a.dart', 'C', |
| 2278 expectedTargetUnit: 2); | 2462 expectedTargetUnit: 2); |
| 2279 } | 2463 } |
| 2280 | 2464 |
| 2281 test_type_unresolved() { | 2465 test_type_unresolved() { |
| 2282 UnlinkedTypeRef typeRef = serializeTypeText('Foo', allowErrors: true); | 2466 UnlinkedTypeRef typeRef = serializeTypeText('Foo', allowErrors: true); |
| 2283 checkUnresolvedTypeRef(typeRef, null, 'Foo'); | 2467 checkUnresolvedTypeRef(typeRef, null, 'Foo'); |
| 2284 } | 2468 } |
| 2285 | 2469 |
| 2470 test_typedef_documented() { |
| 2471 String text = ''' |
| 2472 // Extra comment so doc comment offset != 0 |
| 2473 /** |
| 2474 * Docs |
| 2475 */ |
| 2476 typedef F();'''; |
| 2477 UnlinkedTypedef typedef = serializeTypedefText(text); |
| 2478 expect(typedef.documentationComment, isNotNull); |
| 2479 checkDocumentationComment(typedef.documentationComment, text); |
| 2480 } |
| 2481 |
| 2286 test_typedef_name() { | 2482 test_typedef_name() { |
| 2287 String text = 'typedef F();'; | 2483 String text = 'typedef F();'; |
| 2288 UnlinkedTypedef type = serializeTypedefText(text); | 2484 UnlinkedTypedef type = serializeTypedefText(text); |
| 2289 expect(type.name, 'F'); | 2485 expect(type.name, 'F'); |
| 2290 expect(type.nameOffset, text.indexOf('F')); | 2486 expect(type.nameOffset, text.indexOf('F')); |
| 2291 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); | 2487 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); |
| 2292 expect(unlinkedUnits[0].publicNamespace.names[0].kind, | 2488 expect(unlinkedUnits[0].publicNamespace.names[0].kind, |
| 2293 PrelinkedReferenceKind.typedef); | 2489 PrelinkedReferenceKind.typedef); |
| 2294 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'F'); | 2490 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'F'); |
| 2295 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 0); | 2491 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 0); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2371 expect(unlinkedUnits[0].publicNamespace.names[1].name, 'i='); | 2567 expect(unlinkedUnits[0].publicNamespace.names[1].name, 'i='); |
| 2372 expect(unlinkedUnits[0].publicNamespace.names[1].numTypeParameters, 0); | 2568 expect(unlinkedUnits[0].publicNamespace.names[1].numTypeParameters, 0); |
| 2373 } | 2569 } |
| 2374 | 2570 |
| 2375 test_variable_const() { | 2571 test_variable_const() { |
| 2376 UnlinkedVariable variable = | 2572 UnlinkedVariable variable = |
| 2377 serializeVariableText('const int i = 0;', variableName: 'i'); | 2573 serializeVariableText('const int i = 0;', variableName: 'i'); |
| 2378 expect(variable.isConst, isTrue); | 2574 expect(variable.isConst, isTrue); |
| 2379 } | 2575 } |
| 2380 | 2576 |
| 2577 test_variable_documented() { |
| 2578 String text = ''' |
| 2579 // Extra comment so doc comment offset != 0 |
| 2580 /** |
| 2581 * Docs |
| 2582 */ |
| 2583 var v;'''; |
| 2584 UnlinkedVariable variable = serializeVariableText(text); |
| 2585 expect(variable.documentationComment, isNotNull); |
| 2586 checkDocumentationComment(variable.documentationComment, text); |
| 2587 } |
| 2588 |
| 2381 test_variable_explicit_dynamic() { | 2589 test_variable_explicit_dynamic() { |
| 2382 UnlinkedVariable variable = serializeVariableText('dynamic v;'); | 2590 UnlinkedVariable variable = serializeVariableText('dynamic v;'); |
| 2383 checkDynamicTypeRef(variable.type); | 2591 checkDynamicTypeRef(variable.type); |
| 2384 expect(variable.hasImplicitType, isFalse); | 2592 expect(variable.hasImplicitType, isFalse); |
| 2385 } | 2593 } |
| 2386 | 2594 |
| 2387 test_variable_final_top_level() { | 2595 test_variable_final_top_level() { |
| 2388 UnlinkedVariable variable = | 2596 UnlinkedVariable variable = |
| 2389 serializeVariableText('final int i = 0;', variableName: 'i'); | 2597 serializeVariableText('final int i = 0;', variableName: 'i'); |
| 2390 expect(variable.isFinal, isTrue); | 2598 expect(variable.isFinal, isTrue); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2445 UnlinkedVariable variable = | 2653 UnlinkedVariable variable = |
| 2446 serializeVariableText('int i;', variableName: 'i'); | 2654 serializeVariableText('int i;', variableName: 'i'); |
| 2447 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int'); | 2655 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int'); |
| 2448 } | 2656 } |
| 2449 | 2657 |
| 2450 test_varible_private() { | 2658 test_varible_private() { |
| 2451 serializeVariableText('int _i;', variableName: '_i'); | 2659 serializeVariableText('int _i;', variableName: '_i'); |
| 2452 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); | 2660 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); |
| 2453 } | 2661 } |
| 2454 } | 2662 } |
| OLD | NEW |