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

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

Issue 2941583003: update invalid hex digit 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/lib/src/fasta/scanner/recover.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 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 _assertToken(TokenType.STRING, "'''string'''"); 1036 _assertToken(TokenType.STRING, "'''string'''");
1037 } 1037 }
1038 1038
1039 void test_string_multi_slashEnter() { 1039 void test_string_multi_slashEnter() {
1040 _assertToken(TokenType.STRING, "'''\\\n'''"); 1040 _assertToken(TokenType.STRING, "'''\\\n'''");
1041 } 1041 }
1042 1042
1043 void test_string_multi_unterminated() { 1043 void test_string_multi_unterminated() {
1044 List<Token> expectedTokens = []; 1044 List<Token> expectedTokens = [];
1045 if (usingFasta) { 1045 if (usingFasta) {
1046 // fasta inserts synthetic closers 1046 // Fasta inserts synthetic closers.
1047 expectedTokens.addAll([ 1047 expectedTokens.addAll([
1048 new SyntheticStringToken(TokenType.STRING, "'''string'''", 0, 9), 1048 new SyntheticStringToken(TokenType.STRING, "'''string'''", 0, 9),
1049 ]); 1049 ]);
1050 } else { 1050 } else {
1051 expectedTokens.addAll([ 1051 expectedTokens.addAll([
1052 new StringToken(TokenType.STRING, "'''string", 0), 1052 new StringToken(TokenType.STRING, "'''string", 0),
1053 ]); 1053 ]);
1054 } 1054 }
1055 } 1055 }
1056 1056
1057 void test_string_multi_unterminated_interpolation_block() { 1057 void test_string_multi_unterminated_interpolation_block() {
1058 List<Token> expectedTokens = [ 1058 List<Token> expectedTokens = [
1059 new StringToken(TokenType.STRING, "'''", 0), 1059 new StringToken(TokenType.STRING, "'''", 0),
1060 new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 3), 1060 new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 3),
1061 new StringToken(TokenType.IDENTIFIER, "name", 5), 1061 new StringToken(TokenType.IDENTIFIER, "name", 5),
1062 ]; 1062 ];
1063 var expectedErrors = [ 1063 var expectedErrors = [
1064 new TestError(8, ScannerErrorCode.UNTERMINATED_STRING_LITERAL, null), 1064 new TestError(8, ScannerErrorCode.UNTERMINATED_STRING_LITERAL, null),
1065 ]; 1065 ];
1066 if (usingFasta) { 1066 if (usingFasta) {
1067 // fasta inserts synthetic closers 1067 // Fasta inserts synthetic closers.
1068 expectedTokens.addAll([ 1068 expectedTokens.addAll([
1069 new SyntheticToken(TokenType.CLOSE_CURLY_BRACKET, 9), 1069 new SyntheticToken(TokenType.CLOSE_CURLY_BRACKET, 9),
1070 new SyntheticStringToken(TokenType.STRING, "'''", 9, 0), 1070 new SyntheticStringToken(TokenType.STRING, "'''", 9, 0),
1071 ]); 1071 ]);
1072 expectedErrors.addAll([ 1072 expectedErrors.addAll([
1073 new TestError(3, ScannerErrorCode.EXPECTED_TOKEN, ['}']), 1073 new TestError(3, ScannerErrorCode.EXPECTED_TOKEN, ['}']),
1074 ]); 1074 ]);
1075 } else { 1075 } else {
1076 expectedTokens.addAll([ 1076 expectedTokens.addAll([
1077 new StringToken(TokenType.STRING, "", 9), 1077 new StringToken(TokenType.STRING, "", 9),
1078 ]); 1078 ]);
1079 } 1079 }
1080 ErrorListener listener = new ErrorListener(); 1080 ErrorListener listener = new ErrorListener();
1081 Token token = scanWithListener("'''\${name", listener); 1081 Token token = scanWithListener("'''\${name", listener);
1082 listener.assertErrors(expectedErrors); 1082 listener.assertErrors(expectedErrors);
1083 _checkTokens(token, expectedTokens); 1083 _checkTokens(token, expectedTokens);
1084 } 1084 }
1085 1085
1086 void test_string_multi_unterminated_interpolation_identifier() { 1086 void test_string_multi_unterminated_interpolation_identifier() {
1087 List<Token> expectedTokens = [ 1087 List<Token> expectedTokens = [
1088 new StringToken(TokenType.STRING, "'''", 0), 1088 new StringToken(TokenType.STRING, "'''", 0),
1089 new StringToken(TokenType.STRING_INTERPOLATION_IDENTIFIER, "\$", 3), 1089 new StringToken(TokenType.STRING_INTERPOLATION_IDENTIFIER, "\$", 3),
1090 new StringToken(TokenType.IDENTIFIER, "name", 4), 1090 new StringToken(TokenType.IDENTIFIER, "name", 4),
1091 ]; 1091 ];
1092 if (usingFasta) { 1092 if (usingFasta) {
1093 // fasta inserts synthetic closers 1093 // Fasta inserts synthetic closers.
1094 expectedTokens.addAll([ 1094 expectedTokens.addAll([
1095 new SyntheticStringToken(TokenType.STRING, "'''", 8, 0), 1095 new SyntheticStringToken(TokenType.STRING, "'''", 8, 0),
1096 ]); 1096 ]);
1097 } else { 1097 } else {
1098 expectedTokens.addAll([ 1098 expectedTokens.addAll([
1099 new StringToken(TokenType.STRING, "", 8), 1099 new StringToken(TokenType.STRING, "", 8),
1100 ]); 1100 ]);
1101 } 1101 }
1102 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 7, 1102 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 7,
1103 "'''\$name", expectedTokens); 1103 "'''\$name", expectedTokens);
1104 } 1104 }
1105 1105
1106 void test_string_raw_multi_double() { 1106 void test_string_raw_multi_double() {
1107 _assertToken(TokenType.STRING, "r\"\"\"line1\nline2\"\"\""); 1107 _assertToken(TokenType.STRING, "r\"\"\"line1\nline2\"\"\"");
1108 } 1108 }
1109 1109
1110 void test_string_raw_multi_single() { 1110 void test_string_raw_multi_single() {
1111 _assertToken(TokenType.STRING, "r'''string'''"); 1111 _assertToken(TokenType.STRING, "r'''string'''");
1112 } 1112 }
1113 1113
1114 void test_string_raw_multi_unterminated() { 1114 void test_string_raw_multi_unterminated() {
1115 String source = "r'''string"; 1115 String source = "r'''string";
1116 List<Token> expectedTokens = []; 1116 List<Token> expectedTokens = [];
1117 if (usingFasta) { 1117 if (usingFasta) {
1118 // fasta inserts synthetic closers 1118 // Fasta inserts synthetic closers.
1119 expectedTokens.addAll([ 1119 expectedTokens.addAll([
1120 new SyntheticStringToken(TokenType.STRING, "r'''string'''", 0, 10), 1120 new SyntheticStringToken(TokenType.STRING, "r'''string'''", 0, 10),
1121 ]); 1121 ]);
1122 } else { 1122 } else {
1123 expectedTokens.addAll([ 1123 expectedTokens.addAll([
1124 new StringToken(TokenType.STRING, "r'''string", 0), 1124 new StringToken(TokenType.STRING, "r'''string", 0),
1125 ]); 1125 ]);
1126 } 1126 }
1127 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 9, 1127 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 9,
1128 source, expectedTokens); 1128 source, expectedTokens);
1129 } 1129 }
1130 1130
1131 void test_string_raw_simple_double() { 1131 void test_string_raw_simple_double() {
1132 _assertToken(TokenType.STRING, "r\"string\""); 1132 _assertToken(TokenType.STRING, "r\"string\"");
1133 } 1133 }
1134 1134
1135 void test_string_raw_simple_single() { 1135 void test_string_raw_simple_single() {
1136 _assertToken(TokenType.STRING, "r'string'"); 1136 _assertToken(TokenType.STRING, "r'string'");
1137 } 1137 }
1138 1138
1139 void test_string_raw_simple_unterminated_eof() { 1139 void test_string_raw_simple_unterminated_eof() {
1140 String source = "r'string"; 1140 String source = "r'string";
1141 List<Token> expectedTokens = []; 1141 List<Token> expectedTokens = [];
1142 if (usingFasta) { 1142 if (usingFasta) {
1143 // fasta inserts synthetic closers 1143 // Fasta inserts synthetic closers.
1144 expectedTokens.addAll([ 1144 expectedTokens.addAll([
1145 new SyntheticStringToken(TokenType.STRING, "r'string'", 0, 8), 1145 new SyntheticStringToken(TokenType.STRING, "r'string'", 0, 8),
1146 ]); 1146 ]);
1147 } else { 1147 } else {
1148 expectedTokens.addAll([ 1148 expectedTokens.addAll([
1149 new StringToken(TokenType.STRING, "r'string", 0), 1149 new StringToken(TokenType.STRING, "r'string", 0),
1150 ]); 1150 ]);
1151 } 1151 }
1152 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 7, 1152 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 7,
1153 source, expectedTokens); 1153 source, expectedTokens);
1154 } 1154 }
1155 1155
1156 void test_string_raw_simple_unterminated_eol() { 1156 void test_string_raw_simple_unterminated_eol() {
1157 String source = "r'string\n"; 1157 String source = "r'string\n";
1158 List<Token> expectedTokens = []; 1158 List<Token> expectedTokens = [];
1159 if (usingFasta) { 1159 if (usingFasta) {
1160 // fasta inserts synthetic closers 1160 // Fasta inserts synthetic closers.
1161 expectedTokens.addAll([ 1161 expectedTokens.addAll([
1162 new SyntheticStringToken(TokenType.STRING, "r'string'", 0, 8), 1162 new SyntheticStringToken(TokenType.STRING, "r'string'", 0, 8),
1163 ]); 1163 ]);
1164 } else { 1164 } else {
1165 expectedTokens.addAll([ 1165 expectedTokens.addAll([
1166 new StringToken(TokenType.STRING, "r'string", 0), 1166 new StringToken(TokenType.STRING, "r'string", 0),
1167 ]); 1167 ]);
1168 } 1168 }
1169 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 1169 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL,
1170 usingFasta ? 7 : 8, source, expectedTokens); 1170 usingFasta ? 7 : 8, source, expectedTokens);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 } 1291 }
1292 1292
1293 void test_string_simple_single() { 1293 void test_string_simple_single() {
1294 _assertToken(TokenType.STRING, "'string'"); 1294 _assertToken(TokenType.STRING, "'string'");
1295 } 1295 }
1296 1296
1297 void test_string_simple_unterminated_eof() { 1297 void test_string_simple_unterminated_eof() {
1298 String source = "'string"; 1298 String source = "'string";
1299 List<Token> expectedTokens = []; 1299 List<Token> expectedTokens = [];
1300 if (usingFasta) { 1300 if (usingFasta) {
1301 // fasta inserts synthetic closers 1301 // Fasta inserts synthetic closers.
1302 expectedTokens.addAll([ 1302 expectedTokens.addAll([
1303 new SyntheticStringToken(TokenType.STRING, "'string'", 0, 7), 1303 new SyntheticStringToken(TokenType.STRING, "'string'", 0, 7),
1304 ]); 1304 ]);
1305 } else { 1305 } else {
1306 expectedTokens.addAll([ 1306 expectedTokens.addAll([
1307 new StringToken(TokenType.STRING, "'string", 0), 1307 new StringToken(TokenType.STRING, "'string", 0),
1308 ]); 1308 ]);
1309 } 1309 }
1310 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 6, 1310 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 6,
1311 source, expectedTokens); 1311 source, expectedTokens);
1312 } 1312 }
1313 1313
1314 void test_string_simple_unterminated_eol() { 1314 void test_string_simple_unterminated_eol() {
1315 String source = "'string\r"; 1315 String source = "'string\r";
1316 List<Token> expectedTokens = []; 1316 List<Token> expectedTokens = [];
1317 if (usingFasta) { 1317 if (usingFasta) {
1318 // fasta inserts synthetic closers 1318 // Fasta inserts synthetic closers.
1319 expectedTokens.addAll([ 1319 expectedTokens.addAll([
1320 new SyntheticStringToken(TokenType.STRING, "'string'", 0, 7), 1320 new SyntheticStringToken(TokenType.STRING, "'string'", 0, 7),
1321 ]); 1321 ]);
1322 } else { 1322 } else {
1323 expectedTokens.addAll([ 1323 expectedTokens.addAll([
1324 new StringToken(TokenType.STRING, "'string", 0), 1324 new StringToken(TokenType.STRING, "'string", 0),
1325 ]); 1325 ]);
1326 } 1326 }
1327 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 1327 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL,
1328 usingFasta ? 6 : 7, source, expectedTokens); 1328 usingFasta ? 6 : 7, source, expectedTokens);
1329 } 1329 }
1330 1330
1331 void test_string_simple_unterminated_interpolation_block() { 1331 void test_string_simple_unterminated_interpolation_block() {
1332 List<Token> expectedTokens = [ 1332 List<Token> expectedTokens = [
1333 new StringToken(TokenType.STRING, "'", 0), 1333 new StringToken(TokenType.STRING, "'", 0),
1334 new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 1), 1334 new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 1),
1335 new StringToken(TokenType.IDENTIFIER, "name", 3), 1335 new StringToken(TokenType.IDENTIFIER, "name", 3),
1336 ]; 1336 ];
1337 List<TestError> expectedErrors = [ 1337 List<TestError> expectedErrors = [
1338 new TestError(6, ScannerErrorCode.UNTERMINATED_STRING_LITERAL, null), 1338 new TestError(6, ScannerErrorCode.UNTERMINATED_STRING_LITERAL, null),
1339 ]; 1339 ];
1340 if (usingFasta) { 1340 if (usingFasta) {
1341 // fasta inserts synthetic closers 1341 // Fasta inserts synthetic closers.
1342 expectedTokens.addAll([ 1342 expectedTokens.addAll([
1343 new SyntheticToken(TokenType.CLOSE_CURLY_BRACKET, 7), 1343 new SyntheticToken(TokenType.CLOSE_CURLY_BRACKET, 7),
1344 new SyntheticStringToken(TokenType.STRING, "'", 7, 0), 1344 new SyntheticStringToken(TokenType.STRING, "'", 7, 0),
1345 ]); 1345 ]);
1346 expectedErrors.addAll([ 1346 expectedErrors.addAll([
1347 new TestError(1, ScannerErrorCode.EXPECTED_TOKEN, ['}']), 1347 new TestError(1, ScannerErrorCode.EXPECTED_TOKEN, ['}']),
1348 ]); 1348 ]);
1349 } else { 1349 } else {
1350 expectedTokens.addAll([ 1350 expectedTokens.addAll([
1351 new StringToken(TokenType.STRING, "", 7), 1351 new StringToken(TokenType.STRING, "", 7),
1352 ]); 1352 ]);
1353 } 1353 }
1354 ErrorListener listener = new ErrorListener(); 1354 ErrorListener listener = new ErrorListener();
1355 Token token = scanWithListener("'\${name", listener); 1355 Token token = scanWithListener("'\${name", listener);
1356 listener.assertErrors(expectedErrors); 1356 listener.assertErrors(expectedErrors);
1357 _checkTokens(token, expectedTokens); 1357 _checkTokens(token, expectedTokens);
1358 } 1358 }
1359 1359
1360 void test_string_simple_unterminated_interpolation_identifier() { 1360 void test_string_simple_unterminated_interpolation_identifier() {
1361 List<Token> expectedTokens = [ 1361 List<Token> expectedTokens = [
1362 new StringToken(TokenType.STRING, "'", 0), 1362 new StringToken(TokenType.STRING, "'", 0),
1363 new StringToken(TokenType.STRING_INTERPOLATION_IDENTIFIER, "\$", 1), 1363 new StringToken(TokenType.STRING_INTERPOLATION_IDENTIFIER, "\$", 1),
1364 new StringToken(TokenType.IDENTIFIER, "name", 2), 1364 new StringToken(TokenType.IDENTIFIER, "name", 2),
1365 ]; 1365 ];
1366 if (usingFasta) { 1366 if (usingFasta) {
1367 // fasta inserts synthetic closers 1367 // Fasta inserts synthetic closers.
1368 expectedTokens.addAll([ 1368 expectedTokens.addAll([
1369 new SyntheticStringToken(TokenType.STRING, "'", 6, 0), 1369 new SyntheticStringToken(TokenType.STRING, "'", 6, 0),
1370 ]); 1370 ]);
1371 } else { 1371 } else {
1372 expectedTokens.addAll([ 1372 expectedTokens.addAll([
1373 new StringToken(TokenType.STRING, "", 6), 1373 new StringToken(TokenType.STRING, "", 6),
1374 ]); 1374 ]);
1375 } 1375 }
1376 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 5, 1376 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 5,
1377 "'\$name", expectedTokens); 1377 "'\$name", expectedTokens);
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
1719 _TestScanner(CharacterReader reader, [this.listener]) : super.create(reader); 1719 _TestScanner(CharacterReader reader, [this.listener]) : super.create(reader);
1720 1720
1721 @override 1721 @override
1722 void reportError( 1722 void reportError(
1723 ScannerErrorCode errorCode, int offset, List<Object> arguments) { 1723 ScannerErrorCode errorCode, int offset, List<Object> arguments) {
1724 if (listener != null) { 1724 if (listener != null) {
1725 listener.errors.add(new TestError(offset, errorCode, arguments)); 1725 listener.errors.add(new TestError(offset, errorCode, arguments));
1726 } 1726 }
1727 } 1727 }
1728 } 1728 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/scanner/recover.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698