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

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

Issue 2485043004: Don't serialize elements of top-level function/constructor/method bodies. (Closed)
Patch Set: Created 4 years, 1 month 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_common; 5 library analyzer.test.src.summary.summary_common;
6 6
7 import 'package:analyzer/analyzer.dart'; 7 import 'package:analyzer/analyzer.dart';
8 import 'package:analyzer/dart/ast/ast.dart'; 8 import 'package:analyzer/dart/ast/ast.dart';
9 import 'package:analyzer/error/listener.dart'; 9 import 'package:analyzer/error/listener.dart';
10 import 'package:analyzer/src/dart/scanner/reader.dart'; 10 import 'package:analyzer/src/dart/scanner/reader.dart';
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 signature2 = unlinkedUnits[0].apiSignature; 842 signature2 = unlinkedUnits[0].apiSignature;
843 } 843 }
844 { 844 {
845 serializeLibraryText('class B {}'); 845 serializeLibraryText('class B {}');
846 signature3 = unlinkedUnits[0].apiSignature; 846 signature3 = unlinkedUnits[0].apiSignature;
847 } 847 }
848 expect(signature2, signature1); 848 expect(signature2, signature1);
849 expect(signature3, isNot(signature1)); 849 expect(signature3, isNot(signature1));
850 } 850 }
851 851
852 test_apiSignature_excludeBody_constructor() {
853 List<int> signature1;
854 List<int> signature2;
855 List<int> signature3;
856 {
857 serializeLibraryText(r'''
858 class A {
859 A() {
860 }
861 }
862 ''');
863 signature1 = unlinkedUnits[0].apiSignature;
864 }
865 {
866 serializeLibraryText(r'''
867 class A {
868 A() {
869 int v1;
870 f() {
871 double v2;
872 }
873 }
874 }
875 ''');
876 signature2 = unlinkedUnits[0].apiSignature;
877 }
878 {
879 serializeLibraryText(r'''
880 class A {
881 A(int p) {
882 }
883 }
884 ''');
885 }
886 expect(signature2, signature1);
887 expect(signature3, isNot(signature1));
888 }
889
890 test_apiSignature_excludeBody_method() {
891 List<int> signature1;
892 List<int> signature2;
893 List<int> signature3;
894 {
895 serializeLibraryText(r'''
896 class A {
897 m() {
898 }
899 }
900 ''');
901 signature1 = unlinkedUnits[0].apiSignature;
902 }
903 {
904 serializeLibraryText(r'''
905 class A {
906 m() {
907 int v1;
908 f() {
909 double v2;
910 }
911 }
912 }
913 ''');
914 signature2 = unlinkedUnits[0].apiSignature;
915 }
916 {
917 serializeLibraryText(r'''
918 class A {
919 m(p) {
920 }
921 }
922 ''');
923 }
924 expect(signature2, signature1);
925 expect(signature3, isNot(signature1));
926 }
927
928 test_apiSignature_excludeBody_topLevelFunction() {
929 List<int> signature1;
930 List<int> signature2;
931 List<int> signature3;
932 {
933 serializeLibraryText('main() {}');
934 signature1 = unlinkedUnits[0].apiSignature;
935 }
936 {
937 serializeLibraryText(r'''
938 main() {
939 int v1 = 1;
940 f() {
941 int v2 = 2;
942 }
943 }
944 ''');
945 signature2 = unlinkedUnits[0].apiSignature;
946 }
947 {
948 serializeLibraryText('main(p) {}');
949 signature3 = unlinkedUnits[0].apiSignature;
950 }
951 expect(signature2, signature1);
952 expect(signature3, isNot(signature1));
953 }
954
852 test_bottom_reference_shared() { 955 test_bottom_reference_shared() {
853 if (skipFullyLinkedData) { 956 if (skipFullyLinkedData) {
854 return; 957 return;
855 } 958 }
856 // The synthetic executables for both `x` and `y` have type `() => `Bottom`. 959 // The synthetic executables for both `x` and `y` have type `() => `Bottom`.
857 // Verify that they both use the same reference to `Bottom`. 960 // Verify that they both use the same reference to `Bottom`.
858 serializeLibraryText('int x = null; int y = null;'); 961 serializeLibraryText('int x = null; int y = null;');
859 EntityRef xInitializerReturnType = 962 EntityRef xInitializerReturnType =
860 getTypeRefForSlot(findVariable('x').initializer.inferredReturnTypeSlot); 963 getTypeRefForSlot(findVariable('x').initializer.inferredReturnTypeSlot);
861 EntityRef yInitializerReturnType = 964 EntityRef yInitializerReturnType =
(...skipping 484 matching lines...) Expand 10 before | Expand all | Expand 10 after
1346 String text = 'class C<T> {}'; 1449 String text = 'class C<T> {}';
1347 UnlinkedClass cls = serializeClassText(text); 1450 UnlinkedClass cls = serializeClassText(text);
1348 expect(cls.typeParameters, hasLength(1)); 1451 expect(cls.typeParameters, hasLength(1));
1349 expect(cls.typeParameters[0].name, 'T'); 1452 expect(cls.typeParameters[0].name, 'T');
1350 expect(cls.typeParameters[0].nameOffset, text.indexOf('T')); 1453 expect(cls.typeParameters[0].nameOffset, text.indexOf('T'));
1351 expect(cls.typeParameters[0].bound, isNull); 1454 expect(cls.typeParameters[0].bound, isNull);
1352 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 1); 1455 expect(unlinkedUnits[0].publicNamespace.names[0].numTypeParameters, 1);
1353 } 1456 }
1354 1457
1355 test_closure_executable_with_bottom_return_type() { 1458 test_closure_executable_with_bottom_return_type() {
1356 UnlinkedExecutable executable = 1459 UnlinkedVariable variable = serializeVariableText('var v = (() => null);');
1357 serializeExecutableText('f() { print((() => null)()); }'); 1460 UnlinkedExecutable closure;
1358 expect(executable.localFunctions, hasLength(1)); 1461 {
1359 expect(executable.localFunctions[0].returnType, isNull); 1462 UnlinkedExecutable executable = variable.initializer;
1463 // UnlinkedExecutable executable =
Paul Berry 2016/11/08 20:47:02 Remove commented out code.
1464 // serializeExecutableText('f() { print((() => null)()); }');
1465 expect(executable.localFunctions, hasLength(1));
1466 expect(executable.localFunctions[0].returnType, isNull);
1467 closure = executable.localFunctions[0];
1468 }
1360 if (strongMode) { 1469 if (strongMode) {
1361 // Strong mode infers a type for the closure of `() => dynamic`, so the 1470 // Strong mode infers a type for the closure of `() => dynamic`, so the
1362 // inferred return type slot should be empty. 1471 // inferred return type slot should be empty.
1363 expect( 1472 expect(getTypeRefForSlot(closure.inferredReturnTypeSlot), isNull);
1364 getTypeRefForSlot(
1365 executable.localFunctions[0].inferredReturnTypeSlot),
1366 isNull);
1367 } else { 1473 } else {
1368 // Spec mode infers a type for the closure of `() => Bottom`. 1474 // Spec mode infers a type for the closure of `() => Bottom`.
1369 checkInferredTypeSlot(executable.localFunctions[0].inferredReturnTypeSlot, 1475 checkInferredTypeSlot(
1370 null, null, '*bottom*', 1476 closure.inferredReturnTypeSlot, null, null, '*bottom*',
1371 onlyInStrongMode: false); 1477 onlyInStrongMode: false);
1372 } 1478 }
1373 } 1479 }
1374 1480
1375 test_closure_executable_with_imported_return_type() { 1481 test_closure_executable_with_imported_return_type() {
1376 addNamedSource('/a.dart', 'class C { D d; } class D {}'); 1482 addNamedSource('/a.dart', 'class C { D d; } class D {}');
1377 // The closure has type `() => D`; `D` is defined in a library that is 1483 // The closure has type `() => D`; `D` is defined in a library that is
1378 // imported. 1484 // imported.
1379 UnlinkedExecutable executable = serializeExecutableText( 1485 UnlinkedExecutable executable = serializeVariableText(r'''
1380 'import "a.dart"; f() { print((() => new C().d)()); }'); 1486 import "a.dart";
1487 var v = (() {
1488 print((() => new C().d)());
1489 });
1490 ''').initializer.localFunctions[0];
1381 expect(executable.localFunctions, hasLength(1)); 1491 expect(executable.localFunctions, hasLength(1));
1382 expect(executable.localFunctions[0].returnType, isNull); 1492 expect(executable.localFunctions[0].returnType, isNull);
1383 checkInferredTypeSlot(executable.localFunctions[0].inferredReturnTypeSlot, 1493 checkInferredTypeSlot(executable.localFunctions[0].inferredReturnTypeSlot,
1384 absUri('/a.dart'), 'a.dart', 'D', 1494 absUri('/a.dart'), 'a.dart', 'D',
1385 onlyInStrongMode: false); 1495 onlyInStrongMode: false);
1386 checkHasDependency('a.dart', fullyLinked: false); 1496 checkHasDependency('a.dart', fullyLinked: false);
1387 } 1497 }
1388 1498
1389 test_closure_executable_with_return_type_from_closure() { 1499 test_closure_executable_with_return_type_from_closure() {
1390 if (skipFullyLinkedData) { 1500 if (skipFullyLinkedData) {
(...skipping 22 matching lines...) Expand all
1413 expectedKind: ReferenceKind.topLevelFunction); 1523 expectedKind: ReferenceKind.topLevelFunction);
1414 expect( 1524 expect(
1415 definingUnit.references[topLevelFunctionIndex].containingReference, 0); 1525 definingUnit.references[topLevelFunctionIndex].containingReference, 0);
1416 } 1526 }
1417 1527
1418 test_closure_executable_with_unimported_return_type() { 1528 test_closure_executable_with_unimported_return_type() {
1419 addNamedSource('/a.dart', 'import "b.dart"; class C { D d; }'); 1529 addNamedSource('/a.dart', 'import "b.dart"; class C { D d; }');
1420 addNamedSource('/b.dart', 'class D {}'); 1530 addNamedSource('/b.dart', 'class D {}');
1421 // The closure has type `() => D`; `D` is defined in a library that is not 1531 // The closure has type `() => D`; `D` is defined in a library that is not
1422 // imported. 1532 // imported.
1423 UnlinkedExecutable executable = serializeExecutableText( 1533 UnlinkedExecutable executable = serializeVariableText(r'''
1424 'import "a.dart"; f() { print((() => new C().d)()); }'); 1534 import "a.dart";
1535 var v = (() {
1536 print((() => new C().d)());
1537 });
1538 ''').initializer.localFunctions[0];
1425 expect(executable.localFunctions, hasLength(1)); 1539 expect(executable.localFunctions, hasLength(1));
1426 expect(executable.localFunctions[0].returnType, isNull); 1540 expect(executable.localFunctions[0].returnType, isNull);
1427 checkInferredTypeSlot(executable.localFunctions[0].inferredReturnTypeSlot, 1541 checkInferredTypeSlot(executable.localFunctions[0].inferredReturnTypeSlot,
1428 absUri('/b.dart'), 'b.dart', 'D', 1542 absUri('/b.dart'), 'b.dart', 'D',
1429 onlyInStrongMode: false); 1543 onlyInStrongMode: false);
1430 if (!skipFullyLinkedData) { 1544 if (!skipFullyLinkedData) {
1431 checkHasDependency('b.dart', fullyLinked: true); 1545 checkHasDependency('b.dart', fullyLinked: true);
1432 } 1546 }
1433 } 1547 }
1434 1548
(...skipping 3604 matching lines...) Expand 10 before | Expand all | Expand 10 after
5039 } 5153 }
5040 5154
5041 test_executable_getter_type_implicit() { 5155 test_executable_getter_type_implicit() {
5042 UnlinkedExecutable executable = serializeExecutableText('get f => 1;'); 5156 UnlinkedExecutable executable = serializeExecutableText('get f => 1;');
5043 expect(executable.returnType, isNull); 5157 expect(executable.returnType, isNull);
5044 expect(executable.parameters, isEmpty); 5158 expect(executable.parameters, isEmpty);
5045 } 5159 }
5046 5160
5047 test_executable_localFunctions() { 5161 test_executable_localFunctions() {
5048 String code = r''' 5162 String code = r'''
5049 f() { // 1 5163 f() {
5050 f1() {} 5164 f1() {}
5051 { // 2 5165 {
5052 f2() {} 5166 f2() {}
5053 } // 3 5167 }
5054 } // 4 5168 }
5055 '''; 5169 ''';
5056 UnlinkedExecutable executable = serializeExecutableText(code); 5170 UnlinkedExecutable executable = serializeExecutableText(code);
5057 List<UnlinkedExecutable> functions = executable.localFunctions; 5171 List<UnlinkedExecutable> functions = executable.localFunctions;
5058 expect(functions, hasLength(2)); 5172 expect(functions, isEmpty);
5059 {
5060 UnlinkedExecutable f1 = functions.singleWhere((v) => v.name == 'f1');
5061 _assertExecutableVisible(code, f1, '{ // 1', '} // 4');
5062 }
5063 {
5064 UnlinkedExecutable f2 = functions.singleWhere((v) => v.name == 'f2');
5065 _assertExecutableVisible(code, f2, '{ // 2', '} // 3');
5066 }
5067 } 5173 }
5068 5174
5069 test_executable_localLabels_inMethod() { 5175 test_executable_localLabels_inMethod() {
5070 String code = r''' 5176 String code = r'''
5071 class C { 5177 class C {
5072 m() { 5178 m() {
5073 aaa: while (true) {} 5179 aaa: while (true) {}
5074 bbb: while (true) {} 5180 bbb: while (true) {}
5075 } 5181 }
5076 } 5182 }
5077 '''; 5183 ''';
5078 UnlinkedExecutable executable = 5184 UnlinkedExecutable executable =
5079 findExecutable('m', executables: serializeClassText(code).executables); 5185 findExecutable('m', executables: serializeClassText(code).executables);
5080 List<UnlinkedLabel> labels = executable.localLabels; 5186 List<UnlinkedLabel> labels = executable.localLabels;
5081 expect(labels, hasLength(2)); 5187 expect(labels, isEmpty);
5082 {
5083 UnlinkedLabel aaa = labels.singleWhere((l) => l.name == 'aaa');
5084 expect(aaa, isNotNull);
5085 expect(aaa.isOnSwitchMember, isFalse);
5086 expect(aaa.isOnSwitchStatement, isFalse);
5087 }
5088 {
5089 UnlinkedLabel bbb = labels.singleWhere((l) => l.name == 'bbb');
5090 expect(bbb, isNotNull);
5091 expect(bbb.isOnSwitchMember, isFalse);
5092 expect(bbb.isOnSwitchStatement, isFalse);
5093 }
5094 } 5188 }
5095 5189
5096 test_executable_localLabels_inTopLevelFunction() { 5190 test_executable_localLabels_inTopLevelFunction() {
5097 String code = r''' 5191 String code = r'''
5098 f() { 5192 f() {
5099 aaa: while (true) {} 5193 aaa: while (true) {}
5100 bbb: switch (42) { 5194 bbb: switch (42) {
5101 ccc: case 0: 5195 ccc: case 0:
5102 break; 5196 break;
5103 ddd: default: 5197 ddd: default:
5104 break; 5198 break;
5105 } 5199 }
5106 } 5200 }
5107 '''; 5201 ''';
5108 UnlinkedExecutable executable = serializeExecutableText(code); 5202 UnlinkedExecutable executable = serializeExecutableText(code);
5109 List<UnlinkedLabel> labels = executable.localLabels; 5203 List<UnlinkedLabel> labels = executable.localLabels;
5110 expect(labels, hasLength(4)); 5204 expect(labels, isEmpty);
5111 {
5112 UnlinkedLabel aaa = labels.singleWhere((l) => l.name == 'aaa');
5113 expect(aaa, isNotNull);
5114 expect(aaa.isOnSwitchMember, isFalse);
5115 expect(aaa.isOnSwitchStatement, isFalse);
5116 }
5117 {
5118 UnlinkedLabel bbb = labels.singleWhere((l) => l.name == 'bbb');
5119 expect(bbb, isNotNull);
5120 expect(bbb.isOnSwitchMember, isFalse);
5121 expect(bbb.isOnSwitchStatement, isTrue);
5122 }
5123 {
5124 UnlinkedLabel ccc = labels.singleWhere((l) => l.name == 'ccc');
5125 expect(ccc, isNotNull);
5126 expect(ccc.isOnSwitchMember, isTrue);
5127 expect(ccc.isOnSwitchStatement, isFalse);
5128 }
5129 {
5130 UnlinkedLabel ccc = labels.singleWhere((l) => l.name == 'ddd');
5131 expect(ccc, isNotNull);
5132 expect(ccc.isOnSwitchMember, isTrue);
5133 expect(ccc.isOnSwitchStatement, isFalse);
5134 }
5135 } 5205 }
5136 5206
5137 test_executable_localLabels_inTopLevelGetter() { 5207 test_executable_localLabels_inTopLevelGetter() {
5138 String code = r''' 5208 String code = r'''
5139 get g { 5209 get g {
5140 aaa: while (true) {} 5210 aaa: while (true) {}
5141 bbb: while (true) {} 5211 bbb: while (true) {}
5142 } 5212 }
5143 '''; 5213 ''';
5144 UnlinkedExecutable executable = 5214 UnlinkedExecutable executable =
5145 serializeExecutableText(code, executableName: 'g'); 5215 serializeExecutableText(code, executableName: 'g');
5146 List<UnlinkedLabel> labels = executable.localLabels; 5216 List<UnlinkedLabel> labels = executable.localLabels;
5147 expect(labels, hasLength(2)); 5217 expect(labels, isEmpty);
5148 {
5149 UnlinkedLabel aaa = labels.singleWhere((l) => l.name == 'aaa');
5150 expect(aaa, isNotNull);
5151 expect(aaa.isOnSwitchMember, isFalse);
5152 expect(aaa.isOnSwitchStatement, isFalse);
5153 }
5154 {
5155 UnlinkedLabel bbb = labels.singleWhere((l) => l.name == 'bbb');
5156 expect(bbb, isNotNull);
5157 expect(bbb.isOnSwitchMember, isFalse);
5158 expect(bbb.isOnSwitchStatement, isFalse);
5159 }
5160 } 5218 }
5161 5219
5162 test_executable_localLabels_namedExpressionLabel() { 5220 test_executable_localLabels_namedExpressionLabel() {
5163 String code = r''' 5221 String code = r'''
5164 f() { 5222 f() {
5165 foo(p: 42); 5223 foo(p: 42);
5166 } 5224 }
5167 foo({int p}) {} 5225 foo({int p}) {}
5168 '''; 5226 ''';
5169 UnlinkedExecutable executable = serializeExecutableText(code); 5227 UnlinkedExecutable executable = serializeExecutableText(code);
5170 List<UnlinkedLabel> labels = executable.localLabels; 5228 List<UnlinkedLabel> labels = executable.localLabels;
5171 expect(labels, isEmpty); 5229 expect(labels, isEmpty);
5172 } 5230 }
5173 5231
5174 test_executable_localVariables_catch() { 5232 test_executable_localVariables_catch() {
5175 String code = r''' 5233 String code = r'''
5176 f() { // 1 5234 var v = (
5177 try { 5235 () { // 1
5178 throw 42; 5236 try {
5179 } on int catch (e, st) { // 2 5237 throw 42;
5180 print(e); 5238 } on int catch (e, st) { // 2
5181 print(st); 5239 print(e);
5182 } // 3 5240 print(st);
5183 } // 4 5241 } // 3
5242 } // 4
5243 );
5184 '''; 5244 ''';
5185 UnlinkedExecutable executable = serializeExecutableText(code); 5245 UnlinkedExecutable executable =
5246 serializeVariableText(code).initializer.localFunctions[0];
5186 List<UnlinkedVariable> variables = executable.localVariables; 5247 List<UnlinkedVariable> variables = executable.localVariables;
5187 expect(variables, hasLength(2)); 5248 expect(variables, hasLength(2));
5188 { 5249 {
5189 UnlinkedVariable e = variables.singleWhere((v) => v.name == 'e'); 5250 UnlinkedVariable e = variables.singleWhere((v) => v.name == 'e');
5190 _assertVariableVisible(code, e, 'on int catch (', '} // 3'); 5251 _assertVariableVisible(code, e, 'on int catch (', '} // 3');
5191 checkTypeRef(e.type, 'dart:core', 'dart:core', 'int'); 5252 checkTypeRef(e.type, 'dart:core', 'dart:core', 'int');
5192 } 5253 }
5193 { 5254 {
5194 UnlinkedVariable st = variables.singleWhere((v) => v.name == 'st'); 5255 UnlinkedVariable st = variables.singleWhere((v) => v.name == 'st');
5195 _assertVariableVisible(code, st, 'on int catch (', '} // 3'); 5256 _assertVariableVisible(code, st, 'on int catch (', '} // 3');
(...skipping 16 matching lines...) Expand all
5212 test_executable_localVariables_empty() { 5273 test_executable_localVariables_empty() {
5213 UnlinkedExecutable executable = serializeExecutableText(r''' 5274 UnlinkedExecutable executable = serializeExecutableText(r'''
5214 f() { 5275 f() {
5215 } 5276 }
5216 '''); 5277 ''');
5217 expect(executable.localVariables, isEmpty); 5278 expect(executable.localVariables, isEmpty);
5218 } 5279 }
5219 5280
5220 test_executable_localVariables_forEachLoop() { 5281 test_executable_localVariables_forEachLoop() {
5221 String code = r''' 5282 String code = r'''
5222 f() { // 1 5283 var v = (() {
5223 for (int i in <int>[]) { // 2 5284 f() { // 1
5224 print(i); 5285 for (int i in <int>[]) { // 2
5225 } // 3 5286 print(i);
5226 } // 4 5287 } // 3
5288 } // 4
5289 });
5227 '''; 5290 ''';
5228 UnlinkedExecutable executable = serializeExecutableText(code); 5291 UnlinkedExecutable executable = serializeVariableText(code)
5292 .initializer
5293 .localFunctions[0]
5294 .localFunctions[0];
5229 List<UnlinkedVariable> variables = executable.localVariables; 5295 List<UnlinkedVariable> variables = executable.localVariables;
5230 expect(variables, hasLength(1)); 5296 expect(variables, hasLength(1));
5231 { 5297 {
5232 UnlinkedVariable i = variables.singleWhere((v) => v.name == 'i'); 5298 UnlinkedVariable i = variables.singleWhere((v) => v.name == 'i');
5233 _assertVariableVisible(code, i, 'for', '} // 3'); 5299 _assertVariableVisible(code, i, 'for', '} // 3');
5234 checkTypeRef(i.type, 'dart:core', 'dart:core', 'int'); 5300 checkTypeRef(i.type, 'dart:core', 'dart:core', 'int');
5235 } 5301 }
5236 } 5302 }
5237 5303
5238 test_executable_localVariables_forEachLoop_outside() { 5304 test_executable_localVariables_forEachLoop_outside() {
5239 String code = r''' 5305 String code = r'''
5240 f() { // 1 5306 var v = (() {
5241 int i; 5307 f() { // 1
5242 for (i in <int>[]) { 5308 int i;
5243 print(i); 5309 for (i in <int>[]) {
5244 } 5310 print(i);
5245 } // 4 5311 }
5312 } // 4
5313 });
5246 '''; 5314 ''';
5247 UnlinkedExecutable executable = serializeExecutableText(code); 5315 UnlinkedExecutable executable = serializeVariableText(code)
5316 .initializer
5317 .localFunctions[0]
5318 .localFunctions[0];
5248 List<UnlinkedVariable> variables = executable.localVariables; 5319 List<UnlinkedVariable> variables = executable.localVariables;
5249 expect(variables, hasLength(1)); 5320 expect(variables, hasLength(1));
5250 { 5321 {
5251 UnlinkedVariable i = variables.singleWhere((v) => v.name == 'i'); 5322 UnlinkedVariable i = variables.singleWhere((v) => v.name == 'i');
5252 _assertVariableVisible(code, i, '{ // 1', '} // 4'); 5323 _assertVariableVisible(code, i, '{ // 1', '} // 4');
5253 checkTypeRef(i.type, 'dart:core', 'dart:core', 'int'); 5324 checkTypeRef(i.type, 'dart:core', 'dart:core', 'int');
5254 } 5325 }
5255 } 5326 }
5256 5327
5257 test_executable_localVariables_forLoop() { 5328 test_executable_localVariables_forLoop() {
5258 String code = r''' 5329 String code = r'''
5259 f() { // 1 5330 var v = (() {
5260 for (int i = 0, j = 0; i < 10; i++, j++) { // 2 5331 f() { // 1
5261 print(i); 5332 for (int i = 0, j = 0; i < 10; i++, j++) { // 2
5262 } // 3 5333 print(i);
5263 } // 4 5334 } // 3
5335 } // 4
5336 });
5264 '''; 5337 ''';
5265 UnlinkedExecutable executable = serializeExecutableText(code); 5338 UnlinkedExecutable executable = serializeVariableText(code)
5339 .initializer
5340 .localFunctions[0]
5341 .localFunctions[0];
5266 List<UnlinkedVariable> variables = executable.localVariables; 5342 List<UnlinkedVariable> variables = executable.localVariables;
5267 expect(variables, hasLength(2)); 5343 expect(variables, hasLength(2));
5268 { 5344 {
5269 UnlinkedVariable i = variables.singleWhere((v) => v.name == 'i'); 5345 UnlinkedVariable i = variables.singleWhere((v) => v.name == 'i');
5270 _assertVariableVisible(code, i, 'for', '} // 3'); 5346 _assertVariableVisible(code, i, 'for', '} // 3');
5271 checkTypeRef(i.type, 'dart:core', 'dart:core', 'int'); 5347 checkTypeRef(i.type, 'dart:core', 'dart:core', 'int');
5272 } 5348 }
5273 { 5349 {
5274 UnlinkedVariable i = variables.singleWhere((v) => v.name == 'j'); 5350 UnlinkedVariable i = variables.singleWhere((v) => v.name == 'j');
5275 _assertVariableVisible(code, i, 'for', '} // 3'); 5351 _assertVariableVisible(code, i, 'for', '} // 3');
5276 checkTypeRef(i.type, 'dart:core', 'dart:core', 'int'); 5352 checkTypeRef(i.type, 'dart:core', 'dart:core', 'int');
5277 } 5353 }
5278 } 5354 }
5279 5355
5280 test_executable_localVariables_forLoop_noVariables() { 5356 test_executable_localVariables_forLoop_noVariables() {
5281 String code = r''' 5357 String code = r'''
5282 f() { 5358 var v = (() {
5283 for (; true;) {} 5359 f() {
5284 } 5360 for (; true;) {}
5361 }
5362 });
5285 '''; 5363 ''';
5286 UnlinkedExecutable executable = serializeExecutableText(code); 5364 UnlinkedExecutable executable = serializeVariableText(code)
5365 .initializer
5366 .localFunctions[0]
5367 .localFunctions[0];
5287 List<UnlinkedVariable> variables = executable.localVariables; 5368 List<UnlinkedVariable> variables = executable.localVariables;
5288 expect(variables, isEmpty); 5369 expect(variables, isEmpty);
5289 } 5370 }
5290 5371
5291 test_executable_localVariables_inConstructor() { 5372 test_executable_localVariables_inConstructor() {
5292 String code = r''' 5373 String code = r'''
5293 class C { 5374 class C {
5294 C() { // 1 5375 C() {
5295 int v; 5376 int v;
5296 } // 2 5377 }
5297 } 5378 }
5298 '''; 5379 ''';
5299 UnlinkedExecutable executable = 5380 UnlinkedExecutable executable =
5300 findExecutable('', executables: serializeClassText(code).executables); 5381 findExecutable('', executables: serializeClassText(code).executables);
5301 List<UnlinkedVariable> variables = executable.localVariables; 5382 List<UnlinkedVariable> variables = executable.localVariables;
5302 expect(variables, hasLength(1)); 5383 expect(variables, isEmpty);
5303 {
5304 UnlinkedVariable v = variables.singleWhere((v) => v.name == 'v');
5305 _assertVariableVisible(code, v, '{ // 1', '} // 2');
5306 checkTypeRef(v.type, 'dart:core', 'dart:core', 'int');
5307 }
5308 } 5384 }
5309 5385
5310 test_executable_localVariables_inLocalFunctions() { 5386 test_executable_localVariables_inLocalFunctions() {
5311 String code = r''' 5387 String code = r'''
5312 f() { 5388 var v = (() {
5313 f1() { // 1 5389 f() {
5314 int v1 = 1; 5390 f1() { // 1
5315 } // 2 5391 int v1 = 1;
5316 f2() { // 3 5392 } // 2
5317 int v1 = 1; 5393 f2() { // 3
5318 f3() { // 4 5394 int v1 = 1;
5319 int v2 = 1; 5395 f3() { // 4
5320 } // 5 5396 int v2 = 1;
5321 } // 6 5397 } // 5
5322 } // 7 5398 } // 6
5399 } // 7
5400 });
5323 '''; 5401 ''';
5324 UnlinkedExecutable executable = serializeExecutableText(code); 5402 UnlinkedExecutable executable = serializeVariableText(code)
5403 .initializer
5404 .localFunctions[0]
5405 .localFunctions[0];
5325 List<UnlinkedExecutable> functions = executable.localFunctions; 5406 List<UnlinkedExecutable> functions = executable.localFunctions;
5326 expect(functions, hasLength(2)); 5407 expect(functions, hasLength(2));
5327 // f - f1 5408 // f - f1
5328 { 5409 {
5329 UnlinkedExecutable f1 = functions.singleWhere((v) => v.name == 'f1'); 5410 UnlinkedExecutable f1 = functions.singleWhere((v) => v.name == 'f1');
5330 List<UnlinkedVariable> variables = f1.localVariables; 5411 List<UnlinkedVariable> variables = f1.localVariables;
5331 expect(variables, hasLength(1)); 5412 expect(variables, hasLength(1));
5332 // f1 - v1 5413 // f1 - v1
5333 UnlinkedVariable v1 = variables.singleWhere((v) => v.name == 'v1'); 5414 UnlinkedVariable v1 = variables.singleWhere((v) => v.name == 'v1');
5334 _assertVariableVisible(code, v1, '{ // 1', '} // 2'); 5415 _assertVariableVisible(code, v1, '{ // 1', '} // 2');
(...skipping 20 matching lines...) Expand all
5355 // f - f3 - v2 5436 // f - f3 - v2
5356 UnlinkedVariable v2 = variables3.singleWhere((v) => v.name == 'v2'); 5437 UnlinkedVariable v2 = variables3.singleWhere((v) => v.name == 'v2');
5357 _assertVariableVisible(code, v2, '{ // 4', '} // 5'); 5438 _assertVariableVisible(code, v2, '{ // 4', '} // 5');
5358 checkTypeRef(v2.type, 'dart:core', 'dart:core', 'int'); 5439 checkTypeRef(v2.type, 'dart:core', 'dart:core', 'int');
5359 } 5440 }
5360 } 5441 }
5361 5442
5362 test_executable_localVariables_inMethod() { 5443 test_executable_localVariables_inMethod() {
5363 String code = r''' 5444 String code = r'''
5364 class C { 5445 class C {
5365 m() { // 1 5446 m() {
5366 int v; 5447 int v;
5367 f() {} 5448 f() {}
5368 } // 2 5449 }
5369 } 5450 }
5370 '''; 5451 ''';
5371 UnlinkedExecutable executable = 5452 UnlinkedExecutable executable =
5372 findExecutable('m', executables: serializeClassText(code).executables); 5453 findExecutable('m', executables: serializeClassText(code).executables);
5373 { 5454 expect(executable.localFunctions, isEmpty);
5374 List<UnlinkedExecutable> functions = executable.localFunctions; 5455 expect(executable.localVariables, isEmpty);
5375 expect(functions, hasLength(1));
5376 UnlinkedExecutable f = functions.singleWhere((v) => v.name == 'f');
5377 _assertExecutableVisible(code, f, '{ // 1', '} // 2');
5378 }
5379 {
5380 List<UnlinkedVariable> variables = executable.localVariables;
5381 expect(variables, hasLength(1));
5382 UnlinkedVariable v = variables.singleWhere((v) => v.name == 'v');
5383 _assertVariableVisible(code, v, '{ // 1', '} // 2');
5384 checkTypeRef(v.type, 'dart:core', 'dart:core', 'int');
5385 }
5386 } 5456 }
5387 5457
5388 test_executable_localVariables_inTopLevelFunction() { 5458 test_executable_localVariables_inTopLevelFunction() {
5389 String code = r''' 5459 String code = r'''
5390 f() { // 1 5460 f() {
5391 int v1 = 1; 5461 int v1 = 1;
5392 { // 2 5462 {
5393 int v2 = 2; 5463 int v2 = 2;
5394 } // 3 5464 }
5395 var v3 = 3; 5465 var v3 = 3;
5396 } // 4 5466 }
5397 '''; 5467 ''';
5398 UnlinkedExecutable executable = serializeExecutableText(code); 5468 UnlinkedExecutable executable = serializeExecutableText(code);
5399 List<UnlinkedVariable> variables = executable.localVariables; 5469 List<UnlinkedVariable> variables = executable.localVariables;
5400 expect(variables, hasLength(3)); 5470 expect(variables, isEmpty);
5401 {
5402 UnlinkedVariable v1 = variables.singleWhere((v) => v.name == 'v1');
5403 _assertVariableVisible(code, v1, '{ // 1', '} // 4');
5404 checkTypeRef(v1.type, 'dart:core', 'dart:core', 'int');
5405 }
5406 {
5407 UnlinkedVariable v2 = variables.singleWhere((v) => v.name == 'v2');
5408 _assertVariableVisible(code, v2, '{ // 2', '} // 3');
5409 checkTypeRef(v2.type, 'dart:core', 'dart:core', 'int');
5410 }
5411 {
5412 UnlinkedVariable v3 = variables.singleWhere((v) => v.name == 'v3');
5413 _assertVariableVisible(code, v3, '{ // 1', '} // 4');
5414 expect(v3.type, isNull);
5415 }
5416 } 5471 }
5417 5472
5418 test_executable_localVariables_inTopLevelGetter() { 5473 test_executable_localVariables_inTopLevelGetter() {
5419 String code = r''' 5474 String code = r'''
5420 get g { // 1 5475 get g { // 1
5421 int v; 5476 int v;
5422 f() {} 5477 f() {}
5423 } // 2 5478 } // 2
5424 '''; 5479 ''';
5425 UnlinkedExecutable executable = 5480 UnlinkedExecutable executable =
5426 serializeExecutableText(code, executableName: 'g'); 5481 serializeExecutableText(code, executableName: 'g');
5427 { 5482 expect(executable.localFunctions, isEmpty);
5428 List<UnlinkedExecutable> functions = executable.localFunctions; 5483 expect(executable.localVariables, isEmpty);
5429 expect(functions, hasLength(1));
5430 UnlinkedExecutable f = functions.singleWhere((v) => v.name == 'f');
5431 _assertExecutableVisible(code, f, '{ // 1', '} // 2');
5432 }
5433 {
5434 List<UnlinkedVariable> variables = executable.localVariables;
5435 expect(variables, hasLength(1));
5436 UnlinkedVariable v = variables.singleWhere((v) => v.name == 'v');
5437 _assertVariableVisible(code, v, '{ // 1', '} // 2');
5438 checkTypeRef(v.type, 'dart:core', 'dart:core', 'int');
5439 }
5440 } 5484 }
5441 5485
5442 test_executable_member_function() { 5486 test_executable_member_function() {
5443 UnlinkedExecutable executable = findExecutable('f', 5487 UnlinkedExecutable executable = findExecutable('f',
5444 executables: serializeClassText('class C { f() {} }').executables); 5488 executables: serializeClassText('class C { f() {} }').executables);
5445 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod); 5489 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod);
5446 expect(executable.returnType, isNull); 5490 expect(executable.returnType, isNull);
5447 expect(executable.isAsynchronous, isFalse); 5491 expect(executable.isAsynchronous, isFalse);
5448 expect(executable.isExternal, isFalse); 5492 expect(executable.isExternal, isFalse);
5449 expect(executable.isGenerator, isFalse); 5493 expect(executable.isGenerator, isFalse);
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
5818 UnlinkedExecutable executable = serializeExecutableText('f() {}'); 5862 UnlinkedExecutable executable = serializeExecutableText('f() {}');
5819 expect(executable.parameters, isEmpty); 5863 expect(executable.parameters, isEmpty);
5820 } 5864 }
5821 5865
5822 test_executable_param_of_constructor_no_covariance() { 5866 test_executable_param_of_constructor_no_covariance() {
5823 UnlinkedExecutable executable = 5867 UnlinkedExecutable executable =
5824 serializeClassText('class C { C(x); }').executables[0]; 5868 serializeClassText('class C { C(x); }').executables[0];
5825 expect(executable.parameters[0].inheritsCovariantSlot, 0); 5869 expect(executable.parameters[0].inheritsCovariantSlot, 0);
5826 } 5870 }
5827 5871
5828 test_executable_param_of_local_function_no_covariance() {
5829 UnlinkedExecutable executable =
5830 serializeClassText('class C { m() { f(x) {} } }')
5831 .executables[0]
5832 .localFunctions[0];
5833 expect(executable.parameters[0].inheritsCovariantSlot, 0);
5834 }
5835
5836 test_executable_param_of_method_covariance() { 5872 test_executable_param_of_method_covariance() {
5837 UnlinkedExecutable executable = 5873 UnlinkedExecutable executable =
5838 serializeClassText('class C { m(x) {} }').executables[0]; 5874 serializeClassText('class C { m(x) {} }').executables[0];
5839 expect(executable.parameters[0].inheritsCovariantSlot, isNot(0)); 5875 expect(executable.parameters[0].inheritsCovariantSlot, isNot(0));
5840 } 5876 }
5841 5877
5842 test_executable_param_of_param_no_covariance() { 5878 test_executable_param_of_param_no_covariance() {
5843 UnlinkedExecutable executable = 5879 UnlinkedExecutable executable =
5844 serializeClassText('class C { m(f(x)) {} }').executables[0]; 5880 serializeClassText('class C { m(f(x)) {} }').executables[0];
5845 expect(executable.parameters[0].parameters[0].inheritsCovariantSlot, 0); 5881 expect(executable.parameters[0].parameters[0].inheritsCovariantSlot, 0);
(...skipping 1920 matching lines...) Expand 10 before | Expand all | Expand 10 after
7766 test_function_inferred_type_implicit_param() { 7802 test_function_inferred_type_implicit_param() {
7767 UnlinkedExecutable f = serializeExecutableText('void f(value) {}'); 7803 UnlinkedExecutable f = serializeExecutableText('void f(value) {}');
7768 expect(f.parameters[0].inferredTypeSlot, 0); 7804 expect(f.parameters[0].inferredTypeSlot, 0);
7769 } 7805 }
7770 7806
7771 test_function_inferred_type_implicit_return() { 7807 test_function_inferred_type_implicit_return() {
7772 UnlinkedExecutable f = serializeExecutableText('f() => null;'); 7808 UnlinkedExecutable f = serializeExecutableText('f() => null;');
7773 expect(f.inferredReturnTypeSlot, 0); 7809 expect(f.inferredReturnTypeSlot, 0);
7774 } 7810 }
7775 7811
7776 test_generic_gClass_gMethodStatic() {
7777 UnlinkedClass cls = serializeClassText('''
7778 class C<T, U> {
7779 static void m<V, W>(V v, W w) {
7780 void f<X, Y>(V v, W w, X x, Y y) {
7781 }
7782 }
7783 }
7784 ''');
7785 UnlinkedExecutable m = cls.executables[0];
7786 UnlinkedExecutable f = m.localFunctions[0];
7787 checkParamTypeRef(m.parameters[0].type, 2);
7788 checkParamTypeRef(m.parameters[1].type, 1);
7789 checkParamTypeRef(f.parameters[0].type, 4);
7790 checkParamTypeRef(f.parameters[1].type, 3);
7791 checkParamTypeRef(f.parameters[2].type, 2);
7792 checkParamTypeRef(f.parameters[3].type, 1);
7793 }
7794
7795 test_generic_method_in_generic_class() { 7812 test_generic_method_in_generic_class() {
7796 UnlinkedClass cls = serializeClassText( 7813 UnlinkedClass cls = serializeClassText(
7797 'class C<T, U> { void m<V, W>(T t, U u, V v, W w) {} }'); 7814 'class C<T, U> { void m<V, W>(T t, U u, V v, W w) {} }');
7798 List<UnlinkedParam> params = cls.executables[0].parameters; 7815 List<UnlinkedParam> params = cls.executables[0].parameters;
7799 checkParamTypeRef(params[0].type, 4); 7816 checkParamTypeRef(params[0].type, 4);
7800 checkParamTypeRef(params[1].type, 3); 7817 checkParamTypeRef(params[1].type, 3);
7801 checkParamTypeRef(params[2].type, 2); 7818 checkParamTypeRef(params[2].type, 2);
7802 checkParamTypeRef(params[3].type, 1); 7819 checkParamTypeRef(params[3].type, 1);
7803 } 7820 }
7804 7821
(...skipping 1341 matching lines...) Expand 10 before | Expand all | Expand 10 after
9146 test_method_inferred_type_static_implicit_return() { 9163 test_method_inferred_type_static_implicit_return() {
9147 UnlinkedExecutable f = serializeClassText( 9164 UnlinkedExecutable f = serializeClassText(
9148 'class C extends D { static f() => null; }' 9165 'class C extends D { static f() => null; }'
9149 ' class D { static int f() => null; }', 9166 ' class D { static int f() => null; }',
9150 className: 'C') 9167 className: 'C')
9151 .executables[0]; 9168 .executables[0];
9152 expect(f.inferredReturnTypeSlot, 0); 9169 expect(f.inferredReturnTypeSlot, 0);
9153 } 9170 }
9154 9171
9155 test_nested_generic_functions() { 9172 test_nested_generic_functions() {
9156 UnlinkedExecutable executable = serializeExecutableText(''' 9173 UnlinkedExecutable executable = serializeVariableText('''
9157 void f<T, U>() { 9174 var v = (() {
9158 void g<V, W>() { 9175 void f<T, U>() {
9159 void h<X, Y>() { 9176 void g<V, W>() {
9160 T t; 9177 void h<X, Y>() {
9161 U u; 9178 T t;
9162 V v; 9179 U u;
9163 W w; 9180 V v;
9164 X x; 9181 W w;
9165 Y y; 9182 X x;
9183 Y y;
9184 }
9166 } 9185 }
9167 } 9186 }
9168 } 9187 });
9169 '''); 9188 ''').initializer.localFunctions[0].localFunctions[0];
9170 expect(executable.typeParameters, hasLength(2)); 9189 expect(executable.typeParameters, hasLength(2));
9171 expect(executable.localFunctions[0].typeParameters, hasLength(2)); 9190 expect(executable.localFunctions[0].typeParameters, hasLength(2));
9172 expect(executable.localFunctions[0].localFunctions[0].typeParameters, 9191 expect(executable.localFunctions[0].localFunctions[0].typeParameters,
9173 hasLength(2)); 9192 hasLength(2));
9174 List<UnlinkedVariable> localVariables = 9193 List<UnlinkedVariable> localVariables =
9175 executable.localFunctions[0].localFunctions[0].localVariables; 9194 executable.localFunctions[0].localFunctions[0].localVariables;
9176 checkParamTypeRef(findVariable('t', variables: localVariables).type, 6); 9195 checkParamTypeRef(findVariable('t', variables: localVariables).type, 6);
9177 checkParamTypeRef(findVariable('u', variables: localVariables).type, 5); 9196 checkParamTypeRef(findVariable('u', variables: localVariables).type, 5);
9178 checkParamTypeRef(findVariable('v', variables: localVariables).type, 4); 9197 checkParamTypeRef(findVariable('v', variables: localVariables).type, 4);
9179 checkParamTypeRef(findVariable('w', variables: localVariables).type, 3); 9198 checkParamTypeRef(findVariable('w', variables: localVariables).type, 3);
9180 checkParamTypeRef(findVariable('x', variables: localVariables).type, 2); 9199 checkParamTypeRef(findVariable('x', variables: localVariables).type, 2);
9181 checkParamTypeRef(findVariable('y', variables: localVariables).type, 1); 9200 checkParamTypeRef(findVariable('y', variables: localVariables).type, 1);
9182 } 9201 }
9183 9202
9184 test_nested_generic_functions_in_generic_class() {
9185 UnlinkedClass cls = serializeClassText('''
9186 class C<T, U> {
9187 void g<V, W>() {
9188 void h<X, Y>() {
9189 T t;
9190 U u;
9191 V v;
9192 W w;
9193 X x;
9194 Y y;
9195 }
9196 }
9197 }
9198 ''');
9199 expect(cls.typeParameters, hasLength(2));
9200 expect(cls.executables[0].typeParameters, hasLength(2));
9201 expect(cls.executables[0].localFunctions[0].typeParameters, hasLength(2));
9202 List<UnlinkedVariable> localVariables =
9203 cls.executables[0].localFunctions[0].localVariables;
9204 checkParamTypeRef(findVariable('t', variables: localVariables).type, 6);
9205 checkParamTypeRef(findVariable('u', variables: localVariables).type, 5);
9206 checkParamTypeRef(findVariable('v', variables: localVariables).type, 4);
9207 checkParamTypeRef(findVariable('w', variables: localVariables).type, 3);
9208 checkParamTypeRef(findVariable('x', variables: localVariables).type, 2);
9209 checkParamTypeRef(findVariable('y', variables: localVariables).type, 1);
9210 }
9211
9212 test_parameter_visibleRange_abstractMethod() { 9203 test_parameter_visibleRange_abstractMethod() {
9213 UnlinkedExecutable m = findExecutable('m', 9204 UnlinkedExecutable m = findExecutable('m',
9214 executables: 9205 executables:
9215 serializeClassText('abstract class C { m(p); }').executables, 9206 serializeClassText('abstract class C { m(p); }').executables,
9216 failIfAbsent: true); 9207 failIfAbsent: true);
9217 _assertParameterZeroVisibleRange(m.parameters[0]); 9208 _assertParameterZeroVisibleRange(m.parameters[0]);
9218 } 9209 }
9219 9210
9220 test_parameter_visibleRange_function_blockBody() { 9211 test_parameter_visibleRange_function_blockBody() {
9221 String text = r''' 9212 String text = r'''
9222 f(x) { // 1 9213 var v = (() {
9223 f2(y) { // 2 9214 f(x) { // 1
9224 } // 3 9215 f2(y) { // 2
9225 } // 4 9216 } // 3
9217 } // 4
9218 });
9226 '''; 9219 ''';
9227 UnlinkedExecutable f = serializeExecutableText(text); 9220 var closure = serializeVariableText(text).initializer.localFunctions[0];
9221 UnlinkedExecutable f = closure.localFunctions[0];
9228 UnlinkedExecutable f2 = f.localFunctions[0]; 9222 UnlinkedExecutable f2 = f.localFunctions[0];
9229 _assertParameterVisible(text, f.parameters[0], '{ // 1', '} // 4'); 9223 _assertParameterVisible(text, f.parameters[0], '{ // 1', '} // 4');
9230 _assertParameterVisible(text, f2.parameters[0], '{ // 2', '} // 3'); 9224 _assertParameterVisible(text, f2.parameters[0], '{ // 2', '} // 3');
9231 } 9225 }
9232 9226
9233 test_parameter_visibleRange_function_emptyBody() { 9227 test_parameter_visibleRange_function_emptyBody() {
9234 UnlinkedExecutable f = serializeExecutableText('external f(x);'); 9228 UnlinkedExecutable f = serializeExecutableText('external f(x);');
9235 _assertParameterZeroVisibleRange(f.parameters[0]); 9229 _assertParameterZeroVisibleRange(f.parameters[0]);
9236 } 9230 }
9237 9231
(...skipping 25 matching lines...) Expand all
9263 addNamedSource('/a.dart', 'part of my.lib;'); 9257 addNamedSource('/a.dart', 'part of my.lib;');
9264 String text = 'library my.lib; part "a.dart"; // <-part'; 9258 String text = 'library my.lib; part "a.dart"; // <-part';
9265 serializeLibraryText(text); 9259 serializeLibraryText(text);
9266 expect(unlinkedUnits[0].publicNamespace.parts, hasLength(1)); 9260 expect(unlinkedUnits[0].publicNamespace.parts, hasLength(1));
9267 expect(unlinkedUnits[0].publicNamespace.parts[0], 'a.dart'); 9261 expect(unlinkedUnits[0].publicNamespace.parts[0], 'a.dart');
9268 expect(unlinkedUnits[0].parts, hasLength(1)); 9262 expect(unlinkedUnits[0].parts, hasLength(1));
9269 expect(unlinkedUnits[0].parts[0].uriOffset, text.indexOf('"a.dart"')); 9263 expect(unlinkedUnits[0].parts[0].uriOffset, text.indexOf('"a.dart"'));
9270 expect(unlinkedUnits[0].parts[0].uriEnd, text.indexOf('; // <-part')); 9264 expect(unlinkedUnits[0].parts[0].uriEnd, text.indexOf('; // <-part'));
9271 } 9265 }
9272 9266
9267 test_part_isPartOf() {
9268 addNamedSource('/a.dart', 'part of foo; class C {}');
9269 serializeLibraryText('library foo; part "a.dart";');
9270 expect(unlinkedUnits[0].isPartOf, isFalse);
9271 expect(unlinkedUnits[1].isPartOf, isTrue);
9272 }
9273
9273 test_parts_defining_compilation_unit() { 9274 test_parts_defining_compilation_unit() {
9274 serializeLibraryText(''); 9275 serializeLibraryText('');
9275 expect(linked.units, hasLength(1)); 9276 expect(linked.units, hasLength(1));
9276 expect(unlinkedUnits[0].publicNamespace.parts, isEmpty); 9277 expect(unlinkedUnits[0].publicNamespace.parts, isEmpty);
9277 } 9278 }
9278 9279
9279 test_parts_included() { 9280 test_parts_included() {
9280 addNamedSource('/part1.dart', 'part of my.lib;'); 9281 addNamedSource('/part1.dart', 'part of my.lib;');
9281 String partString = '"part1.dart"'; 9282 String partString = '"part1.dart"';
9282 String libraryText = 'library my.lib; part $partString;'; 9283 String libraryText = 'library my.lib; part $partString;';
9283 serializeLibraryText(libraryText); 9284 serializeLibraryText(libraryText);
9284 expect(linked.units, hasLength(2)); 9285 expect(linked.units, hasLength(2));
9285 expect(unlinkedUnits[0].publicNamespace.parts, hasLength(1)); 9286 expect(unlinkedUnits[0].publicNamespace.parts, hasLength(1));
9286 expect(unlinkedUnits[0].publicNamespace.parts[0], 'part1.dart'); 9287 expect(unlinkedUnits[0].publicNamespace.parts[0], 'part1.dart');
9287 } 9288 }
9288 9289
9289 test_public_namespace_of_part() { 9290 test_public_namespace_of_part() {
9290 addNamedSource('/a.dart', 'part of foo; class C {}'); 9291 addNamedSource('/a.dart', 'part of foo; class C {}');
9291 serializeLibraryText('library foo; part "a.dart";'); 9292 serializeLibraryText('library foo; part "a.dart";');
9292 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); 9293 expect(unlinkedUnits[0].publicNamespace.names, isEmpty);
9293 expect(unlinkedUnits[1].publicNamespace.names, hasLength(1)); 9294 expect(unlinkedUnits[1].publicNamespace.names, hasLength(1));
9294 expect(unlinkedUnits[1].publicNamespace.names[0].name, 'C'); 9295 expect(unlinkedUnits[1].publicNamespace.names[0].name, 'C');
9295 } 9296 }
9296 9297
9297 test_part_isPartOf() {
9298 addNamedSource('/a.dart', 'part of foo; class C {}');
9299 serializeLibraryText('library foo; part "a.dart";');
9300 expect(unlinkedUnits[0].isPartOf, isFalse);
9301 expect(unlinkedUnits[1].isPartOf, isTrue);
9302 }
9303
9304 test_reference_zero() { 9298 test_reference_zero() {
9305 // Element zero of the references table should be populated in a standard 9299 // Element zero of the references table should be populated in a standard
9306 // way. 9300 // way.
9307 serializeLibraryText(''); 9301 serializeLibraryText('');
9308 UnlinkedReference unlinkedReference0 = unlinkedUnits[0].references[0]; 9302 UnlinkedReference unlinkedReference0 = unlinkedUnits[0].references[0];
9309 expect(unlinkedReference0.name, ''); 9303 expect(unlinkedReference0.name, '');
9310 expect(unlinkedReference0.prefixReference, 0); 9304 expect(unlinkedReference0.prefixReference, 0);
9311 LinkedReference linkedReference0 = linked.units[0].references[0]; 9305 LinkedReference linkedReference0 = linked.units[0].references[0];
9312 expect(linkedReference0.containingReference, 0); 9306 expect(linkedReference0.containingReference, 0);
9313 expect(linkedReference0.dependency, 0); 9307 expect(linkedReference0.dependency, 0);
(...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after
10371 class _PrefixExpectation { 10365 class _PrefixExpectation {
10372 final ReferenceKind kind; 10366 final ReferenceKind kind;
10373 final String name; 10367 final String name;
10374 final String absoluteUri; 10368 final String absoluteUri;
10375 final String relativeUri; 10369 final String relativeUri;
10376 final int numTypeParameters; 10370 final int numTypeParameters;
10377 10371
10378 _PrefixExpectation(this.kind, this.name, 10372 _PrefixExpectation(this.kind, this.name,
10379 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0}); 10373 {this.absoluteUri, this.relativeUri, this.numTypeParameters: 0});
10380 } 10374 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698