[clang-format] Fixed line merging of more than two lines
authorCameron Desrochers <cameron@moodycamel.com>
Tue, 15 Nov 2016 15:07:07 +0000 (15:07 +0000)
committerCameron Desrochers <cameron@moodycamel.com>
Tue, 15 Nov 2016 15:07:07 +0000 (15:07 +0000)
Differential Revision: https://reviews.llvm.org/D19063

llvm-svn: 286973

clang/lib/Format/UnwrappedLineFormatter.cpp
clang/unittests/Format/FormatTest.cpp

index 07bfe3e..d7f1c42 100644 (file)
@@ -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;
   }
index 9ce888d..e8e36ab 100644 (file)
@@ -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) {