================
@@ -4266,6 +4266,140 @@ TEST_F(FormatTest, FormatsTypedefEnum) {
                Style);
 }
 
+TEST_F(FormatTest, FormatsVaOptWithTrailingComma) {
+  verifyFormat("#define DEFINE_DESCRIPTOR(Name, ...) \\\n"
+               "  enum ParameterIndices {            \\\n"
+               "    kJSTarget = -1,                  \\\n"
+               "    __VA_OPT__(__VA_ARGS__, )        \\\n"
+               "    kNewTarget,                      \\\n"
+               "    kActualArgumentsCount,           \\\n"
+               "    kContext,                        \\\n"
+               "    kParameterCount,                 \\\n"
+               "  };",
+               getChromiumStyle(FormatStyle::LK_Cpp));
+
+  FormatStyle Style = getLLVMStyle();
+  Style.AlignEscapedNewlines = FormatStyle::ENAS_Left;
+
+  verifyFormat("#define M(...) enum E { __VA_OPT__(__VA_ARGS__, ) kOnly };",
+               Style);
+  FormatStyle NoShortEnums = Style;
+  NoShortEnums.AllowShortEnumsOnASingleLine = false;
+  verifyFormat("#define M(...)                \\\n"
+               "  enum E {                    \\\n"
+               "    __VA_OPT__(__VA_ARGS__, ) \\\n"
+               "    kOnly                     \\\n"
+               "  };",
+               NoShortEnums);
+
+  FormatStyle InsertComma = NoShortEnums;
+  InsertComma.EnumTrailingComma = FormatStyle::ETC_Insert;
+  verifyFormat("#define M(...)                \\\n"
+               "  enum E {                    \\\n"
+               "    kFirst,                   \\\n"
+               "    __VA_OPT__(__VA_ARGS__, ) \\\n"
+               "  };",
+               InsertComma);
+
+  verifyFormat("#define M(...)                  \\\n"
+               "  int x[] = {                   \\\n"
+               "      1,                        \\\n"
+               "      __VA_OPT__(__VA_ARGS__, ) \\\n"
+               "      2,                        \\\n"
+               "  };",
+               Style);
+  verifyFormat("#define M(...)                                          \\\n"
+               "  int x[] = {__VA_OPT__(a, ) 1, 1000000000, 2000000000, \\\n"
+               "             3000000000,     4, 5000000000, 6000000000};",
+               Style);
+
+  FormatStyle Style58 = Style;
+  Style58.ColumnLimit = 58;
----------------
backes wrote:

That test was exercising bin-packing after wrapping at `__VA_OPT__`, which is 
already covered by the `SomeFunction` case (`Style50`). I removed the redundant 
test and unified the remaining column limits to 40 and 50.

https://github.com/llvm/llvm-project/pull/240902
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to