| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library analyzer.test.src.task.dart_test; | 5 library analyzer.test.src.task.dart_test; |
| 6 | 6 |
| 7 import 'package:analyzer/dart/ast/ast.dart'; | 7 import 'package:analyzer/dart/ast/ast.dart'; |
| 8 import 'package:analyzer/dart/ast/token.dart'; | 8 import 'package:analyzer/dart/ast/token.dart'; |
| 9 import 'package:analyzer/dart/ast/visitor.dart'; | 9 import 'package:analyzer/dart/ast/visitor.dart'; |
| 10 import 'package:analyzer/dart/element/element.dart'; | 10 import 'package:analyzer/dart/element/element.dart'; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 runReflectiveTests(InferInstanceMembersInUnitTaskTest); | 60 runReflectiveTests(InferInstanceMembersInUnitTaskTest); |
| 61 runReflectiveTests(InferStaticVariableTypesInUnitTaskTest); | 61 runReflectiveTests(InferStaticVariableTypesInUnitTaskTest); |
| 62 runReflectiveTests(InferStaticVariableTypeTaskTest); | 62 runReflectiveTests(InferStaticVariableTypeTaskTest); |
| 63 runReflectiveTests(LibraryErrorsReadyTaskTest); | 63 runReflectiveTests(LibraryErrorsReadyTaskTest); |
| 64 runReflectiveTests(LibraryUnitErrorsTaskTest); | 64 runReflectiveTests(LibraryUnitErrorsTaskTest); |
| 65 runReflectiveTests(ParseDartTaskTest); | 65 runReflectiveTests(ParseDartTaskTest); |
| 66 runReflectiveTests(PartiallyResolveUnitReferencesTaskTest); | 66 runReflectiveTests(PartiallyResolveUnitReferencesTaskTest); |
| 67 runReflectiveTests(PropagateVariableTypesInUnitTaskTest); | 67 runReflectiveTests(PropagateVariableTypesInUnitTaskTest); |
| 68 runReflectiveTests(PropagateVariableTypeTaskTest); | 68 runReflectiveTests(PropagateVariableTypeTaskTest); |
| 69 runReflectiveTests(ReferencedNamesBuilderTest); | 69 runReflectiveTests(ReferencedNamesBuilderTest); |
| 70 runReflectiveTests(ResolveDirectivesTaskTest); |
| 70 runReflectiveTests(ResolveDirectiveElementsTaskTest); | 71 runReflectiveTests(ResolveDirectiveElementsTaskTest); |
| 71 runReflectiveTests(ResolveInstanceFieldsInUnitTaskTest); | 72 runReflectiveTests(ResolveInstanceFieldsInUnitTaskTest); |
| 72 runReflectiveTests(ResolveLibraryTaskTest); | 73 runReflectiveTests(ResolveLibraryTaskTest); |
| 73 runReflectiveTests(ResolveLibraryTypeNamesTaskTest); | 74 runReflectiveTests(ResolveLibraryTypeNamesTaskTest); |
| 74 runReflectiveTests(ResolveTopLevelUnitTypeBoundsTaskTest); | 75 runReflectiveTests(ResolveTopLevelUnitTypeBoundsTaskTest); |
| 75 runReflectiveTests(ResolveUnitTaskTest); | 76 runReflectiveTests(ResolveUnitTaskTest); |
| 76 runReflectiveTests(ResolveUnitTypeNamesTaskTest); | 77 runReflectiveTests(ResolveUnitTypeNamesTaskTest); |
| 77 runReflectiveTests(ResolveVariableReferencesTaskTest); | 78 runReflectiveTests(ResolveVariableReferencesTaskTest); |
| 78 runReflectiveTests(ScanDartTaskTest); | 79 runReflectiveTests(ScanDartTaskTest); |
| 79 runReflectiveTests(StrongModeInferenceTest); | 80 runReflectiveTests(StrongModeInferenceTest); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 new isInstanceOf<LibraryUnitErrorsTask>(); | 129 new isInstanceOf<LibraryUnitErrorsTask>(); |
| 129 isInstanceOf isParseDartTask = new isInstanceOf<ParseDartTask>(); | 130 isInstanceOf isParseDartTask = new isInstanceOf<ParseDartTask>(); |
| 130 isInstanceOf isPartiallyResolveUnitReferencesTask = | 131 isInstanceOf isPartiallyResolveUnitReferencesTask = |
| 131 new isInstanceOf<PartiallyResolveUnitReferencesTask>(); | 132 new isInstanceOf<PartiallyResolveUnitReferencesTask>(); |
| 132 isInstanceOf isPropagateVariableTypesInUnitTask = | 133 isInstanceOf isPropagateVariableTypesInUnitTask = |
| 133 new isInstanceOf<PropagateVariableTypesInUnitTask>(); | 134 new isInstanceOf<PropagateVariableTypesInUnitTask>(); |
| 134 isInstanceOf isPropagateVariableTypeTask = | 135 isInstanceOf isPropagateVariableTypeTask = |
| 135 new isInstanceOf<PropagateVariableTypeTask>(); | 136 new isInstanceOf<PropagateVariableTypeTask>(); |
| 136 isInstanceOf isResolveDirectiveElementsTask = | 137 isInstanceOf isResolveDirectiveElementsTask = |
| 137 new isInstanceOf<ResolveDirectiveElementsTask>(); | 138 new isInstanceOf<ResolveDirectiveElementsTask>(); |
| 139 isInstanceOf isResolveDirectivesTask = |
| 140 new isInstanceOf<ResolveDirectivesTask>(); |
| 138 isInstanceOf isResolveLibraryReferencesTask = | 141 isInstanceOf isResolveLibraryReferencesTask = |
| 139 new isInstanceOf<ResolveLibraryReferencesTask>(); | 142 new isInstanceOf<ResolveLibraryReferencesTask>(); |
| 140 isInstanceOf isResolveLibraryTask = new isInstanceOf<ResolveLibraryTask>(); | 143 isInstanceOf isResolveLibraryTask = new isInstanceOf<ResolveLibraryTask>(); |
| 141 isInstanceOf isResolveLibraryTypeNamesTask = | 144 isInstanceOf isResolveLibraryTypeNamesTask = |
| 142 new isInstanceOf<ResolveLibraryTypeNamesTask>(); | 145 new isInstanceOf<ResolveLibraryTypeNamesTask>(); |
| 143 isInstanceOf isResolveTopLevelUnitTypeBoundsTask = | 146 isInstanceOf isResolveTopLevelUnitTypeBoundsTask = |
| 144 new isInstanceOf<ResolveTopLevelUnitTypeBoundsTask>(); | 147 new isInstanceOf<ResolveTopLevelUnitTypeBoundsTask>(); |
| 145 isInstanceOf isResolveUnitTask = new isInstanceOf<ResolveUnitTask>(); | 148 isInstanceOf isResolveUnitTask = new isInstanceOf<ResolveUnitTask>(); |
| 146 isInstanceOf isResolveUnitTypeNamesTask = | 149 isInstanceOf isResolveUnitTypeNamesTask = |
| 147 new isInstanceOf<ResolveUnitTypeNamesTask>(); | 150 new isInstanceOf<ResolveUnitTypeNamesTask>(); |
| (...skipping 3062 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3210 List<AnalysisError> errors = getLibraryUnitErrors(outputs); | 3213 List<AnalysisError> errors = getLibraryUnitErrors(outputs); |
| 3211 expect(errors, hasLength(0)); | 3214 expect(errors, hasLength(0)); |
| 3212 } | 3215 } |
| 3213 } | 3216 } |
| 3214 | 3217 |
| 3215 @reflectiveTest | 3218 @reflectiveTest |
| 3216 class ParseDartTaskTest extends _AbstractDartTaskTest { | 3219 class ParseDartTaskTest extends _AbstractDartTaskTest { |
| 3217 Source source; | 3220 Source source; |
| 3218 | 3221 |
| 3219 test_perform() { | 3222 test_perform() { |
| 3220 _performParseTask(r''' | 3223 _performTask(r''' |
| 3221 part of lib; | 3224 part of lib; |
| 3222 class B {}'''); | 3225 class B {}'''); |
| 3223 expect(outputs, hasLength(11)); | 3226 expect(outputs, hasLength(4)); |
| 3224 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0)); | |
| 3225 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); | |
| 3226 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); | |
| 3227 expect(outputs[INCLUDED_PARTS], hasLength(0)); | |
| 3228 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(1)); | |
| 3229 expect(outputs[PARSE_ERRORS], hasLength(0)); | 3227 expect(outputs[PARSE_ERRORS], hasLength(0)); |
| 3230 expect(outputs[PARSED_UNIT], isNotNull); | 3228 expect(outputs[PARSED_UNIT1], isNotNull); |
| 3231 expect(outputs[REFERENCED_NAMES], isNotNull); | 3229 expect(outputs[REFERENCED_NAMES], isNotNull); |
| 3232 expect(outputs[REFERENCED_SOURCES], hasLength(2)); | |
| 3233 expect(outputs[SOURCE_KIND], SourceKind.PART); | 3230 expect(outputs[SOURCE_KIND], SourceKind.PART); |
| 3234 expect(outputs[UNITS], hasLength(1)); | |
| 3235 } | 3231 } |
| 3236 | 3232 |
| 3237 test_perform_computeSourceKind_noDirectives_hasContainingLibrary() { | 3233 test_perform_computeSourceKind_noDirectives_hasContainingLibrary() { |
| 3238 // Parse "lib.dart" to let the context know that "test.dart" is included. | 3234 // Parse "lib.dart" to let the context know that "test.dart" is included. |
| 3239 computeResult( | 3235 computeResult( |
| 3240 newSource( | 3236 newSource( |
| 3241 '/lib.dart', | 3237 '/lib.dart', |
| 3242 r''' | 3238 r''' |
| 3243 library lib; | 3239 library lib; |
| 3244 part 'test.dart'; | 3240 part 'test.dart'; |
| 3245 '''), | 3241 '''), |
| 3246 PARSED_UNIT); | 3242 PARSED_UNIT1); |
| 3247 // If there are no the "part of" directive, then it is not a part. | 3243 // If there are no the "part of" directive, then it is not a part. |
| 3248 _performParseTask(''); | 3244 _performTask(''); |
| 3249 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); | 3245 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); |
| 3250 } | 3246 } |
| 3251 | 3247 |
| 3252 test_perform_computeSourceKind_noDirectives_noContainingLibrary() { | 3248 test_perform_computeSourceKind_noDirectives_noContainingLibrary() { |
| 3253 _performParseTask(''); | 3249 _performTask(''); |
| 3254 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); | 3250 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); |
| 3255 } | 3251 } |
| 3256 | 3252 |
| 3257 test_perform_doesNotExist() { | 3253 test_perform_doesNotExist() { |
| 3258 _performParseTask(null); | 3254 _performTask(null); |
| 3259 expect(outputs, hasLength(11)); | 3255 expect(outputs, hasLength(4)); |
| 3260 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0)); | |
| 3261 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); | |
| 3262 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); | |
| 3263 expect(outputs[INCLUDED_PARTS], hasLength(0)); | |
| 3264 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(1)); | |
| 3265 expect(outputs[PARSE_ERRORS], hasLength(0)); | 3256 expect(outputs[PARSE_ERRORS], hasLength(0)); |
| 3266 expect(outputs[PARSED_UNIT], isNotNull); | 3257 expect(outputs[PARSED_UNIT1], isNotNull); |
| 3267 expect(outputs[REFERENCED_NAMES], isNotNull); | 3258 expect(outputs[REFERENCED_NAMES], isNotNull); |
| 3268 expect(outputs[REFERENCED_SOURCES], hasLength(2)); | |
| 3269 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); | 3259 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); |
| 3270 expect(outputs[UNITS], hasLength(1)); | |
| 3271 } | 3260 } |
| 3272 | 3261 |
| 3273 test_perform_enableAsync_false() { | 3262 test_perform_enableAsync_false() { |
| 3274 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); | 3263 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 3275 options.enableAsync = false; | 3264 options.enableAsync = false; |
| 3276 prepareAnalysisContext(options); | 3265 prepareAnalysisContext(options); |
| 3277 _performParseTask(r''' | 3266 _performTask(r''' |
| 3278 import 'dart:async'; | 3267 import 'dart:async'; |
| 3279 class B {void foo() async {}}'''); | 3268 class B {void foo() async {}}'''); |
| 3280 expect(outputs, hasLength(11)); | 3269 expect(outputs, hasLength(4)); |
| 3281 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(1)); | |
| 3282 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); | |
| 3283 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2); | |
| 3284 expect(outputs[INCLUDED_PARTS], hasLength(0)); | |
| 3285 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(1)); | |
| 3286 expect(outputs[PARSE_ERRORS], hasLength(1)); | 3270 expect(outputs[PARSE_ERRORS], hasLength(1)); |
| 3287 expect(outputs[PARSED_UNIT], isNotNull); | 3271 expect(outputs[PARSED_UNIT1], isNotNull); |
| 3288 expect(outputs[REFERENCED_NAMES], isNotNull); | 3272 expect(outputs[REFERENCED_NAMES], isNotNull); |
| 3289 expect(outputs[REFERENCED_SOURCES], hasLength(3)); | |
| 3290 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); | 3273 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); |
| 3291 expect(outputs[UNITS], hasLength(1)); | |
| 3292 } | 3274 } |
| 3293 | 3275 |
| 3294 test_perform_enableAsync_true() { | 3276 test_perform_enableAsync_true() { |
| 3295 _performParseTask(r''' | 3277 _performTask(r''' |
| 3296 import 'dart:async'; | 3278 import 'dart:async'; |
| 3297 class B {void foo() async {}}'''); | 3279 class B {void foo() async {}}'''); |
| 3298 expect(outputs, hasLength(11)); | 3280 expect(outputs, hasLength(4)); |
| 3299 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(1)); | |
| 3300 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); | |
| 3301 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2); | |
| 3302 expect(outputs[INCLUDED_PARTS], hasLength(0)); | |
| 3303 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(1)); | |
| 3304 expect(outputs[PARSE_ERRORS], hasLength(0)); | 3281 expect(outputs[PARSE_ERRORS], hasLength(0)); |
| 3305 expect(outputs[PARSED_UNIT], isNotNull); | 3282 expect(outputs[PARSED_UNIT1], isNotNull); |
| 3306 expect(outputs[REFERENCED_NAMES], isNotNull); | 3283 expect(outputs[REFERENCED_NAMES], isNotNull); |
| 3307 expect(outputs[REFERENCED_SOURCES], hasLength(3)); | |
| 3308 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); | 3284 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); |
| 3309 expect(outputs[UNITS], hasLength(1)); | |
| 3310 } | 3285 } |
| 3311 | 3286 |
| 3312 test_perform_flushTokenStream() { | 3287 test_perform_flushTokenStream() { |
| 3313 _performParseTask(r''' | 3288 _performTask(r''' |
| 3314 class Test {} | 3289 class Test {} |
| 3315 '''); | 3290 '''); |
| 3316 expect(analysisCache.getState(source, TOKEN_STREAM), CacheState.FLUSHED); | 3291 expect(analysisCache.getState(source, TOKEN_STREAM), CacheState.FLUSHED); |
| 3317 } | 3292 } |
| 3318 | 3293 |
| 3319 test_perform_invalidDirectives() { | 3294 test_perform_invalidDirectives() { |
| 3320 _performParseTask(r''' | 3295 _performTask(r''' |
| 3321 library lib; | 3296 library lib; |
| 3322 import '/does/not/exist.dart'; | 3297 import '/does/not/exist.dart'; |
| 3323 import '://invaliduri.dart'; | 3298 import '://invaliduri.dart'; |
| 3324 export '${a}lib3.dart'; | 3299 export '${a}lib3.dart'; |
| 3325 part 'part.dart'; | 3300 part 'part.dart'; |
| 3326 class A {}'''); | 3301 class A {}'''); |
| 3327 expect(outputs, hasLength(11)); | 3302 expect(outputs, hasLength(4)); |
| 3328 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(1)); | 3303 expect(outputs[PARSE_ERRORS], hasLength(0)); |
| 3329 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); | 3304 expect(outputs[PARSED_UNIT1], isNotNull); |
| 3330 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2); | |
| 3331 expect(outputs[INCLUDED_PARTS], hasLength(1)); | |
| 3332 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(2)); | |
| 3333 expect(outputs[PARSE_ERRORS], hasLength(2)); | |
| 3334 expect(outputs[PARSED_UNIT], isNotNull); | |
| 3335 expect(outputs[REFERENCED_NAMES], isNotNull); | 3305 expect(outputs[REFERENCED_NAMES], isNotNull); |
| 3336 expect(outputs[REFERENCED_SOURCES], hasLength(4)); | |
| 3337 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); | 3306 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); |
| 3338 expect(outputs[UNITS], hasLength(2)); | |
| 3339 } | 3307 } |
| 3340 | 3308 |
| 3341 test_perform_library() { | 3309 test_perform_library() { |
| 3342 _performParseTask(r''' | 3310 _performTask(r''' |
| 3343 library lib; | 3311 library lib; |
| 3344 import 'lib2.dart'; | 3312 import 'lib2.dart'; |
| 3345 export 'lib3.dart'; | 3313 export 'lib3.dart'; |
| 3346 part 'part.dart'; | 3314 part 'part.dart'; |
| 3347 class A {'''); | 3315 class A {'''); |
| 3348 expect(outputs, hasLength(11)); | 3316 expect(outputs, hasLength(4)); |
| 3349 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(1)); | |
| 3350 expect(outputs[EXPORTED_LIBRARIES], hasLength(1)); | |
| 3351 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2); | |
| 3352 expect(outputs[INCLUDED_PARTS], hasLength(1)); | |
| 3353 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(2)); | |
| 3354 expect(outputs[PARSE_ERRORS], hasLength(1)); | 3317 expect(outputs[PARSE_ERRORS], hasLength(1)); |
| 3355 expect(outputs[PARSED_UNIT], isNotNull); | 3318 expect(outputs[PARSED_UNIT1], isNotNull); |
| 3356 expect(outputs[REFERENCED_NAMES], isNotNull); | 3319 expect(outputs[REFERENCED_NAMES], isNotNull); |
| 3357 expect(outputs[REFERENCED_SOURCES], hasLength(5)); | |
| 3358 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); | 3320 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); |
| 3359 expect(outputs[UNITS], hasLength(2)); | |
| 3360 } | |
| 3361 | |
| 3362 test_perform_library_selfReferenceAsPart() { | |
| 3363 _performParseTask(r''' | |
| 3364 library lib; | |
| 3365 part 'test.dart'; | |
| 3366 '''); | |
| 3367 expect(outputs[INCLUDED_PARTS], unorderedEquals(<Source>[source])); | |
| 3368 } | 3321 } |
| 3369 | 3322 |
| 3370 test_perform_part() { | 3323 test_perform_part() { |
| 3371 _performParseTask(r''' | 3324 _performTask(r''' |
| 3372 part of lib; | 3325 part of lib; |
| 3373 class B {}'''); | 3326 class B {}'''); |
| 3374 expect(outputs, hasLength(11)); | 3327 expect(outputs, hasLength(4)); |
| 3375 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0)); | |
| 3376 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); | |
| 3377 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); | |
| 3378 expect(outputs[INCLUDED_PARTS], hasLength(0)); | |
| 3379 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(1)); | |
| 3380 expect(outputs[PARSE_ERRORS], hasLength(0)); | 3328 expect(outputs[PARSE_ERRORS], hasLength(0)); |
| 3381 expect(outputs[PARSED_UNIT], isNotNull); | 3329 expect(outputs[PARSED_UNIT1], isNotNull); |
| 3382 expect(outputs[REFERENCED_NAMES], isNotNull); | 3330 expect(outputs[REFERENCED_NAMES], isNotNull); |
| 3383 expect(outputs[REFERENCED_SOURCES], hasLength(2)); | |
| 3384 expect(outputs[SOURCE_KIND], SourceKind.PART); | 3331 expect(outputs[SOURCE_KIND], SourceKind.PART); |
| 3385 expect(outputs[UNITS], hasLength(1)); | |
| 3386 } | 3332 } |
| 3387 | 3333 |
| 3388 void _performParseTask(String content) { | 3334 void _performTask(String content) { |
| 3389 if (content == null) { | 3335 if (content == null) { |
| 3390 source = resourceProvider.getFile('/test.dart').createSource(); | 3336 source = resourceProvider.getFile('/test.dart').createSource(); |
| 3391 } else { | 3337 } else { |
| 3392 source = newSource('/test.dart', content); | 3338 source = newSource('/test.dart', content); |
| 3393 } | 3339 } |
| 3394 computeResult(source, PARSED_UNIT, matcher: isParseDartTask); | 3340 computeResult(source, PARSED_UNIT1, matcher: isParseDartTask); |
| 3395 } | 3341 } |
| 3396 | 3342 |
| 3397 static void _assertHasCore(dynamic sourceList, int lenght) { | 3343 static void _assertHasCore(dynamic sourceList, int length) { |
| 3398 List<Source> sources = sourceList as List<Source>; | 3344 List<Source> sources = sourceList as List<Source>; |
| 3399 expect(sources, hasLength(lenght)); | 3345 expect(sources, hasLength(length)); |
| 3400 expect(sources, contains(predicate((Source s) { | 3346 expect(sources, contains(predicate((Source s) { |
| 3401 return s.fullName.endsWith('core.dart'); | 3347 return s.fullName.endsWith('core.dart'); |
| 3402 }))); | 3348 }))); |
| 3403 } | 3349 } |
| 3404 } | 3350 } |
| 3405 | 3351 |
| 3406 @reflectiveTest | 3352 @reflectiveTest |
| 3407 class PartiallyResolveUnitReferencesTaskTest extends _AbstractDartTaskTest { | 3353 class PartiallyResolveUnitReferencesTaskTest extends _AbstractDartTaskTest { |
| 3408 test_perform_propagable() { | 3354 test_perform_propagable() { |
| 3409 enableStrongMode(); | 3355 enableStrongMode(); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3537 computeResult(target, RESOLVED_UNIT7, | 3483 computeResult(target, RESOLVED_UNIT7, |
| 3538 matcher: isPartiallyResolveUnitReferencesTask); | 3484 matcher: isPartiallyResolveUnitReferencesTask); |
| 3539 CompilationUnit unit = outputs[RESOLVED_UNIT7]; | 3485 CompilationUnit unit = outputs[RESOLVED_UNIT7]; |
| 3540 NodeList<CompilationUnitMember> declarations = unit.declarations; | 3486 NodeList<CompilationUnitMember> declarations = unit.declarations; |
| 3541 | 3487 |
| 3542 void expectReference(BlockFunctionBody body, bool isResolved) { | 3488 void expectReference(BlockFunctionBody body, bool isResolved) { |
| 3543 ExpressionStatement statement = body.block.statements[0]; | 3489 ExpressionStatement statement = body.block.statements[0]; |
| 3544 SimpleIdentifier reference = statement.expression; | 3490 SimpleIdentifier reference = statement.expression; |
| 3545 expect(reference.staticElement, isResolved ? isNotNull : isNull); | 3491 expect(reference.staticElement, isResolved ? isNotNull : isNull); |
| 3546 } | 3492 } |
| 3493 |
| 3547 // | 3494 // |
| 3548 // The reference to 'A' in 'f1' should not be resolved. | 3495 // The reference to 'A' in 'f1' should not be resolved. |
| 3549 // | 3496 // |
| 3550 FunctionDeclaration f1 = declarations[1]; | 3497 FunctionDeclaration f1 = declarations[1]; |
| 3551 expectReference(f1.functionExpression.body, false); | 3498 expectReference(f1.functionExpression.body, false); |
| 3552 // | 3499 // |
| 3553 // The references to 'A' in 'f2' should be resolved. | 3500 // The references to 'A' in 'f2' should be resolved. |
| 3554 // | 3501 // |
| 3555 TopLevelVariableDeclaration f2 = declarations[2]; | 3502 TopLevelVariableDeclaration f2 = declarations[2]; |
| 3556 FunctionExpression expression2 = f2.variables.variables[0].initializer; | 3503 FunctionExpression expression2 = f2.variables.variables[0].initializer; |
| (...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4214 { | 4161 { |
| 4215 ExportDirective exportNode = unitA.directives[2]; | 4162 ExportDirective exportNode = unitA.directives[2]; |
| 4216 ExportElement exportElement = exportNode.element; | 4163 ExportElement exportElement = exportNode.element; |
| 4217 expect(exportElement, isNotNull); | 4164 expect(exportElement, isNotNull); |
| 4218 expect(exportElement.exportedLibrary, libraryElementC); | 4165 expect(exportElement.exportedLibrary, libraryElementC); |
| 4219 } | 4166 } |
| 4220 } | 4167 } |
| 4221 } | 4168 } |
| 4222 | 4169 |
| 4223 @reflectiveTest | 4170 @reflectiveTest |
| 4171 class ResolveDirectivesTaskTest extends _AbstractDartTaskTest { |
| 4172 Source source; |
| 4173 |
| 4174 test_perform() { |
| 4175 _performTask(r''' |
| 4176 part of lib; |
| 4177 class B {}'''); |
| 4178 expect(outputs, hasLength(9)); |
| 4179 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0)); |
| 4180 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); |
| 4181 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); |
| 4182 expect(outputs[INCLUDED_PARTS], hasLength(0)); |
| 4183 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(1)); |
| 4184 expect(outputs[PARSED_UNIT], isNotNull); |
| 4185 expect(outputs[REFERENCED_SOURCES], hasLength(2)); |
| 4186 expect(outputs[RESOLVE_DIRECTIVES_ERRORS], hasLength(0)); |
| 4187 expect(outputs[UNITS], hasLength(1)); |
| 4188 } |
| 4189 |
| 4190 test_perform_doesNotExist() { |
| 4191 _performTask(null); |
| 4192 expect(outputs, hasLength(9)); |
| 4193 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0)); |
| 4194 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); |
| 4195 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); |
| 4196 expect(outputs[INCLUDED_PARTS], hasLength(0)); |
| 4197 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(1)); |
| 4198 expect(outputs[PARSED_UNIT], isNotNull); |
| 4199 expect(outputs[REFERENCED_SOURCES], hasLength(2)); |
| 4200 expect(outputs[RESOLVE_DIRECTIVES_ERRORS], hasLength(0)); |
| 4201 expect(outputs[UNITS], hasLength(1)); |
| 4202 } |
| 4203 |
| 4204 test_perform_enableAsync_false() { |
| 4205 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 4206 options.enableAsync = false; |
| 4207 prepareAnalysisContext(options); |
| 4208 _performTask(r''' |
| 4209 import 'dart:async'; |
| 4210 class B {void foo() async {}}'''); |
| 4211 expect(outputs, hasLength(9)); |
| 4212 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(1)); |
| 4213 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); |
| 4214 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2); |
| 4215 expect(outputs[INCLUDED_PARTS], hasLength(0)); |
| 4216 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(1)); |
| 4217 expect(outputs[PARSED_UNIT], isNotNull); |
| 4218 expect(outputs[REFERENCED_SOURCES], hasLength(3)); |
| 4219 expect(outputs[RESOLVE_DIRECTIVES_ERRORS], hasLength(0)); |
| 4220 expect(outputs[UNITS], hasLength(1)); |
| 4221 } |
| 4222 |
| 4223 test_perform_enableAsync_true() { |
| 4224 _performTask(r''' |
| 4225 import 'dart:async'; |
| 4226 class B {void foo() async {}}'''); |
| 4227 expect(outputs, hasLength(9)); |
| 4228 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(1)); |
| 4229 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); |
| 4230 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2); |
| 4231 expect(outputs[INCLUDED_PARTS], hasLength(0)); |
| 4232 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(1)); |
| 4233 expect(outputs[PARSED_UNIT], isNotNull); |
| 4234 expect(outputs[REFERENCED_SOURCES], hasLength(3)); |
| 4235 expect(outputs[RESOLVE_DIRECTIVES_ERRORS], hasLength(0)); |
| 4236 expect(outputs[UNITS], hasLength(1)); |
| 4237 } |
| 4238 |
| 4239 test_perform_flushParsedUnit1() { |
| 4240 _performTask(r''' |
| 4241 class Test {} |
| 4242 '''); |
| 4243 expect(analysisCache.getState(source, PARSED_UNIT1), CacheState.FLUSHED); |
| 4244 } |
| 4245 |
| 4246 test_perform_invalidDirectives() { |
| 4247 _performTask(r''' |
| 4248 library lib; |
| 4249 import '/does/not/exist.dart'; |
| 4250 import '://invaliduri.dart'; |
| 4251 export '${a}lib3.dart'; |
| 4252 part 'part.dart'; |
| 4253 class A {}'''); |
| 4254 expect(outputs, hasLength(9)); |
| 4255 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(1)); |
| 4256 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); |
| 4257 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2); |
| 4258 expect(outputs[INCLUDED_PARTS], hasLength(1)); |
| 4259 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(2)); |
| 4260 expect(outputs[PARSED_UNIT], isNotNull); |
| 4261 expect(outputs[REFERENCED_SOURCES], hasLength(4)); |
| 4262 expect(outputs[RESOLVE_DIRECTIVES_ERRORS], hasLength(2)); |
| 4263 expect(outputs[UNITS], hasLength(2)); |
| 4264 } |
| 4265 |
| 4266 test_perform_library() { |
| 4267 _performTask(r''' |
| 4268 library lib; |
| 4269 import 'lib2.dart'; |
| 4270 export 'lib3.dart'; |
| 4271 part 'part.dart'; |
| 4272 class A {'''); |
| 4273 expect(outputs, hasLength(9)); |
| 4274 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(1)); |
| 4275 expect(outputs[EXPORTED_LIBRARIES], hasLength(1)); |
| 4276 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2); |
| 4277 expect(outputs[INCLUDED_PARTS], hasLength(1)); |
| 4278 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(2)); |
| 4279 expect(outputs[PARSED_UNIT], isNotNull); |
| 4280 expect(outputs[REFERENCED_SOURCES], hasLength(5)); |
| 4281 expect(outputs[RESOLVE_DIRECTIVES_ERRORS], hasLength(0)); |
| 4282 expect(outputs[UNITS], hasLength(2)); |
| 4283 } |
| 4284 |
| 4285 test_perform_library_selfReferenceAsPart() { |
| 4286 _performTask(r''' |
| 4287 library lib; |
| 4288 part 'test.dart'; |
| 4289 '''); |
| 4290 expect(outputs[INCLUDED_PARTS], unorderedEquals(<Source>[source])); |
| 4291 } |
| 4292 |
| 4293 test_perform_part() { |
| 4294 _performTask(r''' |
| 4295 part of lib; |
| 4296 class B {}'''); |
| 4297 expect(outputs, hasLength(9)); |
| 4298 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(0)); |
| 4299 expect(outputs[EXPORTED_LIBRARIES], hasLength(0)); |
| 4300 _assertHasCore(outputs[IMPORTED_LIBRARIES], 1); |
| 4301 expect(outputs[INCLUDED_PARTS], hasLength(0)); |
| 4302 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(1)); |
| 4303 expect(outputs[PARSED_UNIT], isNotNull); |
| 4304 expect(outputs[REFERENCED_SOURCES], hasLength(2)); |
| 4305 expect(outputs[RESOLVE_DIRECTIVES_ERRORS], hasLength(0)); |
| 4306 expect(outputs[UNITS], hasLength(1)); |
| 4307 } |
| 4308 |
| 4309 void _performTask(String content) { |
| 4310 if (content == null) { |
| 4311 source = resourceProvider.getFile('/test.dart').createSource(); |
| 4312 } else { |
| 4313 source = newSource('/test.dart', content); |
| 4314 } |
| 4315 computeResult(source, PARSED_UNIT, matcher: isResolveDirectivesTask); |
| 4316 } |
| 4317 |
| 4318 static void _assertHasCore(dynamic sourceList, int length) { |
| 4319 List<Source> sources = sourceList as List<Source>; |
| 4320 expect(sources, hasLength(length)); |
| 4321 expect(sources, contains(predicate((Source s) { |
| 4322 return s.fullName.endsWith('core.dart'); |
| 4323 }))); |
| 4324 } |
| 4325 } |
| 4326 |
| 4327 @reflectiveTest |
| 4224 class ResolveInstanceFieldsInUnitTaskTest extends _AbstractDartTaskTest { | 4328 class ResolveInstanceFieldsInUnitTaskTest extends _AbstractDartTaskTest { |
| 4225 @override | 4329 @override |
| 4226 void setUp() { | 4330 void setUp() { |
| 4227 super.setUp(); | 4331 super.setUp(); |
| 4228 enableStrongMode(); | 4332 enableStrongMode(); |
| 4229 } | 4333 } |
| 4230 | 4334 |
| 4231 test_created_resolved_unit() { | 4335 test_created_resolved_unit() { |
| 4232 Source source = newSource( | 4336 Source source = newSource( |
| 4233 '/test.dart', | 4337 '/test.dart', |
| (...skipping 1544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5778 } | 5882 } |
| 5779 | 5883 |
| 5780 List<dynamic> computeLibraryResults( | 5884 List<dynamic> computeLibraryResults( |
| 5781 List<Source> sources, ResultDescriptor result, | 5885 List<Source> sources, ResultDescriptor result, |
| 5782 {isInstanceOf matcher: null}) { | 5886 {isInstanceOf matcher: null}) { |
| 5783 dynamic compute(Source source) { | 5887 dynamic compute(Source source) { |
| 5784 computeResult(new LibrarySpecificUnit(source, source), result, | 5888 computeResult(new LibrarySpecificUnit(source, source), result, |
| 5785 matcher: matcher); | 5889 matcher: matcher); |
| 5786 return outputs[result]; | 5890 return outputs[result]; |
| 5787 } | 5891 } |
| 5892 |
| 5788 return sources.map(compute).toList(); | 5893 return sources.map(compute).toList(); |
| 5789 } | 5894 } |
| 5790 | 5895 |
| 5791 List<Map<ResultDescriptor, dynamic>> computeLibraryResultsMap( | 5896 List<Map<ResultDescriptor, dynamic>> computeLibraryResultsMap( |
| 5792 List<Source> sources, ResultDescriptor result, | 5897 List<Source> sources, ResultDescriptor result, |
| 5793 {isInstanceOf matcher: null}) { | 5898 {isInstanceOf matcher: null}) { |
| 5794 Map<ResultDescriptor, dynamic> compute(Source source) { | 5899 Map<ResultDescriptor, dynamic> compute(Source source) { |
| 5795 computeResult(source, result, matcher: matcher); | 5900 computeResult(source, result, matcher: matcher); |
| 5796 return outputs; | 5901 return outputs; |
| 5797 } | 5902 } |
| 5903 |
| 5798 return sources.map(compute).toList(); | 5904 return sources.map(compute).toList(); |
| 5799 } | 5905 } |
| 5800 | 5906 |
| 5801 /** | 5907 /** |
| 5802 * Create a script object with a single fragment containing the given | 5908 * Create a script object with a single fragment containing the given |
| 5803 * [scriptContent]. | 5909 * [scriptContent]. |
| 5804 */ | 5910 */ |
| 5805 DartScript createScript(String scriptContent) { | 5911 DartScript createScript(String scriptContent) { |
| 5806 String htmlContent = ''' | 5912 String htmlContent = ''' |
| 5807 <!DOCTYPE html> | 5913 <!DOCTYPE html> |
| (...skipping 27 matching lines...) Expand all Loading... |
| 5835 /** | 5941 /** |
| 5836 * Fill [errorListener] with [result] errors in the current [task]. | 5942 * Fill [errorListener] with [result] errors in the current [task]. |
| 5837 */ | 5943 */ |
| 5838 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 5944 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
| 5839 List<AnalysisError> errors = task.outputs[result] as List<AnalysisError>; | 5945 List<AnalysisError> errors = task.outputs[result] as List<AnalysisError>; |
| 5840 expect(errors, isNotNull, reason: result.name); | 5946 expect(errors, isNotNull, reason: result.name); |
| 5841 errorListener = new GatheringErrorListener(); | 5947 errorListener = new GatheringErrorListener(); |
| 5842 errorListener.addAll(errors); | 5948 errorListener.addAll(errors); |
| 5843 } | 5949 } |
| 5844 } | 5950 } |
| OLD | NEW |