aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Format/FormatTestJS.cpp
diff options
context:
space:
mode:
authorsstwcw <134215812+sstwcw@users.noreply.github.com>2023-09-13 15:04:04 +0000
committerGitHub <noreply@github.com>2023-09-13 17:04:04 +0200
commit5db201fb75e6d1e2777bff8bc8df012174e905f3 (patch)
tree2ef9e067fd1f8e6961af2feadc71cd0a1629aa32 /clang/unittests/Format/FormatTestJS.cpp
parentd65885ae63da517eacbb4a3b25ca6443f0f812f8 (diff)
downloadllvm-5db201fb75e6d1e2777bff8bc8df012174e905f3.zip
llvm-5db201fb75e6d1e2777bff8bc8df012174e905f3.tar.gz
llvm-5db201fb75e6d1e2777bff8bc8df012174e905f3.tar.bz2
[clang-format] Stop breaking unbreakable strings in JS (#66168)
Dictionary literal keys and strings in TypeScript type declarations can not be broken. The problem was pointed out by @alexfh and @e-kud here: https://reviews.llvm.org/D154093#4644512
Diffstat (limited to 'clang/unittests/Format/FormatTestJS.cpp')
-rw-r--r--clang/unittests/Format/FormatTestJS.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp
index bc4c7ff..30932656 100644
--- a/clang/unittests/Format/FormatTestJS.cpp
+++ b/clang/unittests/Format/FormatTestJS.cpp
@@ -1596,6 +1596,28 @@ TEST_F(FormatTestJS, StringLiteralConcatenation) {
"var literal = `xxxxxx ${xxxxxxxxxxxxxxxxxxxxxx + "
"xxxxxxxxxxxxxxxxxxxxxx} xxxxxx`;",
getGoogleJSStyleWithColumns(14));
+
+ // Strings in a TypeScript type declaration can't be broken.
+ verifyFormat("type x =\n"
+ " 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';",
+ getGoogleJSStyleWithColumns(20));
+ verifyFormat("/* type */ type x =\n"
+ " 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';",
+ getGoogleJSStyleWithColumns(20));
+ // Dictionary keys can't be broken. Values can be broken.
+ verifyFormat("var w = {\n"
+ " 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx':\n"
+ " 'xxxxxxxxxx' +\n"
+ " 'xxxxxxxxxx' +\n"
+ " 'xxxxxxxxxx' +\n"
+ " 'xxxxxxxxxx' +\n"
+ " 'xxx',\n"
+ "};",
+ "var w = {\n"
+ " 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx':\n"
+ " 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',\n"
+ "};",
+ getGoogleJSStyleWithColumns(20));
}
TEST_F(FormatTestJS, RegexLiteralClassification) {