[clang] [ClangFormat] Fix formatting bugs. (PR #76245)

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 9 19:57:18 PST 2024


================
@@ -255,6 +255,41 @@ TEST_F(FormatTestMacroExpansion,
                          Style);
 }
 
+TEST_F(FormatTestMacroExpansion, CommaAsOperator) {
+  FormatStyle Style = getGoogleStyle();
+  Style.ColumnLimit = 42;
+  Style.Macros.push_back("MACRO(a, b, c)=a=(b); if(x) c");
+  verifyFormat("MACRO(auto a,\n"
+               "      looooongfunction(first, second,\n"
+               "                       third),\n"
+               "      fourth);",
+               Style);
+}
+
+TEST_F(FormatTestMacroExpansion, ForcedBreakDiffers) {
+  FormatStyle Style = getGoogleStyle();
+  Style.ColumnLimit = 40;
+  Style.Macros.push_back("MACRO(a, b)=a=(b)");
+  verifyFormat("//\n"
+               "MACRO(const type variable,\n"
+               "      functtioncall(\n"
+               "          first, longsecondarg, third));\n",
+               Style);
+}
+
+TEST_F(FormatTestMacroExpansion,
+       PreferNotBreakingBetweenReturnTypeAndFunction) {
+  FormatStyle Style = getGoogleStyle();
+  Style.ColumnLimit = 22;
+  Style.Macros.push_back("MOCK_METHOD(r, n, a)=r n a");
+  // In the expanded code, we parse a full function signature, and afterwards
+  // know that we prefer not to break before the function name.
+  verifyFormat("MOCK_METHOD(\n"
+               "    type, variable,\n"
+               "    (type));\n",
----------------
owenca wrote:

Ditto.

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


More information about the cfe-commits mailing list