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 'dart:convert' show UTF8; | 5 import 'dart:convert' show UTF8; |
6 | 6 |
7 import 'package:front_end/src/fasta/scanner/recover.dart' | 7 import 'package:front_end/src/fasta/scanner/recover.dart' |
8 show defaultRecoveryStrategy; | 8 show defaultRecoveryStrategy; |
9 import 'package:front_end/src/fasta/scanner.dart' as fasta; | 9 import 'package:front_end/src/fasta/scanner.dart' as fasta; |
10 import 'package:front_end/src/fasta/scanner/token.dart' as fasta; | 10 import 'package:front_end/src/fasta/scanner/token.dart' as fasta; |
(...skipping 17 matching lines...) Expand all Loading... |
28 /// token stream before verifying assertions. | 28 /// token stream before verifying assertions. |
29 /// | 29 /// |
30 /// These tests help to validate the correctness of the analyzer->Fasta token | 30 /// These tests help to validate the correctness of the analyzer->Fasta token |
31 /// stream conversion. | 31 /// stream conversion. |
32 @reflectiveTest | 32 @reflectiveTest |
33 class ScannerTest_Replacement extends ScannerTest { | 33 class ScannerTest_Replacement extends ScannerTest { |
34 @override | 34 @override |
35 analyzer.Token scanWithListener(String source, ErrorListener listener, | 35 analyzer.Token scanWithListener(String source, ErrorListener listener, |
36 {bool genericMethodComments: false, | 36 {bool genericMethodComments: false, |
37 bool lazyAssignmentOperators: false}) { | 37 bool lazyAssignmentOperators: false}) { |
38 // Note: Fasta always supports lazy assignment operators (`&&=` and `||=`), | |
39 // so we can ignore the `lazyAssignmentOperators` flag. | |
40 // TODO(danrubel): once lazyAssignmentOperators are fully supported by | |
41 // Dart, remove this flag. | |
42 fasta.ScannerResult result = fasta.scanString(source, | 38 fasta.ScannerResult result = fasta.scanString(source, |
43 includeComments: true, scanGenericMethodComments: genericMethodComments, | 39 includeComments: true, |
| 40 scanGenericMethodComments: genericMethodComments, |
| 41 scanLazyAssignmentOperators: lazyAssignmentOperators, |
44 recover: ((List<int> bytes, fasta.Token tokens, List<int> lineStarts) { | 42 recover: ((List<int> bytes, fasta.Token tokens, List<int> lineStarts) { |
45 // perform recovery as a separate step | 43 // perform recovery as a separate step |
46 // so that the token stream can be validated before and after recovery | 44 // so that the token stream can be validated before and after recovery |
47 return tokens; | 45 return tokens; |
48 })); | 46 })); |
49 fasta.Token tokens = result.tokens; | 47 fasta.Token tokens = result.tokens; |
50 assertValidTokenStream(tokens); | 48 assertValidTokenStream(tokens); |
51 assertValidBeginTokens(tokens); | 49 assertValidBeginTokens(tokens); |
52 if (result.hasErrors) { | 50 if (result.hasErrors) { |
53 List<int> bytes = UTF8.encode(source); | 51 List<int> bytes = UTF8.encode(source); |
54 tokens = defaultRecoveryStrategy(bytes, tokens, result.lineStarts); | 52 tokens = defaultRecoveryStrategy(bytes, tokens, result.lineStarts); |
55 assertValidTokenStream(tokens, errorsFirst: true); | 53 assertValidTokenStream(tokens, errorsFirst: true); |
56 } | 54 } |
57 return extractErrors(tokens, listener); | 55 return extractErrors(tokens, listener); |
58 } | 56 } |
59 | 57 |
60 @override | |
61 @failingTest | |
62 void test_ampersand_ampersand_eq() { | |
63 // TODO(paulberry,ahe): Fasta scanner doesn't support lazy assignment | |
64 // operators. | |
65 super.test_ampersand_ampersand_eq(); | |
66 } | |
67 | |
68 @override | |
69 @failingTest | |
70 void test_bar_bar_eq() { | |
71 // TODO(paulberry,ahe): Fasta scanner doesn't support lazy assignment | |
72 // operators. | |
73 super.test_bar_bar_eq(); | |
74 } | |
75 | |
76 void _assertOpenClosePair(String source) { | 58 void _assertOpenClosePair(String source) { |
77 fasta.BeginGroupToken open = _scan(source); | 59 fasta.BeginGroupToken open = _scan(source); |
78 fasta.Token close = open.next; | 60 fasta.Token close = open.next; |
79 expect(close.next.isEof, isTrue); | 61 expect(close.next.isEof, isTrue); |
80 expect(open.endGroup, close); | 62 expect(open.endGroup, close); |
81 expect(open.isSynthetic, isFalse); | 63 expect(open.isSynthetic, isFalse); |
82 expect(close.isSynthetic, isFalse); | 64 expect(close.isSynthetic, isFalse); |
83 } | 65 } |
84 | 66 |
85 void _assertOpenOnly(String source) { | 67 void _assertOpenOnly(String source) { |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 } else if (token is fasta.UnmatchedToken) { | 351 } else if (token is fasta.UnmatchedToken) { |
370 expect(lastClosedGroup?.endGroup?.next, same(token), | 352 expect(lastClosedGroup?.endGroup?.next, same(token), |
371 reason: 'Unexpected error token for group: $lastClosedGroup'); | 353 reason: 'Unexpected error token for group: $lastClosedGroup'); |
372 expect(token.begin, lastClosedGroup); | 354 expect(token.begin, lastClosedGroup); |
373 } | 355 } |
374 token = token.next; | 356 token = token.next; |
375 } | 357 } |
376 expect(openerStack, isEmpty, reason: 'Missing closers'); | 358 expect(openerStack, isEmpty, reason: 'Missing closers'); |
377 } | 359 } |
378 } | 360 } |
OLD | NEW |