8233116: Escape Sequences For Line Continuation and White Space (Preview)

Reviewed-by: vromero, jlahoda, bchristi, mcimadamore
This commit is contained in:
Jim Laskey 2019-12-03 08:35:21 -04:00
parent 7afaaf1229
commit 234f326d79
6 changed files with 249 additions and 138 deletions

View file

@ -46,7 +46,10 @@ public class TextBlockAPI {
test2();
test3();
test4();
}
test5();
test6();
test7();
}
/*
* Check that correct/incorrect syntax is properly detected
@ -72,35 +75,35 @@ public class TextBlockAPI {
* Check that use of \u0022 is properly detected
*/
static void test2() {
compPass("public class UnicodeDelimiterTest {\n" +
" public static void main(String... args) {\n" +
" String xxx = \\u0022\\u0022\\u0022\nabc\n\\u0022\\u0022\\u0022;\n" +
" }\n" +
"}\n");
compPass("public class UnicodeDelimiterTest {",
" public static void main(String... args) {",
" String xxx = \\u0022\\u0022\\u0022\nabc\n\\u0022\\u0022\\u0022;",
" }",
"}");
}
/*
* Check edge cases of text blocks as last token
*/
static void test3() {
compFail("public class EndTest {\n" +
" public static void main(String... args) {\n" +
" String xxx = \"\"\"\nabc\"\"\"");
compFail("public class TwoQuoteClose {\n" +
" public static void main(String... args) {\n" +
" String xxx = \"\"\"\nabc\"\"");
compFail("public class OneQuoteClose {\n" +
" public static void main(String... args) {\n" +
" String xxx = \"\"\"\nabc\"");
compFail("public class NoClose {\n" +
" public static void main(String... args) {\n" +
" String xxx = \"\"\"\nabc");
compFail("public class ZeroTerminator {\n" +
" public static void main(String... args) {\n" +
" String xxx = \"\"\"\nabc\\u0000");
compFail("public class NonBreakingSpace {\n" +
" public static void main(String... args) {\n" +
" String xxx = \"\"\"\nabc\\u001A");
compFail("public class EndTest {",
" public static void main(String... args) {",
" String xxx = \"\"\"\nabc\"\"\"");
compFail("public class TwoQuoteClose {",
" public static void main(String... args) {",
" String xxx = \"\"\"\nabc\"\"");
compFail("public class OneQuoteClose {",
" public static void main(String... args) {",
" String xxx = \"\"\"\nabc\"");
compFail("public class NoClose {",
" public static void main(String... args) {",
" String xxx = \"\"\"\nabc");
compFail("public class ZeroTerminator {",
" public static void main(String... args) {",
" String xxx = \"\"\"\nabc\\u0000");
compFail("public class NonBreakingSpace {",
" public static void main(String... args) {",
" String xxx = \"\"\"\nabc\\u001A");
}
/*
@ -137,6 +140,61 @@ public class TextBlockAPI {
}
}
/*
* Check escape space
*/
static void test5() {
compPass("public class EscapeSChar {",
" public static void main(String... args) {",
" char xxx = '\\s';",
" }",
"}");
compPass("public class EscapeSString {",
" public static void main(String... args) {",
" String xxx = \"\\s\";",
" }",
"}");
compPass("public class EscapeSTextBlock {",
" public static void main(String... args) {",
" String xxx = \"\"\"",
" \\s",
" \"\"\";",
" }",
"}");
}
/*
* Check escape line terminator
*/
static void test6() {
String[] terminators = new String[] { "\n", "\r\n", "\r" };
for (String terminator : terminators) {
compPass("public class EscapeLineTerminator {",
" public static void main(String... args) {",
" String xxx = \"\"\"",
" \\" + terminator +
" \"\"\";",
" }",
"}");
}
}
/*
* Check incorrect escape line terminator cases
*/
static void test7() {
compFail("public class EscapeLineTerminatorChar {",
" public static void main(String... args) {",
" char xxx = '\\\n';",
" }",
"}");
compFail("public class EscapeLineTerminatorString {",
" public static void main(String... args) {",
" String xxx = \"\\\n\";",
" }",
"}");
}
/*
* Test source for successful compile.
*/
@ -154,6 +212,10 @@ public class TextBlockAPI {
}
}
static void compPass(String... lines) {
compPass(String.join("\n", lines) + "\n");
}
/*
* Test source for unsuccessful compile and specific error.
*/
@ -170,4 +232,8 @@ public class TextBlockAPI {
throw new RuntimeException("No error detected");
}
}
static void compFail(String... lines) {
compFail(String.join("\n", lines) + "\n");
}
}