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

Side by Side Diff: pkg/analyzer/test/generated/resolver_test.dart

Issue 742273005: Annotate remaining analyzer/analysis server tests with "@ReflectiveTestCase()" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 engine.resolver_test; 5 library engine.resolver_test;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import 'package:analyzer/src/generated/ast.dart'; 9 import 'package:analyzer/src/generated/ast.dart';
10 import 'package:analyzer/src/generated/element.dart'; 10 import 'package:analyzer/src/generated/element.dart';
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 } 459 }
460 460
461 void runTasks() { 461 void runTasks() {
462 AnalysisResult result = context.performAnalysisTask(); 462 AnalysisResult result = context.performAnalysisTask();
463 while (result.changeNotices != null) { 463 while (result.changeNotices != null) {
464 result = context.performAnalysisTask(); 464 result = context.performAnalysisTask();
465 } 465 }
466 } 466 }
467 } 467 }
468 468
469 @ReflectiveTestCase()
469 class AnalysisDeltaTest extends EngineTestCase { 470 class AnalysisDeltaTest extends EngineTestCase {
470 TestSource source1 = new TestSource('/1.dart'); 471 TestSource source1 = new TestSource('/1.dart');
471 TestSource source2 = new TestSource('/2.dart'); 472 TestSource source2 = new TestSource('/2.dart');
472 TestSource source3 = new TestSource('/3.dart'); 473 TestSource source3 = new TestSource('/3.dart');
473 474
474 void test_getAddedSources() { 475 void test_getAddedSources() {
475 AnalysisDelta delta = new AnalysisDelta(); 476 AnalysisDelta delta = new AnalysisDelta();
476 delta.setAnalysisLevel(source1, AnalysisLevel.ALL); 477 delta.setAnalysisLevel(source1, AnalysisLevel.ALL);
477 delta.setAnalysisLevel(source2, AnalysisLevel.ERRORS); 478 delta.setAnalysisLevel(source2, AnalysisLevel.ERRORS);
478 delta.setAnalysisLevel(source3, AnalysisLevel.NONE); 479 delta.setAnalysisLevel(source3, AnalysisLevel.NONE);
(...skipping 19 matching lines...) Expand all
498 499
499 void test_toString() { 500 void test_toString() {
500 AnalysisDelta delta = new AnalysisDelta(); 501 AnalysisDelta delta = new AnalysisDelta();
501 delta.setAnalysisLevel(new TestSource(), AnalysisLevel.ALL); 502 delta.setAnalysisLevel(new TestSource(), AnalysisLevel.ALL);
502 String result = delta.toString(); 503 String result = delta.toString();
503 expect(result, isNotNull); 504 expect(result, isNotNull);
504 expect(result.length > 0, isTrue); 505 expect(result.length > 0, isTrue);
505 } 506 }
506 } 507 }
507 508
509 @ReflectiveTestCase()
508 class ChangeSetTest extends EngineTestCase { 510 class ChangeSetTest extends EngineTestCase {
509 void test_changedContent() { 511 void test_changedContent() {
510 TestSource source = new TestSource(); 512 TestSource source = new TestSource();
511 String content = ""; 513 String content = "";
512 ChangeSet changeSet = new ChangeSet(); 514 ChangeSet changeSet = new ChangeSet();
513 changeSet.changedContent(source, content); 515 changeSet.changedContent(source, content);
514 expect(changeSet.addedSources, hasLength(0)); 516 expect(changeSet.addedSources, hasLength(0));
515 expect(changeSet.changedSources, hasLength(0)); 517 expect(changeSet.changedSources, hasLength(0));
516 Map<Source, String> map = changeSet.changedContents; 518 Map<Source, String> map = changeSet.changedContents;
517 expect(map, hasLength(1)); 519 expect(map, hasLength(1));
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 changeSet.changedContent(new TestSource(), ""); 552 changeSet.changedContent(new TestSource(), "");
551 changeSet.changedRange(new TestSource(), "", 0, 0, 0); 553 changeSet.changedRange(new TestSource(), "", 0, 0, 0);
552 changeSet.deletedSource(new TestSource()); 554 changeSet.deletedSource(new TestSource());
553 changeSet.removedSource(new TestSource()); 555 changeSet.removedSource(new TestSource());
554 changeSet.removedContainer( 556 changeSet.removedContainer(
555 new SourceContainer_ChangeSetTest_test_toString()); 557 new SourceContainer_ChangeSetTest_test_toString());
556 expect(changeSet.toString(), isNotNull); 558 expect(changeSet.toString(), isNotNull);
557 } 559 }
558 } 560 }
559 561
562 @ReflectiveTestCase()
560 class CheckedModeCompileTimeErrorCodeTest extends ResolverTestCase { 563 class CheckedModeCompileTimeErrorCodeTest extends ResolverTestCase {
561 void test_fieldFormalParameterAssignableToField_extends() { 564 void test_fieldFormalParameterAssignableToField_extends() {
562 // According to checked-mode type checking rules, a value of type B is 565 // According to checked-mode type checking rules, a value of type B is
563 // assignable to a field of type A, because B extends A (and hence is a 566 // assignable to a field of type A, because B extends A (and hence is a
564 // subtype of A). 567 // subtype of A).
565 Source source = addSource(r''' 568 Source source = addSource(r'''
566 class A { 569 class A {
567 const A(); 570 const A();
568 } 571 }
569 class B extends A { 572 class B extends A {
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 resolve(source); 1138 resolve(source);
1136 assertErrors( 1139 assertErrors(
1137 source, 1140 source,
1138 [ 1141 [
1139 CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH, 1142 CheckedModeCompileTimeErrorCode.VARIABLE_TYPE_MISMATCH,
1140 StaticWarningCode.UNDEFINED_CLASS]); 1143 StaticWarningCode.UNDEFINED_CLASS]);
1141 verify([source]); 1144 verify([source]);
1142 } 1145 }
1143 } 1146 }
1144 1147
1148 @ReflectiveTestCase()
1145 class ElementResolverTest extends EngineTestCase { 1149 class ElementResolverTest extends EngineTestCase {
1146 /** 1150 /**
1147 * The error listener to which errors will be reported. 1151 * The error listener to which errors will be reported.
1148 */ 1152 */
1149 GatheringErrorListener _listener; 1153 GatheringErrorListener _listener;
1150 1154
1151 /** 1155 /**
1152 * The type provider used to access the types. 1156 * The type provider used to access the types.
1153 */ 1157 */
1154 TestTypeProvider _typeProvider; 1158 TestTypeProvider _typeProvider;
(...skipping 913 matching lines...) Expand 10 before | Expand all | Expand 10 after
2068 statement.accept(_resolver); 2072 statement.accept(_resolver);
2069 } finally { 2073 } finally {
2070 _visitor.labelScope_J2DAccessor = outerScope; 2074 _visitor.labelScope_J2DAccessor = outerScope;
2071 } 2075 }
2072 } catch (exception) { 2076 } catch (exception) {
2073 throw new IllegalArgumentException("Could not resolve node", exception); 2077 throw new IllegalArgumentException("Could not resolve node", exception);
2074 } 2078 }
2075 } 2079 }
2076 } 2080 }
2077 2081
2082 @ReflectiveTestCase()
2078 class EnclosedScopeTest extends ResolverTestCase { 2083 class EnclosedScopeTest extends ResolverTestCase {
2079 void test_define_duplicate() { 2084 void test_define_duplicate() {
2080 GatheringErrorListener listener = new GatheringErrorListener(); 2085 GatheringErrorListener listener = new GatheringErrorListener();
2081 Scope rootScope = 2086 Scope rootScope =
2082 new Scope_EnclosedScopeTest_test_define_duplicate(listener); 2087 new Scope_EnclosedScopeTest_test_define_duplicate(listener);
2083 EnclosedScope scope = new EnclosedScope(rootScope); 2088 EnclosedScope scope = new EnclosedScope(rootScope);
2084 VariableElement element1 = 2089 VariableElement element1 =
2085 ElementFactory.localVariableElement(AstFactory.identifier3("v1")); 2090 ElementFactory.localVariableElement(AstFactory.identifier3("v1"));
2086 VariableElement element2 = 2091 VariableElement element2 =
2087 ElementFactory.localVariableElement(AstFactory.identifier3("v1")); 2092 ElementFactory.localVariableElement(AstFactory.identifier3("v1"));
(...skipping 10 matching lines...) Expand all
2098 VariableElement element1 = 2103 VariableElement element1 =
2099 ElementFactory.localVariableElement(AstFactory.identifier3("v1")); 2104 ElementFactory.localVariableElement(AstFactory.identifier3("v1"));
2100 VariableElement element2 = 2105 VariableElement element2 =
2101 ElementFactory.localVariableElement(AstFactory.identifier3("v2")); 2106 ElementFactory.localVariableElement(AstFactory.identifier3("v2"));
2102 outerScope.define(element1); 2107 outerScope.define(element1);
2103 innerScope.define(element2); 2108 innerScope.define(element2);
2104 listener.assertNoErrors(); 2109 listener.assertNoErrors();
2105 } 2110 }
2106 } 2111 }
2107 2112
2113 @ReflectiveTestCase()
2108 class ErrorResolverTest extends ResolverTestCase { 2114 class ErrorResolverTest extends ResolverTestCase {
2109 void test_breakLabelOnSwitchMember() { 2115 void test_breakLabelOnSwitchMember() {
2110 Source source = addSource(r''' 2116 Source source = addSource(r'''
2111 class A { 2117 class A {
2112 void m(int i) { 2118 void m(int i) {
2113 switch (i) { 2119 switch (i) {
2114 l: case 0: 2120 l: case 0:
2115 break; 2121 break;
2116 case 1: 2122 case 1:
2117 break l; 2123 break l;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2160 ConstructorElement constructor = constructors[0]; 2166 ConstructorElement constructor = constructors[0];
2161 expect(constructor, isNotNull); 2167 expect(constructor, isNotNull);
2162 List<FunctionElement> functions = constructor.functions; 2168 List<FunctionElement> functions = constructor.functions;
2163 expect(functions, isNotNull); 2169 expect(functions, isNotNull);
2164 expect(functions, hasLength(1)); 2170 expect(functions, hasLength(1));
2165 expect(functions[0].enclosingElement, constructor); 2171 expect(functions[0].enclosingElement, constructor);
2166 assertErrors(source, [ParserErrorCode.GETTER_IN_FUNCTION]); 2172 assertErrors(source, [ParserErrorCode.GETTER_IN_FUNCTION]);
2167 } 2173 }
2168 } 2174 }
2169 2175
2176 @ReflectiveTestCase()
2170 class HintCodeTest extends ResolverTestCase { 2177 class HintCodeTest extends ResolverTestCase {
2171 void fail_deadCode_statementAfterRehrow() { 2178 void fail_deadCode_statementAfterRehrow() {
2172 Source source = addSource(r''' 2179 Source source = addSource(r'''
2173 f() { 2180 f() {
2174 try { 2181 try {
2175 var one = 1; 2182 var one = 1;
2176 } catch (e) { 2183 } catch (e) {
2177 rethrow; 2184 rethrow;
2178 var two = 2; 2185 var two = 2;
2179 } 2186 }
(...skipping 2250 matching lines...) Expand 10 before | Expand all | Expand 10 after
4430 } 4437 }
4431 }'''); 4438 }''');
4432 resolve(source); 4439 resolve(source);
4433 assertErrors( 4440 assertErrors(
4434 source, 4441 source,
4435 [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]); 4442 [HintCode.USE_OF_VOID_RESULT, HintCode.USE_OF_VOID_RESULT]);
4436 verify([source]); 4443 verify([source]);
4437 } 4444 }
4438 } 4445 }
4439 4446
4447 @ReflectiveTestCase()
4440 class InheritanceManagerTest extends EngineTestCase { 4448 class InheritanceManagerTest extends EngineTestCase {
4441 /** 4449 /**
4442 * The type provider used to access the types. 4450 * The type provider used to access the types.
4443 */ 4451 */
4444 TestTypeProvider _typeProvider; 4452 TestTypeProvider _typeProvider;
4445 4453
4446 /** 4454 /**
4447 * The library containing the code being resolved. 4455 * The library containing the code being resolved.
4448 */ 4456 */
4449 LibraryElementImpl _definingLibrary; 4457 LibraryElementImpl _definingLibrary;
(...skipping 1197 matching lines...) Expand 10 before | Expand all | Expand 10 after
5647 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart")); 5655 new FileBasedSource.con1(FileUtilities2.createFile("/test.dart"));
5648 CompilationUnitElementImpl definingCompilationUnit = 5656 CompilationUnitElementImpl definingCompilationUnit =
5649 new CompilationUnitElementImpl("test.dart"); 5657 new CompilationUnitElementImpl("test.dart");
5650 definingCompilationUnit.source = source; 5658 definingCompilationUnit.source = source;
5651 _definingLibrary = ElementFactory.library(context, "test"); 5659 _definingLibrary = ElementFactory.library(context, "test");
5652 _definingLibrary.definingCompilationUnit = definingCompilationUnit; 5660 _definingLibrary.definingCompilationUnit = definingCompilationUnit;
5653 return new InheritanceManager(_definingLibrary); 5661 return new InheritanceManager(_definingLibrary);
5654 } 5662 }
5655 } 5663 }
5656 5664
5665 @ReflectiveTestCase()
5657 class LibraryElementBuilderTest extends EngineTestCase { 5666 class LibraryElementBuilderTest extends EngineTestCase {
5658 /** 5667 /**
5659 * The analysis context used to analyze sources. 5668 * The analysis context used to analyze sources.
5660 */ 5669 */
5661 AnalysisContextImpl _context; 5670 AnalysisContextImpl _context;
5662 5671
5663 /** 5672 /**
5664 * Add a source file to the content provider. The file path should be absolute . 5673 * Add a source file to the content provider. The file path should be absolute .
5665 * 5674 *
5666 * @param filePath the path of the file being added 5675 * @param filePath the path of the file being added
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
5830 new LibraryElementBuilder(resolver.analysisContext, resolver.errorListen er); 5839 new LibraryElementBuilder(resolver.analysisContext, resolver.errorListen er);
5831 Library library = resolver.createLibrary(librarySource); 5840 Library library = resolver.createLibrary(librarySource);
5832 LibraryElement element = builder.buildLibrary(library); 5841 LibraryElement element = builder.buildLibrary(library);
5833 GatheringErrorListener listener = new GatheringErrorListener(); 5842 GatheringErrorListener listener = new GatheringErrorListener();
5834 listener.addAll2(resolver.errorListener); 5843 listener.addAll2(resolver.errorListener);
5835 listener.assertErrorsWithCodes(expectedErrorCodes); 5844 listener.assertErrorsWithCodes(expectedErrorCodes);
5836 return element; 5845 return element;
5837 } 5846 }
5838 } 5847 }
5839 5848
5849 @ReflectiveTestCase()
5840 class LibraryImportScopeTest extends ResolverTestCase { 5850 class LibraryImportScopeTest extends ResolverTestCase {
5841 void test_conflictingImports() { 5851 void test_conflictingImports() {
5842 AnalysisContext context = new AnalysisContextImpl(); 5852 AnalysisContext context = new AnalysisContextImpl();
5843 context.sourceFactory = new SourceFactory([]); 5853 context.sourceFactory = new SourceFactory([]);
5844 String typeNameA = "A"; 5854 String typeNameA = "A";
5845 String typeNameB = "B"; 5855 String typeNameB = "B";
5846 String typeNameC = "C"; 5856 String typeNameC = "C";
5847 ClassElement typeA = ElementFactory.classElement2(typeNameA); 5857 ClassElement typeA = ElementFactory.classElement2(typeNameA);
5848 ClassElement typeB1 = ElementFactory.classElement2(typeNameB); 5858 ClassElement typeB1 = ElementFactory.classElement2(typeNameB);
5849 ClassElement typeB2 = ElementFactory.classElement2(typeNameB); 5859 ClassElement typeB2 = ElementFactory.classElement2(typeNameB);
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
6025 scope.lookup(AstFactory.identifier5(prefixName, typeName), importingLibr ary); 6035 scope.lookup(AstFactory.identifier5(prefixName, typeName), importingLibr ary);
6026 errorListener.assertNoErrors(); 6036 errorListener.assertNoErrors();
6027 expect(prefixedElement, same(prefixedType)); 6037 expect(prefixedElement, same(prefixedType));
6028 Element nonPrefixedElement = 6038 Element nonPrefixedElement =
6029 scope.lookup(AstFactory.identifier3(typeName), importingLibrary); 6039 scope.lookup(AstFactory.identifier3(typeName), importingLibrary);
6030 errorListener.assertNoErrors(); 6040 errorListener.assertNoErrors();
6031 expect(nonPrefixedElement, same(nonPrefixedType)); 6041 expect(nonPrefixedElement, same(nonPrefixedType));
6032 } 6042 }
6033 } 6043 }
6034 6044
6045 @ReflectiveTestCase()
6035 class LibraryResolver2Test extends ResolverTestCase { 6046 class LibraryResolver2Test extends ResolverTestCase {
6036 LibraryResolver2 _resolver; 6047 LibraryResolver2 _resolver;
6037 6048
6038 Source _coreLibrarySource; 6049 Source _coreLibrarySource;
6039 6050
6040 @override 6051 @override
6041 void setUp() { 6052 void setUp() {
6042 super.setUp(); 6053 super.setUp();
6043 _resolver = new LibraryResolver2(analysisContext2); 6054 _resolver = new LibraryResolver2(analysisContext2);
6044 _coreLibrarySource = 6055 _coreLibrarySource =
(...skipping 26 matching lines...) Expand all
6071 6082
6072 ResolvableLibrary _createResolvableLibrary(Source source) { 6083 ResolvableLibrary _createResolvableLibrary(Source source) {
6073 CompilationUnit unit = analysisContext2.parseCompilationUnit(source); 6084 CompilationUnit unit = analysisContext2.parseCompilationUnit(source);
6074 ResolvableLibrary resolvableLibrary = new ResolvableLibrary(source); 6085 ResolvableLibrary resolvableLibrary = new ResolvableLibrary(source);
6075 resolvableLibrary.resolvableCompilationUnits = 6086 resolvableLibrary.resolvableCompilationUnits =
6076 <ResolvableCompilationUnit>[new ResolvableCompilationUnit(source, unit)] ; 6087 <ResolvableCompilationUnit>[new ResolvableCompilationUnit(source, unit)] ;
6077 return resolvableLibrary; 6088 return resolvableLibrary;
6078 } 6089 }
6079 } 6090 }
6080 6091
6092 @ReflectiveTestCase()
6081 class LibraryResolverTest extends ResolverTestCase { 6093 class LibraryResolverTest extends ResolverTestCase {
6082 LibraryResolver _resolver; 6094 LibraryResolver _resolver;
6083 6095
6084 @override 6096 @override
6085 void setUp() { 6097 void setUp() {
6086 super.setUp(); 6098 super.setUp();
6087 _resolver = new LibraryResolver(analysisContext2); 6099 _resolver = new LibraryResolver(analysisContext2);
6088 } 6100 }
6089 6101
6090 void test_imports_dart_html() { 6102 void test_imports_dart_html() {
(...skipping 20 matching lines...) Expand all
6111 Source source = addSource(r''' 6123 Source source = addSource(r'''
6112 library libA; 6124 library libA;
6113 import 'libB.dart'; 6125 import 'libB.dart';
6114 class A {}'''); 6126 class A {}''');
6115 LibraryElement library = _resolver.resolveLibrary(source, true); 6127 LibraryElement library = _resolver.resolveLibrary(source, true);
6116 List<LibraryElement> importedLibraries = library.importedLibraries; 6128 List<LibraryElement> importedLibraries = library.importedLibraries;
6117 assertNamedElements(importedLibraries, ["dart.core", "libB"]); 6129 assertNamedElements(importedLibraries, ["dart.core", "libB"]);
6118 } 6130 }
6119 } 6131 }
6120 6132
6133 @ReflectiveTestCase()
6121 class LibraryScopeTest extends ResolverTestCase { 6134 class LibraryScopeTest extends ResolverTestCase {
6122 void test_creation_empty() { 6135 void test_creation_empty() {
6123 LibraryElement definingLibrary = createDefaultTestLibrary(); 6136 LibraryElement definingLibrary = createDefaultTestLibrary();
6124 GatheringErrorListener errorListener = new GatheringErrorListener(); 6137 GatheringErrorListener errorListener = new GatheringErrorListener();
6125 new LibraryScope(definingLibrary, errorListener); 6138 new LibraryScope(definingLibrary, errorListener);
6126 } 6139 }
6127 6140
6128 void test_creation_nonEmpty() { 6141 void test_creation_nonEmpty() {
6129 AnalysisContext context = new AnalysisContextImpl(); 6142 AnalysisContext context = new AnalysisContextImpl();
6130 context.sourceFactory = new SourceFactory([]); 6143 context.sourceFactory = new SourceFactory([]);
(...skipping 16 matching lines...) Expand all
6147 } 6160 }
6148 6161
6149 void test_getErrorListener() { 6162 void test_getErrorListener() {
6150 LibraryElement definingLibrary = createDefaultTestLibrary(); 6163 LibraryElement definingLibrary = createDefaultTestLibrary();
6151 GatheringErrorListener errorListener = new GatheringErrorListener(); 6164 GatheringErrorListener errorListener = new GatheringErrorListener();
6152 LibraryScope scope = new LibraryScope(definingLibrary, errorListener); 6165 LibraryScope scope = new LibraryScope(definingLibrary, errorListener);
6153 expect(scope.errorListener, errorListener); 6166 expect(scope.errorListener, errorListener);
6154 } 6167 }
6155 } 6168 }
6156 6169
6170 @ReflectiveTestCase()
6157 class LibraryTest extends EngineTestCase { 6171 class LibraryTest extends EngineTestCase {
6158 /** 6172 /**
6159 * The error listener to which all errors will be reported. 6173 * The error listener to which all errors will be reported.
6160 */ 6174 */
6161 GatheringErrorListener _errorListener; 6175 GatheringErrorListener _errorListener;
6162 6176
6163 /** 6177 /**
6164 * The source factory used to create libraries. 6178 * The source factory used to create libraries.
6165 */ 6179 */
6166 SourceFactory _sourceFactory; 6180 SourceFactory _sourceFactory;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
6263 } 6277 }
6264 6278
6265 Library _createLibrary(String definingCompilationUnitPath) => 6279 Library _createLibrary(String definingCompilationUnitPath) =>
6266 new Library( 6280 new Library(
6267 _analysisContext, 6281 _analysisContext,
6268 _errorListener, 6282 _errorListener,
6269 new FileBasedSource.con1( 6283 new FileBasedSource.con1(
6270 FileUtilities2.createFile(definingCompilationUnitPath))); 6284 FileUtilities2.createFile(definingCompilationUnitPath)));
6271 } 6285 }
6272 6286
6287 @ReflectiveTestCase()
6273 class MemberMapTest { 6288 class MemberMapTest {
6274 /** 6289 /**
6275 * The null type. 6290 * The null type.
6276 */ 6291 */
6277 InterfaceType _nullType; 6292 InterfaceType _nullType;
6278 6293
6279 void setUp() { 6294 void setUp() {
6280 _nullType = new TestTypeProvider().nullType; 6295 _nullType = new TestTypeProvider().nullType;
6281 } 6296 }
6282 6297
(...skipping 25 matching lines...) Expand all
6308 void test_MemberMap_put() { 6323 void test_MemberMap_put() {
6309 MethodElement m1 = ElementFactory.methodElement("m1", _nullType); 6324 MethodElement m1 = ElementFactory.methodElement("m1", _nullType);
6310 MemberMap map = new MemberMap(); 6325 MemberMap map = new MemberMap();
6311 expect(map.size, 0); 6326 expect(map.size, 0);
6312 map.put(m1.name, m1); 6327 map.put(m1.name, m1);
6313 expect(map.size, 1); 6328 expect(map.size, 1);
6314 expect(map.get("m1"), m1); 6329 expect(map.get("m1"), m1);
6315 } 6330 }
6316 } 6331 }
6317 6332
6333 @ReflectiveTestCase()
6318 class NonHintCodeTest extends ResolverTestCase { 6334 class NonHintCodeTest extends ResolverTestCase {
6319 void test_deadCode_deadBlock_conditionalElse_debugConst() { 6335 void test_deadCode_deadBlock_conditionalElse_debugConst() {
6320 Source source = addSource(r''' 6336 Source source = addSource(r'''
6321 const bool DEBUG = true; 6337 const bool DEBUG = true;
6322 f() { 6338 f() {
6323 DEBUG ? 1 : 2; 6339 DEBUG ? 1 : 2;
6324 }'''); 6340 }''');
6325 resolve(source); 6341 resolve(source);
6326 assertNoErrors(source); 6342 assertNoErrors(source);
6327 verify([source]); 6343 verify([source]);
(...skipping 1628 matching lines...) Expand 10 before | Expand all | Expand 10 after
7956 7972
7957 @override 7973 @override
7958 AnalysisErrorListener get errorListener => listener; 7974 AnalysisErrorListener get errorListener => listener;
7959 7975
7960 @override 7976 @override
7961 Element internalLookup(Identifier identifier, String name, 7977 Element internalLookup(Identifier identifier, String name,
7962 LibraryElement referencingLibrary) => 7978 LibraryElement referencingLibrary) =>
7963 null; 7979 null;
7964 } 7980 }
7965 7981
7982 @ReflectiveTestCase()
7966 class ScopeTest extends ResolverTestCase { 7983 class ScopeTest extends ResolverTestCase {
7967 void test_define_duplicate() { 7984 void test_define_duplicate() {
7968 GatheringErrorListener errorListener = new GatheringErrorListener(); 7985 GatheringErrorListener errorListener = new GatheringErrorListener();
7969 ScopeTest_TestScope scope = new ScopeTest_TestScope(errorListener); 7986 ScopeTest_TestScope scope = new ScopeTest_TestScope(errorListener);
7970 VariableElement element1 = 7987 VariableElement element1 =
7971 ElementFactory.localVariableElement(AstFactory.identifier3("v1")); 7988 ElementFactory.localVariableElement(AstFactory.identifier3("v1"));
7972 VariableElement element2 = 7989 VariableElement element2 =
7973 ElementFactory.localVariableElement(AstFactory.identifier3("v1")); 7990 ElementFactory.localVariableElement(AstFactory.identifier3("v1"));
7974 scope.define(element1); 7991 scope.define(element1);
7975 scope.define(element2); 7992 scope.define(element2);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
8013 final AnalysisErrorListener errorListener; 8030 final AnalysisErrorListener errorListener;
8014 8031
8015 ScopeTest_TestScope(this.errorListener); 8032 ScopeTest_TestScope(this.errorListener);
8016 8033
8017 @override 8034 @override
8018 Element internalLookup(Identifier identifier, String name, 8035 Element internalLookup(Identifier identifier, String name,
8019 LibraryElement referencingLibrary) => 8036 LibraryElement referencingLibrary) =>
8020 localLookup(name, referencingLibrary); 8037 localLookup(name, referencingLibrary);
8021 } 8038 }
8022 8039
8040 @ReflectiveTestCase()
8023 class SimpleResolverTest extends ResolverTestCase { 8041 class SimpleResolverTest extends ResolverTestCase {
8024 void fail_staticInvocation() { 8042 void fail_staticInvocation() {
8025 Source source = addSource(r''' 8043 Source source = addSource(r'''
8026 class A { 8044 class A {
8027 static int get g => (a,b) => 0; 8045 static int get g => (a,b) => 0;
8028 } 8046 }
8029 class B { 8047 class B {
8030 f() { 8048 f() {
8031 A.g(1,0); 8049 A.g(1,0);
8032 } 8050 }
(...skipping 1307 matching lines...) Expand 10 before | Expand all | Expand 10 after
9340 } 9358 }
9341 9359
9342 class SourceContainer_ChangeSetTest_test_toString implements SourceContainer { 9360 class SourceContainer_ChangeSetTest_test_toString implements SourceContainer {
9343 @override 9361 @override
9344 bool contains(Source source) => false; 9362 bool contains(Source source) => false;
9345 } 9363 }
9346 9364
9347 /** 9365 /**
9348 * Like [StaticTypeAnalyzerTest], but as end-to-end tests. 9366 * Like [StaticTypeAnalyzerTest], but as end-to-end tests.
9349 */ 9367 */
9368 @ReflectiveTestCase()
9350 class StaticTypeAnalyzer2Test extends ResolverTestCase { 9369 class StaticTypeAnalyzer2Test extends ResolverTestCase {
9351 String testCode; 9370 String testCode;
9352 Source testSource; 9371 Source testSource;
9353 CompilationUnit testUnit; 9372 CompilationUnit testUnit;
9354 9373
9355 void test_MethodInvocation_nameType_localVariable() { 9374 void test_MethodInvocation_nameType_localVariable() {
9356 String code = r""" 9375 String code = r"""
9357 typedef Foo(); 9376 typedef Foo();
9358 main() { 9377 main() {
9359 Foo foo; 9378 Foo foo;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
9412 void _resolveTestUnit(String code) { 9431 void _resolveTestUnit(String code) {
9413 testCode = code; 9432 testCode = code;
9414 testSource = addSource(testCode); 9433 testSource = addSource(testCode);
9415 LibraryElement library = resolve(testSource); 9434 LibraryElement library = resolve(testSource);
9416 assertNoErrors(testSource); 9435 assertNoErrors(testSource);
9417 verify([testSource]); 9436 verify([testSource]);
9418 testUnit = resolveCompilationUnit(testSource, library); 9437 testUnit = resolveCompilationUnit(testSource, library);
9419 } 9438 }
9420 } 9439 }
9421 9440
9441 @ReflectiveTestCase()
9422 class StaticTypeAnalyzerTest extends EngineTestCase { 9442 class StaticTypeAnalyzerTest extends EngineTestCase {
9423 /** 9443 /**
9424 * The error listener to which errors will be reported. 9444 * The error listener to which errors will be reported.
9425 */ 9445 */
9426 GatheringErrorListener _listener; 9446 GatheringErrorListener _listener;
9427 9447
9428 /** 9448 /**
9429 * The resolver visitor used to create the analyzer. 9449 * The resolver visitor used to create the analyzer.
9430 */ 9450 */
9431 ResolverVisitor _visitor; 9451 ResolverVisitor _visitor;
(...skipping 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after
10830 } 10850 }
10831 } 10851 }
10832 return "<unknown file- ASTNode is null>"; 10852 return "<unknown file- ASTNode is null>";
10833 } 10853 }
10834 } 10854 }
10835 10855
10836 /** 10856 /**
10837 * The class `StrictModeTest` contains tests to ensure that the correct errors a nd warnings 10857 * The class `StrictModeTest` contains tests to ensure that the correct errors a nd warnings
10838 * are reported when the analysis engine is run in strict mode. 10858 * are reported when the analysis engine is run in strict mode.
10839 */ 10859 */
10860 @ReflectiveTestCase()
10840 class StrictModeTest extends ResolverTestCase { 10861 class StrictModeTest extends ResolverTestCase {
10841 void fail_for() { 10862 void fail_for() {
10842 Source source = addSource(r''' 10863 Source source = addSource(r'''
10843 int f(List<int> list) { 10864 int f(List<int> list) {
10844 num sum = 0; 10865 num sum = 0;
10845 for (num i = 0; i < list.length; i++) { 10866 for (num i = 0; i < list.length; i++) {
10846 sum += list[i]; 10867 sum += list[i];
10847 } 10868 }
10848 }'''); 10869 }''');
10849 resolve(source); 10870 resolve(source);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
10981 Source source = addSource(r''' 11002 Source source = addSource(r'''
10982 int f() { 11003 int f() {
10983 num n = 1234; 11004 num n = 1234;
10984 return n & 0x0F; 11005 return n & 0x0F;
10985 }'''); 11006 }''');
10986 resolve(source); 11007 resolve(source);
10987 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]); 11008 assertErrors(source, [StaticTypeWarningCode.UNDEFINED_OPERATOR]);
10988 } 11009 }
10989 } 11010 }
10990 11011
11012 @ReflectiveTestCase()
10991 class SubtypeManagerTest extends EngineTestCase { 11013 class SubtypeManagerTest extends EngineTestCase {
10992 /** 11014 /**
10993 * The inheritance manager being tested. 11015 * The inheritance manager being tested.
10994 */ 11016 */
10995 SubtypeManager _subtypeManager; 11017 SubtypeManager _subtypeManager;
10996 11018
10997 /** 11019 /**
10998 * The compilation unit element containing all of the types setup in each test . 11020 * The compilation unit element containing all of the types setup in each test .
10999 */ 11021 */
11000 CompilationUnitElementImpl _definingCompilationUnit; 11022 CompilationUnitElementImpl _definingCompilationUnit;
(...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after
11546 FunctionTypeImpl functionType = method.type as FunctionTypeImpl; 11568 FunctionTypeImpl functionType = method.type as FunctionTypeImpl;
11547 functionType.typeArguments = typeArguments; 11569 functionType.typeArguments = typeArguments;
11548 } 11570 }
11549 for (ConstructorElement constructor in classElement.constructors) { 11571 for (ConstructorElement constructor in classElement.constructors) {
11550 FunctionTypeImpl functionType = constructor.type as FunctionTypeImpl; 11572 FunctionTypeImpl functionType = constructor.type as FunctionTypeImpl;
11551 functionType.typeArguments = typeArguments; 11573 functionType.typeArguments = typeArguments;
11552 } 11574 }
11553 } 11575 }
11554 } 11576 }
11555 11577
11578 @ReflectiveTestCase()
11556 class TypeOverrideManagerTest extends EngineTestCase { 11579 class TypeOverrideManagerTest extends EngineTestCase {
11557 void test_exitScope_noScopes() { 11580 void test_exitScope_noScopes() {
11558 TypeOverrideManager manager = new TypeOverrideManager(); 11581 TypeOverrideManager manager = new TypeOverrideManager();
11559 try { 11582 try {
11560 manager.exitScope(); 11583 manager.exitScope();
11561 fail("Expected IllegalStateException"); 11584 fail("Expected IllegalStateException");
11562 } on IllegalStateException catch (exception) { 11585 } on IllegalStateException catch (exception) {
11563 // Expected 11586 // Expected
11564 } 11587 }
11565 } 11588 }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
11616 manager.enterScope(); 11639 manager.enterScope();
11617 expect(manager.getType(ElementFactory.localVariableElement2("v")), isNull); 11640 expect(manager.getType(ElementFactory.localVariableElement2("v")), isNull);
11618 } 11641 }
11619 11642
11620 void test_getType_noScope() { 11643 void test_getType_noScope() {
11621 TypeOverrideManager manager = new TypeOverrideManager(); 11644 TypeOverrideManager manager = new TypeOverrideManager();
11622 expect(manager.getType(ElementFactory.localVariableElement2("v")), isNull); 11645 expect(manager.getType(ElementFactory.localVariableElement2("v")), isNull);
11623 } 11646 }
11624 } 11647 }
11625 11648
11649 @ReflectiveTestCase()
11626 class TypePropagationTest extends ResolverTestCase { 11650 class TypePropagationTest extends ResolverTestCase {
11627 void fail_mergePropagatedTypesAtJoinPoint_1() { 11651 void fail_mergePropagatedTypesAtJoinPoint_1() {
11628 // https://code.google.com/p/dart/issues/detail?id=19929 11652 // https://code.google.com/p/dart/issues/detail?id=19929
11629 _assertTypeOfMarkedExpression(r''' 11653 _assertTypeOfMarkedExpression(r'''
11630 f1(x) { 11654 f1(x) {
11631 var y = []; 11655 var y = [];
11632 if (x) { 11656 if (x) {
11633 y = 0; 11657 y = 0;
11634 } else { 11658 } else {
11635 y = ''; 11659 y = '';
(...skipping 1455 matching lines...) Expand 10 before | Expand all | Expand 10 after
13091 // assertion failure here should be a failure, in both "test_*" and 13115 // assertion failure here should be a failure, in both "test_*" and
13092 // "fail_*" tests. However, an assertion failure is success for the 13116 // "fail_*" tests. However, an assertion failure is success for the
13093 // purpose of "fail_*" tests, so without catching them here "fail_*" tests 13117 // purpose of "fail_*" tests, so without catching them here "fail_*" tests
13094 // can succeed by failing for the wrong reason. 13118 // can succeed by failing for the wrong reason.
13095 throw new JavaException("Unexexpected assertion failure: $exception"); 13119 throw new JavaException("Unexexpected assertion failure: $exception");
13096 } 13120 }
13097 } 13121 }
13098 } 13122 }
13099 13123
13100 13124
13125 @ReflectiveTestCase()
13101 class TypeProviderImplTest extends EngineTestCase { 13126 class TypeProviderImplTest extends EngineTestCase {
13102 void test_creation() { 13127 void test_creation() {
13103 // 13128 //
13104 // Create a mock library element with the types expected to be in dart:core. 13129 // Create a mock library element with the types expected to be in dart:core.
13105 // We cannot use either ElementFactory or TestTypeProvider (which uses 13130 // We cannot use either ElementFactory or TestTypeProvider (which uses
13106 // ElementFactory) because we side-effect the elements in ways that would 13131 // ElementFactory) because we side-effect the elements in ways that would
13107 // break other tests. 13132 // break other tests.
13108 // 13133 //
13109 InterfaceType objectType = _classElement("Object", null).type; 13134 InterfaceType objectType = _classElement("Object", null).type;
13110 InterfaceType boolType = _classElement("bool", objectType).type; 13135 InterfaceType boolType = _classElement("bool", objectType).type;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
13177 typeParameter.type = typeArguments[i]; 13202 typeParameter.type = typeArguments[i];
13178 } 13203 }
13179 element.typeParameters = typeParameters; 13204 element.typeParameters = typeParameters;
13180 type.typeArguments = typeArguments; 13205 type.typeArguments = typeArguments;
13181 } 13206 }
13182 } 13207 }
13183 return element; 13208 return element;
13184 } 13209 }
13185 } 13210 }
13186 13211
13212 @ReflectiveTestCase()
13187 class TypeResolverVisitorTest extends EngineTestCase { 13213 class TypeResolverVisitorTest extends EngineTestCase {
13188 /** 13214 /**
13189 * The error listener to which errors will be reported. 13215 * The error listener to which errors will be reported.
13190 */ 13216 */
13191 GatheringErrorListener _listener; 13217 GatheringErrorListener _listener;
13192 13218
13193 /** 13219 /**
13194 * The object representing the information about the library in which the type s are being 13220 * The object representing the information about the library in which the type s are being
13195 * resolved. 13221 * resolved.
13196 */ 13222 */
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
13775 // check propagated type 13801 // check propagated type
13776 FunctionType propagatedType = node.propagatedType as FunctionType; 13802 FunctionType propagatedType = node.propagatedType as FunctionType;
13777 expect(propagatedType.returnType, test.typeProvider.stringType); 13803 expect(propagatedType.returnType, test.typeProvider.stringType);
13778 } on AnalysisException catch (e, stackTrace) { 13804 } on AnalysisException catch (e, stackTrace) {
13779 thrownException[0] = new CaughtException(e, stackTrace); 13805 thrownException[0] = new CaughtException(e, stackTrace);
13780 } 13806 }
13781 } 13807 }
13782 return null; 13808 return null;
13783 } 13809 }
13784 } 13810 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698