r209114 - clang-format: Don't force line breaks in ObjC calls with ColumnLimit 0.
Daniel Jasper
djasper at google.com
Mon May 19 01:06:34 PDT 2014
Author: djasper
Date: Mon May 19 03:06:34 2014
New Revision: 209114
URL: http://llvm.org/viewvc/llvm-project?rev=209114&view=rev
Log:
clang-format: Don't force line breaks in ObjC calls with ColumnLimit 0.
Before:
[self.x a:b c:d];
Got reformatted toi (with ColumnLimit set to 0):
[self.x a:b
c:d];
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=209114&r1=209113&r2=209114&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Mon May 19 03:06:34 2014
@@ -739,7 +739,7 @@ unsigned ContinuationIndenter::moveState
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;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=209114&r1=209113&r2=209114&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon May 19 03:06:34 2014
@@ -8547,12 +8547,16 @@ TEST_F(FormatTest, FormatsWithWebKitStyl
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, FormatsWithWebKitStyl
" ]\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) {
More information about the cfe-commits
mailing list