Skip to content

Commit e1eaba9

Browse files
authored
address comments
1 parent a768adb commit e1eaba9

File tree

1 file changed

+19
-86
lines changed

1 file changed

+19
-86
lines changed

clang/unittests/Format/FormatTest.cpp

Lines changed: 19 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -11229,19 +11229,6 @@ TEST_F(FormatTest, BreakBeforeTemplateCloser) {
1122911229
// Begin with tests covering the case where there is no constraint on the
1123011230
// column limit.
1123111231
Style.ColumnLimit = 0;
11232-
// When BreakBeforeTemplateCloser is turned off, the line break that it adds
11233-
// shall be removed:
11234-
verifyFormat("template <\n"
11235-
" typename Foo,\n"
11236-
" typename Bar>\n"
11237-
"void foo() {}",
11238-
"template <\n"
11239-
" typename Foo,\n"
11240-
" typename Bar\n"
11241-
">\n"
11242-
"void foo() {}",
11243-
Style);
11244-
1124511232
Style.BreakBeforeTemplateCloser = true;
1124611233
// BreakBeforeTemplateCloser should NOT force template declarations onto
1124711234
// multiple lines.
@@ -11258,16 +11245,6 @@ TEST_F(FormatTest, BreakBeforeTemplateCloser) {
1125811245
">\n"
1125911246
"void foo() {}",
1126011247
Style);
11261-
verifyNoChange("template <\n"
11262-
" typename Foo,\n"
11263-
" typename Bar\n"
11264-
">\n"
11265-
"void foo() {}",
11266-
Style);
11267-
verifyNoChange("template <typename Foo,\n"
11268-
" typename Bar>\n"
11269-
"void foo() {}",
11270-
Style);
1127111248
// It should add a line break before > if not already present:
1127211249
verifyFormat("template <\n"
1127311250
" typename Foo\n"
@@ -11311,12 +11288,12 @@ TEST_F(FormatTest, BreakBeforeTemplateCloser) {
1131111288
" T0,\n"
1131211289
" T1\n"
1131311290
" >\n"
11314-
">;\n",
11291+
">;",
1131511292
"using type = std::remove_cv_t<\n"
1131611293
" add_common_cv_reference<\n"
1131711294
" std::common_type_t<std::decay_t<T0>, std::decay_t<T1>>,\n"
1131811295
" T0,\n"
11319-
" T1>>;\n",
11296+
" T1>>;",
1132011297
Style);
1132111298

1132211299
// Test lambda goes to next line:
@@ -11361,12 +11338,6 @@ TEST_F(FormatTest, BreakBeforeTemplateCloser) {
1136111338
"}",
1136211339
Style);
1136311340

11364-
// Note that this is the same line (no \n):
11365-
verifyFormat("void foo() {\n"
11366-
" auto lambda = []<typename T>(T t) {};\n"
11367-
"}",
11368-
Style);
11369-
1137011341
// Test template usage goes to next line too:
1137111342
verifyFormat("void foo() {\n"
1137211343
" myFunc<\n"
@@ -11381,29 +11352,11 @@ TEST_F(FormatTest, BreakBeforeTemplateCloser) {
1138111352

1138211353
// Now test that it handles the cases when the column limit forces wrapping.
1138311354
Style.ColumnLimit = 40;
11384-
// When the column limit allows it, the template should be combined back into
11385-
// one line:
11386-
verifyFormat("template <typename Foo, typename Bar>\n"
11387-
"void foo() {}",
11388-
"template <\n"
11389-
" typename Foo,\n"
11390-
" typename Bar\n"
11391-
">\n"
11392-
"void foo() {}",
11393-
Style);
11394-
// But not when the name is looong. Note that these names are exactly 1
11355+
// Breaks when the name is looong. Note that these names are exactly 1
1139511356
// character too long for the ColumnLimit.
1139611357
verifyFormat("template <\n"
1139711358
" typename Foo,\n"
11398-
" typename Barrrrrrrrrrrrrrrrrrrr\n"
11399-
">\n"
11400-
"void foo() {}",
11401-
Style);
11402-
// Note that this "Foo" is 1 character shorter than the previous "Bar" because
11403-
// of the comma.
11404-
verifyFormat("template <\n"
11405-
" typename Foooooooooooooooooooo,\n"
11406-
" typename Bar\n"
11359+
" typename Barrrrrrrrrrrrrrrrrrr\n"
1140711360
">\n"
1140811361
"void foo() {}",
1140911362
Style);
@@ -11416,42 +11369,29 @@ TEST_F(FormatTest, BreakBeforeTemplateCloser) {
1141611369
" typename Bar>\n"
1141711370
"void foo() {}",
1141811371
Style);
11419-
// Same check for only one template parameter.
11420-
// Note how the first line is exactly 40 chars:
11421-
verifyFormat("template <typename Barrrrrrrrrrrrrrrrrr>\n"
11372+
// Additionally, long names should be split in one step:
11373+
verifyFormat("template <\n"
11374+
" typename Foo,\n"
11375+
" typename Barrrrrrrrrrrrrrrrrrr\n"
11376+
">\n"
11377+
"void foo() {}",
11378+
"template <typename Foo, typename Barrrrrrrrrrrrrrrrrrr>\n"
1142211379
"void foo() {}",
1142311380
Style);
11424-
// And when one more "r" is added, it breaks properly:
1142511381
verifyFormat("template <\n"
11426-
" typename Barrrrrrrrrrrrrrrrrrr\n"
11382+
" typename Foooooooooooooooooooo,\n"
11383+
" typename Bar\n"
1142711384
">\n"
1142811385
"void foo() {}",
11386+
"template <typename Foooooooooooooooooooo, typename Bar>\n"
11387+
"void foo() {}",
1142911388
Style);
11430-
// Additionally, long names should be split in one step:
11431-
verifyFormat(
11432-
"template <\n"
11433-
" typename Foo,\n"
11434-
" typename Barrrrrrrrrrrrrrrrrrrrrrrrrr\n"
11435-
">\n"
11436-
"void foo() {}",
11437-
"template <typename Foo, typename Barrrrrrrrrrrrrrrrrrrrrrrrrr>\n"
11438-
"void foo() {}",
11439-
Style);
11440-
verifyFormat(
11441-
"template <\n"
11442-
" typename Fooooooooooooooooooooooooooo,\n"
11443-
" typename Bar\n"
11444-
">\n"
11445-
"void foo() {}",
11446-
"template <typename Fooooooooooooooooooooooooooo, typename Bar>\n"
11447-
"void foo() {}",
11448-
Style);
1144911389
// Even when there is only one long name:
1145011390
verifyFormat("template <\n"
11451-
" typename Fooooooooooooooooooooooooooo\n"
11391+
" typename Foooooooooooooooooooo\n"
1145211392
">\n"
1145311393
"void foo() {}",
11454-
"template <typename Fooooooooooooooooooooooooooo>\n"
11394+
"template <typename Foooooooooooooooooooo>\n"
1145511395
"void foo() {}",
1145611396
Style);
1145711397
// Test lambda goes to next line if the type is looong:
@@ -11520,20 +11460,13 @@ TEST_F(FormatTest, BreakBeforeTemplateCloser) {
1152011460
"}",
1152111461
Style);
1152211462

11523-
// Test template usage goes to next line only if the type is looong:
11524-
verifyFormat("void foo() { myFunc<T>(); }", Style);
11463+
// Test template usage goes to next line if the type is looong:
1152511464
verifyFormat("void foo() {\n"
1152611465
" myFunc<\n"
11527-
" Loooooooooooooooooooooooooooooooooooooooong\n"
11466+
" Looooooooooooooooooooooooong\n"
1152811467
" >();\n"
1152911468
"}",
1153011469
Style);
11531-
// But if the type is short, we don't need block indent style:
11532-
verifyFormat("void foo() {\n"
11533-
" myFunc<Foo, Foo, Foo, Foo, Foo, Foo,\n"
11534-
" Foo, Foo>();\n"
11535-
"}",
11536-
Style);
1153711470
// Even a single type in the middle is enough to force it to block indent
1153811471
// style:
1153911472
verifyFormat("void foo() {\n"

0 commit comments

Comments
 (0)