owenpan created this revision.
owenpan added reviewers: MyDeveloperDay, curdeius, HazardyKnusperkeks, feg208.
owenpan added a project: clang-format.
Herald added a project: All.
owenpan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

As mentioned in D121576#3381295 <https://reviews.llvm.org/D121576#3381295>, I'm 
cleaning up the unit tests in preparation for a redesign of 
`AlignArrayOfStructures` to address most of the accumulated issues and to 
enable alignments of non-rectangular structures.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D123571

Files:
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -19057,14 +19057,14 @@
                "    {56,    23, \"hello\"},\n"
                "    {-1, 93463, \"world\"},\n"
                "    { 7,     5,    \"!!\"}\n"
-               "};\n",
+               "};",
                Style);
 
   verifyFormat("struct test demo[] = {\n"
                "    {56,    23, \"hello\"}, // first line\n"
                "    {-1, 93463, \"world\"}, // second line\n"
                "    { 7,     5,    \"!!\"}  // third line\n"
-               "};\n",
+               "};",
                Style);
 
   verifyFormat("struct test demo[4] = {\n"
@@ -19072,42 +19072,42 @@
                "    { -1, 93463, 22,       \"my\"}, // second line\n"
                "    {  7,     5,  1, \"goodness\"}  // third line\n"
                "    {234,     5,  1, \"gracious\"}  // fourth line\n"
-               "};\n",
+               "};",
                Style);
 
   verifyFormat("struct test demo[3] = {\n"
                "    {56,    23, \"hello\"},\n"
                "    {-1, 93463, \"world\"},\n"
                "    { 7,     5,    \"!!\"}\n"
-               "};\n",
+               "};",
                Style);
 
   verifyFormat("struct test demo[3] = {\n"
                "    {int{56},    23, \"hello\"},\n"
                "    {int{-1}, 93463, \"world\"},\n"
                "    { int{7},     5,    \"!!\"}\n"
-               "};\n",
+               "};",
                Style);
 
   verifyFormat("struct test demo[] = {\n"
                "    {56,    23, \"hello\"},\n"
                "    {-1, 93463, \"world\"},\n"
                "    { 7,     5,    \"!!\"},\n"
-               "};\n",
+               "};",
                Style);
 
   verifyFormat("test demo[] = {\n"
                "    {56,    23, \"hello\"},\n"
                "    {-1, 93463, \"world\"},\n"
                "    { 7,     5,    \"!!\"},\n"
-               "};\n",
+               "};",
                Style);
 
   verifyFormat("demo = std::array<struct test, 3>{\n"
                "    test{56,    23, \"hello\"},\n"
                "    test{-1, 93463, \"world\"},\n"
                "    test{ 7,     5,    \"!!\"},\n"
-               "};\n",
+               "};",
                Style);
 
   verifyFormat("test demo[] = {\n"
@@ -19116,29 +19116,28 @@
                "    {-1, 93463, \"world\"},\n"
                "#endif\n"
                "    { 7,     5,    \"!!\"}\n"
-               "};\n",
+               "};",
                Style);
 
+  // FIXME: Skip AlignArrayOfStructures if any row can't fit on a single line.
+#if 0
   verifyFormat(
-      "test demo[] = {\n"
-      "    { 7,    23,\n"
-      "     \"hello world i am a very long line that really, in any\"\n"
-      "     \"just world, ought to be split over multiple lines\"},\n"
-      "    {-1, 93463,                                  \"world\"},\n"
-      "    {56,     5,                                     \"!!\"}\n"
-      "};\n",
+      "test demo[] = {{7, 23,\n"
+      "                \"hello world i am a long line that really, in any\"\n"
+      "                \"just world, ought to be split to multiple lines\"},\n"
+      "               {-1, 93463, \"world\"},\n"
+      "               {56, 5, \"!!\"}};",
       Style);
+#endif
 
