[clang] [clang-format] Change BinPackParameters to an enum to add a BreakAlways (PR #101882)
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Sat Aug 17 01:14:17 PDT 2024
================
@@ -8925,6 +8925,97 @@ TEST_F(FormatTest, FormatsOneParameterPerLineIfNecessary) {
NoBinPacking);
}
+TEST_F(FormatTest, FormatsDeclarationBreakAlways) {
+ FormatStyle BreakAlways = getGoogleStyle();
+ BreakAlways.BinPackParameters = FormatStyle::BPPS_OnePerLine;
+ verifyFormat("void f(int a,\n"
+ " int b);",
+ BreakAlways);
+ verifyFormat("void f(int aaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ " int bbbbbbbbbbbbbbbbbbbbbbbbb,\n"
+ " int cccccccccccccccccccccccc);",
+ BreakAlways);
+
+ // Ensure AlignAFterOpenBracket interacts correctly with
+ // PackParameters set to BreakAlways.
+ BreakAlways.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
+ verifyFormat(
+ "void someLongFunctionName(\n"
+ " int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ " int b);",
+ BreakAlways);
+ BreakAlways.AlignAfterOpenBracket = FormatStyle::BAS_BlockIndent;
+ verifyFormat(
+ "void someLongFunctionName(\n"
+ " int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ " int b\n"
+ ");",
+ BreakAlways);
+}
+
+TEST_F(FormatTest, FormatsDefinitionBreakAlways) {
+ FormatStyle BreakAlways = getGoogleStyle();
+ BreakAlways.BinPackParameters = FormatStyle::BPPS_OnePerLine;
+ verifyFormat("void f(int a,\n"
+ " int b) {\n"
+ " f(a, b);\n"
+ "}",
+ BreakAlways);
+
+ // Ensure BinPackArguments interact correctly when BinPackParameters is set to
+ // BreakAlways.
+ verifyFormat("void f(int aaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ " int bbbbbbbbbbbbbbbbbbbbbbbbb,\n"
+ " int cccccccccccccccccccccccc) {\n"
+ " f(aaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbb,\n"
+ " cccccccccccccccccccccccc);\n"
+ "}",
+ BreakAlways);
+ BreakAlways.BinPackArguments = false;
+ verifyFormat("void f(int aaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ " int bbbbbbbbbbbbbbbbbbbbbbbbb,\n"
+ " int cccccccccccccccccccccccc) {\n"
+ " f(aaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
+ " bbbbbbbbbbbbbbbbbbbbbbbbb,\n"
+ " cccccccccccccccccccccccc);\n"
+ "}",
+ BreakAlways);
+
+ // Ensure BreakFunctionDefinitionParameters interacts correctly when
+ // BinPackParameters is set to BreakAlways
----------------
owenca wrote:
```suggestion
// BinPackParameters is set to BPPS_Never.
```
https://github.com/llvm/llvm-project/pull/101882
More information about the cfe-commits
mailing list