]> granicus.if.org Git - clang/commitdiff
clang-format: Don't force line breaks in ObjC calls with ColumnLimit 0.
authorDaniel Jasper <djasper@google.com>
Mon, 19 May 2014 08:06:34 +0000 (08:06 +0000)
committerDaniel Jasper <djasper@google.com>
Mon, 19 May 2014 08:06:34 +0000 (08:06 +0000)
Before:
  [self.x a:b c:d];

Got reformatted toi (with ColumnLimit set to 0):
  [self.x a:b
          c:d];

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209114 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/ContinuationIndenter.cpp
unittests/Format/FormatTest.cpp

index 77d981b8f5ed44961d7ad0ebd4fb6e0b1135088a..63bb5e9918b7c51e7c698ca3ec8a4bd9d464594a 100644 (file)
@@ -739,7 +739,7 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State,
                            Current.PackingKind == PPK_Inconclusive)));
       // If this '[' opens an ObjC call, determine whether all parameters fit
       // into one line and put one per line if they don't.
-      if (Current.Type == TT_ObjCMethodExpr &&
+      if (Current.Type == TT_ObjCMethodExpr && Style.ColumnLimit != 0 &&
           getLengthToMatchingParen(Current) + State.Column >
               getColumnLimit(State))
         BreakBeforeParameter = true;
index 7ac6cb49873eb12666ce047d79f5ef65ece63b55..e5a94cf1e94287cff524d986cbb46995e7649c75 100644 (file)
@@ -8547,12 +8547,16 @@ TEST_F(FormatTest, FormatsWithWebKitStyle) {
                    Style));
 
   // Keep empty and one-element array literals on a single line.
-  verifyFormat("NSArray* a = [[NSArray alloc] initWithArray:@[]\n"
-               "                                  copyItems:YES];",
-               Style);
-  verifyFormat("NSArray* a = [[NSArray alloc] initWithArray:@[ @\"a\" ]\n"
-               "                                  copyItems:YES];",
-               Style);
+  EXPECT_EQ("NSArray* a = [[NSArray alloc] initWithArray:@[]\n"
+            "                                  copyItems:YES];",
+            format("NSArray*a=[[NSArray alloc] initWithArray:@[]\n"
+                   "copyItems:YES];",
+                   Style));
+  EXPECT_EQ("NSArray* a = [[NSArray alloc] initWithArray:@[ @\"a\" ]\n"
+            "                                  copyItems:YES];",
+            format("NSArray*a=[[NSArray alloc]initWithArray:@[ @\"a\" ]\n"
+                   "             copyItems:YES];",
+                   Style));
   EXPECT_EQ("NSArray* a = [[NSArray alloc] initWithArray:@[\n"
             "                                               @\"a\",\n"
             "                                               @\"a\"\n"
@@ -8564,10 +8568,19 @@ TEST_F(FormatTest, FormatsWithWebKitStyle) {
                    "     ]\n"
                    "       copyItems:YES];",
                    Style));
-  verifyFormat(
+  EXPECT_EQ(
       "NSArray* a = [[NSArray alloc] initWithArray:@[ @\"a\", @\"a\" ]\n"
       "                                  copyItems:YES];",
-      Style);
+      format("NSArray* a = [[NSArray alloc] initWithArray:@[ @\"a\", @\"a\" ]\n"
+             "   copyItems:YES];",
+             Style));
+
+  verifyFormat("[self.a b:c c:d];", Style);
+  EXPECT_EQ("[self.a b:c\n"
+            "        c:d];",
+            format("[self.a b:c\n"
+                   "c:d];",
+                   Style));
 }
 
 TEST_F(FormatTest, FormatsLambdas) {