@@ -11174,6 +11174,32 @@ TEST_F(FormatTest, BreakBeforeTemplateClose) {
11174
11174
"}\n",
11175
11175
Style);
11176
11176
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
+
11177
11203
// now test that it handles the cases when the column limit forces wrapping
11178
11204
Style.ColumnLimit = 40;
11179
11205
// when the column limit allows it, the template should be combined back into
@@ -11226,6 +11252,44 @@ TEST_F(FormatTest, BreakBeforeTemplateClose) {
11226
11252
"template <typename Fooooooooooooooooooooooooooo>\n"
11227
11253
"void foo() {}",
11228
11254
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);
11229
11293
}
11230
11294
11231
11295
TEST_F(FormatTest, WrapsTemplateParameters) {
0 commit comments