[clang] [clang-format] Add BinPackBinaryOperations configuration (PR #95013)

Björn Schäpers via cfe-commits cfe-commits at lists.llvm.org
Mon Jun 10 11:41:27 PDT 2024


================
@@ -27492,6 +27492,86 @@ TEST_F(FormatTest, SpaceBetweenKeywordAndLiteral) {
   verifyFormat("return sizeof \"5\";");
 }
 
+TEST_F(FormatTest, BinPackBinaryOperations) {
+  auto Style = getLLVMStyle();
+  Style.BinPackBinaryOperations = false;
+
+  // Logical operations
+  verifyFormat("if (condition1 && condition2) {\n"
+               "}",
+               Style);
+  verifyFormat("if (condition1 && // comment\n"
+               "    condition2 &&\n"
+               "    (condition3 || condition4) && // comment\n"
+               "    condition5 &&\n"
+               "    condition6) {\n"
+               "}",
+               Style);
+  verifyFormat("if (loooooooooooooooooooooongcondition1 &&\n"
+               "    loooooooooooooooooooooongcondition2) {\n"
+               "}",
+               Style);
+
+  // Arithmetic
+  verifyFormat("const int result = lhs + rhs;\n", Style);
+  verifyFormat("const int result = loooooooooooooooooooooongop1 +\n"
+               "                   loooooooooooooooooooooongop2 +\n"
+               "                   loooooooooooooooooooooongop3;\n",
+               Style);
+
+  // clang-format off
+  verifyFormat("const int result =\n"
+               "    operand1 + operand2 - (operand3 + operand4) - operand5 * operand6;\n",
+               Style);
+  // clang-format on
+
+  verifyFormat("const int result = longOperand1 +\n"
+               "                   longOperand2 -\n"
+               "                   (longOperand3 + longOperand4) -\n"
+               "                   longOperand5 * longOperand6;\n",
+               Style);
+
+  Style.BinPackBinaryOperations = true;
----------------
HazardyKnusperkeks wrote:

Swap the tests, first test plain LLVM style, then the modification.

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


More information about the cfe-commits mailing list