From 8d29f537f5348d03c9d74e0d99c3e021f37f382f Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Mon, 14 Apr 2014 12:11:07 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@206162 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/ContinuationIndenter.cpp | 2 +- unittests/Format/FormatTest.cpp | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index 43997f9957..0ad8c1eb41 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -142,7 +142,7 @@ bool ContinuationIndenter::mustBreak(const LineState &State) { 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 && diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 7bae21b89e..f829dccbe9 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -8156,12 +8156,21 @@ TEST_F(FormatTest, FormatsWithWebKitStyle) { 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) { -- 2.40.0