OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'package:analyzer/src/fasta/token_utils.dart'; | 5 import 'package:analyzer/src/fasta/token_utils.dart'; |
6 import 'package:front_end/src/fasta/scanner/error_token.dart' as fasta; | 6 import 'package:front_end/src/fasta/scanner/error_token.dart' as fasta; |
7 import 'package:front_end/src/fasta/scanner/string_scanner.dart' as fasta; | 7 import 'package:front_end/src/fasta/scanner/string_scanner.dart' as fasta; |
8 import 'package:front_end/src/fasta/scanner/token.dart' as fasta; | 8 import 'package:front_end/src/fasta/scanner/token.dart' as fasta; |
9 import 'package:front_end/src/fasta/scanner/token_constants.dart' as fasta; | 9 import 'package:front_end/src/fasta/scanner/token_constants.dart' as fasta; |
10 import 'package:front_end/src/scanner/errors.dart'; | 10 import 'package:front_end/src/scanner/errors.dart'; |
11 import 'package:front_end/src/scanner/token.dart'; | 11 import 'package:front_end/src/scanner/token.dart'; |
12 import 'package:test/test.dart'; | 12 import 'package:test/test.dart'; |
13 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 13 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
14 | 14 |
15 import 'scanner_test.dart'; | 15 import 'scanner_test.dart'; |
16 | 16 |
17 main() { | 17 main() { |
18 defineReflectiveSuite(() { | 18 defineReflectiveSuite(() { |
19 defineReflectiveTests(ScannerTest_Fasta); | 19 defineReflectiveTests(ScannerTest_Fasta); |
20 defineReflectiveTests(ScannerTest_Fasta_Direct); | 20 defineReflectiveTests(ScannerTest_Fasta_Direct); |
21 defineReflectiveTests(ScannerTest_Fasta_Roundtrip); | |
22 }); | 21 }); |
23 } | 22 } |
24 | 23 |
25 @reflectiveTest | 24 @reflectiveTest |
26 class ScannerTest_Fasta extends ScannerTestBase { | 25 class ScannerTest_Fasta extends ScannerTestBase { |
27 @override | 26 @override |
28 Token scanWithListener(String source, ErrorListener listener, | 27 Token scanWithListener(String source, ErrorListener listener, |
29 {bool genericMethodComments: false, | 28 {bool genericMethodComments: false, |
30 bool lazyAssignmentOperators: false}) { | 29 bool lazyAssignmentOperators: false}) { |
31 var scanner = new fasta.StringScanner(source, | 30 var scanner = new fasta.StringScanner(source, |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 /// Scanner tests that exercise the Fasta scanner directly. | 499 /// Scanner tests that exercise the Fasta scanner directly. |
501 @reflectiveTest | 500 @reflectiveTest |
502 class ScannerTest_Fasta_Direct extends ScannerTest_Fasta_Base { | 501 class ScannerTest_Fasta_Direct extends ScannerTest_Fasta_Base { |
503 @override | 502 @override |
504 Token scan(String source) { | 503 Token scan(String source) { |
505 var scanner = new fasta.StringScanner(source, includeComments: true); | 504 var scanner = new fasta.StringScanner(source, includeComments: true); |
506 return scanner.tokenize(); | 505 return scanner.tokenize(); |
507 } | 506 } |
508 } | 507 } |
509 | 508 |
510 /// Scanner tests that exercise the Fasta scanner, then convert the tokens to | |
511 /// analyzer tokens, then convert back to Fasta tokens before checking | |
512 /// assertions. | |
513 @reflectiveTest | |
514 class ScannerTest_Fasta_Roundtrip extends ScannerTest_Fasta_Base { | |
515 @override | |
516 Token scan(String source) { | |
517 var scanner = new fasta.StringScanner(source, includeComments: true); | |
518 var fastaTokenStream = scanner.tokenize(); | |
519 var analyzerTokenStream = new ToAnalyzerTokenStreamConverter_NoErrors() | |
520 .convertTokens(fastaTokenStream); | |
521 return fromAnalyzerTokenStream(analyzerTokenStream); | |
522 } | |
523 } | |
524 | |
525 /// Override of [ToAnalyzerTokenStreamConverter] that verifies that there are no | 509 /// Override of [ToAnalyzerTokenStreamConverter] that verifies that there are no |
526 /// errors. | 510 /// errors. |
527 class ToAnalyzerTokenStreamConverter_NoErrors | 511 class ToAnalyzerTokenStreamConverter_NoErrors |
528 extends ToAnalyzerTokenStreamConverter { | 512 extends ToAnalyzerTokenStreamConverter { |
529 @override | 513 @override |
530 void reportError( | 514 void reportError( |
531 ScannerErrorCode errorCode, int offset, List<Object> arguments) { | 515 ScannerErrorCode errorCode, int offset, List<Object> arguments) { |
532 fail('Unexpected error: $errorCode, $offset, $arguments'); | 516 fail('Unexpected error: $errorCode, $offset, $arguments'); |
533 } | 517 } |
534 } | 518 } |
535 | 519 |
536 /// Override of [ToAnalyzerTokenStreamConverter] that records errors in an | 520 /// Override of [ToAnalyzerTokenStreamConverter] that records errors in an |
537 /// [ErrorListener]. | 521 /// [ErrorListener]. |
538 class ToAnalyzerTokenStreamConverter_WithListener | 522 class ToAnalyzerTokenStreamConverter_WithListener |
539 extends ToAnalyzerTokenStreamConverter { | 523 extends ToAnalyzerTokenStreamConverter { |
540 final ErrorListener _listener; | 524 final ErrorListener _listener; |
541 | 525 |
542 ToAnalyzerTokenStreamConverter_WithListener(this._listener); | 526 ToAnalyzerTokenStreamConverter_WithListener(this._listener); |
543 | 527 |
544 @override | 528 @override |
545 void reportError( | 529 void reportError( |
546 ScannerErrorCode errorCode, int offset, List<Object> arguments) { | 530 ScannerErrorCode errorCode, int offset, List<Object> arguments) { |
547 _listener.errors.add(new TestError(offset, errorCode, arguments)); | 531 _listener.errors.add(new TestError(offset, errorCode, arguments)); |
548 } | 532 } |
549 } | 533 } |
OLD | NEW |