From: Cameron Desrochers Date: Tue, 15 Nov 2016 15:07:07 +0000 (+0000) Subject: [clang-format] Fixed line merging of more than two lines X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8c6b7e858a5e207171f47a35f591acfc15950cea;p=clang [clang-format] Fixed line merging of more than two lines Differential Revision: https://reviews.llvm.org/D19063 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@286973 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/UnwrappedLineFormatter.cpp b/lib/Format/UnwrappedLineFormatter.cpp index 07bfe3e7ac..d7f1c4232d 100644 --- a/lib/Format/UnwrappedLineFormatter.cpp +++ b/lib/Format/UnwrappedLineFormatter.cpp @@ -151,7 +151,7 @@ public: MergedLines = 0; if (!DryRun) for (unsigned i = 0; i < MergedLines; ++i) - join(*Next[i], *Next[i + 1]); + join(*Next[0], *Next[i + 1]); Next = Next + MergedLines + 1; return Current; } diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 9ce888d548..e8e36abe68 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -276,6 +276,30 @@ TEST_F(FormatTest, RemovesEmptyLines) { "int i;\n" "\n" "} // namespace")); + + FormatStyle Style = getLLVMStyle(); + Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All; + Style.MaxEmptyLinesToKeep = 2; + Style.BreakBeforeBraces = FormatStyle::BS_Custom; + Style.BraceWrapping.AfterClass = true; + Style.BraceWrapping.AfterFunction = true; + Style.KeepEmptyLinesAtTheStartOfBlocks = false; + + EXPECT_EQ("class Foo\n" + "{\n" + " Foo() {}\n" + "\n" + " void funk() {}\n" + "};", + format("class Foo\n" + "{\n" + " Foo()\n" + " {\n" + " }\n" + "\n" + " void funk() {}\n" + "};", + Style)); } TEST_F(FormatTest, RecognizesBinaryOperatorKeywords) {