Skip to content

Commit 3927d41

Browse files
committed
more tests
1 parent 212e444 commit 3927d41

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

clang/unittests/Format/FormatTest.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11174,6 +11174,32 @@ TEST_F(FormatTest, BreakBeforeTemplateClose) {
1117411174
"}\n",
1117511175
Style);
1117611176

11177+
// test lambda goes to next line:
11178+
verifyFormat("void foo() {\n"
11179+
" auto lambda = []<\n"
11180+
" typename T\n"
11181+
" >(T t) {\n"
11182+
" };\n"
11183+
"}\n",
11184+
"void foo() {\n"
11185+
" auto lambda = []<\n"
11186+
" typename T>(T t){\n"
11187+
" };\n"
11188+
"}\n",
11189+
Style);
11190+
11191+
// test template usage goes to next line:
11192+
verifyFormat("void foo() {\n"
11193+
" myFunc<\n"
11194+
" T\n"
11195+
" >();\n"
11196+
"}\n",
11197+
"void foo() {\n"
11198+
" myFunc<\n"
11199+
" T>();\n"
11200+
"}\n",
11201+
Style);
11202+
1117711203
// now test that it handles the cases when the column limit forces wrapping
1117811204
Style.ColumnLimit = 40;
1117911205
// when the column limit allows it, the template should be combined back into
@@ -11226,6 +11252,44 @@ TEST_F(FormatTest, BreakBeforeTemplateClose) {
1122611252
"template <typename Fooooooooooooooooooooooooooo>\n"
1122711253
"void foo() {}",
1122811254
Style);
11255+
// test lambda goes to next line if the type is looong:
11256+
verifyFormat(
11257+
"void foo() {\n"
11258+
// in this case, breaking "typename Looong" onto the next line would
11259+
// actually exceed the column limit by even more. same goes for "auto
11260+
// lambda = []<\n" because then the continuation indent would be all the
11261+
// way to the "[". therefore, this is correct for the column limited case:
11262+
" auto lambda =\n"
11263+
" []<typename Loooooooooooooooooooooooooooooooooong\n"
11264+
" >(T t) {};\n"
11265+
// for completeness, let's also make sure it's willing to break if and
11266+
// when doing so is helpful. if we put something long into the square
11267+
// brackets, now it's worth it:
11268+
" auto lambda =\n"
11269+
" [looooooooooooooong]<\n"
11270+
" typename Loooooooooooooooooooooooooooooooooong\n"
11271+
" >(T t) {};\n"
11272+
"}\n",
11273+
Style);
11274+
// test that if the type is NOT long, it pulls it back into one line:
11275+
verifyFormat("void foo() {\n"
11276+
" auto lambda = []<typename T>(T t) {};\n"
11277+
"}\n",
11278+
"void foo() {\n"
11279+
" auto lambda = []<\n"
11280+
" typename T\n"
11281+
" >(T t) {};\n"
11282+
"}\n",
11283+
Style);
11284+
11285+
// test template usage goes to next line only if the type is looong:
11286+
verifyFormat("void foo() { myFunc<T>(); }\n", Style);
11287+
verifyFormat("void foo() {\n"
11288+
" myFunc<\n"
11289+
" Loooooooooooooooooooooooooooooooooooooooong\n"
11290+
" >();\n"
11291+
"}\n",
11292+
Style);
1122911293
}
1123011294

1123111295
TEST_F(FormatTest, WrapsTemplateParameters) {

0 commit comments

Comments
 (0)