-  verifyFormat("return GradForUnaryCwise(g, {\n"
-               "                                {{\"sign\"}, \"Sign\",  "
-               "  {\"x\", \"dy\"}},\n"
-               "                                {  {\"dx\"},  \"Mul\", {\"dy\""
-               ", \"sign\"}},\n"
-               "});\n",
+  verifyFormat("return f(g, {\n"
+               "                {{\"sign\"}, \"Sign\",    {\"x\", \"dy\"}},\n"
+               "                {  {\"dx\"},  \"Mul\", {\"dy\", \"sign\"}},\n"
+               "});",
                Style);
 
   Style.ColumnLimit = 0;
-  EXPECT_EQ(
+  verifyFormat(
       "test demo[] = {\n"
       "    {56,    23, \"hello world i am a very long line that really, "
       "in any just world, ought to be split over multiple lines\"},\n"
@@ -19147,63 +19146,63 @@
       "    { 7,     5,                                                  "
       "                                                    \"!!\"},\n"
       "};",
-      format("test demo[] = {{56, 23, \"hello world i am a very long line "
-             "that really, in any just world, ought to be split over multiple "
-             "lines\"},{-1, 93463, \"world\"},{7, 5, \"!!\"},};",
-             Style));
+      "test demo[] = {{56, 23, \"hello world i am a very long line "
+      "that really, in any just world, ought to be split over multiple "
+      "lines\"},{-1, 93463, \"world\"},{7, 5, \"!!\"},};",
+      Style);
 
   Style.ColumnLimit = 80;
+  // FIXME: Skip AlignArrayOfStructures if any row has a non-trailing comment.
+#if 0
   verifyFormat("test demo[] = {\n"
-               "    {56,    23, /* a comment */ \"hello\"},\n"
-               "    {-1, 93463,                 \"world\"},\n"
-               "    { 7,     5,                    \"!!\"}\n"
-               "};\n",
+               "    {56, 23, /* a comment */ \"hello\"}, "
+               "{-1, 93463, \"world\"}, {7, 5, \"!!\"}};",
                Style);
 
   verifyFormat("test demo[] = {\n"
-               "    {56,    23,                    \"hello\"},\n"
-               "    {-1, 93463, \"world\" /* comment here */},\n"
-               "    { 7,     5,                       \"!!\"}\n"
-               "};\n",
+               "    {56, 23, \"hello\"}, "
+               "{-1, 93463, \"world\" /* comment here */}, {7, 5, \"!!\"}};",
                Style);
 
   verifyFormat("test demo[] = {\n"
-               "    {56, /* a comment */ 23, \"hello\"},\n"
-               "    {-1,              93463, \"world\"},\n"
-               "    { 7,                  5,    \"!!\"}\n"
-               "};\n",
+               "    {56, /* a comment */ 23, \"hello\"}, "
+               "{-1, 93463, \"world\"}, {7, 5, \"!!\"}};",
                Style);
+#endif
 
   Style.ColumnLimit = 20;
-  EXPECT_EQ(
+  // FIXME: Skip AlignArrayOfStructures if any row can't fit on a single line.
+#if 0
+  verifyFormat(
       "demo = std::array<\n"
       "    struct test, 3>{\n"
       "    test{\n"
-      "         56,    23,\n"
-      "         \"hello \"\n"
-      "         \"world i \"\n"
-      "         \"am a very \"\n"
-      "         \"long line \"\n"
-      "         \"that \"\n"
-      "         \"really, \"\n"
-      "         \"in any \"\n"
-      "         \"just \"\n"
-      "         \"world, \"\n"
-      "         \"ought to \"\n"
-      "         \"be split \"\n"
-      "         \"over \"\n"
-      "         \"multiple \"\n"
-      "         \"lines\"},\n"
+      "        56, 23,\n"
+      "        \"hello \"\n"
+      "        \"world i \"\n"
+      "        \"am a very \"\n"
+      "        \"long line \"\n"
+      "        \"that \"\n"
+      "        \"really, \"\n"
+      "        \"in any \"\n"
+      "        \"just \"\n"
+      "        \"world, \"\n"
+      "        \"ought to \"\n"
+      "        \"be split \"\n"
+      "        \"over \"\n"
+      "        \"multiple \"\n"
+      "        \"lines\"},\n"
       "    test{-1, 93463,\n"
       "         \"world\"},\n"
-      "    test{ 7,     5,\n"
-      "         \"!!\"   },\n"
+      "    test{7, 5,\n"
+      "         \"!!\"},\n"
       "};",
-      format("demo = std::array<struct test, 3>{test{56, 23, \"hello world "
-             "i am a very long line that really, in any just world, ought "
-             "to be split over multiple lines\"},test{-1, 93463, \"world\"},"
-             "test{7, 5, \"!!\"},};",
-             Style));
+      "demo = std::array<struct test, 3>{test{56, 23, \"hello world "
+      "i am a very long line that really, in any just world, ought "
+      "to be split over multiple lines\"},test{-1, 93463, \"world\"},"
+      "test{7, 5, \"!!\"},};",
+      Style);
+#endif
   // This caused a core dump by enabling Alignment in the LLVMStyle globally
   Style = getLLVMStyleWithColumns(50);
   Style.AlignArrayOfStructures = FormatStyle::AIAS_Right;
@@ -19220,23 +19219,6 @@
                "    }\n"
                "};",
                Style);
