summaryrefslogtreecommitdiffstats
path: root/unittests/Format/FormatTestJS.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'unittests/Format/FormatTestJS.cpp')
-rw-r--r--unittests/Format/FormatTestJS.cpp30
1 files changed, 23 insertions, 7 deletions
diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp
index 15d62eb..e6c12f4 100644
--- a/unittests/Format/FormatTestJS.cpp
+++ b/unittests/Format/FormatTestJS.cpp
@@ -579,6 +579,7 @@ TEST_F(FormatTestJS, RegexLiteralClassification) {
verifyFormat("var x = a && /abc/.test(y);");
verifyFormat("var x = a || /abc/.test(y);");
verifyFormat("var x = a + /abc/.search(y);");
+ verifyFormat("/abc/.search(y);");
verifyFormat("var regexs = {/abc/, /abc/};");
verifyFormat("return /abc/;");
@@ -624,10 +625,23 @@ TEST_F(FormatTestJS, RegexLiteralSpecialCharacters) {
verifyFormat("var regex = /\a\\//g;");
verifyFormat("var regex = /a\\//;\n"
"var x = 0;");
+ EXPECT_EQ("var regex = /'/g;", format("var regex = /'/g ;"));
+ EXPECT_EQ("var regex = /'/g; //'", format("var regex = /'/g ; //'"));
EXPECT_EQ("var regex = /\\/*/;\n"
"var x = 0;",
format("var regex = /\\/*/;\n"
"var x=0;"));
+ EXPECT_EQ("var x = /a\\//;", format("var x = /a\\// \n;"));
+ verifyFormat("var regex = /\"/;", getGoogleJSStyleWithColumns(16));
+ verifyFormat("var regex =\n"
+ " /\"/;",
+ getGoogleJSStyleWithColumns(15));
+ verifyFormat("var regex = //\n"
+ " /a/;");
+ verifyFormat("var regexs = [\n"
+ " /d/, //\n"
+ " /aa/, //\n"
+ "];");
}
TEST_F(FormatTestJS, RegexLiteralModifiers) {
@@ -789,15 +803,11 @@ TEST_F(FormatTestJS, TemplateStrings) {
" ${ name }\n"
" !`;"));
- // FIXME: +1 / -1 offsets are to work around clang-format miscalculating
- // widths for unknown tokens that are not whitespace (e.g. '`'). Remove when
- // the code is corrected.
-
verifyFormat("var x =\n"
" `hello ${world}` >= some();",
getGoogleJSStyleWithColumns(34)); // Barely doesn't fit.
verifyFormat("var x = `hello ${world}` >= some();",
- getGoogleJSStyleWithColumns(35 + 1)); // Barely fits.
+ getGoogleJSStyleWithColumns(35)); // Barely fits.
EXPECT_EQ("var x = `hello\n"
" ${world}` >=\n"
" some();",
@@ -812,10 +822,14 @@ TEST_F(FormatTestJS, TemplateStrings) {
" ${world}` >= some();",
getGoogleJSStyleWithColumns(22))); // Barely fits.
- verifyFormat("var x =\n `h`;", getGoogleJSStyleWithColumns(13 - 1));
+ verifyFormat("var x =\n"
+ " `h`;",
+ getGoogleJSStyleWithColumns(11));
EXPECT_EQ(
"var x =\n `multi\n line`;",
- format("var x = `multi\n line`;", getGoogleJSStyleWithColumns(14 - 1)));
+ format("var x = `multi\n line`;", getGoogleJSStyleWithColumns(13)));
+ verifyFormat("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
+ " `aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa`);");
// Make sure template strings get a proper ColumnWidth assigned, even if they
// are first token in line.
@@ -869,6 +883,8 @@ TEST_F(FormatTestJS, TypeArguments) {
verifyFormat("class C extends D<E> implements F<G>, H<I> {}");
verifyFormat("function f(a: List<any> = null) {}");
verifyFormat("function f(): List<any> {}");
+ verifyFormat("function aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa():\n"
+ " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb {}");
}
TEST_F(FormatTestJS, OptionalTypes) {
OpenPOWER on IntegriCloud