r206162 - clang-format: Improve array literal formatting fix in r206161.

Daniel Jasper djasper at google.com
Mon Apr 14 05:11:07 PDT 2014


Author: djasper
Date: Mon Apr 14 07:11:07 2014
New Revision: 206162

URL: http://llvm.org/viewvc/llvm-project?rev=206162&view=rev
Log:
clang-format: Improve array literal formatting fix in r206161.

Instead of choosing based on the number of elements, simply respect the
user's choice of where to wrap array literals.

Modified:
    cfe/trunk/lib/Format/ContinuationIndenter.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=206162&r1=206161&r2=206162&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Mon Apr 14 07:11:07 2014
@@ -142,7 +142,7 @@ bool ContinuationIndenter::mustBreak(con
     return true;
   if (((Previous.Type == TT_DictLiteral && Previous.is(tok::l_brace)) ||
        Previous.Type == TT_ArrayInitializerLSquare) &&
-      (Style.ColumnLimit > 0 || Previous.ParameterCount > 1) &&
+      Style.ColumnLimit > 0 &&
       getLengthToMatchingParen(Previous) + State.Column > getColumnLimit(State))
     return true;
   if (Current.Type == TT_CtorInitializerColon &&

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=206162&r1=206161&r2=206162&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Apr 14 07:11:07 2014
@@ -8156,12 +8156,21 @@ TEST_F(FormatTest, FormatsWithWebKitStyl
   verifyFormat("NSArray* a = [[NSArray alloc] initWithArray:@[ @\"a\" ]\n"
                "                                  copyItems:YES];",
                Style);
-  verifyFormat("NSArray* a = [[NSArray alloc] initWithArray:@[\n"
-               "                                               @\"a\",\n"
-               "                                               @\"a\"\n"
-               "                                            ]\n"
-               "                                  copyItems:YES];",
-               Style);
+  EXPECT_EQ("NSArray* a = [[NSArray alloc] initWithArray:@[\n"
+            "                                               @\"a\",\n"
+            "                                               @\"a\"\n"
+            "                                            ]\n"
+            "                                  copyItems:YES];",
+            format("NSArray* a = [[NSArray alloc] initWithArray:@[\n"
+                   "     @\"a\",\n"
+                   "     @\"a\"\n"
+                   "     ]\n"
+                   "       copyItems:YES];",
+                   Style));
+  verifyFormat(
+      "NSArray* a = [[NSArray alloc] initWithArray:@[ @\"a\", @\"a\" ]\n"
+      "                                  copyItems:YES];",
+      Style);
 }
 
 TEST_F(FormatTest, FormatsLambdas) {





More information about the cfe-commits mailing list