[clang] [clang-format] Add BinPackBinaryOperations configuration (PR #95013)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 10 23:50:51 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;
+
+ // Logical operations
+ verifyFormat("if (condition1 && condition2) {\n"
+ "}",
+ Style);
+
+ // clang-format off
+ verifyFormat("if (condition1 && condition2 && (condition3 || condition4) && condition5 &&\n"
+ " condition6) {\n"
+ "}",
+ Style);
+ // clang-format on
+
+ verifyFormat("if (loooooooooooooooooooooongcondition1 &&\n"
+ " loooooooooooooooooooooongcondition2) {\n"
+ "}",
+ Style);
+
+ // Arithmetic
+ verifyFormat("const int result = lhs + rhs;\n", Style);
+
+ // clang-format off
----------------
mydeveloperday wrote:
why do you need these here?
https://github.com/llvm/llvm-project/pull/95013
More information about the cfe-commits
mailing list