diff options
author | sstwcw <su3e8a96kzlver@posteo.net> | 2023-09-15 12:36:09 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-15 12:36:09 +0000 |
commit | ae90f689a59fa0ac0b29ca49743757842ba32bf4 (patch) | |
tree | 07a88202f77faa3e87090ecc2d40418fb7824bf9 /clang/unittests/Format/FormatTestJS.cpp | |
parent | 0069004856dd216ffed48a860a38b986dfe3e871 (diff) | |
download | llvm-ae90f689a59fa0ac0b29ca49743757842ba32bf4.zip llvm-ae90f689a59fa0ac0b29ca49743757842ba32bf4.tar.gz llvm-ae90f689a59fa0ac0b29ca49743757842ba32bf4.tar.bz2 |
[clang-format] Disable string breaking in JS for now (#66372)
See the discussion
[here](https://github.com/llvm/llvm-project/pull/66168#issuecomment-1719038797).
The functionality is not mature enough.
Diffstat (limited to 'clang/unittests/Format/FormatTestJS.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTestJS.cpp | 114 |
1 files changed, 2 insertions, 112 deletions
diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 51543d0..23b010d 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -1506,121 +1506,11 @@ TEST_F(FormatTestJS, StringLiteralConcatenation) { verifyFormat("var literal = 'hello ' +\n" " 'world';"); - // Long strings should be broken. + // String breaking is disabled for now. verifyFormat("var literal =\n" - " 'xxxxxxxx ' +\n" - " 'xxxxxxxx';", + " 'xxxxxxxx xxxxxxxx';", "var literal = 'xxxxxxxx xxxxxxxx';", getGoogleJSStyleWithColumns(17)); - verifyFormat("var literal =\n" - " 'xxxxxxxx ' +\n" - " 'xxxxxxxx';", - "var literal = 'xxxxxxxx xxxxxxxx';", - getGoogleJSStyleWithColumns(18)); - verifyFormat("var literal =\n" - " 'xxxxxxxx' +\n" - " ' xxxxxxxx';", - "var literal = 'xxxxxxxx xxxxxxxx';", - getGoogleJSStyleWithColumns(16)); - // The quotes should be correct. - for (char OriginalQuote : {'\'', '"'}) { - auto VerifyQuotes = [=](FormatStyle::JavaScriptQuoteStyle StyleQuote, - char TargetQuote) { - auto Style = getGoogleJSStyleWithColumns(17); - Style.JavaScriptQuotes = StyleQuote; - std::string Target{"var literal =\n" - " \"xxxxxxxx \" +\n" - " \"xxxxxxxx\";"}; - std::string Original{"var literal = \"xxxxxxxx xxxxxxxx\";"}; - std::replace(Target.begin(), Target.end(), '"', TargetQuote); - std::replace(Original.begin(), Original.end(), '"', OriginalQuote); - verifyFormat(Target, Original, Style); - }; - VerifyQuotes(FormatStyle::JSQS_Leave, OriginalQuote); - VerifyQuotes(FormatStyle::JSQS_Single, '\''); - VerifyQuotes(FormatStyle::JSQS_Double, '"'); - } - // Parentheses should be added when necessary. - verifyFormat("var literal =\n" - " ('xxxxxxxx ' +\n" - " 'xxxxxx')[0];", - "var literal = 'xxxxxxxx xxxxxx'[0];", - getGoogleJSStyleWithColumns(18)); - auto Style = getGoogleJSStyleWithColumns(20); - Style.SpacesInParens = FormatStyle::SIPO_Custom; - Style.SpacesInParensOptions.Other = true; - verifyFormat("var literal =\n" - " ( 'xxxxxxxx ' +\n" - " 'xxxxxx' )[0];", - "var literal = 'xxxxxxxx xxxxxx'[0];", Style); - // FIXME: When the part before the string literal is shorter than the - // continuation indentation, and the option AlignAfterOpenBracket is set to - // AlwaysBreak which is the default for the Google style, the unbroken string - // does not get to a new line while the broken string does due to the added - // parentheses. The formatter does not do it in one pass. - EXPECT_EQ( - "x = ('xxxxxxxx ' +\n" - " 'xxxxxx')[0];", - format("x = 'xxxxxxxx xxxxxx'[0];", getGoogleJSStyleWithColumns(18))); - verifyFormat("x =\n" - " ('xxxxxxxx ' +\n" - " 'xxxxxx')[0];", - getGoogleJSStyleWithColumns(18)); - // Breaking of template strings and regular expressions is not implemented. - verifyFormat("var literal =\n" - " `xxxxxxxx xxxxxxxx`;", - getGoogleJSStyleWithColumns(18)); - verifyFormat("var literal =\n" - " /xxxxxxxx xxxxxxxx/;", - getGoogleJSStyleWithColumns(18)); - // There can be breaks in the code inside a template string. - verifyFormat("var literal = `xxxxxx ${\n" - " xxxxxxxxxx} xxxxxx`;", - "var literal = `xxxxxx ${xxxxxxxxxx} xxxxxx`;", - getGoogleJSStyleWithColumns(14)); - verifyFormat("var literal = `xxxxxx ${\n" - " xxxxxxxxxx} xxxxxx`;", - "var literal = `xxxxxx ${xxxxxxxxxx} xxxxxx`;", - getGoogleJSStyleWithColumns(15)); - // Identifiers inside the code inside a template string should not be broken - // even if the column limit is exceeded. This following behavior is not - // optimal. The part after the closing brace which exceeds the column limit - // can be put on a new line. Change this test when it is implemented. - verifyFormat("var literal = `xxxxxx ${\n" - " xxxxxxxxxxxxxxxxxxxxxx} xxxxxx`;", - "var literal = `xxxxxx ${xxxxxxxxxxxxxxxxxxxxxx} xxxxxx`;", - getGoogleJSStyleWithColumns(14)); - verifyFormat("var literal = `xxxxxx ${\n" - " xxxxxxxxxxxxxxxxxxxxxx +\n" - " xxxxxxxxxxxxxxxxxxxxxx} xxxxxx`;", - "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)); - verifyFormat("export 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) { |