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.dart' as usedForFuzzTesting; |
9 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; |
10 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; |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 // Remove the last token. | 218 // Remove the last token. |
219 { | 219 { |
220 prepareTokens(); | 220 prepareTokens(); |
221 c3.remove(); | 221 c3.remove(); |
222 expect(token.precedingComments, c1); | 222 expect(token.precedingComments, c1); |
223 expect(c1.next, c2); | 223 expect(c1.next, c2); |
224 expect(c2.next, isNull); | 224 expect(c2.next, isNull); |
225 } | 225 } |
226 } | 226 } |
227 | 227 |
| 228 void test_double_error() { |
| 229 String source = "3457e"; |
| 230 ErrorListener listener = new ErrorListener(); |
| 231 Token token = scanWithListener(source, listener); |
| 232 expect(token, isNotNull); |
| 233 expect(token.type, TokenType.DOUBLE); |
| 234 expect(token.offset, 0); |
| 235 expect(token.isSynthetic, isTrue); |
| 236 // the invalid token is updated to be valid ... |
| 237 expect(token.lexeme, source + "0"); |
| 238 // ... but the length does *not* include the additional character |
| 239 // so as to be true to the original source. |
| 240 expect(token.length, source.length); |
| 241 expect(token.next.isEof, isTrue); |
| 242 expect(listener.errors, hasLength(1)); |
| 243 TestError error = listener.errors[0]; |
| 244 expect(error.errorCode, ScannerErrorCode.MISSING_DIGIT); |
| 245 expect(error.offset, source.length - 1); |
| 246 } |
| 247 |
228 @override | 248 @override |
229 void test_mismatched_opener_in_interpolation() { | 249 void test_mismatched_opener_in_interpolation() { |
230 // When openers and closers are mismatched, | 250 // When openers and closers are mismatched, |
231 // fasta favors considering the opener to be mismatched | 251 // fasta favors considering the opener to be mismatched |
232 // and inserts synthetic closers as needed. | 252 // and inserts synthetic closers as needed. |
233 // r'"${({(}}"' is parsed as r'"${({()})}"' | 253 // r'"${({(}}"' is parsed as r'"${({()})}"' |
234 // where both ')' are synthetic | 254 // where both ')' are synthetic |
235 ErrorListener listener = new ErrorListener(); | 255 ErrorListener listener = new ErrorListener(); |
236 BeginToken interpolationStart = | 256 BeginToken interpolationStart = |
237 scanWithListener(r'"${({(}}"', listener).next; | 257 scanWithListener(r'"${({(}}"', listener).next; |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
746 final ErrorListener _listener; | 766 final ErrorListener _listener; |
747 | 767 |
748 ToAnalyzerTokenStreamConverter_WithListener(this._listener); | 768 ToAnalyzerTokenStreamConverter_WithListener(this._listener); |
749 | 769 |
750 @override | 770 @override |
751 void reportError( | 771 void reportError( |
752 ScannerErrorCode errorCode, int offset, List<Object> arguments) { | 772 ScannerErrorCode errorCode, int offset, List<Object> arguments) { |
753 _listener.errors.add(new TestError(offset, errorCode, arguments)); | 773 _listener.errors.add(new TestError(offset, errorCode, arguments)); |
754 } | 774 } |
755 } | 775 } |
OLD | NEW |