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

Side by Side Diff: pkg/analyzer/test/src/summary/summary_test.dart

Issue 1569033002: Add Element.nameOffset and LibraryElement.nameLength to summaries. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 822 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 '''); 833 ''');
834 expect(cls.mixins, hasLength(2)); 834 expect(cls.mixins, hasLength(2));
835 checkTypeRef(cls.mixins[0], null, null, 'D'); 835 checkTypeRef(cls.mixins[0], null, null, 'D');
836 checkTypeRef(cls.mixins[1], null, null, 'E'); 836 checkTypeRef(cls.mixins[1], null, null, 'E');
837 } 837 }
838 838
839 test_class_name() { 839 test_class_name() {
840 var classText = 'class C {}'; 840 var classText = 'class C {}';
841 UnlinkedClass cls = serializeClassText(classText); 841 UnlinkedClass cls = serializeClassText(classText);
842 expect(cls.name, 'C'); 842 expect(cls.name, 'C');
843 expect(cls.nameOffset, classText.indexOf('C'));
843 } 844 }
844 845
845 test_class_no_flags() { 846 test_class_no_flags() {
846 UnlinkedClass cls = serializeClassText('class C {}'); 847 UnlinkedClass cls = serializeClassText('class C {}');
847 expect(cls.isAbstract, false); 848 expect(cls.isAbstract, false);
848 expect(cls.isMixinApplication, false); 849 expect(cls.isMixinApplication, false);
849 } 850 }
850 851
851 test_class_no_interface() { 852 test_class_no_interface() {
852 UnlinkedClass cls = serializeClassText('class C {}'); 853 UnlinkedClass cls = serializeClassText('class C {}');
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 checkParamTypeRef(typeArgument, 2); 916 checkParamTypeRef(typeArgument, 2);
916 } 917 }
917 918
918 test_class_type_param_f_bound_self_ref() { 919 test_class_type_param_f_bound_self_ref() {
919 UnlinkedClass cls = serializeClassText('class C<T, U extends List<U>> {}'); 920 UnlinkedClass cls = serializeClassText('class C<T, U extends List<U>> {}');
920 UnlinkedTypeRef typeArgument = cls.typeParameters[1].bound.typeArguments[0]; 921 UnlinkedTypeRef typeArgument = cls.typeParameters[1].bound.typeArguments[0];
921 checkParamTypeRef(typeArgument, 1); 922 checkParamTypeRef(typeArgument, 1);
922 } 923 }
923 924
924 test_class_type_param_no_bound() { 925 test_class_type_param_no_bound() {
925 UnlinkedClass cls = serializeClassText('class C<T> {}'); 926 String text = 'class C<T> {}';
927 UnlinkedClass cls = serializeClassText(text);
926 expect(cls.typeParameters, hasLength(1)); 928 expect(cls.typeParameters, hasLength(1));
927 expect(cls.typeParameters[0].name, 'T'); 929 expect(cls.typeParameters[0].name, 'T');
930 expect(cls.typeParameters[0].nameOffset, text.indexOf('T'));
928 expect(cls.typeParameters[0].bound, isNull); 931 expect(cls.typeParameters[0].bound, isNull);
929 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 1); 932 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 1);
930 } 933 }
931 934
932 test_constructor() { 935 test_constructor() {
933 UnlinkedExecutable executable = findExecutable('', 936 String text = 'class C { C(); }';
934 executables: serializeClassText('class C { C(); }').executables); 937 UnlinkedExecutable executable =
938 findExecutable('', executables: serializeClassText(text).executables);
935 expect(executable.kind, UnlinkedExecutableKind.constructor); 939 expect(executable.kind, UnlinkedExecutableKind.constructor);
936 expect(executable.hasImplicitReturnType, isFalse); 940 expect(executable.hasImplicitReturnType, isFalse);
937 expect(executable.isExternal, isFalse); 941 expect(executable.isExternal, isFalse);
942 expect(executable.nameOffset, text.indexOf('C();'));
938 } 943 }
939 944
940 test_constructor_anonymous() { 945 test_constructor_anonymous() {
941 UnlinkedExecutable executable = findExecutable('', 946 UnlinkedExecutable executable = findExecutable('',
942 executables: serializeClassText('class C { C(); }').executables); 947 executables: serializeClassText('class C { C(); }').executables);
943 expect(executable.name, isEmpty); 948 expect(executable.name, isEmpty);
944 } 949 }
945 950
946 test_constructor_const() { 951 test_constructor_const() {
947 UnlinkedExecutable executable = findExecutable('', 952 UnlinkedExecutable executable = findExecutable('',
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 test_constructor_initializing_formal_typedef() { 1112 test_constructor_initializing_formal_typedef() {
1108 UnlinkedExecutable executable = findExecutable('', 1113 UnlinkedExecutable executable = findExecutable('',
1109 executables: serializeClassText( 1114 executables: serializeClassText(
1110 'typedef F<T>(T x); class C<X> { C(this.f); F<X> f; }') 1115 'typedef F<T>(T x); class C<X> { C(this.f); F<X> f; }')
1111 .executables); 1116 .executables);
1112 UnlinkedParam parameter = executable.parameters[0]; 1117 UnlinkedParam parameter = executable.parameters[0];
1113 expect(parameter.parameters, hasLength(1)); 1118 expect(parameter.parameters, hasLength(1));
1114 } 1119 }
1115 1120
1116 test_constructor_named() { 1121 test_constructor_named() {
1122 String text = 'class C { C.foo(); }';
1117 UnlinkedExecutable executable = findExecutable('foo', 1123 UnlinkedExecutable executable = findExecutable('foo',
1118 executables: serializeClassText('class C { C.foo(); }').executables); 1124 executables: serializeClassText(text).executables);
1119 expect(executable.name, 'foo'); 1125 expect(executable.name, 'foo');
1126 expect(executable.nameOffset, text.indexOf('foo'));
1120 } 1127 }
1121 1128
1122 test_constructor_non_const() { 1129 test_constructor_non_const() {
1123 UnlinkedExecutable executable = findExecutable('', 1130 UnlinkedExecutable executable = findExecutable('',
1124 executables: serializeClassText('class C { C(); }').executables); 1131 executables: serializeClassText('class C { C(); }').executables);
1125 expect(executable.isConst, isFalse); 1132 expect(executable.isConst, isFalse);
1126 } 1133 }
1127 1134
1128 test_constructor_non_factory() { 1135 test_constructor_non_factory() {
1129 UnlinkedExecutable executable = findExecutable('', 1136 UnlinkedExecutable executable = findExecutable('',
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1241 serializeLibraryText('library my.lib; part "part1.dart";'); 1248 serializeLibraryText('library my.lib; part "part1.dart";');
1242 UnlinkedUnit unit = unlinkedUnits[1]; 1249 UnlinkedUnit unit = unlinkedUnits[1];
1243 expect(findClass('C', unit: unit), isNotNull); 1250 expect(findClass('C', unit: unit), isNotNull);
1244 expect(findEnum('E', unit: unit), isNotNull); 1251 expect(findEnum('E', unit: unit), isNotNull);
1245 expect(findVariable('v', variables: unit.variables), isNotNull); 1252 expect(findVariable('v', variables: unit.variables), isNotNull);
1246 expect(findExecutable('f', executables: unit.executables), isNotNull); 1253 expect(findExecutable('f', executables: unit.executables), isNotNull);
1247 expect(findTypedef('F', unit: unit), isNotNull); 1254 expect(findTypedef('F', unit: unit), isNotNull);
1248 } 1255 }
1249 1256
1250 test_enum() { 1257 test_enum() {
1251 UnlinkedEnum e = serializeEnumText('enum E { v1 }'); 1258 String text = 'enum E { v1 }';
1259 UnlinkedEnum e = serializeEnumText(text);
1252 expect(e.name, 'E'); 1260 expect(e.name, 'E');
1261 expect(e.nameOffset, text.indexOf('E'));
1253 expect(e.values, hasLength(1)); 1262 expect(e.values, hasLength(1));
1254 expect(e.values[0].name, 'v1'); 1263 expect(e.values[0].name, 'v1');
1264 expect(e.values[0].nameOffset, text.indexOf('v1'));
1255 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); 1265 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1));
1256 expect(unlinkedUnits[0].publicNamespace.names[0].kind, 1266 expect(unlinkedUnits[0].publicNamespace.names[0].kind,
1257 PrelinkedReferenceKind.classOrEnum); 1267 PrelinkedReferenceKind.classOrEnum);
1258 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'E'); 1268 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'E');
1259 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 0); 1269 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 0);
1260 } 1270 }
1261 1271
1262 test_enum_order() { 1272 test_enum_order() {
1263 UnlinkedEnum e = serializeEnumText('enum E { v1, v2 }'); 1273 UnlinkedEnum e = serializeEnumText('enum E { v1, v2 }');
1264 expect(e.values, hasLength(2)); 1274 expect(e.values, hasLength(2));
(...skipping 12 matching lines...) Expand all
1277 expect(executable.isAbstract, isTrue); 1287 expect(executable.isAbstract, isTrue);
1278 } 1288 }
1279 1289
1280 test_executable_concrete() { 1290 test_executable_concrete() {
1281 UnlinkedExecutable executable = 1291 UnlinkedExecutable executable =
1282 serializeClassText('abstract class C { f() {} }').executables[0]; 1292 serializeClassText('abstract class C { f() {} }').executables[0];
1283 expect(executable.isAbstract, isFalse); 1293 expect(executable.isAbstract, isFalse);
1284 } 1294 }
1285 1295
1286 test_executable_function() { 1296 test_executable_function() {
1287 UnlinkedExecutable executable = serializeExecutableText('f() {}'); 1297 String text = ' f() {}';
1298 UnlinkedExecutable executable = serializeExecutableText(text);
1288 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod); 1299 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod);
1289 expect(executable.hasImplicitReturnType, isTrue); 1300 expect(executable.hasImplicitReturnType, isTrue);
1290 checkDynamicTypeRef(executable.returnType); 1301 checkDynamicTypeRef(executable.returnType);
1291 expect(executable.isExternal, isFalse); 1302 expect(executable.isExternal, isFalse);
1303 expect(executable.nameOffset, text.indexOf('f'));
1292 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); 1304 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1));
1293 expect(unlinkedUnits[0].publicNamespace.names[0].kind, 1305 expect(unlinkedUnits[0].publicNamespace.names[0].kind,
1294 PrelinkedReferenceKind.other); 1306 PrelinkedReferenceKind.other);
1295 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'f'); 1307 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'f');
1296 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 0); 1308 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 0);
1297 } 1309 }
1298 1310
1299 test_executable_function_explicit_return() { 1311 test_executable_function_explicit_return() {
1300 UnlinkedExecutable executable = 1312 UnlinkedExecutable executable =
1301 serializeExecutableText('dynamic f() => null;'); 1313 serializeExecutableText('dynamic f() => null;');
1302 expect(executable.hasImplicitReturnType, isFalse); 1314 expect(executable.hasImplicitReturnType, isFalse);
1303 checkDynamicTypeRef(executable.returnType); 1315 checkDynamicTypeRef(executable.returnType);
1304 } 1316 }
1305 1317
1306 test_executable_function_external() { 1318 test_executable_function_external() {
1307 UnlinkedExecutable executable = serializeExecutableText('external f();'); 1319 UnlinkedExecutable executable = serializeExecutableText('external f();');
1308 expect(executable.isExternal, isTrue); 1320 expect(executable.isExternal, isTrue);
1309 } 1321 }
1310 1322
1311 test_executable_function_private() { 1323 test_executable_function_private() {
1312 serializeExecutableText('_f() {}', '_f'); 1324 serializeExecutableText('_f() {}', '_f');
1313 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); 1325 expect(unlinkedUnits[0].publicNamespace.names, isEmpty);
1314 } 1326 }
1315 1327
1316 test_executable_getter() { 1328 test_executable_getter() {
1317 UnlinkedExecutable executable = serializeExecutableText('int get f => 1;'); 1329 String text = 'int get f => 1;';
1330 UnlinkedExecutable executable = serializeExecutableText(text);
1318 expect(executable.kind, UnlinkedExecutableKind.getter); 1331 expect(executable.kind, UnlinkedExecutableKind.getter);
1319 expect(executable.hasImplicitReturnType, isFalse); 1332 expect(executable.hasImplicitReturnType, isFalse);
1320 expect(executable.isExternal, isFalse); 1333 expect(executable.isExternal, isFalse);
1334 expect(executable.nameOffset, text.indexOf('f'));
1321 expect(findVariable('f'), isNull); 1335 expect(findVariable('f'), isNull);
1322 expect(findExecutable('f='), isNull); 1336 expect(findExecutable('f='), isNull);
1323 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); 1337 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1));
1324 expect(unlinkedUnits[0].publicNamespace.names[0].kind, 1338 expect(unlinkedUnits[0].publicNamespace.names[0].kind,
1325 PrelinkedReferenceKind.other); 1339 PrelinkedReferenceKind.other);
1326 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'f'); 1340 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'f');
1327 } 1341 }
1328 1342
1329 test_executable_getter_external() { 1343 test_executable_getter_external() {
1330 UnlinkedExecutable executable = 1344 UnlinkedExecutable executable =
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1576 UnlinkedExecutable executable = serializeExecutableText('f([x]) {}'); 1590 UnlinkedExecutable executable = serializeExecutableText('f([x]) {}');
1577 expect(executable.parameters[0].kind, UnlinkedParamKind.positional); 1591 expect(executable.parameters[0].kind, UnlinkedParamKind.positional);
1578 } 1592 }
1579 1593
1580 test_executable_param_kind_required() { 1594 test_executable_param_kind_required() {
1581 UnlinkedExecutable executable = serializeExecutableText('f(x) {}'); 1595 UnlinkedExecutable executable = serializeExecutableText('f(x) {}');
1582 expect(executable.parameters[0].kind, UnlinkedParamKind.required); 1596 expect(executable.parameters[0].kind, UnlinkedParamKind.required);
1583 } 1597 }
1584 1598
1585 test_executable_param_name() { 1599 test_executable_param_name() {
1586 UnlinkedExecutable executable = serializeExecutableText('f(x) {}'); 1600 String text = 'f(x) {}';
1601 UnlinkedExecutable executable = serializeExecutableText(text);
1587 expect(executable.parameters, hasLength(1)); 1602 expect(executable.parameters, hasLength(1));
1588 expect(executable.parameters[0].name, 'x'); 1603 expect(executable.parameters[0].name, 'x');
1604 expect(executable.parameters[0].nameOffset, text.indexOf('x'));
1589 } 1605 }
1590 1606
1591 test_executable_param_no_flags() { 1607 test_executable_param_no_flags() {
1592 UnlinkedExecutable executable = serializeExecutableText('f(x) {}'); 1608 UnlinkedExecutable executable = serializeExecutableText('f(x) {}');
1593 expect(executable.parameters[0].isFunctionTyped, isFalse); 1609 expect(executable.parameters[0].isFunctionTyped, isFalse);
1594 expect(executable.parameters[0].isInitializingFormal, isFalse); 1610 expect(executable.parameters[0].isInitializingFormal, isFalse);
1595 } 1611 }
1596 1612
1597 test_executable_param_non_function_typed() { 1613 test_executable_param_non_function_typed() {
1598 UnlinkedExecutable executable = serializeExecutableText('f(g) {}'); 1614 UnlinkedExecutable executable = serializeExecutableText('f(g) {}');
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1634 checkDynamicTypeRef(executable.returnType); 1650 checkDynamicTypeRef(executable.returnType);
1635 expect(executable.hasImplicitReturnType, isTrue); 1651 expect(executable.hasImplicitReturnType, isTrue);
1636 } 1652 }
1637 1653
1638 test_executable_return_type_void() { 1654 test_executable_return_type_void() {
1639 UnlinkedExecutable executable = serializeExecutableText('void f() {}'); 1655 UnlinkedExecutable executable = serializeExecutableText('void f() {}');
1640 expect(executable.returnType, isNull); 1656 expect(executable.returnType, isNull);
1641 } 1657 }
1642 1658
1643 test_executable_setter() { 1659 test_executable_setter() {
1644 UnlinkedExecutable executable = 1660 String text = 'void set f(value) {}';
1645 serializeExecutableText('void set f(value) {}', 'f='); 1661 UnlinkedExecutable executable = serializeExecutableText(text, 'f=');
1646 expect(executable.kind, UnlinkedExecutableKind.setter); 1662 expect(executable.kind, UnlinkedExecutableKind.setter);
1647 expect(executable.hasImplicitReturnType, isFalse); 1663 expect(executable.hasImplicitReturnType, isFalse);
1648 expect(executable.isExternal, isFalse); 1664 expect(executable.isExternal, isFalse);
1665 expect(executable.nameOffset, text.indexOf('f'));
1649 expect(findVariable('f'), isNull); 1666 expect(findVariable('f'), isNull);
1650 expect(findExecutable('f'), isNull); 1667 expect(findExecutable('f'), isNull);
1651 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); 1668 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1));
1652 expect(unlinkedUnits[0].publicNamespace.names[0].kind, 1669 expect(unlinkedUnits[0].publicNamespace.names[0].kind,
1653 PrelinkedReferenceKind.other); 1670 PrelinkedReferenceKind.other);
1654 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'f='); 1671 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'f=');
1655 } 1672 }
1656 1673
1657 test_executable_setter_external() { 1674 test_executable_setter_external() {
1658 UnlinkedExecutable executable = 1675 UnlinkedExecutable executable =
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1758 expect(unlinkedUnits[0].publicNamespace.exports, hasLength(1)); 1775 expect(unlinkedUnits[0].publicNamespace.exports, hasLength(1));
1759 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators, isEmpty); 1776 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators, isEmpty);
1760 } 1777 }
1761 1778
1762 test_export_offset() { 1779 test_export_offset() {
1763 String libraryText = ' export "dart:async";'; 1780 String libraryText = ' export "dart:async";';
1764 serializeLibraryText(libraryText); 1781 serializeLibraryText(libraryText);
1765 expect(unlinkedUnits[0].exports[0].uriOffset, 1782 expect(unlinkedUnits[0].exports[0].uriOffset,
1766 libraryText.indexOf('"dart:async"')); 1783 libraryText.indexOf('"dart:async"'));
1767 expect(unlinkedUnits[0].exports[0].uriEnd, libraryText.indexOf(';')); 1784 expect(unlinkedUnits[0].exports[0].uriEnd, libraryText.indexOf(';'));
1785 expect(unlinkedUnits[0].exports[0].offset, libraryText.indexOf('export'));
1768 } 1786 }
1769 1787
1770 test_export_show_order() { 1788 test_export_show_order() {
1771 serializeLibraryText('export "dart:async" show Future, Stream;'); 1789 serializeLibraryText('export "dart:async" show Future, Stream;');
1772 expect(unlinkedUnits[0].publicNamespace.exports, hasLength(1)); 1790 expect(unlinkedUnits[0].publicNamespace.exports, hasLength(1));
1773 expect( 1791 expect(
1774 unlinkedUnits[0].publicNamespace.exports[0].combinators, hasLength(1)); 1792 unlinkedUnits[0].publicNamespace.exports[0].combinators, hasLength(1));
1775 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].shows, 1793 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].shows,
1776 hasLength(2)); 1794 hasLength(2));
1777 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].hides, 1795 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].hides,
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1918 libraryText.indexOf('"dart:async"')); 1936 libraryText.indexOf('"dart:async"'));
1919 expect(unlinkedUnits[0].imports[0].uriEnd, libraryText.indexOf('; Future')); 1937 expect(unlinkedUnits[0].imports[0].uriEnd, libraryText.indexOf('; Future'));
1920 } 1938 }
1921 1939
1922 test_import_prefix_name() { 1940 test_import_prefix_name() {
1923 String libraryText = 'import "dart:async" as a; a.Future x;'; 1941 String libraryText = 'import "dart:async" as a; a.Future x;';
1924 serializeLibraryText(libraryText); 1942 serializeLibraryText(libraryText);
1925 // Second import is the implicit import of dart:core 1943 // Second import is the implicit import of dart:core
1926 expect(unlinkedUnits[0].imports, hasLength(2)); 1944 expect(unlinkedUnits[0].imports, hasLength(2));
1927 checkPrefix(unlinkedUnits[0].imports[0].prefixReference, 'a'); 1945 checkPrefix(unlinkedUnits[0].imports[0].prefixReference, 'a');
1946 expect(unlinkedUnits[0].imports[0].prefixOffset, libraryText.indexOf('a;'));
1928 } 1947 }
1929 1948
1930 test_import_prefix_none() { 1949 test_import_prefix_none() {
1931 serializeLibraryText('import "dart:async"; Future x;'); 1950 serializeLibraryText('import "dart:async"; Future x;');
1932 // Second import is the implicit import of dart:core 1951 // Second import is the implicit import of dart:core
1933 expect(unlinkedUnits[0].imports, hasLength(2)); 1952 expect(unlinkedUnits[0].imports, hasLength(2));
1934 expect(unlinkedUnits[0].imports[0].prefixReference, 0); 1953 expect(unlinkedUnits[0].imports[0].prefixReference, 0);
1935 } 1954 }
1936 1955
1937 test_import_prefix_not_in_public_namespace() { 1956 test_import_prefix_not_in_public_namespace() {
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1998 2017
1999 test_import_uri() { 2018 test_import_uri() {
2000 String uriString = '"dart:async"'; 2019 String uriString = '"dart:async"';
2001 String libraryText = 'import $uriString; Future x;'; 2020 String libraryText = 'import $uriString; Future x;';
2002 serializeLibraryText(libraryText); 2021 serializeLibraryText(libraryText);
2003 // Second import is the implicit import of dart:core 2022 // Second import is the implicit import of dart:core
2004 expect(unlinkedUnits[0].imports, hasLength(2)); 2023 expect(unlinkedUnits[0].imports, hasLength(2));
2005 expect(unlinkedUnits[0].imports[0].uri, 'dart:async'); 2024 expect(unlinkedUnits[0].imports[0].uri, 'dart:async');
2006 } 2025 }
2007 2026
2027 test_library_name_with_spaces() {
2028 String text = 'library foo . bar ;';
2029 serializeLibraryText(text);
2030 expect(unlinkedUnits[0].libraryName, 'foo.bar');
2031 expect(unlinkedUnits[0].libraryNameOffset, text.indexOf('foo . bar'));
2032 expect(unlinkedUnits[0].libraryNameLength, 'foo . bar'.length);
2033 }
2034
2008 test_library_named() { 2035 test_library_named() {
2009 String text = 'library foo.bar;'; 2036 String text = 'library foo.bar;';
2010 serializeLibraryText(text); 2037 serializeLibraryText(text);
2011 expect(unlinkedUnits[0].libraryName, 'foo.bar'); 2038 expect(unlinkedUnits[0].libraryName, 'foo.bar');
2039 expect(unlinkedUnits[0].libraryNameOffset, text.indexOf('foo.bar'));
2040 expect(unlinkedUnits[0].libraryNameLength, 'foo.bar'.length);
2012 } 2041 }
2013 2042
2014 test_library_unnamed() { 2043 test_library_unnamed() {
2015 serializeLibraryText(''); 2044 serializeLibraryText('');
2016 expect(unlinkedUnits[0].libraryName, isEmpty); 2045 expect(unlinkedUnits[0].libraryName, isEmpty);
2046 expect(unlinkedUnits[0].libraryNameOffset, 0);
2047 expect(unlinkedUnits[0].libraryNameLength, 0);
2017 } 2048 }
2018 2049
2019 test_part_declaration() { 2050 test_part_declaration() {
2020 addNamedSource('/a.dart', 'part of my.lib;'); 2051 addNamedSource('/a.dart', 'part of my.lib;');
2021 String text = 'library my.lib; part "a.dart"; // <-part'; 2052 String text = 'library my.lib; part "a.dart"; // <-part';
2022 serializeLibraryText(text); 2053 serializeLibraryText(text);
2023 expect(unlinkedUnits[0].publicNamespace.parts, hasLength(1)); 2054 expect(unlinkedUnits[0].publicNamespace.parts, hasLength(1));
2024 expect(unlinkedUnits[0].publicNamespace.parts[0], 'a.dart'); 2055 expect(unlinkedUnits[0].publicNamespace.parts[0], 'a.dart');
2025 expect(unlinkedUnits[0].parts, hasLength(1)); 2056 expect(unlinkedUnits[0].parts, hasLength(1));
2026 expect(unlinkedUnits[0].parts[0].uriOffset, text.indexOf('"a.dart"')); 2057 expect(unlinkedUnits[0].parts[0].uriOffset, text.indexOf('"a.dart"'));
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
2246 checkTypeRef(typeRef, absUri('/a.dart'), 'a.dart', 'C', 2277 checkTypeRef(typeRef, absUri('/a.dart'), 'a.dart', 'C',
2247 expectedTargetUnit: 2); 2278 expectedTargetUnit: 2);
2248 } 2279 }
2249 2280
2250 test_type_unresolved() { 2281 test_type_unresolved() {
2251 UnlinkedTypeRef typeRef = serializeTypeText('Foo', allowErrors: true); 2282 UnlinkedTypeRef typeRef = serializeTypeText('Foo', allowErrors: true);
2252 checkUnresolvedTypeRef(typeRef, null, 'Foo'); 2283 checkUnresolvedTypeRef(typeRef, null, 'Foo');
2253 } 2284 }
2254 2285
2255 test_typedef_name() { 2286 test_typedef_name() {
2256 UnlinkedTypedef type = serializeTypedefText('typedef F();'); 2287 String text = 'typedef F();';
2288 UnlinkedTypedef type = serializeTypedefText(text);
2257 expect(type.name, 'F'); 2289 expect(type.name, 'F');
2290 expect(type.nameOffset, text.indexOf('F'));
2258 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1)); 2291 expect(unlinkedUnits[0].publicNamespace.names, hasLength(1));
2259 expect(unlinkedUnits[0].publicNamespace.names[0].kind, 2292 expect(unlinkedUnits[0].publicNamespace.names[0].kind,
2260 PrelinkedReferenceKind.typedef); 2293 PrelinkedReferenceKind.typedef);
2261 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'F'); 2294 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'F');
2262 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 0); 2295 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 0);
2263 } 2296 }
2264 2297
2265 test_typedef_param_none() { 2298 test_typedef_param_none() {
2266 UnlinkedTypedef type = serializeTypedefText('typedef F();'); 2299 UnlinkedTypedef type = serializeTypedefText('typedef F();');
2267 expect(type.parameters, isEmpty); 2300 expect(type.parameters, isEmpty);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2316 } 2349 }
2317 2350
2318 test_typedef_type_param_order() { 2351 test_typedef_type_param_order() {
2319 UnlinkedTypedef type = serializeTypedefText('typedef F<T, U>();'); 2352 UnlinkedTypedef type = serializeTypedefText('typedef F<T, U>();');
2320 expect(type.typeParameters, hasLength(2)); 2353 expect(type.typeParameters, hasLength(2));
2321 expect(type.typeParameters[0].name, 'T'); 2354 expect(type.typeParameters[0].name, 'T');
2322 expect(type.typeParameters[1].name, 'U'); 2355 expect(type.typeParameters[1].name, 'U');
2323 } 2356 }
2324 2357
2325 test_variable() { 2358 test_variable() {
2326 serializeVariableText('int i;', variableName: 'i'); 2359 String text = 'int i;';
2360 UnlinkedVariable v = serializeVariableText(text, variableName: 'i');
2361 expect(v.nameOffset, text.indexOf('i;'));
2327 expect(findExecutable('i'), isNull); 2362 expect(findExecutable('i'), isNull);
2328 expect(findExecutable('i='), isNull); 2363 expect(findExecutable('i='), isNull);
2329 expect(unlinkedUnits[0].publicNamespace.names, hasLength(2)); 2364 expect(unlinkedUnits[0].publicNamespace.names, hasLength(2));
2330 expect(unlinkedUnits[0].publicNamespace.names[0].kind, 2365 expect(unlinkedUnits[0].publicNamespace.names[0].kind,
2331 PrelinkedReferenceKind.other); 2366 PrelinkedReferenceKind.other);
2332 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'i'); 2367 expect(unlinkedUnits[0].publicNamespace.names[0].name, 'i');
2333 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 0); 2368 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 0);
2334 expect(unlinkedUnits[0].publicNamespace.names[1].kind, 2369 expect(unlinkedUnits[0].publicNamespace.names[1].kind,
2335 PrelinkedReferenceKind.other); 2370 PrelinkedReferenceKind.other);
2336 expect(unlinkedUnits[0].publicNamespace.names[1].name, 'i='); 2371 expect(unlinkedUnits[0].publicNamespace.names[1].name, 'i=');
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
2410 UnlinkedVariable variable = 2445 UnlinkedVariable variable =
2411 serializeVariableText('int i;', variableName: 'i'); 2446 serializeVariableText('int i;', variableName: 'i');
2412 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int'); 2447 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int');
2413 } 2448 }
2414 2449
2415 test_varible_private() { 2450 test_varible_private() {
2416 serializeVariableText('int _i;', variableName: '_i'); 2451 serializeVariableText('int _i;', variableName: '_i');
2417 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); 2452 expect(unlinkedUnits[0].publicNamespace.names, isEmpty);
2418 } 2453 }
2419 } 2454 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/src/summary/resynthesize_test.dart ('k') | pkg/analyzer/tool/summary/idl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698