[PATCH] D93938: [clang-format] Fixed AfterEnum handling

Ally Tiritoglu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jan 3 11:42:06 PST 2021


atirit updated this revision to Diff 314296.
atirit added a comment.

Added unit test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93938/new/

https://reviews.llvm.org/D93938

Files:
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -1352,6 +1352,49 @@
                Style);
 }
 
+TEST_F(FormatTest, AfterEnum) {
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+
+  Style.AllowShortEnumsOnASingleLine = true;
+  Style.BraceWrapping.AfterEnum = true;
+  verifyFormat("enum { A, B, C } Test1, AfterEnum2;", Style);
+  verifyFormat("enum\n"
+               "{\n"
+               "  A,\n"
+               "  B, // foo\n"
+               "  C\n"
+               "} Test2,\n"
+               "    AfterEnum2;",
+               Style);
+  Style.BraceWrapping.AfterEnum = false;
+  verifyFormat("enum { A, B, C } Test3, AfterEnum2;", Style);
+  verifyFormat("enum {\n"
+               "  A,\n"
+               "  B, // foo\n"
+               "  C\n"
+               "} Test4,\n"
+               "    AfterEnum2;",
+               Style);
+
+  Style.AllowShortEnumsOnASingleLine = false;
+  Style.BraceWrapping.AfterEnum = true;
+  verifyFormat("enum\n"
+               "{\n"
+               "  A,\n"
+               "  B,\n"
+               "  C\n"
+               "} Test5, AfterEnum2;",
+               Style);
+  Style.BraceWrapping.AfterEnum = false;
+  verifyFormat("enum {\n"
+               "  A,\n"
+               "  B,\n"
+               "  C\n"
+               "} Test6, AfterEnum2;",
+               Style);
+}
+
 TEST_F(FormatTest, ShortCaseLabels) {
   FormatStyle Style = getLLVMStyle();
   Style.AllowShortCaseLabelsOnASingleLine = true;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93938.314296.patch
Type: text/x-patch
Size: 1659 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210103/4b96dcb9/attachment.bin>


More information about the cfe-commits mailing list