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

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

Issue 2907093002: Revert "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
« no previous file with comments | « pkg/front_end/test/scanner_replacement_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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),
443 ]); 442 ]);
444 } else { 443 } else {
445 expectedTokens.addAll([ 444 expectedTokens.addAll([
446 new StringToken(TokenType.STRING, "", 10), 445 new StringToken(TokenType.STRING, "", 10),
447 ]); 446 ]);
448 } 447 }
449 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 9, 448 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 9,
450 "\"foo \${bar", expectedTokens); 449 "\"foo \${bar", expectedTokens);
451 } 450 }
452 451
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 985
987 void test_string_multi_single() { 986 void test_string_multi_single() {
988 _assertToken(TokenType.STRING, "'''string'''"); 987 _assertToken(TokenType.STRING, "'''string'''");
989 } 988 }
990 989
991 void test_string_multi_slashEnter() { 990 void test_string_multi_slashEnter() {
992 _assertToken(TokenType.STRING, "'''\\\n'''"); 991 _assertToken(TokenType.STRING, "'''\\\n'''");
993 } 992 }
994 993
995 void test_string_multi_unterminated() { 994 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 }
1005 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 8, 995 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 8,
1006 "'''string", expectedTokens); 996 "'''string", [new StringToken(TokenType.STRING, "'''string", 0)]);
1007 } 997 }
1008 998
1009 void test_string_multi_unterminated_interpolation_block() { 999 void test_string_multi_unterminated_interpolation_block() {
1010 _assertErrorAndTokens( 1000 _assertErrorAndTokens(
1011 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 8, "'''\${name", [ 1001 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 8, "'''\${name", [
1012 new StringToken(TokenType.STRING, "'''", 0), 1002 new StringToken(TokenType.STRING, "'''", 0),
1013 new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 3), 1003 new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 3),
1014 new StringToken(TokenType.IDENTIFIER, "name", 5), 1004 new StringToken(TokenType.IDENTIFIER, "name", 5),
1015 new StringToken(TokenType.STRING, "", 9) 1005 new StringToken(TokenType.STRING, "", 9)
1016 ]); 1006 ]);
(...skipping 12 matching lines...) Expand all
1029 void test_string_raw_multi_double() { 1019 void test_string_raw_multi_double() {
1030 _assertToken(TokenType.STRING, "r\"\"\"line1\nline2\"\"\""); 1020 _assertToken(TokenType.STRING, "r\"\"\"line1\nline2\"\"\"");
1031 } 1021 }
1032 1022
1033 void test_string_raw_multi_single() { 1023 void test_string_raw_multi_single() {
1034 _assertToken(TokenType.STRING, "r'''string'''"); 1024 _assertToken(TokenType.STRING, "r'''string'''");
1035 } 1025 }
1036 1026
1037 void test_string_raw_multi_unterminated() { 1027 void test_string_raw_multi_unterminated() {
1038 String source = "r'''string"; 1028 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 }
1048 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 9, 1029 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 9,
1049 source, expectedTokens); 1030 source, [new StringToken(TokenType.STRING, source, 0)]);
1050 } 1031 }
1051 1032
1052 void test_string_raw_simple_double() { 1033 void test_string_raw_simple_double() {
1053 _assertToken(TokenType.STRING, "r\"string\""); 1034 _assertToken(TokenType.STRING, "r\"string\"");
1054 } 1035 }
1055 1036
1056 void test_string_raw_simple_single() { 1037 void test_string_raw_simple_single() {
1057 _assertToken(TokenType.STRING, "r'string'"); 1038 _assertToken(TokenType.STRING, "r'string'");
1058 } 1039 }
1059 1040
1060 void test_string_raw_simple_unterminated_eof() { 1041 void test_string_raw_simple_unterminated_eof() {
1061 String source = "r'string"; 1042 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 }
1071 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 7, 1043 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 7,
1072 source, expectedTokens); 1044 source, [new StringToken(TokenType.STRING, source, 0)]);
1073 } 1045 }
1074 1046
1075 void test_string_raw_simple_unterminated_eol() { 1047 void test_string_raw_simple_unterminated_eol() {
1076 String source = "r'string\n"; 1048 String source = "r'string";
1077 List<Token> expectedTokens = [ 1049 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 8,
1078 new StringToken(TokenType.STRING, "r'string", 0), 1050 "$source\n", [new StringToken(TokenType.STRING, source, 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);
1088 } 1051 }
1089 1052
1090 void test_string_simple_double() { 1053 void test_string_simple_double() {
1091 _assertToken(TokenType.STRING, "\"string\""); 1054 _assertToken(TokenType.STRING, "\"string\"");
1092 } 1055 }
1093 1056
1094 void test_string_simple_escapedDollar() { 1057 void test_string_simple_escapedDollar() {
1095 _assertToken(TokenType.STRING, "'a\\\$b'"); 1058 _assertToken(TokenType.STRING, "'a\\\$b'");
1096 } 1059 }
1097 1060
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 new StringToken(TokenType.STRING, "1'", 2) 1136 new StringToken(TokenType.STRING, "1'", 2)
1174 ]); 1137 ]);
1175 } 1138 }
1176 1139
1177 void test_string_simple_single() { 1140 void test_string_simple_single() {
1178 _assertToken(TokenType.STRING, "'string'"); 1141 _assertToken(TokenType.STRING, "'string'");
1179 } 1142 }
1180 1143
1181 void test_string_simple_unterminated_eof() { 1144 void test_string_simple_unterminated_eof() {
1182 String source = "'string"; 1145 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 }
1192 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 6, 1146 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 6,
1193 source, expectedTokens); 1147 source, [new StringToken(TokenType.STRING, source, 0)]);
1194 } 1148 }
1195 1149
1196 void test_string_simple_unterminated_eol() { 1150 void test_string_simple_unterminated_eol() {
1197 String source = "'string\r"; 1151 String source = "'string";
1198 List<Token> expectedTokens = [ 1152 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 7,
1199 new StringToken(TokenType.STRING, "'string", 0), 1153 "$source\r", [new StringToken(TokenType.STRING, source, 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);
1209 } 1154 }
1210 1155
1211 void test_string_simple_unterminated_interpolation_block() { 1156 void test_string_simple_unterminated_interpolation_block() {
1212 _assertErrorAndTokens( 1157 _assertErrorAndTokens(
1213 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 6, "'\${name", [ 1158 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 6, "'\${name", [
1214 new StringToken(TokenType.STRING, "'", 0), 1159 new StringToken(TokenType.STRING, "'", 0),
1215 new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 1), 1160 new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 1),
1216 new StringToken(TokenType.IDENTIFIER, "name", 3), 1161 new StringToken(TokenType.IDENTIFIER, "name", 3),
1217 new StringToken(TokenType.STRING, "", 7) 1162 new StringToken(TokenType.STRING, "", 7)
1218 ]); 1163 ]);
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1561 _TestScanner(CharacterReader reader, [this.listener]) : super.create(reader); 1506 _TestScanner(CharacterReader reader, [this.listener]) : super.create(reader);
1562 1507
1563 @override 1508 @override
1564 void reportError( 1509 void reportError(
1565 ScannerErrorCode errorCode, int offset, List<Object> arguments) { 1510 ScannerErrorCode errorCode, int offset, List<Object> arguments) {
1566 if (listener != null) { 1511 if (listener != null) {
1567 listener.errors.add(new TestError(offset, errorCode, arguments)); 1512 listener.errors.add(new TestError(offset, errorCode, arguments));
1568 } 1513 }
1569 } 1514 }
1570 } 1515 }
OLDNEW
« no previous file with comments | « 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