[clang] [clang-format] Change BinPackParameters to enum and add AlwaysOnePerLine (PR #101882)

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 20 08:52:40 PDT 2024


================
@@ -403,13 +416,25 @@ TEST_F(FormatTestComments, UnderstandsBlockComments) {
   verifyFormat("f(/* aaaaaaaaaaaaaaaaaa = */\n"
                "  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);");
 
-  FormatStyle NoBinPacking = getLLVMStyle();
-  NoBinPacking.BinPackParameters = false;
-  verifyFormat("aaaaaaaa(/* parameter 1 */ aaaaaa,\n"
-               "         /* parameter 2 */ aaaaaa,\n"
-               "         /* parameter 3 */ aaaaaa,\n"
-               "         /* parameter 4 */ aaaaaa);",
-               NoBinPacking);
+  FormatStyle BinPack = getLLVMStyle();
+  verifyFormat(
+      "int aaaaaaaaaaaaa(/* 1st */ int bbbbbbbbbb, /* 2nd */ int ccccccccccc,\n"
+      "                  /* 3rd */ int dddddddddddd);",
+      BinPack);
+
+  FormatStyle OnePerLine = getLLVMStyle();
+  OnePerLine.BinPackParameters = FormatStyle::BPPS_OnePerLine;
+  verifyFormat("int a(/* 1st */ int b, /* 2nd */ int c);", OnePerLine);
+  verifyFormat("int aaaaaaaaaaaaa(/* 1st */ int bbbbbbbbbb,\n"
+               "                  /* 2nd */ int ccccccccccc,\n"
+               "                  /* 3rd */ int dddddddddddd);",
+               OnePerLine);
+
+  FormatStyle AlwaysOnePerLine = getLLVMStyle();
+  AlwaysOnePerLine.BinPackParameters = FormatStyle::BPPS_AlwaysOnePerLine;
+  verifyFormat("int a(/* 1st */ int b,\n"
+               "      /* 2nd */ int c);",
+               AlwaysOnePerLine);
----------------
owenca wrote:

```suggestion
  verifyFormat(
      "int aaaaaaaaaaaaa(/* 1st */ int bbbbbbbbbb, /* 2nd */ int ccccccccccc,\n"
      "                  /* 3rd */ int dddddddddddd);");

  auto Style = getLLVMStyle();
  Style.BinPackParameters = false;
  verifyFormat("aaaaaaaa(/* parameter 1 */ aaaaaa,\n"
               "         /* parameter 2 */ aaaaaa,\n"
               "         /* parameter 3 */ aaaaaa,\n"
               "         /* parameter 4 */ aaaaaa);",
               Style);

  Style.BinPackParameters = FormatStyle::BPPS_OnePerLine;
  verifyFormat("int a(/* 1st */ int b, /* 2nd */ int c);", OnePerLine);
  verifyFormat("int aaaaaaaaaaaaa(/* 1st */ int bbbbbbbbbb,\n"
               "                  /* 2nd */ int ccccccccccc,\n"
               "                  /* 3rd */ int dddddddddddd);",
               Style);

  Style.BinPackParameters = FormatStyle::BPPS_AlwaysOnePerLine;
  verifyFormat("int a(/* 1st */ int b,\n"
               "      /* 2nd */ int c);",
               Style);
```
Reuse `Style` and don't delete the old test.

https://github.com/llvm/llvm-project/pull/101882


More information about the cfe-commits mailing list