-  Style.ColumnLimit = 100;
-  EXPECT_EQ(
-      "test demo[] = {\n"
-      "    {56,    23,\n"
-      "     \"hello world i am a very long line that really, in any just world"
-      ", ought to be split over \"\n"
-      "     \"multiple lines\"  },\n"
-      "    {-1, 93463, \"world\"},\n"
-      "    { 7,     5,    \"!!\"},\n"
-      "};",
-      format("test demo[] = {{56, 23, \"hello world i am a very long line "
-             "that really, in any just world, ought to be split over multiple "
-             "lines\"},{-1, 93463, \"world\"},{7, 5, \"!!\"},};",
-             Style));
-
-  Style = getLLVMStyleWithColumns(50);
-  Style.AlignArrayOfStructures = FormatStyle::AIAS_Right;
   verifyFormat("struct test demo[] = {\n"
                "    {56,    23, \"hello\"},\n"
                "    {-1, 93463, \"world\"},\n"
@@ -19248,6 +19230,23 @@
                "};",
                Style);
   Style.ColumnLimit = 100;
+  // FIXME: Skip AlignArrayOfStructures if any row can't fit on a single line.
+#if 0
+  verifyFormat(
+      "test demo[] = {\n"
+      "    {56, 23,\n"
+      "     \"hello world i am a very long line that really, in any just world"
+      ", ought to be split over \"\n"
+      "     \"multiple lines\"},\n"
+      "    {-1, 93463, \"world\"},\n"
+      "    {7, 5, \"!!\"},\n"
+      "};",
+      "test demo[] = {{56, 23, \"hello world i am a very long line "
+      "that really, in any just world, ought to be split over multiple "
+      "lines\"},{-1, 93463, \"world\"},{7, 5, \"!!\"},};",
+      Style);
+#endif
+
   Style.AlignConsecutiveAssignments.AcrossComments = true;
   Style.AlignConsecutiveDeclarations.AcrossComments = true;
   verifyFormat("struct test demo[] = {\n"
@@ -19260,88 +19259,90 @@
                "    { -1, 93463, 22,       \"my\"}, // second line\n"
                "    {  7,     5,  1, \"goodness\"}  // third line\n"
                "    {234,     5,  1, \"gracious\"}  // fourth line\n"
-               "};\n",
+               "};",
                Style);
