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/error_token.dart' as fasta; | 8 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; | 9 import 'package:front_end/src/fasta/scanner/string_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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 expect((token as fasta.ErrorToken).errorCode, same(codeUnmatchedToken)); | 322 expect((token as fasta.ErrorToken).errorCode, same(codeUnmatchedToken)); |
323 expect((token as fasta.UnmatchedToken).begin, same(interpolationStart)); | 323 expect((token as fasta.UnmatchedToken).begin, same(interpolationStart)); |
324 | 324 |
325 token = token.next; | 325 token = token.next; |
326 expectToken(token, TokenType.STRING, 10, 0, isSynthetic: true, lexeme: '"'); | 326 expectToken(token, TokenType.STRING, 10, 0, isSynthetic: true, lexeme: '"'); |
327 | 327 |
328 token = token.next; | 328 token = token.next; |
329 expect((token as fasta.ErrorToken).errorCode, same(codeUnterminatedString)); | 329 expect((token as fasta.ErrorToken).errorCode, same(codeUnterminatedString)); |
330 } | 330 } |
331 | 331 |
| 332 void test_string_simple_unterminated_interpolation_block2() { |
| 333 Token token = scan(r'"foo ${bar(baz['); |
| 334 expectToken(token, TokenType.STRING, 0, 5, lexeme: '"foo '); |
| 335 |
| 336 token = token.next; |
| 337 expectToken(token, TokenType.STRING_INTERPOLATION_EXPRESSION, 5, 2); |
| 338 BeginToken interpolationStart = token; |
| 339 |
| 340 token = token.next; |
| 341 expectToken(token, TokenType.IDENTIFIER, 7, 3, lexeme: 'bar'); |
| 342 |
| 343 token = token.next; |
| 344 expectToken(token, TokenType.OPEN_PAREN, 10, 1); |
| 345 BeginToken openParen = token; |
| 346 |
| 347 token = token.next; |
| 348 expectToken(token, TokenType.IDENTIFIER, 11, 3, lexeme: 'baz'); |
| 349 |
| 350 token = token.next; |
| 351 expectToken(token, TokenType.OPEN_SQUARE_BRACKET, 14, 1); |
| 352 BeginToken openSquareBracket = token; |
| 353 |
| 354 token = token.next; |
| 355 expectToken(token, TokenType.CLOSE_SQUARE_BRACKET, 15, 0, |
| 356 isSynthetic: true, lexeme: ']'); |
| 357 expect(openSquareBracket.endToken, same(token)); |
| 358 |
| 359 token = token.next; |
| 360 expect((token as fasta.ErrorToken).errorCode, same(codeUnmatchedToken)); |
| 361 expect((token as fasta.UnmatchedToken).begin, same(openSquareBracket)); |
| 362 |
| 363 token = token.next; |
| 364 expectToken(token, TokenType.CLOSE_PAREN, 15, 0, |
| 365 isSynthetic: true, lexeme: ')'); |
| 366 expect(openParen.endToken, same(token)); |
| 367 |
| 368 token = token.next; |
| 369 expect((token as fasta.ErrorToken).errorCode, same(codeUnmatchedToken)); |
| 370 expect((token as fasta.UnmatchedToken).begin, same(openParen)); |
| 371 |
| 372 token = token.next; |
| 373 expectToken(token, TokenType.CLOSE_CURLY_BRACKET, 15, 0, |
| 374 isSynthetic: true, lexeme: '}'); |
| 375 expect(interpolationStart.endToken, same(token)); |
| 376 |
| 377 token = token.next; |
| 378 expect((token as fasta.ErrorToken).errorCode, same(codeUnmatchedToken)); |
| 379 expect((token as fasta.UnmatchedToken).begin, same(interpolationStart)); |
| 380 |
| 381 token = token.next; |
| 382 expectToken(token, TokenType.STRING, 15, 0, isSynthetic: true, lexeme: '"'); |
| 383 |
| 384 token = token.next; |
| 385 expect((token as fasta.ErrorToken).errorCode, same(codeUnterminatedString)); |
| 386 } |
| 387 |
332 void test_string_simple_missing_interpolation_identifier() { | 388 void test_string_simple_missing_interpolation_identifier() { |
333 Token token = scan(r'"foo $'); | 389 Token token = scan(r'"foo $'); |
334 expectToken(token, TokenType.STRING, 0, 5, lexeme: '"foo '); | 390 expectToken(token, TokenType.STRING, 0, 5, lexeme: '"foo '); |
335 | 391 |
336 token = token.next; | 392 token = token.next; |
337 expectToken(token, TokenType.STRING_INTERPOLATION_IDENTIFIER, 5, 1); | 393 expectToken(token, TokenType.STRING_INTERPOLATION_IDENTIFIER, 5, 1); |
338 | 394 |
339 token = token.next; | 395 token = token.next; |
340 expect((token as fasta.ErrorToken).errorCode, | 396 expect((token as fasta.ErrorToken).errorCode, |
341 same(codeUnexpectedDollarInString)); | 397 same(codeUnexpectedDollarInString)); |
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 final ErrorListener _listener; | 666 final ErrorListener _listener; |
611 | 667 |
612 ToAnalyzerTokenStreamConverter_WithListener(this._listener); | 668 ToAnalyzerTokenStreamConverter_WithListener(this._listener); |
613 | 669 |
614 @override | 670 @override |
615 void reportError( | 671 void reportError( |
616 ScannerErrorCode errorCode, int offset, List<Object> arguments) { | 672 ScannerErrorCode errorCode, int offset, List<Object> arguments) { |
617 _listener.errors.add(new TestError(offset, errorCode, arguments)); | 673 _listener.errors.add(new TestError(offset, errorCode, arguments)); |
618 } | 674 } |
619 } | 675 } |
OLD | NEW |