Java: Add tests for text blocks

This commit is contained in:
Marcono1234
2021-09-07 00:02:12 +02:00
parent 924b7320bc
commit e3fed55945
5 changed files with 117 additions and 37 deletions

View File

@@ -32,10 +32,64 @@ public class StringLiterals {
\u0022\u0061\u0022, // "a"
};
String[] textBlocks = {
// trailing whitespaces after """ (will be ignored)
"""
test "text" and escaped \u0022
""",
// Indentation tests
"""
indented
""",
"""
no indentation last line
""", // Line is blank, therefore not indented
"""
indentation last line
\s""", // Line is not blank therefore indented
"""
not-indented
""",
"""
indented
""",
"""
not-indented
""",
"""
spaces (only single space is trimmed)
tab
""",
"""
end on same line""",
"""
trailing spaces ignored:
not ignored: \s
""",
"""
3 quotes:""\"""",
"""
line \
continuation \
""",
"""
Explicit line breaks:\n
\r\n
\r
""",
// Using Unicode escapes (which are handled during pre-processing)
// Currently not detected by StringLiteral.isTextBlock()
\uuu0022"\u0022
test
\u0022\uu0022",
};
// The concatenation (`+`) is not a string literal
String[] stringConcatenation = {
// CodeQL erroneously reports this as one literal, see https://github.com/github/codeql/issues/5469
"hello" + "world",
"""
hello""" + "world",
null + "a",
"a" + null,
"a" + 1,