diff options
author | Daniel Jasper <djasper@google.com> | 2015-04-07 08:20:35 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2015-04-07 08:20:35 +0000 |
commit | acf67e3ecd26c71bd2581a5b4fca4fed50d46ab8 (patch) | |
tree | beadbffc5eb1e3bf33a78310b1b317d7a8000784 /clang | |
parent | dd7adf7a185d725b34721c4de446bae77a483fe2 (diff) | |
download | bcm5719-llvm-acf67e3ecd26c71bd2581a5b4fca4fed50d46ab8.tar.gz bcm5719-llvm-acf67e3ecd26c71bd2581a5b4fca4fed50d46ab8.zip |
clang-format: Improve nested block formatting.
Before:
functionA(functionB({
int i;
int j;
}),
aaaa, bbbb, cccc);
After:
functionA(functionB({
int i;
int j;
}),
aaaa, bbbb, cccc);
llvm-svn: 234304
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 3 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 61 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTestJS.cpp | 7 |
3 files changed, 37 insertions, 34 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 3e4bf3e88a3..a2a68bd6d48 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -849,7 +849,8 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State, bool NoLineBreak = State.Stack.back().NoLineBreak || (Current.is(TT_TemplateOpener) && State.Stack.back().ContainsUnwrappedBuilder); - unsigned NestedBlockIndent = State.Stack.back().NestedBlockIndent; + unsigned NestedBlockIndent = std::max(State.Stack.back().StartOfFunctionCall, + State.Stack.back().NestedBlockIndent); State.Stack.push_back(ParenState(NewIndent, NewIndentLevel, State.Stack.back().LastSpace, AvoidBinPacking, NoLineBreak)); diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index bf98eceacd8..183fa4418be 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -3048,35 +3048,38 @@ TEST_F(FormatTest, FormatsJoinedLinesOnSubsequentRuns) { } TEST_F(FormatTest, LayoutBlockInsideParens) { - EXPECT_EQ("functionCall({ int i; });", format(" functionCall ( {int i;} );")); - EXPECT_EQ("functionCall({\n" - " int i;\n" - " int j;\n" - "});", - format(" functionCall ( {int i;int j;} );")); - EXPECT_EQ("functionCall({\n" - " int i;\n" - " int j;\n" - "}, aaaa, bbbb, cccc);", - format(" functionCall ( {int i;int j;}, aaaa, bbbb, cccc);")); - EXPECT_EQ("functionCall(\n" - " {\n" - " int i;\n" - " int j;\n" - " },\n" - " aaaa, bbbb, // comment\n" - " cccc);", - format(" functionCall ( {int i;int j;}, aaaa, bbbb, // comment\n" - "cccc);")); - EXPECT_EQ("functionCall(aaaa, bbbb, { int i; });", - format(" functionCall (aaaa, bbbb, {int i;});")); - EXPECT_EQ("functionCall(aaaa, bbbb, {\n" - " int i;\n" - " int j;\n" - "});", - format(" functionCall (aaaa, bbbb, {int i;int j;});")); - EXPECT_EQ("functionCall(aaaa, bbbb, { int i; });", - format(" functionCall (aaaa, bbbb, {int i;});")); + verifyFormat("functionCall({ int i; });"); + verifyFormat("functionCall({\n" + " int i;\n" + " int j;\n" + "});"); + verifyFormat("functionCall({\n" + " int i;\n" + " int j;\n" + "}, aaaa, bbbb, cccc);"); + verifyFormat("functionA(functionB({\n" + " int i;\n" + " int j;\n" + " }),\n" + " aaaa, bbbb, cccc);"); + verifyFormat("functionCall(\n" + " {\n" + " int i;\n" + " int j;\n" + " },\n" + " aaaa, bbbb, // comment\n" + " cccc);"); + verifyFormat("functionA(functionB({\n" + " int i;\n" + " int j;\n" + " }),\n" + " aaaa, bbbb, // comment\n" + " cccc);"); + verifyFormat("functionCall(aaaa, bbbb, { int i; });"); + verifyFormat("functionCall(aaaa, bbbb, {\n" + " int i;\n" + " int j;\n" + "});"); verifyFormat( "Aaa(\n" // FIXME: There shouldn't be a linebreak here. " {\n" diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 35727eb686b..76c2730960e 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -408,10 +408,9 @@ TEST_F(FormatTestJS, MultipleFunctionLiterals) { " body();\n" " });"); - // FIXME: This is bad, but it used to be formatted correctly by accident. - verifyFormat("getSomeLongPromise().then(function(value) {\n" - " body();\n" - "}).thenCatch(function(error) { body(); });"); + verifyFormat("getSomeLongPromise()\n" + " .then(function(value) { body(); })\n" + " .thenCatch(function(error) { body(); });"); } TEST_F(FormatTestJS, ReturnStatements) { |