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

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

Issue 1565643002: Eliminate constructor return types from 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 543 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 554
555 /** 555 /**
556 * Serialize a type declaration using the given [text] as a type name, and 556 * Serialize a type declaration using the given [text] as a type name, and
557 * return a summary of the corresponding [UnlinkedTypeRef]. If the type 557 * return a summary of the corresponding [UnlinkedTypeRef]. If the type
558 * declaration needs to refer to types that are not available in core, those 558 * declaration needs to refer to types that are not available in core, those
559 * types may be declared in [otherDeclarations]. 559 * types may be declared in [otherDeclarations].
560 */ 560 */
561 UnlinkedTypeRef serializeTypeText(String text, 561 UnlinkedTypeRef serializeTypeText(String text,
562 {String otherDeclarations: '', bool allowErrors: false}) { 562 {String otherDeclarations: '', bool allowErrors: false}) {
563 return serializeVariableText('$otherDeclarations\n$text v;', 563 return serializeVariableText('$otherDeclarations\n$text v;',
564 allowErrors: allowErrors) 564 allowErrors: allowErrors).type;
565 .type;
566 } 565 }
567 566
568 /** 567 /**
569 * Serialize the given library [text] and return the summary of the variable 568 * Serialize the given library [text] and return the summary of the variable
570 * with the given [variableName]. 569 * with the given [variableName].
571 */ 570 */
572 UnlinkedVariable serializeVariableText(String text, 571 UnlinkedVariable serializeVariableText(String text,
573 {String variableName: 'v', bool allowErrors: false}) { 572 {String variableName: 'v', bool allowErrors: false}) {
574 serializeLibraryText(text, allowErrors: allowErrors); 573 serializeLibraryText(text, allowErrors: allowErrors);
575 return findVariable(variableName, failIfAbsent: true); 574 return findVariable(variableName, failIfAbsent: true);
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 1119
1121 test_constructor_non_factory() { 1120 test_constructor_non_factory() {
1122 UnlinkedExecutable executable = findExecutable('', 1121 UnlinkedExecutable executable = findExecutable('',
1123 executables: serializeClassText('class C { C(); }').executables); 1122 executables: serializeClassText('class C { C(); }').executables);
1124 expect(executable.isFactory, isFalse); 1123 expect(executable.isFactory, isFalse);
1125 } 1124 }
1126 1125
1127 test_constructor_return_type() { 1126 test_constructor_return_type() {
1128 UnlinkedExecutable executable = findExecutable('', 1127 UnlinkedExecutable executable = findExecutable('',
1129 executables: serializeClassText('class C { C(); }').executables); 1128 executables: serializeClassText('class C { C(); }').executables);
1130 checkTypeRef(executable.returnType, null, null, 'C'); 1129 expect(executable.returnType, isNull);
1131 } 1130 }
1132 1131
1133 test_constructor_return_type_parameterized() { 1132 test_constructor_return_type_parameterized() {
1134 UnlinkedExecutable executable = findExecutable('', 1133 UnlinkedExecutable executable = findExecutable('',
1135 executables: serializeClassText('class C<T, U> { C(); }').executables); 1134 executables: serializeClassText('class C<T, U> { C(); }').executables);
1136 checkTypeRef(executable.returnType, null, null, 'C', 1135 expect(executable.returnType, isNull);
1137 allowTypeParameters: true, numTypeParameters: 2);
1138 expect(executable.returnType.typeArguments, hasLength(2));
1139 {
1140 UnlinkedTypeRef typeRef = executable.returnType.typeArguments[0];
1141 checkParamTypeRef(typeRef, 2);
1142 }
1143 {
1144 UnlinkedTypeRef typeRef = executable.returnType.typeArguments[1];
1145 checkParamTypeRef(typeRef, 1);
1146 }
1147 } 1136 }
1148 1137
1149 test_dependencies_export_none() { 1138 test_dependencies_export_none() {
1150 // Exports are not listed as dependencies since no change to the exported 1139 // Exports are not listed as dependencies since no change to the exported
1151 // file can change the summary of the exporting file. 1140 // file can change the summary of the exporting file.
1152 addNamedSource('/a.dart', 'library a; export "b.dart";'); 1141 addNamedSource('/a.dart', 'library a; export "b.dart";');
1153 addNamedSource('/b.dart', 'library b;'); 1142 addNamedSource('/b.dart', 'library b;');
1154 serializeLibraryText('export "a.dart";'); 1143 serializeLibraryText('export "a.dart";');
1155 checkLacksDependency(absUri('/a.dart'), 'a.dart'); 1144 checkLacksDependency(absUri('/a.dart'), 'a.dart');
1156 checkLacksDependency(absUri('/b.dart'), 'b.dart'); 1145 checkLacksDependency(absUri('/b.dart'), 'b.dart');
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
1493 expect(executable.isConst, false); 1482 expect(executable.isConst, false);
1494 expect(executable.isFactory, false); 1483 expect(executable.isFactory, false);
1495 expect(executable.isStatic, false); 1484 expect(executable.isStatic, false);
1496 expect(executable.parameters, hasLength(1)); 1485 expect(executable.parameters, hasLength(1));
1497 checkTypeRef(executable.returnType, 'dart:core', 'dart:core', 'bool'); 1486 checkTypeRef(executable.returnType, 'dart:core', 'dart:core', 'bool');
1498 expect(executable.typeParameters, isEmpty); 1487 expect(executable.typeParameters, isEmpty);
1499 } 1488 }
1500 1489
1501 test_executable_operator_index_set() { 1490 test_executable_operator_index_set() {
1502 UnlinkedExecutable executable = serializeClassText( 1491 UnlinkedExecutable executable = serializeClassText(
1503 'class C { void operator[]=(int i, bool v) => null; }') 1492 'class C { void operator[]=(int i, bool v) => null; }').executables[0];
1504 .executables[0];
1505 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod); 1493 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod);
1506 expect(executable.name, '[]='); 1494 expect(executable.name, '[]=');
1507 expect(executable.hasImplicitReturnType, false); 1495 expect(executable.hasImplicitReturnType, false);
1508 expect(executable.isAbstract, false); 1496 expect(executable.isAbstract, false);
1509 expect(executable.isConst, false); 1497 expect(executable.isConst, false);
1510 expect(executable.isFactory, false); 1498 expect(executable.isFactory, false);
1511 expect(executable.isStatic, false); 1499 expect(executable.isStatic, false);
1512 expect(executable.parameters, hasLength(2)); 1500 expect(executable.parameters, hasLength(2));
1513 expect(executable.returnType, isNull); 1501 expect(executable.returnType, isNull);
1514 expect(executable.typeParameters, isEmpty); 1502 expect(executable.typeParameters, isEmpty);
(...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after
2193 2181
2194 test_type_reference_to_nonexistent_file_via_prefix() { 2182 test_type_reference_to_nonexistent_file_via_prefix() {
2195 UnlinkedTypeRef typeRef = serializeTypeText('p.C', 2183 UnlinkedTypeRef typeRef = serializeTypeText('p.C',
2196 otherDeclarations: 'import "foo.dart" as p;', allowErrors: true); 2184 otherDeclarations: 'import "foo.dart" as p;', allowErrors: true);
2197 checkUnresolvedTypeRef(typeRef, 'p', 'C'); 2185 checkUnresolvedTypeRef(typeRef, 'p', 'C');
2198 } 2186 }
2199 2187
2200 test_type_reference_to_part() { 2188 test_type_reference_to_part() {
2201 addNamedSource('/a.dart', 'part of foo; class C { C(); }'); 2189 addNamedSource('/a.dart', 'part of foo; class C { C(); }');
2202 serializeLibraryText('library foo; part "a.dart"; C c;'); 2190 serializeLibraryText('library foo; part "a.dart"; C c;');
2203 UnlinkedClass classA = findClass('C', unit: unlinkedUnits[1]); 2191 checkTypeRef(unlinkedUnits[0].variables.single.type, null, null, 'C',
Paul Berry 2016/01/06 02:18:12 Note that this test was completely bogus--it was c
2204 checkTypeRef(classA.executables.single.returnType, null, null, 'C',
2205 expectedKind: PrelinkedReferenceKind.classOrEnum, 2192 expectedKind: PrelinkedReferenceKind.classOrEnum,
2206 expectedTargetUnit: 1, 2193 expectedTargetUnit: 1);
2207 prelinkedSourceUnit: prelinked.units[1],
2208 unlinkedSourceUnit: unlinkedUnits[1]);
2209 } 2194 }
2210 2195
2211 test_type_reference_to_typedef() { 2196 test_type_reference_to_typedef() {
2212 checkTypeRef(serializeTypeText('F', otherDeclarations: 'typedef void F();'), 2197 checkTypeRef(serializeTypeText('F', otherDeclarations: 'typedef void F();'),
2213 null, null, 'F', 2198 null, null, 'F',
2214 expectedKind: PrelinkedReferenceKind.typedef); 2199 expectedKind: PrelinkedReferenceKind.typedef);
2215 } 2200 }
2216 2201
2217 test_type_unit_counts_unreferenced_units() { 2202 test_type_unit_counts_unreferenced_units() {
2218 addNamedSource('/a.dart', 'library a; part "b.dart"; part "c.dart";'); 2203 addNamedSource('/a.dart', 'library a; part "b.dart"; part "c.dart";');
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
2386 UnlinkedVariable variable = 2371 UnlinkedVariable variable =
2387 serializeVariableText('int i;', variableName: 'i'); 2372 serializeVariableText('int i;', variableName: 'i');
2388 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int'); 2373 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int');
2389 } 2374 }
2390 2375
2391 test_varible_private() { 2376 test_varible_private() {
2392 serializeVariableText('int _i;', variableName: '_i'); 2377 serializeVariableText('int _i;', variableName: '_i');
2393 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); 2378 expect(unlinkedUnits[0].publicNamespace.names, isEmpty);
2394 } 2379 }
2395 } 2380 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/summary/summarize_elements.dart ('k') | pkg/analyzer/tool/summary/idl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698