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

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

Issue 2912693002: improve fasta unterminated string recovery (Closed)
Patch Set: Created 3 years, 6 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) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 'package:front_end/src/base/errors.dart'; 5 import 'package:front_end/src/base/errors.dart';
6 import 'package:front_end/src/base/jenkins_smi_hash.dart'; 6 import 'package:front_end/src/base/jenkins_smi_hash.dart';
7 import 'package:front_end/src/scanner/errors.dart'; 7 import 'package:front_end/src/scanner/errors.dart';
8 import 'package:front_end/src/scanner/reader.dart'; 8 import 'package:front_end/src/scanner/reader.dart';
9 import 'package:front_end/src/scanner/scanner.dart'; 9 import 'package:front_end/src/scanner/scanner.dart';
10 import 'package:front_end/src/scanner/token.dart'; 10 import 'package:front_end/src/scanner/token.dart';
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 // https://code.google.com/p/dart/issues/detail?id=18073 432 // https://code.google.com/p/dart/issues/detail?id=18073
433 List<Token> expectedTokens = [ 433 List<Token> expectedTokens = [
434 new StringToken(TokenType.STRING, "\"foo ", 0), 434 new StringToken(TokenType.STRING, "\"foo ", 0),
435 new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 5), 435 new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 5),
436 new StringToken(TokenType.IDENTIFIER, "bar", 7), 436 new StringToken(TokenType.IDENTIFIER, "bar", 7),
437 ]; 437 ];
438 if (usingFasta) { 438 if (usingFasta) {
439 // fasta inserts synthetic closers 439 // fasta inserts synthetic closers
440 expectedTokens.addAll([ 440 expectedTokens.addAll([
441 new SyntheticToken(TokenType.CLOSE_CURLY_BRACKET, 10), 441 new SyntheticToken(TokenType.CLOSE_CURLY_BRACKET, 10),
442 new SyntheticStringToken(TokenType.STRING, '"', 10, 0),
442 ]); 443 ]);
443 } else { 444 } else {
444 expectedTokens.addAll([ 445 expectedTokens.addAll([
445 new StringToken(TokenType.STRING, "", 10), 446 new StringToken(TokenType.STRING, "", 10),
446 ]); 447 ]);
447 } 448 }
448 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 9, 449 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 9,
449 "\"foo \${bar", expectedTokens); 450 "\"foo \${bar", expectedTokens);
450 } 451 }
451 452
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 986
986 void test_string_multi_single() { 987 void test_string_multi_single() {
987 _assertToken(TokenType.STRING, "'''string'''"); 988 _assertToken(TokenType.STRING, "'''string'''");
988 } 989 }
989 990
990 void test_string_multi_slashEnter() { 991 void test_string_multi_slashEnter() {
991 _assertToken(TokenType.STRING, "'''\\\n'''"); 992 _assertToken(TokenType.STRING, "'''\\\n'''");
992 } 993 }
993 994
994 void test_string_multi_unterminated() { 995 void test_string_multi_unterminated() {
996 List<Token> expectedTokens = [
997 new StringToken(TokenType.STRING, "'''string", 0),
998 ];
999 if (usingFasta) {
1000 // fasta inserts synthetic closers
1001 expectedTokens.addAll([
1002 new SyntheticStringToken(TokenType.STRING, "'''", 9, 0),
1003 ]);
1004 }
995 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 8, 1005 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 8,
996 "'''string", [new StringToken(TokenType.STRING, "'''string", 0)]); 1006 "'''string", expectedTokens);
997 } 1007 }
998 1008
999 void test_string_multi_unterminated_interpolation_block() { 1009 void test_string_multi_unterminated_interpolation_block() {
1000 _assertErrorAndTokens( 1010 _assertErrorAndTokens(
1001 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 8, "'''\${name", [ 1011 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 8, "'''\${name", [
1002 new StringToken(TokenType.STRING, "'''", 0), 1012 new StringToken(TokenType.STRING, "'''", 0),
1003 new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 3), 1013 new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 3),
1004 new StringToken(TokenType.IDENTIFIER, "name", 5), 1014 new StringToken(TokenType.IDENTIFIER, "name", 5),
1005 new StringToken(TokenType.STRING, "", 9) 1015 new StringToken(TokenType.STRING, "", 9)
1006 ]); 1016 ]);
(...skipping 12 matching lines...) Expand all
1019 void test_string_raw_multi_double() { 1029 void test_string_raw_multi_double() {
1020 _assertToken(TokenType.STRING, "r\"\"\"line1\nline2\"\"\""); 1030 _assertToken(TokenType.STRING, "r\"\"\"line1\nline2\"\"\"");
1021 } 1031 }
1022 1032
1023 void test_string_raw_multi_single() { 1033 void test_string_raw_multi_single() {
1024 _assertToken(TokenType.STRING, "r'''string'''"); 1034 _assertToken(TokenType.STRING, "r'''string'''");
1025 } 1035 }
1026 1036
1027 void test_string_raw_multi_unterminated() { 1037 void test_string_raw_multi_unterminated() {
1028 String source = "r'''string"; 1038 String source = "r'''string";
1039 List<Token> expectedTokens = [
1040 new StringToken(TokenType.STRING, source, 0),
1041 ];
1042 if (usingFasta) {
1043 // fasta inserts synthetic closers
1044 expectedTokens.addAll([
1045 new SyntheticStringToken(TokenType.STRING, "'''", 10, 0),
1046 ]);
1047 }
1029 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 9, 1048 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 9,
1030 source, [new StringToken(TokenType.STRING, source, 0)]); 1049 source, expectedTokens);
1031 } 1050 }
1032 1051
1033 void test_string_raw_simple_double() { 1052 void test_string_raw_simple_double() {
1034 _assertToken(TokenType.STRING, "r\"string\""); 1053 _assertToken(TokenType.STRING, "r\"string\"");
1035 } 1054 }
1036 1055
1037 void test_string_raw_simple_single() { 1056 void test_string_raw_simple_single() {
1038 _assertToken(TokenType.STRING, "r'string'"); 1057 _assertToken(TokenType.STRING, "r'string'");
1039 } 1058 }
1040 1059
1041 void test_string_raw_simple_unterminated_eof() { 1060 void test_string_raw_simple_unterminated_eof() {
1042 String source = "r'string"; 1061 String source = "r'string";
1062 List<Token> expectedTokens = [
1063 new StringToken(TokenType.STRING, source, 0),
1064 ];
1065 if (usingFasta) {
1066 // fasta inserts synthetic closers
1067 expectedTokens.addAll([
1068 new SyntheticStringToken(TokenType.STRING, "'", 8, 0),
1069 ]);
1070 }
1043 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 7, 1071 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 7,
1044 source, [new StringToken(TokenType.STRING, source, 0)]); 1072 source, expectedTokens);
1045 } 1073 }
1046 1074
1047 void test_string_raw_simple_unterminated_eol() { 1075 void test_string_raw_simple_unterminated_eol() {
1048 String source = "r'string"; 1076 String source = "r'string\n";
1049 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 8, 1077 List<Token> expectedTokens = [
1050 "$source\n", [new StringToken(TokenType.STRING, source, 0)]); 1078 new StringToken(TokenType.STRING, "r'string", 0),
1079 ];
1080 if (usingFasta) {
1081 // fasta inserts synthetic closers
1082 expectedTokens.addAll([
1083 new SyntheticStringToken(TokenType.STRING, "'", 8, 0),
1084 ]);
1085 }
1086 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL,
1087 usingFasta ? 7 : 8, source, expectedTokens);
1051 } 1088 }
1052 1089
1053 void test_string_simple_double() { 1090 void test_string_simple_double() {
1054 _assertToken(TokenType.STRING, "\"string\""); 1091 _assertToken(TokenType.STRING, "\"string\"");
1055 } 1092 }
1056 1093
1057 void test_string_simple_escapedDollar() { 1094 void test_string_simple_escapedDollar() {
1058 _assertToken(TokenType.STRING, "'a\\\$b'"); 1095 _assertToken(TokenType.STRING, "'a\\\$b'");
1059 } 1096 }
1060 1097
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 new StringToken(TokenType.STRING, "1'", 2) 1173 new StringToken(TokenType.STRING, "1'", 2)
1137 ]); 1174 ]);
1138 } 1175 }
1139 1176
1140 void test_string_simple_single() { 1177 void test_string_simple_single() {
1141 _assertToken(TokenType.STRING, "'string'"); 1178 _assertToken(TokenType.STRING, "'string'");
1142 } 1179 }
1143 1180
1144 void test_string_simple_unterminated_eof() { 1181 void test_string_simple_unterminated_eof() {
1145 String source = "'string"; 1182 String source = "'string";
1183 List<Token> expectedTokens = [
1184 new StringToken(TokenType.STRING, source, 0),
1185 ];
1186 if (usingFasta) {
1187 // fasta inserts synthetic closers
1188 expectedTokens.addAll([
1189 new SyntheticStringToken(TokenType.STRING, "'", 7, 0),
1190 ]);
1191 }
1146 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 6, 1192 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 6,
1147 source, [new StringToken(TokenType.STRING, source, 0)]); 1193 source, expectedTokens);
1148 } 1194 }
1149 1195
1150 void test_string_simple_unterminated_eol() { 1196 void test_string_simple_unterminated_eol() {
1151 String source = "'string"; 1197 String source = "'string\r";
1152 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 7, 1198 List<Token> expectedTokens = [
1153 "$source\r", [new StringToken(TokenType.STRING, source, 0)]); 1199 new StringToken(TokenType.STRING, "'string", 0),
1200 ];
1201 if (usingFasta) {
1202 // fasta inserts synthetic closers
1203 expectedTokens.addAll([
1204 new SyntheticStringToken(TokenType.STRING, "'", 7, 0),
1205 ]);
1206 }
1207 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL,
1208 usingFasta ? 6 : 7, source, expectedTokens);
1154 } 1209 }
1155 1210
1156 void test_string_simple_unterminated_interpolation_block() { 1211 void test_string_simple_unterminated_interpolation_block() {
1157 _assertErrorAndTokens( 1212 _assertErrorAndTokens(
1158 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 6, "'\${name", [ 1213 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 6, "'\${name", [
1159 new StringToken(TokenType.STRING, "'", 0), 1214 new StringToken(TokenType.STRING, "'", 0),
1160 new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 1), 1215 new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 1),
1161 new StringToken(TokenType.IDENTIFIER, "name", 3), 1216 new StringToken(TokenType.IDENTIFIER, "name", 3),
1162 new StringToken(TokenType.STRING, "", 7) 1217 new StringToken(TokenType.STRING, "", 7)
1163 ]); 1218 ]);
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1506 _TestScanner(CharacterReader reader, [this.listener]) : super.create(reader); 1561 _TestScanner(CharacterReader reader, [this.listener]) : super.create(reader);
1507 1562
1508 @override 1563 @override
1509 void reportError( 1564 void reportError(
1510 ScannerErrorCode errorCode, int offset, List<Object> arguments) { 1565 ScannerErrorCode errorCode, int offset, List<Object> arguments) {
1511 if (listener != null) { 1566 if (listener != null) {
1512 listener.errors.add(new TestError(offset, errorCode, arguments)); 1567 listener.errors.add(new TestError(offset, errorCode, arguments));
1513 } 1568 }
1514 } 1569 }
1515 } 1570 }
OLDNEW
« pkg/front_end/lib/src/fasta/quote.dart ('K') | « pkg/front_end/test/scanner_replacement_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698