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/standard_resolution_map.dart'; | 8 import 'package:analyzer/dart/ast/standard_resolution_map.dart'; |
9 import 'package:analyzer/dart/ast/token.dart'; | 9 import 'package:analyzer/dart/ast/token.dart'; |
10 import 'package:analyzer/dart/ast/visitor.dart'; | 10 import 'package:analyzer/dart/ast/visitor.dart'; |
11 import 'package:analyzer/dart/element/element.dart'; | 11 import 'package:analyzer/dart/element/element.dart'; |
12 import 'package:analyzer/dart/element/type.dart'; | 12 import 'package:analyzer/dart/element/type.dart'; |
13 import 'package:analyzer/error/error.dart'; | 13 import 'package:analyzer/error/error.dart'; |
14 import 'package:analyzer/src/context/cache.dart'; | 14 import 'package:analyzer/src/context/cache.dart'; |
15 import 'package:analyzer/src/dart/element/element.dart'; | 15 import 'package:analyzer/src/dart/element/element.dart'; |
16 import 'package:analyzer/src/error/codes.dart'; | 16 import 'package:analyzer/src/error/codes.dart'; |
17 import 'package:analyzer/src/generated/constant.dart'; | 17 import 'package:analyzer/src/generated/constant.dart'; |
18 import 'package:analyzer/src/generated/engine.dart' | 18 import 'package:analyzer/src/generated/engine.dart' |
19 show AnalysisOptionsImpl, CacheState; | 19 show AnalysisOptionsImpl, CacheState; |
20 import 'package:analyzer/src/generated/resolver.dart'; | 20 import 'package:analyzer/src/generated/resolver.dart'; |
21 import 'package:analyzer/src/generated/sdk.dart'; | 21 import 'package:analyzer/src/generated/sdk.dart'; |
22 import 'package:analyzer/src/generated/source.dart'; | 22 import 'package:analyzer/src/generated/source.dart'; |
23 import 'package:analyzer/src/services/lint.dart'; | 23 import 'package:analyzer/src/services/lint.dart'; |
24 import 'package:analyzer/src/task/dart.dart'; | 24 import 'package:analyzer/src/task/dart.dart'; |
25 import 'package:analyzer/src/task/html.dart'; | 25 import 'package:analyzer/src/task/html.dart'; |
26 import 'package:analyzer/src/task/strong/ast_properties.dart' as strong_ast; | 26 import 'package:analyzer/src/task/strong/ast_properties.dart' as strong_ast; |
27 import 'package:analyzer/task/dart.dart'; | 27 import 'package:analyzer/task/dart.dart'; |
28 import 'package:analyzer/task/general.dart'; | 28 import 'package:analyzer/task/general.dart'; |
29 import 'package:analyzer/task/model.dart'; | 29 import 'package:analyzer/task/model.dart'; |
| 30 import 'package:front_end/src/scanner/scanner.dart' as fe; |
30 import 'package:test/test.dart'; | 31 import 'package:test/test.dart'; |
31 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 32 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
32 | 33 |
33 import '../../generated/resolver_test_case.dart'; | 34 import '../../generated/resolver_test_case.dart'; |
34 import '../../generated/test_support.dart'; | 35 import '../../generated/test_support.dart'; |
35 import '../../utils.dart'; | 36 import '../../utils.dart'; |
36 import '../context/abstract_context.dart'; | 37 import '../context/abstract_context.dart'; |
37 | 38 |
38 main() { | 39 main() { |
39 defineReflectiveSuite(() { | 40 defineReflectiveSuite(() { |
(...skipping 3214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3254 import 'lib2.dart'; | 3255 import 'lib2.dart'; |
3255 export 'lib3.dart'; | 3256 export 'lib3.dart'; |
3256 part 'part.dart'; | 3257 part 'part.dart'; |
3257 class A {'''); | 3258 class A {'''); |
3258 expect(outputs, hasLength(10)); | 3259 expect(outputs, hasLength(10)); |
3259 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(1)); | 3260 expect(outputs[EXPLICITLY_IMPORTED_LIBRARIES], hasLength(1)); |
3260 expect(outputs[EXPORTED_LIBRARIES], hasLength(1)); | 3261 expect(outputs[EXPORTED_LIBRARIES], hasLength(1)); |
3261 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2); | 3262 _assertHasCore(outputs[IMPORTED_LIBRARIES], 2); |
3262 expect(outputs[INCLUDED_PARTS], hasLength(1)); | 3263 expect(outputs[INCLUDED_PARTS], hasLength(1)); |
3263 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(2)); | 3264 expect(outputs[LIBRARY_SPECIFIC_UNITS], hasLength(2)); |
3264 expect(outputs[PARSE_ERRORS], hasLength(1)); | 3265 if (fe.Scanner.useFasta) { |
| 3266 // Missing closing brace error is reported by the Fasta scanner. |
| 3267 expect(outputs[PARSE_ERRORS], hasLength(0)); |
| 3268 } else { |
| 3269 expect(outputs[PARSE_ERRORS], hasLength(1)); |
| 3270 } |
3265 expect(outputs[PARSED_UNIT], isNotNull); | 3271 expect(outputs[PARSED_UNIT], isNotNull); |
3266 expect(outputs[REFERENCED_SOURCES], hasLength(5)); | 3272 expect(outputs[REFERENCED_SOURCES], hasLength(5)); |
3267 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); | 3273 expect(outputs[SOURCE_KIND], SourceKind.LIBRARY); |
3268 expect(outputs[UNITS], hasLength(2)); | 3274 expect(outputs[UNITS], hasLength(2)); |
3269 } | 3275 } |
3270 | 3276 |
3271 test_perform_library_configurations_bool1() { | 3277 test_perform_library_configurations_bool1() { |
3272 context.declaredVariables.define('dart.library.io', 'true'); | 3278 context.declaredVariables.define('dart.library.io', 'true'); |
3273 newSource('/foo.dart', ''); | 3279 newSource('/foo.dart', ''); |
3274 newSource('/foo_io.dart', ''); | 3280 newSource('/foo_io.dart', ''); |
(...skipping 1105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4380 _performScanTask('import "'); | 4386 _performScanTask('import "'); |
4381 expect(outputs, hasLength(4)); | 4387 expect(outputs, hasLength(4)); |
4382 expect(outputs[LINE_INFO], isNotNull); | 4388 expect(outputs[LINE_INFO], isNotNull); |
4383 expect(outputs[SCAN_ERRORS], hasLength(1)); | 4389 expect(outputs[SCAN_ERRORS], hasLength(1)); |
4384 expect(outputs[TOKEN_STREAM], isNotNull); | 4390 expect(outputs[TOKEN_STREAM], isNotNull); |
4385 IgnoreInfo ignoreInfo = outputs[IGNORE_INFO]; | 4391 IgnoreInfo ignoreInfo = outputs[IGNORE_INFO]; |
4386 expect(ignoreInfo, isNotNull); | 4392 expect(ignoreInfo, isNotNull); |
4387 expect(ignoreInfo.hasIgnores, isFalse); | 4393 expect(ignoreInfo.hasIgnores, isFalse); |
4388 } | 4394 } |
4389 | 4395 |
| 4396 test_perform_library() { |
| 4397 _performScanTask(r''' |
| 4398 library lib; |
| 4399 import 'lib2.dart'; |
| 4400 export 'lib3.dart'; |
| 4401 part 'part.dart'; |
| 4402 class A {'''); |
| 4403 expect(outputs, hasLength(4)); |
| 4404 expect(outputs[LINE_INFO], isNotNull); |
| 4405 // Missing closing brace error is reported by the Fasta scanner. |
| 4406 expect(outputs[SCAN_ERRORS], hasLength(fe.Scanner.useFasta ? 1 : 0)); |
| 4407 expect(outputs[TOKEN_STREAM], isNotNull); |
| 4408 IgnoreInfo ignoreInfo = outputs[IGNORE_INFO]; |
| 4409 expect(ignoreInfo, isNotNull); |
| 4410 expect(ignoreInfo.hasIgnores, isFalse); |
| 4411 } |
| 4412 |
4390 test_perform_noErrors() { | 4413 test_perform_noErrors() { |
4391 _performScanTask('class A {}'); | 4414 _performScanTask('class A {}'); |
4392 expect(outputs, hasLength(4)); | 4415 expect(outputs, hasLength(4)); |
4393 expect(outputs[LINE_INFO], isNotNull); | 4416 expect(outputs[LINE_INFO], isNotNull); |
4394 expect(outputs[SCAN_ERRORS], hasLength(0)); | 4417 expect(outputs[SCAN_ERRORS], hasLength(0)); |
4395 expect(outputs[TOKEN_STREAM], isNotNull); | 4418 expect(outputs[TOKEN_STREAM], isNotNull); |
4396 IgnoreInfo ignoreInfo = outputs[IGNORE_INFO]; | 4419 IgnoreInfo ignoreInfo = outputs[IGNORE_INFO]; |
4397 expect(ignoreInfo, isNotNull); | 4420 expect(ignoreInfo, isNotNull); |
4398 expect(ignoreInfo.hasIgnores, isFalse); | 4421 expect(ignoreInfo.hasIgnores, isFalse); |
4399 } | 4422 } |
(...skipping 11 matching lines...) Expand all Loading... |
4411 </head> | 4434 </head> |
4412 <body>Test</body> | 4435 <body>Test</body> |
4413 </html> | 4436 </html> |
4414 '''; | 4437 '''; |
4415 Source source = newSource('/test.html', htmlContent); | 4438 Source source = newSource('/test.html', htmlContent); |
4416 DartScript script = | 4439 DartScript script = |
4417 new DartScript(source, [new ScriptFragment(97, 5, 36, scriptContent)]); | 4440 new DartScript(source, [new ScriptFragment(97, 5, 36, scriptContent)]); |
4418 | 4441 |
4419 computeResult(script, TOKEN_STREAM, matcher: isScanDartTask); | 4442 computeResult(script, TOKEN_STREAM, matcher: isScanDartTask); |
4420 expect(outputs[LINE_INFO], isNotNull); | 4443 expect(outputs[LINE_INFO], isNotNull); |
4421 expect(outputs[SCAN_ERRORS], isEmpty); | 4444 if (fe.Scanner.useFasta) { |
| 4445 // Missing closing brace error is reported by Fasta scanner. |
| 4446 expect(outputs[SCAN_ERRORS], hasLength(1)); |
| 4447 } else { |
| 4448 expect(outputs[SCAN_ERRORS], isEmpty); |
| 4449 } |
4422 Token tokenStream = outputs[TOKEN_STREAM]; | 4450 Token tokenStream = outputs[TOKEN_STREAM]; |
4423 expect(tokenStream, isNotNull); | 4451 expect(tokenStream, isNotNull); |
4424 expect(tokenStream.lexeme, 'void'); | 4452 expect(tokenStream.lexeme, 'void'); |
4425 } | 4453 } |
4426 | 4454 |
4427 void _performScanTask(String content) { | 4455 void _performScanTask(String content) { |
4428 AnalysisTarget target = newSource('/test.dart', content); | 4456 AnalysisTarget target = newSource('/test.dart', content); |
4429 computeResult(target, TOKEN_STREAM, matcher: isScanDartTask); | 4457 computeResult(target, TOKEN_STREAM, matcher: isScanDartTask); |
4430 } | 4458 } |
4431 } | 4459 } |
(...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5279 /** | 5307 /** |
5280 * Fill [errorListener] with [result] errors in the current [task]. | 5308 * Fill [errorListener] with [result] errors in the current [task]. |
5281 */ | 5309 */ |
5282 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { | 5310 void _fillErrorListener(ResultDescriptor<List<AnalysisError>> result) { |
5283 List<AnalysisError> errors = task.outputs[result] as List<AnalysisError>; | 5311 List<AnalysisError> errors = task.outputs[result] as List<AnalysisError>; |
5284 expect(errors, isNotNull, reason: result.name); | 5312 expect(errors, isNotNull, reason: result.name); |
5285 errorListener = new GatheringErrorListener(); | 5313 errorListener = new GatheringErrorListener(); |
5286 errorListener.addAll(errors); | 5314 errorListener.addAll(errors); |
5287 } | 5315 } |
5288 } | 5316 } |
OLD | NEW |