Several improvements to the formatting of static initializers.

1. Never avoid bin packing in static initializers as this can
   lead to terrible results.
2. If an element has to be broken over multiple lines, break after
   the following comma.

This should be a step forward, but there are still many cases
especially with nested static initializers that we handle badly.
More patches will follow.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@174061 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 9735898..5ffd351 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -506,13 +506,20 @@
                "                         bbbbbbbbbbb, ccccccccccc };");
   verifyGoogleFormat(
       "static SomeType type = { aaaaaaaaaaa,  // comment for aa...\n"
-      "                         bbbbbbbbbbb,\n"
-      "                         ccccccccccc };");
+      "                         bbbbbbbbbbb, ccccccccccc };");
   verifyGoogleFormat("static SomeType type = { aaaaaaaaaaa,\n"
                      "                         // comment for bb....\n"
-                     "                         bbbbbbbbbbb,\n"
-                     "                         ccccccccccc };");
+                     "                         bbbbbbbbbbb, ccccccccccc };");
 
+  verifyFormat("S s = { { a, b, c },   // Group #1\n"
+               "        { d, e, f },   // Group #2\n"
+               "        { g, h, i } }; // Group #3");
+  verifyFormat("S s = { { // Group #1\n"
+               "          a, b, c },\n"
+               "        { // Group #2\n"
+               "          d, e, f },\n"
+               "        { // Group #3\n"
+               "          g, h, i } };");
 }
 
 //===----------------------------------------------------------------------===//
@@ -649,6 +656,12 @@
       "static SomeClass = { a, b, c, d, e, f, g, h, i, j,\n"
       "                     looooooooooooooooooooooooooooooooooongname,\n"
       "                     looooooooooooooooooooooooooooooong };");
+  // Allow bin-packing in static initializers as this would often lead to
+  // terrible results, e.g.:
+  verifyGoogleFormat(
+      "static SomeClass = { a, b, c, d, e, f, g, h, i, j,\n"
+      "                     looooooooooooooooooooooooooooooooooongname,\n"
+      "                     looooooooooooooooooooooooooooooong };");
 }
 
 TEST_F(FormatTest, NestedStaticInitializers) {
@@ -657,7 +670,12 @@
       "static A x = { { { init1, init2, init3, init4 },\n"
       "                 { init1, init2, init3, init4 } } };");
 
-  // FIXME: Fix this in general and verify that it works in LLVM style again.
+  verifyFormat(
+      "somes Status::global_reps[3] = {\n"
+      "  { kGlobalRef, OK_CODE, NULL, NULL, NULL },\n"
+      "  { kGlobalRef, CANCELLED_CODE, NULL, NULL, NULL },\n"
+      "  { kGlobalRef, UNKNOWN_CODE, NULL, NULL, NULL }\n"
+      "};");
   verifyGoogleFormat(
       "somes Status::global_reps[3] = {\n"
       "  { kGlobalRef, OK_CODE, NULL, NULL, NULL },\n"
@@ -669,6 +687,13 @@
       "                   { rect.fRight - rect.fLeft, rect.fBottom - rect.fTop"
       " } };");
 
+  verifyFormat(
+      "SomeArrayOfSomeType a = { { { 1, 2, 3 }, { 1, 2, 3 },\n"
+      "                            { 111111111111111111111111111111,\n"
+      "                              222222222222222222222222222222,\n"
+      "                              333333333333333333333333333333 },\n"
+      "                            { 1, 2, 3 }, { 1, 2, 3 } } };");
+
   // FIXME: We might at some point want to handle this similar to parameter
   // lists, where we have an option to put each on a single line.
   verifyFormat("struct {\n"