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 import 'dart:convert'; | 4 import 'dart:convert'; |
5 | 5 |
6 import 'package:analyzer/src/fasta/token_utils.dart'; | 6 import 'package:analyzer/src/fasta/token_utils.dart'; |
7 import 'package:front_end/src/fasta/fasta_codes.dart'; | 7 import 'package:front_end/src/fasta/fasta_codes.dart'; |
| 8 import 'package:front_end/src/fasta/scanner.dart' as usedForFuzzTesting; |
8 import 'package:front_end/src/fasta/scanner/error_token.dart' as fasta; | 9 import 'package:front_end/src/fasta/scanner/error_token.dart' as fasta; |
9 import 'package:front_end/src/fasta/scanner/string_scanner.dart' as fasta; | 10 import 'package:front_end/src/fasta/scanner/string_scanner.dart' as fasta; |
10 import 'package:front_end/src/fasta/scanner/token.dart' as fasta; | 11 import 'package:front_end/src/fasta/scanner/token.dart' as fasta; |
11 import 'package:front_end/src/fasta/scanner/token_constants.dart' as fasta; | 12 import 'package:front_end/src/fasta/scanner/token_constants.dart' as fasta; |
12 import 'package:front_end/src/fasta/scanner/utf8_bytes_scanner.dart' as fasta; | 13 import 'package:front_end/src/fasta/scanner/utf8_bytes_scanner.dart' as fasta; |
13 import 'package:front_end/src/scanner/errors.dart'; | 14 import 'package:front_end/src/scanner/errors.dart'; |
14 import 'package:front_end/src/scanner/token.dart'; | 15 import 'package:front_end/src/scanner/token.dart'; |
15 import 'package:test/test.dart'; | 16 import 'package:test/test.dart'; |
16 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 17 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
17 | 18 |
18 import 'scanner_test.dart'; | 19 import 'scanner_test.dart'; |
19 | 20 |
20 main() { | 21 main() { |
21 defineReflectiveSuite(() { | 22 defineReflectiveSuite(() { |
22 defineReflectiveTests(ScannerTest_Fasta); | 23 defineReflectiveTests(ScannerTest_Fasta); |
| 24 defineReflectiveTests(ScannerTest_Fasta_FuzzTestAPI); |
23 defineReflectiveTests(ScannerTest_Fasta_UTF8); | 25 defineReflectiveTests(ScannerTest_Fasta_UTF8); |
24 defineReflectiveTests(ScannerTest_Fasta_Direct); | 26 defineReflectiveTests(ScannerTest_Fasta_Direct); |
25 defineReflectiveTests(ScannerTest_Fasta_Direct_UTF8); | 27 defineReflectiveTests(ScannerTest_Fasta_Direct_UTF8); |
26 }); | 28 }); |
27 } | 29 } |
28 | 30 |
29 @reflectiveTest | 31 @reflectiveTest |
| 32 class ScannerTest_Fasta_FuzzTestAPI { |
| 33 test_API() { |
| 34 // These two API are used when fuzz testing the scanner. |
| 35 String source = 'class A { }'; |
| 36 |
| 37 usedForFuzzTesting.ScannerResult result = |
| 38 usedForFuzzTesting.scanString(source); |
| 39 expect(result?.hasErrors, isFalse); |
| 40 expect(result.tokens?.type, same(Keyword.CLASS)); |
| 41 |
| 42 // UTF8 encode source with trailing zero |
| 43 List<int> bytes = UTF8.encode(source).toList(); |
| 44 bytes.add(0); |
| 45 |
| 46 result = usedForFuzzTesting.scan(bytes); |
| 47 expect(result?.hasErrors, isFalse); |
| 48 expect(result.tokens?.type, same(Keyword.CLASS)); |
| 49 } |
| 50 } |
| 51 |
| 52 @reflectiveTest |
30 class ScannerTest_Fasta_UTF8 extends ScannerTest_Fasta { | 53 class ScannerTest_Fasta_UTF8 extends ScannerTest_Fasta { |
31 @override | 54 @override |
32 createScanner(String source, {bool genericMethodComments: false}) { | 55 createScanner(String source, {bool genericMethodComments: false}) { |
33 List<int> encoded = UTF8.encode(source).toList(growable: true); | 56 List<int> encoded = UTF8.encode(source).toList(growable: true); |
34 encoded.add(0); // Ensure 0 terminted bytes for UTF8 scanner | 57 encoded.add(0); // Ensure 0 terminted bytes for UTF8 scanner |
35 return new fasta.Utf8BytesScanner(encoded, | 58 return new fasta.Utf8BytesScanner(encoded, |
36 includeComments: true, | 59 includeComments: true, |
37 scanGenericMethodComments: genericMethodComments); | 60 scanGenericMethodComments: genericMethodComments); |
38 } | 61 } |
39 } | 62 } |
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
682 final ErrorListener _listener; | 705 final ErrorListener _listener; |
683 | 706 |
684 ToAnalyzerTokenStreamConverter_WithListener(this._listener); | 707 ToAnalyzerTokenStreamConverter_WithListener(this._listener); |
685 | 708 |
686 @override | 709 @override |
687 void reportError( | 710 void reportError( |
688 ScannerErrorCode errorCode, int offset, List<Object> arguments) { | 711 ScannerErrorCode errorCode, int offset, List<Object> arguments) { |
689 _listener.errors.add(new TestError(offset, errorCode, arguments)); | 712 _listener.errors.add(new TestError(offset, errorCode, arguments)); |
690 } | 713 } |
691 } | 714 } |
OLD | NEW |