Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1122)

Side by Side Diff: pkg/front_end/test/scanner_fasta_test.dart

Issue 2984713002: Fix scanning of unterminated strings (Closed)
Patch Set: address comments Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 return createScanner(source, includeComments: true).tokenize(); 678 return createScanner(source, includeComments: true).tokenize();
679 } 679 }
680 680
681 void test_linestarts() { 681 void test_linestarts() {
682 var scanner = createScanner("var\r\ni\n=\n1;\n"); 682 var scanner = createScanner("var\r\ni\n=\n1;\n");
683 var token = scanner.tokenize(); 683 var token = scanner.tokenize();
684 expect(token.lexeme, 'var'); 684 expect(token.lexeme, 'var');
685 var lineStarts = scanner.lineStarts; 685 var lineStarts = scanner.lineStarts;
686 expect(lineStarts, orderedEquals([0, 5, 7, 9, 12, 13])); 686 expect(lineStarts, orderedEquals([0, 5, 7, 9, 12, 13]));
687 } 687 }
688
689 void test_linestarts_synthetic_string() {
690 var scanner = createScanner("var\r\ns\n=\n'eh'\n'eh\n;\n");
691 Token firstToken = scanner.tokenize();
692 expect(firstToken.lexeme, 'var');
693 var lineStarts = scanner.lineStarts;
694 expect(lineStarts, orderedEquals([0, 5, 7, 9, 14, 18, 20, 21]));
695 var token = firstToken;
696 int index = 0;
697 while (!token.isEof) {
698 if (token is fasta.ErrorToken) {
699 expect(token.charOffset, 14,
700 reason: 'error token : $token, ${token.type}');
701 expect(token.charCount, 3,
702 reason: 'error token : $token, ${token.type}');
703 } else {
704 expect(token.charOffset, lineStarts[index],
705 reason: 'token # $index : $token, ${token.type}');
706 ++index;
707 }
708 token = token.next;
709 }
710 }
711
712 void test_linestarts_synthetic_string_utf8() {
713 var scanner = createScanner("var\r\ns\n=\n'éh'\n'éh\n;\n");
714 Token firstToken = scanner.tokenize();
715 expect(firstToken.lexeme, 'var');
716 var lineStarts = scanner.lineStarts;
717 expect(lineStarts, orderedEquals([0, 5, 7, 9, 14, 18, 20, 21]));
718 var token = firstToken;
719 int index = 0;
720 while (!token.isEof) {
721 if (token is! fasta.ErrorToken) {
722 expect(token.charOffset, lineStarts[index],
723 reason: 'token # $index : $token, ${token.type}');
724 ++index;
725 }
726 token = token.next;
727 }
728 }
688 } 729 }
689 730
690 /// Override of [ToAnalyzerTokenStreamConverter] that verifies that there are no 731 /// Override of [ToAnalyzerTokenStreamConverter] that verifies that there are no
691 /// errors. 732 /// errors.
692 class ToAnalyzerTokenStreamConverter_NoErrors 733 class ToAnalyzerTokenStreamConverter_NoErrors
693 extends ToAnalyzerTokenStreamConverter { 734 extends ToAnalyzerTokenStreamConverter {
694 @override 735 @override
695 void reportError( 736 void reportError(
696 ScannerErrorCode errorCode, int offset, List<Object> arguments) { 737 ScannerErrorCode errorCode, int offset, List<Object> arguments) {
697 fail('Unexpected error: $errorCode, $offset, $arguments'); 738 fail('Unexpected error: $errorCode, $offset, $arguments');
698 } 739 }
699 } 740 }
700 741
701 /// Override of [ToAnalyzerTokenStreamConverter] that records errors in an 742 /// Override of [ToAnalyzerTokenStreamConverter] that records errors in an
702 /// [ErrorListener]. 743 /// [ErrorListener].
703 class ToAnalyzerTokenStreamConverter_WithListener 744 class ToAnalyzerTokenStreamConverter_WithListener
704 extends ToAnalyzerTokenStreamConverter { 745 extends ToAnalyzerTokenStreamConverter {
705 final ErrorListener _listener; 746 final ErrorListener _listener;
706 747
707 ToAnalyzerTokenStreamConverter_WithListener(this._listener); 748 ToAnalyzerTokenStreamConverter_WithListener(this._listener);
708 749
709 @override 750 @override
710 void reportError( 751 void reportError(
711 ScannerErrorCode errorCode, int offset, List<Object> arguments) { 752 ScannerErrorCode errorCode, int offset, List<Object> arguments) {
712 _listener.errors.add(new TestError(offset, errorCode, arguments)); 753 _listener.errors.add(new TestError(offset, errorCode, arguments));
713 } 754 }
714 } 755 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/scanner/utf8_bytes_scanner.dart ('k') | pkg/front_end/testcases/ast_builder.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698