-  EXPECT_EQ(
+  // FIXME: Skip AlignArrayOfStructures if any row can't fit on a single line.
+#if 0
+  verifyFormat(
       "test demo[] = {\n"
       "    {56,\n"
       "     \"hello world i am a very long line that really, in any just world"
       ", ought to be split over \"\n"
-      "     \"multiple lines\",    23},\n"
-      "    {-1,      \"world\", 93463},\n"
-      "    { 7,         \"!!\",     5},\n"
+      "     \"multiple lines\",\n"
+      "     23},\n"
+      "    {-1, \"world\", 93463},\n"
+      "    {7, \"!!\", 5},\n"
       "};",
-      format("test demo[] = {{56, \"hello world i am a very long line "
-             "that really, in any just world, ought to be split over multiple "
-             "lines\", 23},{-1, \"world\", 93463},{7, \"!!\", 5},};",
-             Style));
+      "test demo[] = {{56, \"hello world i am a very long line "
+      "that really, in any just world, ought to be split over multiple "
+      "lines\", 23},{-1, \"world\", 93463},{7, \"!!\", 5},};",
+      Style);
+#endif
 }
 
 TEST_F(FormatTest, CatchAlignArrayOfStructuresLeftAlignment) {
   auto Style = getLLVMStyle();
   Style.AlignArrayOfStructures = FormatStyle::AIAS_Left;
-  /* FIXME: This case gets misformatted.
+  /* FIXME: These cases get misformatted.
   verifyFormat("auto foo = Items{\n"
                "    Section{0, bar(), },\n"
                "    Section{1, boo()  }\n"
-               "};\n",
+               "};",
                Style);
-  */
   verifyFormat("auto foo = Items{\n"
-               "    Section{\n"
-               "            0, bar(),\n"
-               "            }\n"
-               "};\n",
+               "    Section{0, bar(), }\n"
+               "};",
                Style);
+  */
   verifyFormat("struct test demo[] = {\n"
                "    {56, 23,    \"hello\"},\n"
                "    {-1, 93463, \"world\"},\n"
                "    {7,  5,     \"!!\"   }\n"
-               "};\n",
+               "};",
                Style);
   verifyFormat("struct test demo[] = {\n"
                "    {56, 23,    \"hello\"}, // first line\n"
                "    {-1, 93463, \"world\"}, // second line\n"
                "    {7,  5,     \"!!\"   }  // third line\n"
-               "};\n",
+               "};",
                Style);
   verifyFormat("struct test demo[4] = {\n"
                "    {56,  23,    21, \"oh\"      }, // first line\n"
                "    {-1,  93463, 22, \"my\"      }, // second line\n"
                "    {7,   5,     1,  \"goodness\"}  // third line\n"
                "    {234, 5,     1,  \"gracious\"}  // fourth line\n"
-               "};\n",
+               "};",
                Style);
   verifyFormat("struct test demo[3] = {\n"
                "    {56, 23,    \"hello\"},\n"
                "    {-1, 93463, \"world\"},\n"
                "    {7,  5,     \"!!\"   }\n"
-               "};\n",
+               "};",
                Style);
 
   verifyFormat("struct test demo[3] = {\n"
                "    {int{56}, 23,    \"hello\"},\n"
                "    {int{-1}, 93463, \"world\"},\n"
                "    {int{7},  5,     \"!!\"   }\n"
-               "};\n",
+               "};",
                Style);
   verifyFormat("struct test demo[] = {\n"
                "    {56, 23,    \"hello\"},\n"
                "    {-1, 93463, \"world\"},\n"
                "    {7,  5,     \"!!\"   },\n"
-               "};\n",
+               "};",
                Style);
   verifyFormat("test demo[] = {\n"
                "    {56, 23,    \"hello\"},\n"
                "    {-1, 93463, \"world\"},\n"
                "    {7,  5,     \"!!\"   },\n"
-               "};\n",
+               "};",
                Style);
   verifyFormat("demo = std::array<struct test, 3>{\n"
                "    test{56, 23,    \"hello\"},\n"
                "    test{-1, 93463, \"world\"},\n"
                "    test{7,  5,     \"!!\"   },\n"
-               "};\n",
+               "};",
                Style);
   verifyFormat("test demo[] = {\n"
                "    {56, 23,    \"hello\"},\n"
@@ -19349,28 +19350,45 @@
                "    {-1, 93463, \"world\"},\n"
                "#endif\n"
                "    {7,  5,     \"!!\"   }\n"
-               "};\n",
+               "};",
                Style);
+  // FIXME: Skip AlignArrayOfStructures if any row can't fit on a single line.
+#if 0
   verifyFormat(
-      "test demo[] = {\n"
-      "    {7,  23,\n"
-      "     \"hello world i am a very long line that really, in any\"\n"
-      "     \"just world, ought to be split over multiple lines\"},\n"
-      "    {-1, 93463, \"world\"                                 },\n"
-      "    {56, 5,     \"!!\"                                    }\n"
-      "};\n",
+      "test demo[] = {{7, 23,\n"
+      "                \"hello world i am a long line that really, in any\"\n"
+      "                \"just world, ought to be split to multiple lines\"},\n"
+      "               {-1, 93463, \"world\"},\n"
+      "               {56, 5, \"!!\"}};",
       Style);
+#endif
+
+  verifyFormat("return f(g, {\n"
+               "                {{\"sign\"}, \"Sign\", {\"x\", \"dy\"}   },\n"
+               "                {{\"dx\"},   \"Mul\",  {\"dy\", \"sign\"}},\n"
+               "});",
+               Style);
+
+  // FIXME: Skip AlignArrayOfStructures if any row has a non-trailing comment.
+#if 0
+  verifyFormat("test demo[] = {\n"
+               "    {56, 23, /* a comment */ \"hello\"}, "
+               "{-1, 93463, \"world\"}, {7, 5, \"!!\"}};",
+               Style);
+
+  verifyFormat("test demo[] = {\n"
+               "    {56, 23, \"hello\"}, "
+               "{-1, 93463, \"world\" /* comment here */}, {7, 5, \"!!\"}};",
+               Style);
 
-  verifyFormat("return GradForUnaryCwise(g, {\n"
-               "                                {{\"sign\"}, \"Sign\", {\"x\", "
-               "\"dy\"}   },\n"
-               "                                {{\"dx\"},   \"Mul\",  "
-               "{\"dy\", \"sign\"}},\n"
-               "});\n",
+  verifyFormat("test demo[] = {\n"
+               "    {56, /* a comment */ 23, \"hello\"}, "
+               "{-1, 93463, \"world\"}, {7, 5, \"!!\"}};",
                Style);
+#endif
 
   Style.ColumnLimit = 0;
-  EXPECT_EQ(
+  verifyFormat(
       "test demo[] = {\n"
       "    {56, 23,    \"hello world i am a very long line that really, in any "
       "just world, ought to be split over multiple lines\"},\n"
@@ -19379,86 +19397,69 @@
       "    {7,  5,     \"!!\"                                                  "
       "                                                   },\n"
       "};",
-      format("test demo[] = {{56, 23, \"hello world i am a very long line "
-             "that really, in any just world, ought to be split over multiple "
-             "lines\"},{-1, 93463, \"world\"},{7, 5, \"!!\"},};",
-             Style));
-
-  Style.ColumnLimit = 80;
-  verifyFormat("test demo[] = {\n"
-               "    {56, 23,    /* a comment */ \"hello\"},\n"
-               "    {-1, 93463, \"world\"                },\n"
-               "    {7,  5,     \"!!\"                   }\n"
-               "};\n",
-               Style);
-
-  verifyFormat("test demo[] = {\n"
-               "    {56, 23,    \"hello\"                   },\n"
-               "    {-1, 93463, \"world\" /* comment here */},\n"
-               "    {7,  5,     \"!!\"                      }\n"
-               "};\n",
-               Style);
-
-  verifyFormat("test demo[] = {\n"
-               "    {56, /* a comment */ 23, \"hello\"},\n"
-               "    {-1, 93463,              \"world\"},\n"
-               "    {7,  5,                  \"!!\"   }\n"
-               "};\n",
-               Style);
+      "test demo[] = {{56, 23, \"hello world i am a very long line "
+      "that really, in any just world, ought to be split over multiple "
+      "lines\"},{-1, 93463, \"world\"},{7, 5, \"!!\"},};",
+      Style);
 
   Style.ColumnLimit = 20;
-  EXPECT_EQ(
+  // FIXME: Skip AlignArrayOfStructures if any row can't fit on a single line.
+#if 0
+  verifyFormat(
       "demo = std::array<\n"
       "    struct test, 3>{\n"
       "    test{\n"
-      "         56, 23,\n"
-      "         \"hello \"\n"
-      "         \"world i \"\n"
-      "         \"am a very \"\n"
-      "         \"long line \"\n"
-      "         \"that \"\n"
-      "         \"really, \"\n"
-      "         \"in any \"\n"
-      "         \"just \"\n"
-      "         \"world, \"\n"
-      "         \"ought to \"\n"
-      "         \"be split \"\n"
-      "         \"over \"\n"
-      "         \"multiple \"\n"
-      "         \"lines\"},\n"
+      "        56, 23,\n"
+      "        \"hello \"\n"
+      "        \"world i \"\n"
+      "        \"am a very \"\n"
+      "        \"long line \"\n"
+      "        \"that \"\n"
+      "        \"really, \"\n"
+      "        \"in any \"\n"
+      "        \"just \"\n"
+      "        \"world, \"\n"
+      "        \"ought to \"\n"
+      "        \"be split \"\n"
+      "        \"over \"\n"
+      "        \"multiple \"\n"
+      "        \"lines\"},\n"
       "    test{-1, 93463,\n"
       "         \"world\"},\n"
-      "    test{7,  5,\n"
-      "         \"!!\"   },\n"
+      "    test{7, 5,\n"
+      "         \"!!\"},\n"
       "};",
-      format("demo = std::array<struct test, 3>{test{56, 23, \"hello world "
-             "i am a very long line that really, in any just world, ought "
-             "to be split over multiple lines\"},test{-1, 93463, \"world\"},"
-             "test{7, 5, \"!!\"},};",
-             Style));
+      "demo = std::array<struct test, 3>{test{56, 23, \"hello world "
+      "i am a very long line that really, in any just world, ought "
+      "to be split over multiple lines\"},test{-1, 93463, \"world\"},"
+      "test{7, 5, \"!!\"},};",
+      Style);
+#endif
 
   // This caused a core dump by enabling Alignment in the LLVMStyle globally
-  Style = getLLVMStyleWithColumns(50);
-  Style.AlignArrayOfStructures = FormatStyle::AIAS_Left;
+  Style.ColumnLimit = 50;
   verifyFormat("static A x = {\n"
                "    {{init1, init2, init3, init4},\n"
                "     {init1, init2, init3, init4}}\n"
                "};",
                Style);
   Style.ColumnLimit = 100;
-  EXPECT_EQ(
+  // FIXME: Skip AlignArrayOfStructures if any row can't fit on a single line.
+#if 0
+  verifyFormat(
       "test demo[] = {\n"
       "    {56, 23,\n"
       "     \"hello world i am a very long line that really, in any just world"
       ", ought to be split over \"\n"
-      "     \"multiple lines\"  },\n"
+      "     \"multiple lines\"},\n"
       "    {-1, 93463, \"world\"},\n"
-      "    {7,  5,     \"!!\"   },\n"
+      "    {7, 5, \"!!\"},\n"
       "};",
-      format("test demo[] = {{56, 23, \"hello world i am a very long line "
-             "that really, in any just world, ought to be split over multiple "
-             "lines\"},{-1, 93463, \"world\"},{7, 5, \"!!\"},};",
-             Style));
+      "test demo[] = {{56, 23, \"hello world i am a very long line "
+      "that really, in any just world, ought to be split over multiple "
+      "lines\"},{-1, 93463, \"world\"},{7, 5, \"!!\"},};",
+      Style);
+#endif
 }
 
 TEST_F(FormatTest, UnderstandsPragmas) {
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D123571: [clang-for... Owen Pan via Phabricator via cfe-commits

Reply via email to