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

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

Issue 686793002: Replace EngineTestCase.assertSize() with hasLength(). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 | 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 import 'package:analyzer/src/generated/java_core.dart'; 8 import 'package:analyzer/src/generated/java_core.dart';
9 import 'package:analyzer/src/generated/java_engine.dart'; 9 import 'package:analyzer/src/generated/java_engine.dart';
10 import 'package:analyzer/src/generated/java_engine_io.dart'; 10 import 'package:analyzer/src/generated/java_engine_io.dart';
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 TestSource source1 = new TestSource('/1.dart'); 328 TestSource source1 = new TestSource('/1.dart');
329 TestSource source2 = new TestSource('/2.dart'); 329 TestSource source2 = new TestSource('/2.dart');
330 TestSource source3 = new TestSource('/3.dart'); 330 TestSource source3 = new TestSource('/3.dart');
331 331
332 void test_getAddedSources() { 332 void test_getAddedSources() {
333 AnalysisDelta delta = new AnalysisDelta(); 333 AnalysisDelta delta = new AnalysisDelta();
334 delta.setAnalysisLevel(source1, AnalysisLevel.ALL); 334 delta.setAnalysisLevel(source1, AnalysisLevel.ALL);
335 delta.setAnalysisLevel(source2, AnalysisLevel.ERRORS); 335 delta.setAnalysisLevel(source2, AnalysisLevel.ERRORS);
336 delta.setAnalysisLevel(source3, AnalysisLevel.NONE); 336 delta.setAnalysisLevel(source3, AnalysisLevel.NONE);
337 List<Source> addedSources = delta.addedSources; 337 List<Source> addedSources = delta.addedSources;
338 EngineTestCase.assertLength(2, addedSources); 338 expect(addedSources, hasLength(2));
339 EngineTestCase.assertContains(addedSources, [source1, source2]); 339 EngineTestCase.assertContains(addedSources, [source1, source2]);
340 } 340 }
341 341
342 void test_getAnalysisLevels() { 342 void test_getAnalysisLevels() {
343 AnalysisDelta delta = new AnalysisDelta(); 343 AnalysisDelta delta = new AnalysisDelta();
344 expect(delta.analysisLevels.length, 0); 344 expect(delta.analysisLevels.length, 0);
345 } 345 }
346 346
347 void test_setAnalysisLevel() { 347 void test_setAnalysisLevel() {
348 AnalysisDelta delta = new AnalysisDelta(); 348 AnalysisDelta delta = new AnalysisDelta();
(...skipping 13 matching lines...) Expand all
362 expect(result.length > 0, isTrue); 362 expect(result.length > 0, isTrue);
363 } 363 }
364 } 364 }
365 365
366 class ChangeSetTest extends EngineTestCase { 366 class ChangeSetTest extends EngineTestCase {
367 void test_changedContent() { 367 void test_changedContent() {
368 TestSource source = new TestSource(); 368 TestSource source = new TestSource();
369 String content = ""; 369 String content = "";
370 ChangeSet changeSet = new ChangeSet(); 370 ChangeSet changeSet = new ChangeSet();
371 changeSet.changedContent(source, content); 371 changeSet.changedContent(source, content);
372 EngineTestCase.assertSizeOfList(0, changeSet.addedSources); 372 expect(changeSet.addedSources, hasLength(0));
373 EngineTestCase.assertSizeOfList(0, changeSet.changedSources); 373 expect(changeSet.changedSources, hasLength(0));
374 Map<Source, String> map = changeSet.changedContents; 374 Map<Source, String> map = changeSet.changedContents;
375 EngineTestCase.assertSizeOfMap(1, map); 375 expect(map, hasLength(1));
376 expect(map[source], same(content)); 376 expect(map[source], same(content));
377 EngineTestCase.assertSizeOfMap(0, changeSet.changedRanges); 377 expect(changeSet.changedRanges, hasLength(0));
378 EngineTestCase.assertSizeOfList(0, changeSet.deletedSources); 378 expect(changeSet.deletedSources, hasLength(0));
379 EngineTestCase.assertSizeOfList(0, changeSet.removedSources); 379 expect(changeSet.removedSources, hasLength(0));
380 EngineTestCase.assertSizeOfList(0, changeSet.removedContainers); 380 expect(changeSet.removedContainers, hasLength(0));
381 } 381 }
382 382
383 void test_changedRange() { 383 void test_changedRange() {
384 TestSource source = new TestSource(); 384 TestSource source = new TestSource();
385 String content = ""; 385 String content = "";
386 ChangeSet changeSet = new ChangeSet(); 386 ChangeSet changeSet = new ChangeSet();
387 changeSet.changedRange(source, content, 1, 2, 3); 387 changeSet.changedRange(source, content, 1, 2, 3);
388 EngineTestCase.assertSizeOfList(0, changeSet.addedSources); 388 expect(changeSet.addedSources, hasLength(0));
389 EngineTestCase.assertSizeOfList(0, changeSet.changedSources); 389 expect(changeSet.changedSources, hasLength(0));
390 EngineTestCase.assertSizeOfMap(0, changeSet.changedContents); 390 expect(changeSet.changedContents, hasLength(0));
391 Map<Source, ChangeSet_ContentChange> map = changeSet.changedRanges; 391 Map<Source, ChangeSet_ContentChange> map = changeSet.changedRanges;
392 EngineTestCase.assertSizeOfMap(1, map); 392 expect(map, hasLength(1));
393 ChangeSet_ContentChange change = map[source]; 393 ChangeSet_ContentChange change = map[source];
394 expect(change, isNotNull); 394 expect(change, isNotNull);
395 expect(change.contents, content); 395 expect(change.contents, content);
396 expect(change.offset, 1); 396 expect(change.offset, 1);
397 expect(change.oldLength, 2); 397 expect(change.oldLength, 2);
398 expect(change.newLength, 3); 398 expect(change.newLength, 3);
399 EngineTestCase.assertSizeOfList(0, changeSet.deletedSources); 399 expect(changeSet.deletedSources, hasLength(0));
400 EngineTestCase.assertSizeOfList(0, changeSet.removedSources); 400 expect(changeSet.removedSources, hasLength(0));
401 EngineTestCase.assertSizeOfList(0, changeSet.removedContainers); 401 expect(changeSet.removedContainers, hasLength(0));
402 } 402 }
403 403
404 void test_toString() { 404 void test_toString() {
405 ChangeSet changeSet = new ChangeSet(); 405 ChangeSet changeSet = new ChangeSet();
406 changeSet.addedSource(new TestSource()); 406 changeSet.addedSource(new TestSource());
407 changeSet.changedSource(new TestSource()); 407 changeSet.changedSource(new TestSource());
408 changeSet.changedContent(new TestSource(), ""); 408 changeSet.changedContent(new TestSource(), "");
409 changeSet.changedRange(new TestSource(), "", 0, 0, 0); 409 changeSet.changedRange(new TestSource(), "", 0, 0, 0);
410 changeSet.deletedSource(new TestSource()); 410 changeSet.deletedSource(new TestSource());
411 changeSet.removedSource(new TestSource()); 411 changeSet.removedSource(new TestSource());
(...skipping 1508 matching lines...) Expand 10 before | Expand all | Expand 10 after
1920 C() { 1920 C() {
1921 int get x => 0; 1921 int get x => 0;
1922 } 1922 }
1923 }'''); 1923 }''');
1924 LibraryElement library = resolve(source); 1924 LibraryElement library = resolve(source);
1925 expect(library, isNotNull); 1925 expect(library, isNotNull);
1926 var unit = library.definingCompilationUnit; 1926 var unit = library.definingCompilationUnit;
1927 expect(unit, isNotNull); 1927 expect(unit, isNotNull);
1928 var types = unit.types; 1928 var types = unit.types;
1929 expect(types, isNotNull); 1929 expect(types, isNotNull);
1930 EngineTestCase.assertSizeOfList(1, types); 1930 expect(types, hasLength(1));
1931 var type = types[0]; 1931 var type = types[0];
1932 expect(type, isNotNull); 1932 expect(type, isNotNull);
1933 var constructors = type.constructors; 1933 var constructors = type.constructors;
1934 expect(constructors, isNotNull); 1934 expect(constructors, isNotNull);
1935 EngineTestCase.assertSizeOfList(1, constructors); 1935 expect(constructors, hasLength(1));
1936 ConstructorElement constructor = constructors[0]; 1936 ConstructorElement constructor = constructors[0];
1937 expect(constructor, isNotNull); 1937 expect(constructor, isNotNull);
1938 List<FunctionElement> functions = constructor.functions; 1938 List<FunctionElement> functions = constructor.functions;
1939 expect(functions, isNotNull); 1939 expect(functions, isNotNull);
1940 EngineTestCase.assertSizeOfList(1, functions); 1940 expect(functions, hasLength(1));
1941 expect(functions[0].enclosingElement, constructor); 1941 expect(functions[0].enclosingElement, constructor);
1942 assertErrors(source, [ParserErrorCode.GETTER_IN_FUNCTION]); 1942 assertErrors(source, [ParserErrorCode.GETTER_IN_FUNCTION]);
1943 } 1943 }
1944 } 1944 }
1945 1945
1946 class HintCodeTest extends ResolverTestCase { 1946 class HintCodeTest extends ResolverTestCase {
1947 void fail_deadCode_statementAfterRehrow() { 1947 void fail_deadCode_statementAfterRehrow() {
1948 Source source = addSource(r''' 1948 Source source = addSource(r'''
1949 f() { 1949 f() {
1950 try { 1950 try {
(...skipping 2287 matching lines...) Expand 10 before | Expand all | Expand 10 after
4238 classA.accessors = <PropertyAccessorElement> [setterS]; 4238 classA.accessors = <PropertyAccessorElement> [setterS];
4239 expect(_inheritanceManager.lookupMember(classA, setterName), isNull); 4239 expect(_inheritanceManager.lookupMember(classA, setterName), isNull);
4240 _assertNoErrors(classA); 4240 _assertNoErrors(classA);
4241 } 4241 }
4242 4242
4243 void test_lookupOverrides_noParentClasses() { 4243 void test_lookupOverrides_noParentClasses() {
4244 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4244 ClassElementImpl classA = ElementFactory.classElement2("A", []);
4245 String methodName = "m"; 4245 String methodName = "m";
4246 MethodElementImpl methodM = ElementFactory.methodElement(methodName, _typePr ovider.intType, []); 4246 MethodElementImpl methodM = ElementFactory.methodElement(methodName, _typePr ovider.intType, []);
4247 classA.methods = <MethodElement> [methodM]; 4247 classA.methods = <MethodElement> [methodM];
4248 EngineTestCase.assertSizeOfList(0, _inheritanceManager.lookupOverrides(class A, methodName)); 4248 expect(_inheritanceManager.lookupOverrides(classA, methodName), hasLength(0) );
4249 _assertNoErrors(classA); 4249 _assertNoErrors(classA);
4250 } 4250 }
4251 4251
4252 void test_lookupOverrides_overrideBaseClass() { 4252 void test_lookupOverrides_overrideBaseClass() {
4253 ClassElementImpl classA = ElementFactory.classElement2("A", []); 4253 ClassElementImpl classA = ElementFactory.classElement2("A", []);
4254 String methodName = "m"; 4254 String methodName = "m";
4255 MethodElementImpl methodMinA = ElementFactory.methodElement(methodName, _typ eProvider.intType, []); 4255 MethodElementImpl methodMinA = ElementFactory.methodElement(methodName, _typ eProvider.intType, []);
4256 classA.methods = <MethodElement> [methodMinA]; 4256 classA.methods = <MethodElement> [methodMinA];
4257 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); 4257 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []);
4258 MethodElementImpl methodMinB = ElementFactory.methodElement(methodName, _typ eProvider.intType, []); 4258 MethodElementImpl methodMinB = ElementFactory.methodElement(methodName, _typ eProvider.intType, []);
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
4350 part 'second.dart';'''); 4350 part 'second.dart';''');
4351 addSource("/first.dart", r''' 4351 addSource("/first.dart", r'''
4352 part of lib; 4352 part of lib;
4353 int get V => 0;'''); 4353 int get V => 0;''');
4354 addSource("/second.dart", r''' 4354 addSource("/second.dart", r'''
4355 part of lib; 4355 part of lib;
4356 void set V(int v) {}'''); 4356 void set V(int v) {}''');
4357 LibraryElement element = _buildLibrary(librarySource, []); 4357 LibraryElement element = _buildLibrary(librarySource, []);
4358 expect(element, isNotNull); 4358 expect(element, isNotNull);
4359 List<CompilationUnitElement> sourcedUnits = element.parts; 4359 List<CompilationUnitElement> sourcedUnits = element.parts;
4360 EngineTestCase.assertLength(2, sourcedUnits); 4360 expect(sourcedUnits, hasLength(2));
4361 List<PropertyAccessorElement> firstAccessors = sourcedUnits[0].accessors; 4361 List<PropertyAccessorElement> firstAccessors = sourcedUnits[0].accessors;
4362 EngineTestCase.assertLength(1, firstAccessors); 4362 expect(firstAccessors, hasLength(1));
4363 List<PropertyAccessorElement> secondAccessors = sourcedUnits[1].accessors; 4363 List<PropertyAccessorElement> secondAccessors = sourcedUnits[1].accessors;
4364 EngineTestCase.assertLength(1, secondAccessors); 4364 expect(secondAccessors, hasLength(1));
4365 expect(secondAccessors[0].variable, same(firstAccessors[0].variable)); 4365 expect(secondAccessors[0].variable, same(firstAccessors[0].variable));
4366 } 4366 }
4367 4367
4368 void test_empty() { 4368 void test_empty() {
4369 Source librarySource = addSource("/lib.dart", "library lib;"); 4369 Source librarySource = addSource("/lib.dart", "library lib;");
4370 LibraryElement element = _buildLibrary(librarySource, []); 4370 LibraryElement element = _buildLibrary(librarySource, []);
4371 expect(element, isNotNull); 4371 expect(element, isNotNull);
4372 expect(element.name, "lib"); 4372 expect(element.name, "lib");
4373 expect(element.entryPoint, isNull); 4373 expect(element.entryPoint, isNull);
4374 EngineTestCase.assertLength(0, element.importedLibraries); 4374 expect(element.importedLibraries, hasLength(0));
4375 EngineTestCase.assertLength(0, element.imports); 4375 expect(element.imports, hasLength(0));
4376 expect(element.library, same(element)); 4376 expect(element.library, same(element));
4377 EngineTestCase.assertLength(0, element.prefixes); 4377 expect(element.prefixes, hasLength(0));
4378 EngineTestCase.assertLength(0, element.parts); 4378 expect(element.parts, hasLength(0));
4379 CompilationUnitElement unit = element.definingCompilationUnit; 4379 CompilationUnitElement unit = element.definingCompilationUnit;
4380 expect(unit, isNotNull); 4380 expect(unit, isNotNull);
4381 expect(unit.name, "lib.dart"); 4381 expect(unit.name, "lib.dart");
4382 expect(unit.library, element); 4382 expect(unit.library, element);
4383 EngineTestCase.assertLength(0, unit.accessors); 4383 expect(unit.accessors, hasLength(0));
4384 EngineTestCase.assertLength(0, unit.functions); 4384 expect(unit.functions, hasLength(0));
4385 EngineTestCase.assertLength(0, unit.functionTypeAliases); 4385 expect(unit.functionTypeAliases, hasLength(0));
4386 EngineTestCase.assertLength(0, unit.types); 4386 expect(unit.types, hasLength(0));
4387 EngineTestCase.assertLength(0, unit.topLevelVariables); 4387 expect(unit.topLevelVariables, hasLength(0));
4388 } 4388 }
4389 4389
4390 void test_missingLibraryDirectiveWithPart() { 4390 void test_missingLibraryDirectiveWithPart() {
4391 addSource("/a.dart", "part of lib;"); 4391 addSource("/a.dart", "part of lib;");
4392 Source librarySource = addSource("/lib.dart", "part 'a.dart';"); 4392 Source librarySource = addSource("/lib.dart", "part 'a.dart';");
4393 LibraryElement element = _buildLibrary(librarySource, [ResolverErrorCode.MIS SING_LIBRARY_DIRECTIVE_WITH_PART]); 4393 LibraryElement element = _buildLibrary(librarySource, [ResolverErrorCode.MIS SING_LIBRARY_DIRECTIVE_WITH_PART]);
4394 expect(element, isNotNull); 4394 expect(element, isNotNull);
4395 } 4395 }
4396 4396
4397 void test_missingPartOfDirective() { 4397 void test_missingPartOfDirective() {
(...skipping 15 matching lines...) Expand all
4413 class A {}'''); 4413 class A {}''');
4414 addSource("/first.dart", r''' 4414 addSource("/first.dart", r'''
4415 part of lib; 4415 part of lib;
4416 class B {}'''); 4416 class B {}''');
4417 addSource("/second.dart", r''' 4417 addSource("/second.dart", r'''
4418 part of lib; 4418 part of lib;
4419 class C {}'''); 4419 class C {}''');
4420 LibraryElement element = _buildLibrary(librarySource, []); 4420 LibraryElement element = _buildLibrary(librarySource, []);
4421 expect(element, isNotNull); 4421 expect(element, isNotNull);
4422 List<CompilationUnitElement> sourcedUnits = element.parts; 4422 List<CompilationUnitElement> sourcedUnits = element.parts;
4423 EngineTestCase.assertLength(2, sourcedUnits); 4423 expect(sourcedUnits, hasLength(2));
4424 _assertTypes(element.definingCompilationUnit, ["A"]); 4424 _assertTypes(element.definingCompilationUnit, ["A"]);
4425 if (sourcedUnits[0].name == "first.dart") { 4425 if (sourcedUnits[0].name == "first.dart") {
4426 _assertTypes(sourcedUnits[0], ["B"]); 4426 _assertTypes(sourcedUnits[0], ["B"]);
4427 _assertTypes(sourcedUnits[1], ["C"]); 4427 _assertTypes(sourcedUnits[1], ["C"]);
4428 } else { 4428 } else {
4429 _assertTypes(sourcedUnits[0], ["C"]); 4429 _assertTypes(sourcedUnits[0], ["C"]);
4430 _assertTypes(sourcedUnits[1], ["B"]); 4430 _assertTypes(sourcedUnits[1], ["B"]);
4431 } 4431 }
4432 } 4432 }
4433 4433
(...skipping 28 matching lines...) Expand all
4462 4462
4463 /** 4463 /**
4464 * Ensure that there are elements representing all of the types in the given a rray of type names. 4464 * Ensure that there are elements representing all of the types in the given a rray of type names.
4465 * 4465 *
4466 * @param unit the compilation unit containing the types 4466 * @param unit the compilation unit containing the types
4467 * @param typeNames the names of the types that should be found 4467 * @param typeNames the names of the types that should be found
4468 */ 4468 */
4469 void _assertTypes(CompilationUnitElement unit, List<String> typeNames) { 4469 void _assertTypes(CompilationUnitElement unit, List<String> typeNames) {
4470 expect(unit, isNotNull); 4470 expect(unit, isNotNull);
4471 List<ClassElement> types = unit.types; 4471 List<ClassElement> types = unit.types;
4472 EngineTestCase.assertLength(typeNames.length, types); 4472 expect(types, hasLength(typeNames.length));
4473 for (ClassElement type in types) { 4473 for (ClassElement type in types) {
4474 expect(type, isNotNull); 4474 expect(type, isNotNull);
4475 String actualTypeName = type.displayName; 4475 String actualTypeName = type.displayName;
4476 bool wasExpected = false; 4476 bool wasExpected = false;
4477 for (String expectedTypeName in typeNames) { 4477 for (String expectedTypeName in typeNames) {
4478 if (expectedTypeName == actualTypeName) { 4478 if (expectedTypeName == actualTypeName) {
4479 wasExpected = true; 4479 wasExpected = true;
4480 } 4480 }
4481 } 4481 }
4482 if (!wasExpected) { 4482 if (!wasExpected) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
4529 GatheringErrorListener errorListener = new GatheringErrorListener(); 4529 GatheringErrorListener errorListener = new GatheringErrorListener();
4530 Scope scope = new LibraryImportScope(importingLibrary, errorListener); 4530 Scope scope = new LibraryImportScope(importingLibrary, errorListener);
4531 expect(scope.lookup(AstFactory.identifier3(typeNameA), importingLibrary), typeA); 4531 expect(scope.lookup(AstFactory.identifier3(typeNameA), importingLibrary), typeA);
4532 errorListener.assertNoErrors(); 4532 errorListener.assertNoErrors();
4533 expect(scope.lookup(AstFactory.identifier3(typeNameC), importingLibrary), typeC); 4533 expect(scope.lookup(AstFactory.identifier3(typeNameC), importingLibrary), typeC);
4534 errorListener.assertNoErrors(); 4534 errorListener.assertNoErrors();
4535 Element element = scope.lookup(AstFactory.identifier3(typeNameB), importin gLibrary); 4535 Element element = scope.lookup(AstFactory.identifier3(typeNameB), importin gLibrary);
4536 errorListener.assertErrorsWithCodes([StaticWarningCode.AMBIGUOUS_IMPORT]); 4536 errorListener.assertErrorsWithCodes([StaticWarningCode.AMBIGUOUS_IMPORT]);
4537 EngineTestCase.assertInstanceOf((obj) => obj is MultiplyDefinedElement, Mu ltiplyDefinedElement, element); 4537 EngineTestCase.assertInstanceOf((obj) => obj is MultiplyDefinedElement, Mu ltiplyDefinedElement, element);
4538 List<Element> conflictingElements = (element as MultiplyDefinedElement).co nflictingElements; 4538 List<Element> conflictingElements = (element as MultiplyDefinedElement).co nflictingElements;
4539 EngineTestCase.assertLength(2, conflictingElements); 4539 expect(conflictingElements, hasLength(2));
4540 if (identical(conflictingElements[0], typeB1)) { 4540 if (identical(conflictingElements[0], typeB1)) {
4541 expect(conflictingElements[1], same(typeB2)); 4541 expect(conflictingElements[1], same(typeB2));
4542 } else if (identical(conflictingElements[0], typeB2)) { 4542 } else if (identical(conflictingElements[0], typeB2)) {
4543 expect(conflictingElements[1], same(typeB1)); 4543 expect(conflictingElements[1], same(typeB1));
4544 } else { 4544 } else {
4545 expect(conflictingElements[0], same(typeB1)); 4545 expect(conflictingElements[0], same(typeB1));
4546 } 4546 }
4547 } 4547 }
4548 { 4548 {
4549 GatheringErrorListener errorListener = new GatheringErrorListener(); 4549 GatheringErrorListener errorListener = new GatheringErrorListener();
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
4793 _errorListener = new GatheringErrorListener(); 4793 _errorListener = new GatheringErrorListener();
4794 _library = _createLibrary("/lib.dart"); 4794 _library = _createLibrary("/lib.dart");
4795 } 4795 }
4796 4796
4797 void test_getExplicitlyImportsCore() { 4797 void test_getExplicitlyImportsCore() {
4798 expect(_library.explicitlyImportsCore, isFalse); 4798 expect(_library.explicitlyImportsCore, isFalse);
4799 _errorListener.assertNoErrors(); 4799 _errorListener.assertNoErrors();
4800 } 4800 }
4801 4801
4802 void test_getExports() { 4802 void test_getExports() {
4803 EngineTestCase.assertLength(0, _library.exports); 4803 expect(_library.exports, hasLength(0));
4804 _errorListener.assertNoErrors(); 4804 _errorListener.assertNoErrors();
4805 } 4805 }
4806 4806
4807 void test_getImports() { 4807 void test_getImports() {
4808 EngineTestCase.assertLength(0, _library.imports); 4808 expect(_library.imports, hasLength(0));
4809 _errorListener.assertNoErrors(); 4809 _errorListener.assertNoErrors();
4810 } 4810 }
4811 4811
4812 void test_getImportsAndExports() { 4812 void test_getImportsAndExports() {
4813 _library.importedLibraries = <Library> [_createLibrary("/imported.dart")]; 4813 _library.importedLibraries = <Library> [_createLibrary("/imported.dart")];
4814 _library.exportedLibraries = <Library> [_createLibrary("/exported.dart")]; 4814 _library.exportedLibraries = <Library> [_createLibrary("/exported.dart")];
4815 EngineTestCase.assertLength(2, _library.importsAndExports); 4815 expect(_library.importsAndExports, hasLength(2));
4816 _errorListener.assertNoErrors(); 4816 _errorListener.assertNoErrors();
4817 } 4817 }
4818 4818
4819 void test_getLibraryScope() { 4819 void test_getLibraryScope() {
4820 LibraryElementImpl element = new LibraryElementImpl.forNode(_analysisContext , AstFactory.libraryIdentifier2(["lib"])); 4820 LibraryElementImpl element = new LibraryElementImpl.forNode(_analysisContext , AstFactory.libraryIdentifier2(["lib"]));
4821 element.definingCompilationUnit = new CompilationUnitElementImpl("lib.dart") ; 4821 element.definingCompilationUnit = new CompilationUnitElementImpl("lib.dart") ;
4822 _library.libraryElement = element; 4822 _library.libraryElement = element;
4823 expect(_library.libraryScope, isNotNull); 4823 expect(_library.libraryScope, isNotNull);
4824 _errorListener.assertNoErrors(); 4824 _errorListener.assertNoErrors();
4825 } 4825 }
4826 4826
4827 void test_getLibrarySource() { 4827 void test_getLibrarySource() {
4828 expect(_library.librarySource, isNotNull); 4828 expect(_library.librarySource, isNotNull);
4829 } 4829 }
4830 4830
4831 void test_setExplicitlyImportsCore() { 4831 void test_setExplicitlyImportsCore() {
4832 _library.explicitlyImportsCore = true; 4832 _library.explicitlyImportsCore = true;
4833 expect(_library.explicitlyImportsCore, isTrue); 4833 expect(_library.explicitlyImportsCore, isTrue);
4834 _errorListener.assertNoErrors(); 4834 _errorListener.assertNoErrors();
4835 } 4835 }
4836 4836
4837 void test_setExportedLibraries() { 4837 void test_setExportedLibraries() {
4838 Library exportLibrary = _createLibrary("/exported.dart"); 4838 Library exportLibrary = _createLibrary("/exported.dart");
4839 _library.exportedLibraries = <Library> [exportLibrary]; 4839 _library.exportedLibraries = <Library> [exportLibrary];
4840 List<Library> exports = _library.exports; 4840 List<Library> exports = _library.exports;
4841 EngineTestCase.assertLength(1, exports); 4841 expect(exports, hasLength(1));
4842 expect(exports[0], same(exportLibrary)); 4842 expect(exports[0], same(exportLibrary));
4843 _errorListener.assertNoErrors(); 4843 _errorListener.assertNoErrors();
4844 } 4844 }
4845 4845
4846 void test_setImportedLibraries() { 4846 void test_setImportedLibraries() {
4847 Library importLibrary = _createLibrary("/imported.dart"); 4847 Library importLibrary = _createLibrary("/imported.dart");
4848 _library.importedLibraries = <Library> [importLibrary]; 4848 _library.importedLibraries = <Library> [importLibrary];
4849 List<Library> imports = _library.imports; 4849 List<Library> imports = _library.imports;
4850 EngineTestCase.assertLength(1, imports); 4850 expect(imports, hasLength(1));
4851 expect(imports[0], same(importLibrary)); 4851 expect(imports[0], same(importLibrary));
4852 _errorListener.assertNoErrors(); 4852 _errorListener.assertNoErrors();
4853 } 4853 }
4854 4854
4855 void test_setLibraryElement() { 4855 void test_setLibraryElement() {
4856 LibraryElementImpl element = new LibraryElementImpl.forNode(_analysisContext , AstFactory.libraryIdentifier2(["lib"])); 4856 LibraryElementImpl element = new LibraryElementImpl.forNode(_analysisContext , AstFactory.libraryIdentifier2(["lib"]));
4857 _library.libraryElement = element; 4857 _library.libraryElement = element;
4858 expect(_library.libraryElement, same(element)); 4858 expect(_library.libraryElement, same(element));
4859 } 4859 }
4860 4860
(...skipping 2282 matching lines...) Expand 10 before | Expand all | Expand 10 after
7143 7143
7144 void test_hasReferenceToSuper() { 7144 void test_hasReferenceToSuper() {
7145 Source source = addSource(r''' 7145 Source source = addSource(r'''
7146 class A {} 7146 class A {}
7147 class B {toString() => super.toString();}'''); 7147 class B {toString() => super.toString();}''');
7148 LibraryElement library = resolve(source); 7148 LibraryElement library = resolve(source);
7149 expect(library, isNotNull); 7149 expect(library, isNotNull);
7150 CompilationUnitElement unit = library.definingCompilationUnit; 7150 CompilationUnitElement unit = library.definingCompilationUnit;
7151 expect(unit, isNotNull); 7151 expect(unit, isNotNull);
7152 List<ClassElement> classes = unit.types; 7152 List<ClassElement> classes = unit.types;
7153 EngineTestCase.assertLength(2, classes); 7153 expect(classes, hasLength(2));
7154 expect(classes[0].hasReferenceToSuper, isFalse); 7154 expect(classes[0].hasReferenceToSuper, isFalse);
7155 expect(classes[1].hasReferenceToSuper, isTrue); 7155 expect(classes[1].hasReferenceToSuper, isTrue);
7156 assertNoErrors(source); 7156 assertNoErrors(source);
7157 verify([source]); 7157 verify([source]);
7158 } 7158 }
7159 7159
7160 void test_import_hide() { 7160 void test_import_hide() {
7161 addNamedSource("lib1.dart", r''' 7161 addNamedSource("lib1.dart", r'''
7162 library lib1; 7162 library lib1;
7163 set foo(value) {} 7163 set foo(value) {}
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
7273 7273
7274 void test_isValidMixin_badSuperclass() { 7274 void test_isValidMixin_badSuperclass() {
7275 Source source = addSource(r''' 7275 Source source = addSource(r'''
7276 class A extends B {} 7276 class A extends B {}
7277 class B {}'''); 7277 class B {}''');
7278 LibraryElement library = resolve(source); 7278 LibraryElement library = resolve(source);
7279 expect(library, isNotNull); 7279 expect(library, isNotNull);
7280 CompilationUnitElement unit = library.definingCompilationUnit; 7280 CompilationUnitElement unit = library.definingCompilationUnit;
7281 expect(unit, isNotNull); 7281 expect(unit, isNotNull);
7282 List<ClassElement> classes = unit.types; 7282 List<ClassElement> classes = unit.types;
7283 EngineTestCase.assertLength(2, classes); 7283 expect(classes, hasLength(2));
7284 expect(classes[0].isValidMixin, isFalse); 7284 expect(classes[0].isValidMixin, isFalse);
7285 assertNoErrors(source); 7285 assertNoErrors(source);
7286 verify([source]); 7286 verify([source]);
7287 } 7287 }
7288 7288
7289 void test_isValidMixin_constructor() { 7289 void test_isValidMixin_constructor() {
7290 Source source = addSource(r''' 7290 Source source = addSource(r'''
7291 class A { 7291 class A {
7292 A() {} 7292 A() {}
7293 }'''); 7293 }''');
7294 LibraryElement library = resolve(source); 7294 LibraryElement library = resolve(source);
7295 expect(library, isNotNull); 7295 expect(library, isNotNull);
7296 CompilationUnitElement unit = library.definingCompilationUnit; 7296 CompilationUnitElement unit = library.definingCompilationUnit;
7297 expect(unit, isNotNull); 7297 expect(unit, isNotNull);
7298 List<ClassElement> classes = unit.types; 7298 List<ClassElement> classes = unit.types;
7299 EngineTestCase.assertLength(1, classes); 7299 expect(classes, hasLength(1));
7300 expect(classes[0].isValidMixin, isFalse); 7300 expect(classes[0].isValidMixin, isFalse);
7301 assertNoErrors(source); 7301 assertNoErrors(source);
7302 verify([source]); 7302 verify([source]);
7303 } 7303 }
7304 7304
7305 void test_isValidMixin_super() { 7305 void test_isValidMixin_super() {
7306 Source source = addSource(r''' 7306 Source source = addSource(r'''
7307 class A { 7307 class A {
7308 toString() { 7308 toString() {
7309 return super.toString(); 7309 return super.toString();
7310 } 7310 }
7311 }'''); 7311 }''');
7312 LibraryElement library = resolve(source); 7312 LibraryElement library = resolve(source);
7313 expect(library, isNotNull); 7313 expect(library, isNotNull);
7314 CompilationUnitElement unit = library.definingCompilationUnit; 7314 CompilationUnitElement unit = library.definingCompilationUnit;
7315 expect(unit, isNotNull); 7315 expect(unit, isNotNull);
7316 List<ClassElement> classes = unit.types; 7316 List<ClassElement> classes = unit.types;
7317 EngineTestCase.assertLength(1, classes); 7317 expect(classes, hasLength(1));
7318 expect(classes[0].isValidMixin, isFalse); 7318 expect(classes[0].isValidMixin, isFalse);
7319 assertNoErrors(source); 7319 assertNoErrors(source);
7320 verify([source]); 7320 verify([source]);
7321 } 7321 }
7322 7322
7323 void test_isValidMixin_valid() { 7323 void test_isValidMixin_valid() {
7324 Source source = addSource("class A {}"); 7324 Source source = addSource("class A {}");
7325 LibraryElement library = resolve(source); 7325 LibraryElement library = resolve(source);
7326 expect(library, isNotNull); 7326 expect(library, isNotNull);
7327 CompilationUnitElement unit = library.definingCompilationUnit; 7327 CompilationUnitElement unit = library.definingCompilationUnit;
7328 expect(unit, isNotNull); 7328 expect(unit, isNotNull);
7329 List<ClassElement> classes = unit.types; 7329 List<ClassElement> classes = unit.types;
7330 EngineTestCase.assertLength(1, classes); 7330 expect(classes, hasLength(1));
7331 expect(classes[0].isValidMixin, isTrue); 7331 expect(classes[0].isValidMixin, isTrue);
7332 assertNoErrors(source); 7332 assertNoErrors(source);
7333 verify([source]); 7333 verify([source]);
7334 } 7334 }
7335 7335
7336 void test_labels_switch() { 7336 void test_labels_switch() {
7337 Source source = addSource(r''' 7337 Source source = addSource(r'''
7338 void doSwitch(int target) { 7338 void doSwitch(int target) {
7339 switch (target) { 7339 switch (target) {
7340 l0: case 0: 7340 l0: case 0:
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
7373 7373
7374 void test_metadata_class() { 7374 void test_metadata_class() {
7375 Source source = addSource(r''' 7375 Source source = addSource(r'''
7376 const A = null; 7376 const A = null;
7377 @A class C<A> {}'''); 7377 @A class C<A> {}''');
7378 LibraryElement library = resolve(source); 7378 LibraryElement library = resolve(source);
7379 expect(library, isNotNull); 7379 expect(library, isNotNull);
7380 CompilationUnitElement unitElement = library.definingCompilationUnit; 7380 CompilationUnitElement unitElement = library.definingCompilationUnit;
7381 expect(unitElement, isNotNull); 7381 expect(unitElement, isNotNull);
7382 List<ClassElement> classes = unitElement.types; 7382 List<ClassElement> classes = unitElement.types;
7383 EngineTestCase.assertLength(1, classes); 7383 expect(classes, hasLength(1));
7384 List<ElementAnnotation> annotations = classes[0].metadata; 7384 List<ElementAnnotation> annotations = classes[0].metadata;
7385 EngineTestCase.assertLength(1, annotations); 7385 expect(annotations, hasLength(1));
7386 assertNoErrors(source); 7386 assertNoErrors(source);
7387 verify([source]); 7387 verify([source]);
7388 CompilationUnit unit = resolveCompilationUnit(source, library); 7388 CompilationUnit unit = resolveCompilationUnit(source, library);
7389 NodeList<CompilationUnitMember> declarations = unit.declarations; 7389 NodeList<CompilationUnitMember> declarations = unit.declarations;
7390 EngineTestCase.assertSizeOfList(2, declarations); 7390 expect(declarations, hasLength(2));
7391 Element expectedElement = (declarations[0] as TopLevelVariableDeclaration).v ariables.variables[0].name.staticElement; 7391 Element expectedElement = (declarations[0] as TopLevelVariableDeclaration).v ariables.variables[0].name.staticElement;
7392 EngineTestCase.assertInstanceOf((obj) => obj is PropertyInducingElement, Pro pertyInducingElement, expectedElement); 7392 EngineTestCase.assertInstanceOf((obj) => obj is PropertyInducingElement, Pro pertyInducingElement, expectedElement);
7393 expectedElement = (expectedElement as PropertyInducingElement).getter; 7393 expectedElement = (expectedElement as PropertyInducingElement).getter;
7394 Element actualElement = (declarations[1] as ClassDeclaration).metadata[0].na me.staticElement; 7394 Element actualElement = (declarations[1] as ClassDeclaration).metadata[0].na me.staticElement;
7395 expect(actualElement, same(expectedElement)); 7395 expect(actualElement, same(expectedElement));
7396 } 7396 }
7397 7397
7398 void test_metadata_field() { 7398 void test_metadata_field() {
7399 Source source = addSource(r''' 7399 Source source = addSource(r'''
7400 const A = null; 7400 const A = null;
7401 class C { 7401 class C {
7402 @A int f; 7402 @A int f;
7403 }'''); 7403 }''');
7404 LibraryElement library = resolve(source); 7404 LibraryElement library = resolve(source);
7405 expect(library, isNotNull); 7405 expect(library, isNotNull);
7406 CompilationUnitElement unit = library.definingCompilationUnit; 7406 CompilationUnitElement unit = library.definingCompilationUnit;
7407 expect(unit, isNotNull); 7407 expect(unit, isNotNull);
7408 List<ClassElement> classes = unit.types; 7408 List<ClassElement> classes = unit.types;
7409 EngineTestCase.assertLength(1, classes); 7409 expect(classes, hasLength(1));
7410 FieldElement field = classes[0].fields[0]; 7410 FieldElement field = classes[0].fields[0];
7411 List<ElementAnnotation> annotations = field.metadata; 7411 List<ElementAnnotation> annotations = field.metadata;
7412 EngineTestCase.assertLength(1, annotations); 7412 expect(annotations, hasLength(1));
7413 assertNoErrors(source); 7413 assertNoErrors(source);
7414 verify([source]); 7414 verify([source]);
7415 } 7415 }
7416 7416
7417 void test_metadata_fieldFormalParameter() { 7417 void test_metadata_fieldFormalParameter() {
7418 Source source = addSource(r''' 7418 Source source = addSource(r'''
7419 const A = null; 7419 const A = null;
7420 class C { 7420 class C {
7421 int f; 7421 int f;
7422 C(@A this.f); 7422 C(@A this.f);
7423 }'''); 7423 }''');
7424 LibraryElement library = resolve(source); 7424 LibraryElement library = resolve(source);
7425 expect(library, isNotNull); 7425 expect(library, isNotNull);
7426 CompilationUnitElement unit = library.definingCompilationUnit; 7426 CompilationUnitElement unit = library.definingCompilationUnit;
7427 expect(unit, isNotNull); 7427 expect(unit, isNotNull);
7428 List<ClassElement> classes = unit.types; 7428 List<ClassElement> classes = unit.types;
7429 EngineTestCase.assertLength(1, classes); 7429 expect(classes, hasLength(1));
7430 List<ConstructorElement> constructors = classes[0].constructors; 7430 List<ConstructorElement> constructors = classes[0].constructors;
7431 EngineTestCase.assertLength(1, constructors); 7431 expect(constructors, hasLength(1));
7432 List<ParameterElement> parameters = constructors[0].parameters; 7432 List<ParameterElement> parameters = constructors[0].parameters;
7433 EngineTestCase.assertLength(1, parameters); 7433 expect(parameters, hasLength(1));
7434 List<ElementAnnotation> annotations = parameters[0].metadata; 7434 List<ElementAnnotation> annotations = parameters[0].metadata;
7435 EngineTestCase.assertLength(1, annotations); 7435 expect(annotations, hasLength(1));
7436 assertNoErrors(source); 7436 assertNoErrors(source);
7437 verify([source]); 7437 verify([source]);
7438 } 7438 }
7439 7439
7440 void test_metadata_function() { 7440 void test_metadata_function() {
7441 Source source = addSource(r''' 7441 Source source = addSource(r'''
7442 const A = null; 7442 const A = null;
7443 @A f() {}'''); 7443 @A f() {}''');
7444 LibraryElement library = resolve(source); 7444 LibraryElement library = resolve(source);
7445 expect(library, isNotNull); 7445 expect(library, isNotNull);
7446 CompilationUnitElement unit = library.definingCompilationUnit; 7446 CompilationUnitElement unit = library.definingCompilationUnit;
7447 expect(unit, isNotNull); 7447 expect(unit, isNotNull);
7448 List<FunctionElement> functions = unit.functions; 7448 List<FunctionElement> functions = unit.functions;
7449 EngineTestCase.assertLength(1, functions); 7449 expect(functions, hasLength(1));
7450 List<ElementAnnotation> annotations = functions[0].metadata; 7450 List<ElementAnnotation> annotations = functions[0].metadata;
7451 EngineTestCase.assertLength(1, annotations); 7451 expect(annotations, hasLength(1));
7452 assertNoErrors(source); 7452 assertNoErrors(source);
7453 verify([source]); 7453 verify([source]);
7454 } 7454 }
7455 7455
7456 void test_metadata_functionTypedParameter() { 7456 void test_metadata_functionTypedParameter() {
7457 Source source = addSource(r''' 7457 Source source = addSource(r'''
7458 const A = null; 7458 const A = null;
7459 f(@A int p(int x)) {}'''); 7459 f(@A int p(int x)) {}''');
7460 LibraryElement library = resolve(source); 7460 LibraryElement library = resolve(source);
7461 expect(library, isNotNull); 7461 expect(library, isNotNull);
7462 CompilationUnitElement unit = library.definingCompilationUnit; 7462 CompilationUnitElement unit = library.definingCompilationUnit;
7463 expect(unit, isNotNull); 7463 expect(unit, isNotNull);
7464 List<FunctionElement> functions = unit.functions; 7464 List<FunctionElement> functions = unit.functions;
7465 EngineTestCase.assertLength(1, functions); 7465 expect(functions, hasLength(1));
7466 List<ParameterElement> parameters = functions[0].parameters; 7466 List<ParameterElement> parameters = functions[0].parameters;
7467 EngineTestCase.assertLength(1, parameters); 7467 expect(parameters, hasLength(1));
7468 List<ElementAnnotation> annotations1 = parameters[0].metadata; 7468 List<ElementAnnotation> annotations1 = parameters[0].metadata;
7469 EngineTestCase.assertLength(1, annotations1); 7469 expect(annotations1, hasLength(1));
7470 assertNoErrors(source); 7470 assertNoErrors(source);
7471 verify([source]); 7471 verify([source]);
7472 } 7472 }
7473 7473
7474 void test_metadata_libraryDirective() { 7474 void test_metadata_libraryDirective() {
7475 Source source = addSource(r''' 7475 Source source = addSource(r'''
7476 @A library lib; 7476 @A library lib;
7477 const A = null;'''); 7477 const A = null;''');
7478 LibraryElement library = resolve(source); 7478 LibraryElement library = resolve(source);
7479 expect(library, isNotNull); 7479 expect(library, isNotNull);
7480 List<ElementAnnotation> annotations = library.metadata; 7480 List<ElementAnnotation> annotations = library.metadata;
7481 EngineTestCase.assertLength(1, annotations); 7481 expect(annotations, hasLength(1));
7482 assertNoErrors(source); 7482 assertNoErrors(source);
7483 verify([source]); 7483 verify([source]);
7484 } 7484 }
7485 7485
7486 void test_metadata_method() { 7486 void test_metadata_method() {
7487 Source source = addSource(r''' 7487 Source source = addSource(r'''
7488 const A = null; 7488 const A = null;
7489 class C { 7489 class C {
7490 @A void m() {} 7490 @A void m() {}
7491 }'''); 7491 }''');
7492 LibraryElement library = resolve(source); 7492 LibraryElement library = resolve(source);
7493 expect(library, isNotNull); 7493 expect(library, isNotNull);
7494 CompilationUnitElement unit = library.definingCompilationUnit; 7494 CompilationUnitElement unit = library.definingCompilationUnit;
7495 expect(unit, isNotNull); 7495 expect(unit, isNotNull);
7496 List<ClassElement> classes = unit.types; 7496 List<ClassElement> classes = unit.types;
7497 EngineTestCase.assertLength(1, classes); 7497 expect(classes, hasLength(1));
7498 MethodElement method = classes[0].methods[0]; 7498 MethodElement method = classes[0].methods[0];
7499 List<ElementAnnotation> annotations = method.metadata; 7499 List<ElementAnnotation> annotations = method.metadata;
7500 EngineTestCase.assertLength(1, annotations); 7500 expect(annotations, hasLength(1));
7501 assertNoErrors(source); 7501 assertNoErrors(source);
7502 verify([source]); 7502 verify([source]);
7503 } 7503 }
7504 7504
7505 void test_metadata_namedParameter() { 7505 void test_metadata_namedParameter() {
7506 Source source = addSource(r''' 7506 Source source = addSource(r'''
7507 const A = null; 7507 const A = null;
7508 f({@A int p : 0}) {}'''); 7508 f({@A int p : 0}) {}''');
7509 LibraryElement library = resolve(source); 7509 LibraryElement library = resolve(source);
7510 expect(library, isNotNull); 7510 expect(library, isNotNull);
7511 CompilationUnitElement unit = library.definingCompilationUnit; 7511 CompilationUnitElement unit = library.definingCompilationUnit;
7512 expect(unit, isNotNull); 7512 expect(unit, isNotNull);
7513 List<FunctionElement> functions = unit.functions; 7513 List<FunctionElement> functions = unit.functions;
7514 EngineTestCase.assertLength(1, functions); 7514 expect(functions, hasLength(1));
7515 List<ParameterElement> parameters = functions[0].parameters; 7515 List<ParameterElement> parameters = functions[0].parameters;
7516 EngineTestCase.assertLength(1, parameters); 7516 expect(parameters, hasLength(1));
7517 List<ElementAnnotation> annotations1 = parameters[0].metadata; 7517 List<ElementAnnotation> annotations1 = parameters[0].metadata;
7518 EngineTestCase.assertLength(1, annotations1); 7518 expect(annotations1, hasLength(1));
7519 assertNoErrors(source); 7519 assertNoErrors(source);
7520 verify([source]); 7520 verify([source]);
7521 } 7521 }
7522 7522
7523 void test_metadata_positionalParameter() { 7523 void test_metadata_positionalParameter() {
7524 Source source = addSource(r''' 7524 Source source = addSource(r'''
7525 const A = null; 7525 const A = null;
7526 f([@A int p = 0]) {}'''); 7526 f([@A int p = 0]) {}''');
7527 LibraryElement library = resolve(source); 7527 LibraryElement library = resolve(source);
7528 expect(library, isNotNull); 7528 expect(library, isNotNull);
7529 CompilationUnitElement unit = library.definingCompilationUnit; 7529 CompilationUnitElement unit = library.definingCompilationUnit;
7530 expect(unit, isNotNull); 7530 expect(unit, isNotNull);
7531 List<FunctionElement> functions = unit.functions; 7531 List<FunctionElement> functions = unit.functions;
7532 EngineTestCase.assertLength(1, functions); 7532 expect(functions, hasLength(1));
7533 List<ParameterElement> parameters = functions[0].parameters; 7533 List<ParameterElement> parameters = functions[0].parameters;
7534 EngineTestCase.assertLength(1, parameters); 7534 expect(parameters, hasLength(1));
7535 List<ElementAnnotation> annotations1 = parameters[0].metadata; 7535 List<ElementAnnotation> annotations1 = parameters[0].metadata;
7536 EngineTestCase.assertLength(1, annotations1); 7536 expect(annotations1, hasLength(1));
7537 assertNoErrors(source); 7537 assertNoErrors(source);
7538 verify([source]); 7538 verify([source]);
7539 } 7539 }
7540 7540
7541 void test_metadata_simpleParameter() { 7541 void test_metadata_simpleParameter() {
7542 Source source = addSource(r''' 7542 Source source = addSource(r'''
7543 const A = null; 7543 const A = null;
7544 f(@A p1, @A int p2) {}'''); 7544 f(@A p1, @A int p2) {}''');
7545 LibraryElement library = resolve(source); 7545 LibraryElement library = resolve(source);
7546 expect(library, isNotNull); 7546 expect(library, isNotNull);
7547 CompilationUnitElement unit = library.definingCompilationUnit; 7547 CompilationUnitElement unit = library.definingCompilationUnit;
7548 expect(unit, isNotNull); 7548 expect(unit, isNotNull);
7549 List<FunctionElement> functions = unit.functions; 7549 List<FunctionElement> functions = unit.functions;
7550 EngineTestCase.assertLength(1, functions); 7550 expect(functions, hasLength(1));
7551 List<ParameterElement> parameters = functions[0].parameters; 7551 List<ParameterElement> parameters = functions[0].parameters;
7552 EngineTestCase.assertLength(2, parameters); 7552 expect(parameters, hasLength(2));
7553 List<ElementAnnotation> annotations1 = parameters[0].metadata; 7553 List<ElementAnnotation> annotations1 = parameters[0].metadata;
7554 EngineTestCase.assertLength(1, annotations1); 7554 expect(annotations1, hasLength(1));
7555 List<ElementAnnotation> annotations2 = parameters[1].metadata; 7555 List<ElementAnnotation> annotations2 = parameters[1].metadata;
7556 EngineTestCase.assertLength(1, annotations2); 7556 expect(annotations2, hasLength(1));
7557 assertNoErrors(source); 7557 assertNoErrors(source);
7558 verify([source]); 7558 verify([source]);
7559 } 7559 }
7560 7560
7561 void test_metadata_typedef() { 7561 void test_metadata_typedef() {
7562 Source source = addSource(r''' 7562 Source source = addSource(r'''
7563 const A = null; 7563 const A = null;
7564 @A typedef F<A>();'''); 7564 @A typedef F<A>();''');
7565 LibraryElement library = resolve(source); 7565 LibraryElement library = resolve(source);
7566 expect(library, isNotNull); 7566 expect(library, isNotNull);
7567 CompilationUnitElement unitElement = library.definingCompilationUnit; 7567 CompilationUnitElement unitElement = library.definingCompilationUnit;
7568 expect(unitElement, isNotNull); 7568 expect(unitElement, isNotNull);
7569 List<FunctionTypeAliasElement> aliases = unitElement.functionTypeAliases; 7569 List<FunctionTypeAliasElement> aliases = unitElement.functionTypeAliases;
7570 EngineTestCase.assertLength(1, aliases); 7570 expect(aliases, hasLength(1));
7571 List<ElementAnnotation> annotations = aliases[0].metadata; 7571 List<ElementAnnotation> annotations = aliases[0].metadata;
7572 EngineTestCase.assertLength(1, annotations); 7572 expect(annotations, hasLength(1));
7573 assertNoErrors(source); 7573 assertNoErrors(source);
7574 verify([source]); 7574 verify([source]);
7575 CompilationUnit unit = resolveCompilationUnit(source, library); 7575 CompilationUnit unit = resolveCompilationUnit(source, library);
7576 NodeList<CompilationUnitMember> declarations = unit.declarations; 7576 NodeList<CompilationUnitMember> declarations = unit.declarations;
7577 EngineTestCase.assertSizeOfList(2, declarations); 7577 expect(declarations, hasLength(2));
7578 Element expectedElement = (declarations[0] as TopLevelVariableDeclaration).v ariables.variables[0].name.staticElement; 7578 Element expectedElement = (declarations[0] as TopLevelVariableDeclaration).v ariables.variables[0].name.staticElement;
7579 EngineTestCase.assertInstanceOf((obj) => obj is PropertyInducingElement, Pro pertyInducingElement, expectedElement); 7579 EngineTestCase.assertInstanceOf((obj) => obj is PropertyInducingElement, Pro pertyInducingElement, expectedElement);
7580 expectedElement = (expectedElement as PropertyInducingElement).getter; 7580 expectedElement = (expectedElement as PropertyInducingElement).getter;
7581 Element actualElement = (declarations[1] as FunctionTypeAlias).metadata[0].n ame.staticElement; 7581 Element actualElement = (declarations[1] as FunctionTypeAlias).metadata[0].n ame.staticElement;
7582 expect(actualElement, same(expectedElement)); 7582 expect(actualElement, same(expectedElement));
7583 } 7583 }
7584 7584
7585 void test_method_fromMixin() { 7585 void test_method_fromMixin() {
7586 Source source = addSource(r''' 7586 Source source = addSource(r'''
7587 class B { 7587 class B {
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after
8540 * @param expectedNormalTypes the expected types of the normal parameters 8540 * @param expectedNormalTypes the expected types of the normal parameters
8541 * @param expectedOptionalTypes the expected types of the optional parameters 8541 * @param expectedOptionalTypes the expected types of the optional parameters
8542 * @param expectedNamedTypes the expected types of the named parameters 8542 * @param expectedNamedTypes the expected types of the named parameters
8543 * @param actualType the type being tested 8543 * @param actualType the type being tested
8544 */ 8544 */
8545 void _assertFunctionType(DartType expectedReturnType, List<DartType> expectedN ormalTypes, List<DartType> expectedOptionalTypes, Map<String, DartType> expected NamedTypes, DartType actualType) { 8545 void _assertFunctionType(DartType expectedReturnType, List<DartType> expectedN ormalTypes, List<DartType> expectedOptionalTypes, Map<String, DartType> expected NamedTypes, DartType actualType) {
8546 EngineTestCase.assertInstanceOf((obj) => obj is FunctionType, FunctionType, actualType); 8546 EngineTestCase.assertInstanceOf((obj) => obj is FunctionType, FunctionType, actualType);
8547 FunctionType functionType = actualType as FunctionType; 8547 FunctionType functionType = actualType as FunctionType;
8548 List<DartType> normalTypes = functionType.normalParameterTypes; 8548 List<DartType> normalTypes = functionType.normalParameterTypes;
8549 if (expectedNormalTypes == null) { 8549 if (expectedNormalTypes == null) {
8550 EngineTestCase.assertLength(0, normalTypes); 8550 expect(normalTypes, hasLength(0));
8551 } else { 8551 } else {
8552 int expectedCount = expectedNormalTypes.length; 8552 int expectedCount = expectedNormalTypes.length;
8553 EngineTestCase.assertLength(expectedCount, normalTypes); 8553 expect(normalTypes, hasLength(expectedCount));
8554 for (int i = 0; i < expectedCount; i++) { 8554 for (int i = 0; i < expectedCount; i++) {
8555 expect(normalTypes[i], same(expectedNormalTypes[i])); 8555 expect(normalTypes[i], same(expectedNormalTypes[i]));
8556 } 8556 }
8557 } 8557 }
8558 List<DartType> optionalTypes = functionType.optionalParameterTypes; 8558 List<DartType> optionalTypes = functionType.optionalParameterTypes;
8559 if (expectedOptionalTypes == null) { 8559 if (expectedOptionalTypes == null) {
8560 EngineTestCase.assertLength(0, optionalTypes); 8560 expect(optionalTypes, hasLength(0));
8561 } else { 8561 } else {
8562 int expectedCount = expectedOptionalTypes.length; 8562 int expectedCount = expectedOptionalTypes.length;
8563 EngineTestCase.assertLength(expectedCount, optionalTypes); 8563 expect(optionalTypes, hasLength(expectedCount));
8564 for (int i = 0; i < expectedCount; i++) { 8564 for (int i = 0; i < expectedCount; i++) {
8565 expect(optionalTypes[i], same(expectedOptionalTypes[i])); 8565 expect(optionalTypes[i], same(expectedOptionalTypes[i]));
8566 } 8566 }
8567 } 8567 }
8568 Map<String, DartType> namedTypes = functionType.namedParameterTypes; 8568 Map<String, DartType> namedTypes = functionType.namedParameterTypes;
8569 if (expectedNamedTypes == null) { 8569 if (expectedNamedTypes == null) {
8570 EngineTestCase.assertSizeOfMap(0, namedTypes); 8570 expect(namedTypes, hasLength(0));
8571 } else { 8571 } else {
8572 EngineTestCase.assertSizeOfMap(expectedNamedTypes.length, namedTypes); 8572 expect(namedTypes, hasLength(expectedNamedTypes.length));
8573 expectedNamedTypes.forEach((String name, DartType type) { 8573 expectedNamedTypes.forEach((String name, DartType type) {
8574 expect(namedTypes[name], same(type)); 8574 expect(namedTypes[name], same(type));
8575 }); 8575 });
8576 } 8576 }
8577 expect(functionType.returnType, same(expectedReturnType)); 8577 expect(functionType.returnType, same(expectedReturnType));
8578 } 8578 }
8579 8579
8580 void _assertType(InterfaceTypeImpl expectedType, InterfaceTypeImpl actualType) { 8580 void _assertType(InterfaceTypeImpl expectedType, InterfaceTypeImpl actualType) {
8581 expect(actualType.displayName, expectedType.displayName); 8581 expect(actualType.displayName, expectedType.displayName);
8582 expect(actualType.element, expectedType.element); 8582 expect(actualType.element, expectedType.element);
8583 List<DartType> expectedArguments = expectedType.typeArguments; 8583 List<DartType> expectedArguments = expectedType.typeArguments;
8584 int length = expectedArguments.length; 8584 int length = expectedArguments.length;
8585 List<DartType> actualArguments = actualType.typeArguments; 8585 List<DartType> actualArguments = actualType.typeArguments;
8586 EngineTestCase.assertLength(length, actualArguments); 8586 expect(actualArguments, hasLength(length));
8587 for (int i = 0; i < length; i++) { 8587 for (int i = 0; i < length; i++) {
8588 _assertType2(expectedArguments[i], actualArguments[i]); 8588 _assertType2(expectedArguments[i], actualArguments[i]);
8589 } 8589 }
8590 } 8590 }
8591 8591
8592 void _assertType2(DartType expectedType, DartType actualType) { 8592 void _assertType2(DartType expectedType, DartType actualType) {
8593 if (expectedType is InterfaceTypeImpl) { 8593 if (expectedType is InterfaceTypeImpl) {
8594 EngineTestCase.assertInstanceOf((obj) => obj is InterfaceTypeImpl, Interfa ceTypeImpl, actualType); 8594 EngineTestCase.assertInstanceOf((obj) => obj is InterfaceTypeImpl, Interfa ceTypeImpl, actualType);
8595 _assertType(expectedType, actualType as InterfaceTypeImpl); 8595 _assertType(expectedType, actualType as InterfaceTypeImpl);
8596 } 8596 }
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after
9170 // 9170 //
9171 // class A extends B 9171 // class A extends B
9172 // class B extends A 9172 // class B extends A
9173 // 9173 //
9174 ClassElementImpl classA = ElementFactory.classElement2("A", []); 9174 ClassElementImpl classA = ElementFactory.classElement2("A", []);
9175 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); 9175 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []);
9176 classA.supertype = classB.type; 9176 classA.supertype = classB.type;
9177 _definingCompilationUnit.types = <ClassElement> [classA, classB]; 9177 _definingCompilationUnit.types = <ClassElement> [classA, classB];
9178 HashSet<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(class A); 9178 HashSet<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(class A);
9179 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA); 9179 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA);
9180 EngineTestCase.assertSizeOfSet(2, subtypesOfA); 9180 expect(subtypesOfA, hasLength(2));
9181 EngineTestCase.assertContains(arraySubtypesOfA, [classA, classB]); 9181 EngineTestCase.assertContains(arraySubtypesOfA, [classA, classB]);
9182 } 9182 }
9183 9183
9184 void test_computeAllSubtypes_manyRecursiveSubtypes() { 9184 void test_computeAllSubtypes_manyRecursiveSubtypes() {
9185 // 9185 //
9186 // class A 9186 // class A
9187 // class B extends A 9187 // class B extends A
9188 // class C extends B 9188 // class C extends B
9189 // class D extends B 9189 // class D extends B
9190 // class E extends B 9190 // class E extends B
9191 // 9191 //
9192 ClassElementImpl classA = ElementFactory.classElement2("A", []); 9192 ClassElementImpl classA = ElementFactory.classElement2("A", []);
9193 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); 9193 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []);
9194 ClassElementImpl classC = ElementFactory.classElement("C", classB.type, []); 9194 ClassElementImpl classC = ElementFactory.classElement("C", classB.type, []);
9195 ClassElementImpl classD = ElementFactory.classElement("D", classB.type, []); 9195 ClassElementImpl classD = ElementFactory.classElement("D", classB.type, []);
9196 ClassElementImpl classE = ElementFactory.classElement("E", classB.type, []); 9196 ClassElementImpl classE = ElementFactory.classElement("E", classB.type, []);
9197 _definingCompilationUnit.types = <ClassElement> [classA, classB, classC, cla ssD, classE]; 9197 _definingCompilationUnit.types = <ClassElement> [classA, classB, classC, cla ssD, classE];
9198 HashSet<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(class A); 9198 HashSet<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(class A);
9199 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA); 9199 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA);
9200 HashSet<ClassElement> subtypesOfB = _subtypeManager.computeAllSubtypes(class B); 9200 HashSet<ClassElement> subtypesOfB = _subtypeManager.computeAllSubtypes(class B);
9201 List<ClassElement> arraySubtypesOfB = new List.from(subtypesOfB); 9201 List<ClassElement> arraySubtypesOfB = new List.from(subtypesOfB);
9202 EngineTestCase.assertSizeOfSet(4, subtypesOfA); 9202 expect(subtypesOfA, hasLength(4));
9203 EngineTestCase.assertContains(arraySubtypesOfA, [classB, classC, classD, cla ssE]); 9203 EngineTestCase.assertContains(arraySubtypesOfA, [classB, classC, classD, cla ssE]);
9204 EngineTestCase.assertSizeOfSet(3, subtypesOfB); 9204 expect(subtypesOfB, hasLength(3));
9205 EngineTestCase.assertContains(arraySubtypesOfB, [classC, classD, classE]); 9205 EngineTestCase.assertContains(arraySubtypesOfB, [classC, classD, classE]);
9206 } 9206 }
9207 9207
9208 void test_computeAllSubtypes_noSubtypes() { 9208 void test_computeAllSubtypes_noSubtypes() {
9209 // 9209 //
9210 // class A 9210 // class A
9211 // 9211 //
9212 ClassElementImpl classA = ElementFactory.classElement2("A", []); 9212 ClassElementImpl classA = ElementFactory.classElement2("A", []);
9213 _definingCompilationUnit.types = <ClassElement> [classA]; 9213 _definingCompilationUnit.types = <ClassElement> [classA];
9214 HashSet<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(class A); 9214 HashSet<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(class A);
9215 EngineTestCase.assertSizeOfSet(0, subtypesOfA); 9215 expect(subtypesOfA, hasLength(0));
9216 } 9216 }
9217 9217
9218 void test_computeAllSubtypes_oneSubtype() { 9218 void test_computeAllSubtypes_oneSubtype() {
9219 // 9219 //
9220 // class A 9220 // class A
9221 // class B extends A 9221 // class B extends A
9222 // 9222 //
9223 ClassElementImpl classA = ElementFactory.classElement2("A", []); 9223 ClassElementImpl classA = ElementFactory.classElement2("A", []);
9224 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []); 9224 ClassElementImpl classB = ElementFactory.classElement("B", classA.type, []);
9225 _definingCompilationUnit.types = <ClassElement> [classA, classB]; 9225 _definingCompilationUnit.types = <ClassElement> [classA, classB];
9226 HashSet<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(class A); 9226 HashSet<ClassElement> subtypesOfA = _subtypeManager.computeAllSubtypes(class A);
9227 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA); 9227 List<ClassElement> arraySubtypesOfA = new List.from(subtypesOfA);
9228 EngineTestCase.assertSizeOfSet(1, subtypesOfA); 9228 expect(subtypesOfA, hasLength(1));
9229 EngineTestCase.assertContains(arraySubtypesOfA, [classB]); 9229 EngineTestCase.assertContains(arraySubtypesOfA, [classB]);
9230 } 9230 }
9231 9231
9232 @override 9232 @override
9233 void setUp() { 9233 void setUp() {
9234 super.setUp(); 9234 super.setUp();
9235 AnalysisContextImpl context = AnalysisContextFactory.contextWithCore(); 9235 AnalysisContextImpl context = AnalysisContextFactory.contextWithCore();
9236 FileBasedSource source = new FileBasedSource.con1(FileUtilities2.createFile( "/test.dart")); 9236 FileBasedSource source = new FileBasedSource.con1(FileUtilities2.createFile( "/test.dart"));
9237 _definingCompilationUnit = new CompilationUnitElementImpl("test.dart"); 9237 _definingCompilationUnit = new CompilationUnitElementImpl("test.dart");
9238 _definingCompilationUnit.source = source; 9238 _definingCompilationUnit.source = source;
(...skipping 1508 matching lines...) Expand 10 before | Expand all | Expand 10 after
10747 CompilationUnit unit = resolveCompilationUnit(source, library); 10747 CompilationUnit unit = resolveCompilationUnit(source, library);
10748 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 10748 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
10749 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo dy; 10749 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo dy;
10750 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 10750 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
10751 IndexExpression indexExpression = statement.expression as IndexExpression; 10751 IndexExpression indexExpression = statement.expression as IndexExpression;
10752 expect(indexExpression.propagatedType, isNull); 10752 expect(indexExpression.propagatedType, isNull);
10753 Expression v = indexExpression.target; 10753 Expression v = indexExpression.target;
10754 InterfaceType propagatedType = v.propagatedType as InterfaceType; 10754 InterfaceType propagatedType = v.propagatedType as InterfaceType;
10755 expect(propagatedType.element, same(typeProvider.listType.element)); 10755 expect(propagatedType.element, same(typeProvider.listType.element));
10756 List<DartType> typeArguments = propagatedType.typeArguments; 10756 List<DartType> typeArguments = propagatedType.typeArguments;
10757 EngineTestCase.assertLength(1, typeArguments); 10757 expect(typeArguments, hasLength(1));
10758 expect(typeArguments[0], same(typeProvider.dynamicType)); 10758 expect(typeArguments[0], same(typeProvider.dynamicType));
10759 } 10759 }
10760 10760
10761 void test_mapLiteral_different() { 10761 void test_mapLiteral_different() {
10762 Source source = addSource(r''' 10762 Source source = addSource(r'''
10763 f() { 10763 f() {
10764 var v = {'0' : 0, 1 : '1', '2' : 2}; 10764 var v = {'0' : 0, 1 : '1', '2' : 2};
10765 return v; 10765 return v;
10766 }'''); 10766 }''');
10767 LibraryElement library = resolve(source); 10767 LibraryElement library = resolve(source);
10768 assertNoErrors(source); 10768 assertNoErrors(source);
10769 verify([source]); 10769 verify([source]);
10770 CompilationUnit unit = resolveCompilationUnit(source, library); 10770 CompilationUnit unit = resolveCompilationUnit(source, library);
10771 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 10771 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
10772 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo dy; 10772 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo dy;
10773 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 10773 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
10774 SimpleIdentifier identifier = statement.expression as SimpleIdentifier; 10774 SimpleIdentifier identifier = statement.expression as SimpleIdentifier;
10775 InterfaceType propagatedType = identifier.propagatedType as InterfaceType; 10775 InterfaceType propagatedType = identifier.propagatedType as InterfaceType;
10776 expect(propagatedType.element, same(typeProvider.mapType.element)); 10776 expect(propagatedType.element, same(typeProvider.mapType.element));
10777 List<DartType> typeArguments = propagatedType.typeArguments; 10777 List<DartType> typeArguments = propagatedType.typeArguments;
10778 EngineTestCase.assertLength(2, typeArguments); 10778 expect(typeArguments, hasLength(2));
10779 expect(typeArguments[0], same(typeProvider.dynamicType)); 10779 expect(typeArguments[0], same(typeProvider.dynamicType));
10780 expect(typeArguments[1], same(typeProvider.dynamicType)); 10780 expect(typeArguments[1], same(typeProvider.dynamicType));
10781 } 10781 }
10782 10782
10783 void test_mapLiteral_same() { 10783 void test_mapLiteral_same() {
10784 Source source = addSource(r''' 10784 Source source = addSource(r'''
10785 f() { 10785 f() {
10786 var v = {'a' : 0, 'b' : 1, 'c' : 2}; 10786 var v = {'a' : 0, 'b' : 1, 'c' : 2};
10787 return v; 10787 return v;
10788 }'''); 10788 }''');
10789 LibraryElement library = resolve(source); 10789 LibraryElement library = resolve(source);
10790 assertNoErrors(source); 10790 assertNoErrors(source);
10791 verify([source]); 10791 verify([source]);
10792 CompilationUnit unit = resolveCompilationUnit(source, library); 10792 CompilationUnit unit = resolveCompilationUnit(source, library);
10793 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration; 10793 FunctionDeclaration function = unit.declarations[0] as FunctionDeclaration;
10794 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo dy; 10794 BlockFunctionBody body = function.functionExpression.body as BlockFunctionBo dy;
10795 ReturnStatement statement = body.block.statements[1] as ReturnStatement; 10795 ReturnStatement statement = body.block.statements[1] as ReturnStatement;
10796 SimpleIdentifier identifier = statement.expression as SimpleIdentifier; 10796 SimpleIdentifier identifier = statement.expression as SimpleIdentifier;
10797 InterfaceType propagatedType = identifier.propagatedType as InterfaceType; 10797 InterfaceType propagatedType = identifier.propagatedType as InterfaceType;
10798 expect(propagatedType.element, same(typeProvider.mapType.element)); 10798 expect(propagatedType.element, same(typeProvider.mapType.element));
10799 List<DartType> typeArguments = propagatedType.typeArguments; 10799 List<DartType> typeArguments = propagatedType.typeArguments;
10800 EngineTestCase.assertLength(2, typeArguments); 10800 expect(typeArguments, hasLength(2));
10801 expect(typeArguments[0], same(typeProvider.dynamicType)); 10801 expect(typeArguments[0], same(typeProvider.dynamicType));
10802 expect(typeArguments[1], same(typeProvider.dynamicType)); 10802 expect(typeArguments[1], same(typeProvider.dynamicType));
10803 } 10803 }
10804 10804
10805 void test_mergePropagatedTypesAtJoinPoint_4() { 10805 void test_mergePropagatedTypesAtJoinPoint_4() {
10806 // https://code.google.com/p/dart/issues/detail?id=19929 10806 // https://code.google.com/p/dart/issues/detail?id=19929
10807 _assertTypeOfMarkedExpression(r''' 10807 _assertTypeOfMarkedExpression(r'''
10808 f5(x) { 10808 f5(x) {
10809 var y = []; 10809 var y = [];
10810 if (x) { 10810 if (x) {
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
11259 ClassElement elementC = ElementFactory.classElement2("C", []); 11259 ClassElement elementC = ElementFactory.classElement2("C", []);
11260 ClassElement elementD = ElementFactory.classElement2("D", []); 11260 ClassElement elementD = ElementFactory.classElement2("D", []);
11261 ExtendsClause extendsClause = AstFactory.extendsClause(AstFactory.typeName(e lementB, [])); 11261 ExtendsClause extendsClause = AstFactory.extendsClause(AstFactory.typeName(e lementB, []));
11262 WithClause withClause = AstFactory.withClause([AstFactory.typeName(elementC, [])]); 11262 WithClause withClause = AstFactory.withClause([AstFactory.typeName(elementC, [])]);
11263 ImplementsClause implementsClause = AstFactory.implementsClause([AstFactory. typeName(elementD, [])]); 11263 ImplementsClause implementsClause = AstFactory.implementsClause([AstFactory. typeName(elementD, [])]);
11264 ClassDeclaration declaration = AstFactory.classDeclaration(null, "A", null, extendsClause, withClause, implementsClause, []); 11264 ClassDeclaration declaration = AstFactory.classDeclaration(null, "A", null, extendsClause, withClause, implementsClause, []);
11265 declaration.name.staticElement = elementA; 11265 declaration.name.staticElement = elementA;
11266 _resolveNode(declaration, [elementA, elementB, elementC, elementD]); 11266 _resolveNode(declaration, [elementA, elementB, elementC, elementD]);
11267 expect(elementA.supertype, same(elementB.type)); 11267 expect(elementA.supertype, same(elementB.type));
11268 List<InterfaceType> mixins = elementA.mixins; 11268 List<InterfaceType> mixins = elementA.mixins;
11269 EngineTestCase.assertLength(1, mixins); 11269 expect(mixins, hasLength(1));
11270 expect(mixins[0], same(elementC.type)); 11270 expect(mixins[0], same(elementC.type));
11271 List<InterfaceType> interfaces = elementA.interfaces; 11271 List<InterfaceType> interfaces = elementA.interfaces;
11272 EngineTestCase.assertLength(1, interfaces); 11272 expect(interfaces, hasLength(1));
11273 expect(interfaces[0], same(elementD.type)); 11273 expect(interfaces[0], same(elementD.type));
11274 _listener.assertNoErrors(); 11274 _listener.assertNoErrors();
11275 } 11275 }
11276 11276
11277 void test_visitClassDeclaration_instanceMemberCollidesWithClass() { 11277 void test_visitClassDeclaration_instanceMemberCollidesWithClass() {
11278 // class A {} 11278 // class A {}
11279 // class B extends A { 11279 // class B extends A {
11280 // void A() {} 11280 // void A() {}
11281 // } 11281 // }
11282 ClassElementImpl elementA = ElementFactory.classElement2("A", []); 11282 ClassElementImpl elementA = ElementFactory.classElement2("A", []);
(...skipping 13 matching lines...) Expand all
11296 ClassElement elementB = ElementFactory.classElement2("B", []); 11296 ClassElement elementB = ElementFactory.classElement2("B", []);
11297 ClassElement elementC = ElementFactory.classElement2("C", []); 11297 ClassElement elementC = ElementFactory.classElement2("C", []);
11298 ClassElement elementD = ElementFactory.classElement2("D", []); 11298 ClassElement elementD = ElementFactory.classElement2("D", []);
11299 WithClause withClause = AstFactory.withClause([AstFactory.typeName(elementC, [])]); 11299 WithClause withClause = AstFactory.withClause([AstFactory.typeName(elementC, [])]);
11300 ImplementsClause implementsClause = AstFactory.implementsClause([AstFactory. typeName(elementD, [])]); 11300 ImplementsClause implementsClause = AstFactory.implementsClause([AstFactory. typeName(elementD, [])]);
11301 ClassTypeAlias alias = AstFactory.classTypeAlias("A", null, null, AstFactory .typeName(elementB, []), withClause, implementsClause); 11301 ClassTypeAlias alias = AstFactory.classTypeAlias("A", null, null, AstFactory .typeName(elementB, []), withClause, implementsClause);
11302 alias.name.staticElement = elementA; 11302 alias.name.staticElement = elementA;
11303 _resolveNode(alias, [elementA, elementB, elementC, elementD]); 11303 _resolveNode(alias, [elementA, elementB, elementC, elementD]);
11304 expect(elementA.supertype, same(elementB.type)); 11304 expect(elementA.supertype, same(elementB.type));
11305 List<InterfaceType> mixins = elementA.mixins; 11305 List<InterfaceType> mixins = elementA.mixins;
11306 EngineTestCase.assertLength(1, mixins); 11306 expect(mixins, hasLength(1));
11307 expect(mixins[0], same(elementC.type)); 11307 expect(mixins[0], same(elementC.type));
11308 List<InterfaceType> interfaces = elementA.interfaces; 11308 List<InterfaceType> interfaces = elementA.interfaces;
11309 EngineTestCase.assertLength(1, interfaces); 11309 expect(interfaces, hasLength(1));
11310 expect(interfaces[0], same(elementD.type)); 11310 expect(interfaces[0], same(elementD.type));
11311 _listener.assertNoErrors(); 11311 _listener.assertNoErrors();
11312 } 11312 }
11313 11313
11314 void test_visitFieldFormalParameter_functionType() { 11314 void test_visitFieldFormalParameter_functionType() {
11315 InterfaceType intType = _typeProvider.intType; 11315 InterfaceType intType = _typeProvider.intType;
11316 TypeName intTypeName = AstFactory.typeName4("int", []); 11316 TypeName intTypeName = AstFactory.typeName4("int", []);
11317 String innerParameterName = "a"; 11317 String innerParameterName = "a";
11318 SimpleFormalParameter parameter = AstFactory.simpleFormalParameter3(innerPar ameterName); 11318 SimpleFormalParameter parameter = AstFactory.simpleFormalParameter3(innerPar ameterName);
11319 parameter.identifier.staticElement = ElementFactory.requiredParameter(innerP arameterName); 11319 parameter.identifier.staticElement = ElementFactory.requiredParameter(innerP arameterName);
11320 String outerParameterName = "p"; 11320 String outerParameterName = "p";
11321 FormalParameter node = AstFactory.fieldFormalParameter(null, intTypeName, ou terParameterName, AstFactory.formalParameterList([parameter])); 11321 FormalParameter node = AstFactory.fieldFormalParameter(null, intTypeName, ou terParameterName, AstFactory.formalParameterList([parameter]));
11322 node.identifier.staticElement = ElementFactory.requiredParameter(outerParame terName); 11322 node.identifier.staticElement = ElementFactory.requiredParameter(outerParame terName);
11323 DartType parameterType = _resolveFormalParameter(node, [intType.element]); 11323 DartType parameterType = _resolveFormalParameter(node, [intType.element]);
11324 EngineTestCase.assertInstanceOf((obj) => obj is FunctionType, FunctionType, parameterType); 11324 EngineTestCase.assertInstanceOf((obj) => obj is FunctionType, FunctionType, parameterType);
11325 FunctionType functionType = parameterType as FunctionType; 11325 FunctionType functionType = parameterType as FunctionType;
11326 expect(functionType.returnType, same(intType)); 11326 expect(functionType.returnType, same(intType));
11327 EngineTestCase.assertLength(1, functionType.parameters); 11327 expect(functionType.parameters, hasLength(1));
11328 _listener.assertNoErrors(); 11328 _listener.assertNoErrors();
11329 } 11329 }
11330 11330
11331 void test_visitFieldFormalParameter_noType() { 11331 void test_visitFieldFormalParameter_noType() {
11332 String parameterName = "p"; 11332 String parameterName = "p";
11333 FormalParameter node = AstFactory.fieldFormalParameter(Keyword.VAR, null, pa rameterName); 11333 FormalParameter node = AstFactory.fieldFormalParameter(Keyword.VAR, null, pa rameterName);
11334 node.identifier.staticElement = ElementFactory.requiredParameter(parameterNa me); 11334 node.identifier.staticElement = ElementFactory.requiredParameter(parameterNa me);
11335 expect(_resolveFormalParameter(node, []), same(_typeProvider.dynamicType)); 11335 expect(_resolveFormalParameter(node, []), same(_typeProvider.dynamicType));
11336 _listener.assertNoErrors(); 11336 _listener.assertNoErrors();
11337 } 11337 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
11377 11377
11378 void test_visitTypeName_parameters_arguments() { 11378 void test_visitTypeName_parameters_arguments() {
11379 ClassElement classA = ElementFactory.classElement2("A", ["E"]); 11379 ClassElement classA = ElementFactory.classElement2("A", ["E"]);
11380 ClassElement classB = ElementFactory.classElement2("B", []); 11380 ClassElement classB = ElementFactory.classElement2("B", []);
11381 TypeName typeName = AstFactory.typeName(classA, [AstFactory.typeName(classB, [])]); 11381 TypeName typeName = AstFactory.typeName(classA, [AstFactory.typeName(classB, [])]);
11382 typeName.type = null; 11382 typeName.type = null;
11383 _resolveNode(typeName, [classA, classB]); 11383 _resolveNode(typeName, [classA, classB]);
11384 InterfaceType resultType = typeName.type as InterfaceType; 11384 InterfaceType resultType = typeName.type as InterfaceType;
11385 expect(resultType.element, same(classA)); 11385 expect(resultType.element, same(classA));
11386 List<DartType> resultArguments = resultType.typeArguments; 11386 List<DartType> resultArguments = resultType.typeArguments;
11387 EngineTestCase.assertLength(1, resultArguments); 11387 expect(resultArguments, hasLength(1));
11388 expect(resultArguments[0], same(classB.type)); 11388 expect(resultArguments[0], same(classB.type));
11389 _listener.assertNoErrors(); 11389 _listener.assertNoErrors();
11390 } 11390 }
11391 11391
11392 void test_visitTypeName_parameters_noArguments() { 11392 void test_visitTypeName_parameters_noArguments() {
11393 ClassElement classA = ElementFactory.classElement2("A", ["E"]); 11393 ClassElement classA = ElementFactory.classElement2("A", ["E"]);
11394 TypeName typeName = AstFactory.typeName(classA, []); 11394 TypeName typeName = AstFactory.typeName(classA, []);
11395 typeName.type = null; 11395 typeName.type = null;
11396 _resolveNode(typeName, [classA]); 11396 _resolveNode(typeName, [classA]);
11397 InterfaceType resultType = typeName.type as InterfaceType; 11397 InterfaceType resultType = typeName.type as InterfaceType;
11398 expect(resultType.element, same(classA)); 11398 expect(resultType.element, same(classA));
11399 List<DartType> resultArguments = resultType.typeArguments; 11399 List<DartType> resultArguments = resultType.typeArguments;
11400 EngineTestCase.assertLength(1, resultArguments); 11400 expect(resultArguments, hasLength(1));
11401 expect(resultArguments[0], same(DynamicTypeImpl.instance)); 11401 expect(resultArguments[0], same(DynamicTypeImpl.instance));
11402 _listener.assertNoErrors(); 11402 _listener.assertNoErrors();
11403 } 11403 }
11404 11404
11405 void test_visitTypeName_void() { 11405 void test_visitTypeName_void() {
11406 ClassElement classA = ElementFactory.classElement2("A", []); 11406 ClassElement classA = ElementFactory.classElement2("A", []);
11407 TypeName typeName = AstFactory.typeName4("void", []); 11407 TypeName typeName = AstFactory.typeName4("void", []);
11408 _resolveNode(typeName, [classA]); 11408 _resolveNode(typeName, [classA]);
11409 expect(typeName.type, same(VoidTypeImpl.instance)); 11409 expect(typeName.type, same(VoidTypeImpl.instance));
11410 _listener.assertNoErrors(); 11410 _listener.assertNoErrors();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
11490 runReflectiveTests(TypeResolverVisitorTest); 11490 runReflectiveTests(TypeResolverVisitorTest);
11491 runReflectiveTests(CheckedModeCompileTimeErrorCodeTest); 11491 runReflectiveTests(CheckedModeCompileTimeErrorCodeTest);
11492 runReflectiveTests(ErrorResolverTest); 11492 runReflectiveTests(ErrorResolverTest);
11493 runReflectiveTests(HintCodeTest); 11493 runReflectiveTests(HintCodeTest);
11494 runReflectiveTests(MemberMapTest); 11494 runReflectiveTests(MemberMapTest);
11495 runReflectiveTests(NonHintCodeTest); 11495 runReflectiveTests(NonHintCodeTest);
11496 runReflectiveTests(SimpleResolverTest); 11496 runReflectiveTests(SimpleResolverTest);
11497 runReflectiveTests(StrictModeTest); 11497 runReflectiveTests(StrictModeTest);
11498 runReflectiveTests(TypePropagationTest); 11498 runReflectiveTests(TypePropagationTest);
11499 } 11499 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/parser_test.dart ('k') | pkg/analyzer/test/generated/static_warning_code_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698