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

Unified Diff: pkg/front_end/test/scanner_test.dart

Issue 2912693002: improve fasta unterminated string recovery (Closed)
Patch Set: Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: pkg/front_end/test/scanner_test.dart
diff --git a/pkg/front_end/test/scanner_test.dart b/pkg/front_end/test/scanner_test.dart
index ca8d75e126ca7ac18a1001683c117d87518b9167..886695bfcfe570a3e4beae144fbe45099afc5e2b 100644
--- a/pkg/front_end/test/scanner_test.dart
+++ b/pkg/front_end/test/scanner_test.dart
@@ -439,6 +439,7 @@ abstract class ScannerTestBase {
// fasta inserts synthetic closers
expectedTokens.addAll([
new SyntheticToken(TokenType.CLOSE_CURLY_BRACKET, 10),
+ new SyntheticStringToken(TokenType.STRING, '"', 10, 0),
]);
} else {
expectedTokens.addAll([
@@ -992,8 +993,17 @@ abstract class ScannerTestBase {
}
void test_string_multi_unterminated() {
+ List<Token> expectedTokens = [
+ new StringToken(TokenType.STRING, "'''string", 0),
+ ];
+ if (usingFasta) {
+ // fasta inserts synthetic closers
+ expectedTokens.addAll([
+ new SyntheticStringToken(TokenType.STRING, "'''", 9, 0),
+ ]);
+ }
_assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 8,
- "'''string", [new StringToken(TokenType.STRING, "'''string", 0)]);
+ "'''string", expectedTokens);
}
void test_string_multi_unterminated_interpolation_block() {
@@ -1026,8 +1036,17 @@ abstract class ScannerTestBase {
void test_string_raw_multi_unterminated() {
String source = "r'''string";
+ List<Token> expectedTokens = [
+ new StringToken(TokenType.STRING, source, 0),
+ ];
+ if (usingFasta) {
+ // fasta inserts synthetic closers
+ expectedTokens.addAll([
+ new SyntheticStringToken(TokenType.STRING, "'''", 10, 0),
+ ]);
+ }
_assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 9,
- source, [new StringToken(TokenType.STRING, source, 0)]);
+ source, expectedTokens);
}
void test_string_raw_simple_double() {
@@ -1040,14 +1059,32 @@ abstract class ScannerTestBase {
void test_string_raw_simple_unterminated_eof() {
String source = "r'string";
+ List<Token> expectedTokens = [
+ new StringToken(TokenType.STRING, source, 0),
+ ];
+ if (usingFasta) {
+ // fasta inserts synthetic closers
+ expectedTokens.addAll([
+ new SyntheticStringToken(TokenType.STRING, "'", 8, 0),
+ ]);
+ }
_assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 7,
- source, [new StringToken(TokenType.STRING, source, 0)]);
+ source, expectedTokens);
}
void test_string_raw_simple_unterminated_eol() {
- String source = "r'string";
- _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 8,
- "$source\n", [new StringToken(TokenType.STRING, source, 0)]);
+ String source = "r'string\n";
+ List<Token> expectedTokens = [
+ new StringToken(TokenType.STRING, "r'string", 0),
+ ];
+ if (usingFasta) {
+ // fasta inserts synthetic closers
+ expectedTokens.addAll([
+ new SyntheticStringToken(TokenType.STRING, "'", 8, 0),
+ ]);
+ }
+ _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL,
+ usingFasta ? 7 : 8, source, expectedTokens);
}
void test_string_simple_double() {
@@ -1143,14 +1180,32 @@ abstract class ScannerTestBase {
void test_string_simple_unterminated_eof() {
String source = "'string";
+ List<Token> expectedTokens = [
+ new StringToken(TokenType.STRING, source, 0),
+ ];
+ if (usingFasta) {
+ // fasta inserts synthetic closers
+ expectedTokens.addAll([
+ new SyntheticStringToken(TokenType.STRING, "'", 7, 0),
+ ]);
+ }
_assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 6,
- source, [new StringToken(TokenType.STRING, source, 0)]);
+ source, expectedTokens);
}
void test_string_simple_unterminated_eol() {
- String source = "'string";
- _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 7,
- "$source\r", [new StringToken(TokenType.STRING, source, 0)]);
+ String source = "'string\r";
+ List<Token> expectedTokens = [
+ new StringToken(TokenType.STRING, "'string", 0),
+ ];
+ if (usingFasta) {
+ // fasta inserts synthetic closers
+ expectedTokens.addAll([
+ new SyntheticStringToken(TokenType.STRING, "'", 7, 0),
+ ]);
+ }
+ _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL,
+ usingFasta ? 6 : 7, source, expectedTokens);
}
void test_string_simple_unterminated_interpolation_block() {
« 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