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

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

Issue 1566533002: Tests for generic functions in 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 * equivalent to that produced by [summarize_elements.serializeLibrary]. 144 * equivalent to that produced by [summarize_elements.serializeLibrary].
145 */ 145 */
146 void verifyPublicNamespace() { 146 void verifyPublicNamespace() {
147 for (int i = 0; i < unlinkedUnits.length; i++) { 147 for (int i = 0; i < unlinkedUnits.length; i++) {
148 Source source = analysisContext.sourceFactory.forUri(unitUris[i]); 148 Source source = analysisContext.sourceFactory.forUri(unitUris[i]);
149 String text = analysisContext.getContents(source).data; 149 String text = analysisContext.getContents(source).data;
150 CharacterReader reader = new CharSequenceReader(text); 150 CharacterReader reader = new CharSequenceReader(text);
151 Scanner scanner = 151 Scanner scanner =
152 new Scanner(source, reader, AnalysisErrorListener.NULL_LISTENER); 152 new Scanner(source, reader, AnalysisErrorListener.NULL_LISTENER);
153 Parser parser = new Parser(source, AnalysisErrorListener.NULL_LISTENER); 153 Parser parser = new Parser(source, AnalysisErrorListener.NULL_LISTENER);
154 parser.parseGenericMethods = true;
154 CompilationUnit unit = parser.parseCompilationUnit(scanner.tokenize()); 155 CompilationUnit unit = parser.parseCompilationUnit(scanner.tokenize());
155 UnlinkedPublicNamespace namespace = 156 UnlinkedPublicNamespace namespace =
156 new UnlinkedPublicNamespace.fromBuffer(public_namespace 157 new UnlinkedPublicNamespace.fromBuffer(public_namespace
157 .computePublicNamespace(builderContext, unit) 158 .computePublicNamespace(builderContext, unit)
158 .toBuffer()); 159 .toBuffer());
159 expect(canonicalize(namespace), 160 expect(canonicalize(namespace),
160 canonicalize(unlinkedUnits[i].publicNamespace), 161 canonicalize(unlinkedUnits[i].publicNamespace),
161 reason: 'publicNamespace(${unitUris[i]})'); 162 reason: 'publicNamespace(${unitUris[i]})');
162 } 163 }
163 } 164 }
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 554
554 /** 555 /**
555 * 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
556 * return a summary of the corresponding [UnlinkedTypeRef]. If the type 557 * return a summary of the corresponding [UnlinkedTypeRef]. If the type
557 * 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
558 * types may be declared in [otherDeclarations]. 559 * types may be declared in [otherDeclarations].
559 */ 560 */
560 UnlinkedTypeRef serializeTypeText(String text, 561 UnlinkedTypeRef serializeTypeText(String text,
561 {String otherDeclarations: '', bool allowErrors: false}) { 562 {String otherDeclarations: '', bool allowErrors: false}) {
562 return serializeVariableText('$otherDeclarations\n$text v;', 563 return serializeVariableText('$otherDeclarations\n$text v;',
563 allowErrors: allowErrors).type; 564 allowErrors: allowErrors)
565 .type;
564 } 566 }
565 567
566 /** 568 /**
567 * Serialize the given library [text] and return the summary of the variable 569 * Serialize the given library [text] and return the summary of the variable
568 * with the given [variableName]. 570 * with the given [variableName].
569 */ 571 */
570 UnlinkedVariable serializeVariableText(String text, 572 UnlinkedVariable serializeVariableText(String text,
571 {String variableName: 'v', bool allowErrors: false}) { 573 {String variableName: 'v', bool allowErrors: false}) {
572 serializeLibraryText(text, allowErrors: allowErrors); 574 serializeLibraryText(text, allowErrors: allowErrors);
573 return findVariable(variableName, failIfAbsent: true); 575 return findVariable(variableName, failIfAbsent: true);
(...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after
1491 expect(executable.isConst, false); 1493 expect(executable.isConst, false);
1492 expect(executable.isFactory, false); 1494 expect(executable.isFactory, false);
1493 expect(executable.isStatic, false); 1495 expect(executable.isStatic, false);
1494 expect(executable.parameters, hasLength(1)); 1496 expect(executable.parameters, hasLength(1));
1495 checkTypeRef(executable.returnType, 'dart:core', 'dart:core', 'bool'); 1497 checkTypeRef(executable.returnType, 'dart:core', 'dart:core', 'bool');
1496 expect(executable.typeParameters, isEmpty); 1498 expect(executable.typeParameters, isEmpty);
1497 } 1499 }
1498 1500
1499 test_executable_operator_index_set() { 1501 test_executable_operator_index_set() {
1500 UnlinkedExecutable executable = serializeClassText( 1502 UnlinkedExecutable executable = serializeClassText(
1501 'class C { void operator[]=(int i, bool v) => null; }').executables[0]; 1503 'class C { void operator[]=(int i, bool v) => null; }')
1504 .executables[0];
1502 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod); 1505 expect(executable.kind, UnlinkedExecutableKind.functionOrMethod);
1503 expect(executable.name, '[]='); 1506 expect(executable.name, '[]=');
1504 expect(executable.hasImplicitReturnType, false); 1507 expect(executable.hasImplicitReturnType, false);
1505 expect(executable.isAbstract, false); 1508 expect(executable.isAbstract, false);
1506 expect(executable.isConst, false); 1509 expect(executable.isConst, false);
1507 expect(executable.isFactory, false); 1510 expect(executable.isFactory, false);
1508 expect(executable.isStatic, false); 1511 expect(executable.isStatic, false);
1509 expect(executable.parameters, hasLength(2)); 1512 expect(executable.parameters, hasLength(2));
1510 expect(executable.returnType, isNull); 1513 expect(executable.returnType, isNull);
1511 expect(executable.typeParameters, isEmpty); 1514 expect(executable.typeParameters, isEmpty);
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1681 checkTypeRef( 1684 checkTypeRef(
1682 executable.parameters[0].type, 'dart:core', 'dart:core', 'int'); 1685 executable.parameters[0].type, 'dart:core', 'dart:core', 'int');
1683 } 1686 }
1684 1687
1685 test_executable_static() { 1688 test_executable_static() {
1686 UnlinkedExecutable executable = 1689 UnlinkedExecutable executable =
1687 serializeClassText('class C { static f() {} }').executables[0]; 1690 serializeClassText('class C { static f() {} }').executables[0];
1688 expect(executable.isStatic, isTrue); 1691 expect(executable.isStatic, isTrue);
1689 } 1692 }
1690 1693
1691 test_executable_type_param_f_bound() { 1694 test_executable_type_param_f_bound_function() {
1692 // TODO(paulberry): also test top level executables. 1695 UnlinkedExecutable ex =
1696 serializeExecutableText('void f<T, U extends List<T>>() {}');
1697 UnlinkedTypeRef typeArgument = ex.typeParameters[1].bound.typeArguments[0];
1698 checkParamTypeRef(typeArgument, 2);
1699 }
1700
1701 test_executable_type_param_f_bound_method() {
1693 UnlinkedExecutable ex = 1702 UnlinkedExecutable ex =
1694 serializeMethodText('void f<T, U extends List<T>>() {}'); 1703 serializeMethodText('void f<T, U extends List<T>>() {}');
1695 UnlinkedTypeRef typeArgument = ex.typeParameters[1].bound.typeArguments[0]; 1704 UnlinkedTypeRef typeArgument = ex.typeParameters[1].bound.typeArguments[0];
1696 checkParamTypeRef(typeArgument, 2); 1705 checkParamTypeRef(typeArgument, 2);
1697 } 1706 }
1698 1707
1699 test_executable_type_param_f_bound_self_ref() { 1708 test_executable_type_param_f_bound_self_ref_function() {
1700 // TODO(paulberry): also test top level executables. 1709 UnlinkedExecutable ex =
1710 serializeExecutableText('void f<T, U extends List<U>>() {}');
1711 UnlinkedTypeRef typeArgument = ex.typeParameters[1].bound.typeArguments[0];
1712 checkParamTypeRef(typeArgument, 1);
1713 }
1714
1715 test_executable_type_param_f_bound_self_ref_method() {
1701 UnlinkedExecutable ex = 1716 UnlinkedExecutable ex =
1702 serializeMethodText('void f<T, U extends List<U>>() {}'); 1717 serializeMethodText('void f<T, U extends List<U>>() {}');
1703 UnlinkedTypeRef typeArgument = ex.typeParameters[1].bound.typeArguments[0]; 1718 UnlinkedTypeRef typeArgument = ex.typeParameters[1].bound.typeArguments[0];
1704 checkParamTypeRef(typeArgument, 1); 1719 checkParamTypeRef(typeArgument, 1);
1705 } 1720 }
1706 1721
1707 test_executable_type_param_in_parameter() { 1722 test_executable_type_param_in_parameter_function() {
1708 // TODO(paulberry): also test top level executables. 1723 UnlinkedExecutable ex = serializeExecutableText('void f<T>(T t) {}');
1724 checkParamTypeRef(ex.parameters[0].type, 1);
1725 }
1726
1727 test_executable_type_param_in_parameter_method() {
1709 UnlinkedExecutable ex = serializeMethodText('void f<T>(T t) {}'); 1728 UnlinkedExecutable ex = serializeMethodText('void f<T>(T t) {}');
1710 checkParamTypeRef(ex.parameters[0].type, 1); 1729 checkParamTypeRef(ex.parameters[0].type, 1);
1711 } 1730 }
1712 1731
1713 test_executable_type_param_in_return_type() { 1732 test_executable_type_param_in_return_type_function() {
1714 // TODO(paulberry): also test top level executables. 1733 UnlinkedExecutable ex = serializeExecutableText('T f<T>() => null;');
1734 checkParamTypeRef(ex.returnType, 1);
1735 }
1736
1737 test_executable_type_param_in_return_type_method() {
1715 UnlinkedExecutable ex = serializeMethodText('T f<T>() => null;'); 1738 UnlinkedExecutable ex = serializeMethodText('T f<T>() => null;');
1716 checkParamTypeRef(ex.returnType, 1); 1739 checkParamTypeRef(ex.returnType, 1);
1717 } 1740 }
1718 1741
1719 test_export_hide_order() { 1742 test_export_hide_order() {
1720 serializeLibraryText('export "dart:async" hide Future, Stream;'); 1743 serializeLibraryText('export "dart:async" hide Future, Stream;');
1721 expect(unlinkedUnits[0].publicNamespace.exports, hasLength(1)); 1744 expect(unlinkedUnits[0].publicNamespace.exports, hasLength(1));
1722 expect( 1745 expect(
1723 unlinkedUnits[0].publicNamespace.exports[0].combinators, hasLength(1)); 1746 unlinkedUnits[0].publicNamespace.exports[0].combinators, hasLength(1));
1724 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].shows, 1747 expect(unlinkedUnits[0].publicNamespace.exports[0].combinators[0].shows,
(...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after
2363 UnlinkedVariable variable = 2386 UnlinkedVariable variable =
2364 serializeVariableText('int i;', variableName: 'i'); 2387 serializeVariableText('int i;', variableName: 'i');
2365 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int'); 2388 checkTypeRef(variable.type, 'dart:core', 'dart:core', 'int');
2366 } 2389 }
2367 2390
2368 test_varible_private() { 2391 test_varible_private() {
2369 serializeVariableText('int _i;', variableName: '_i'); 2392 serializeVariableText('int _i;', variableName: '_i');
2370 expect(unlinkedUnits[0].publicNamespace.names, isEmpty); 2393 expect(unlinkedUnits[0].publicNamespace.names, isEmpty);
2371 } 2394 }
2372 } 2395 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698