From c5f562c2a448e0b757adc6b752614496f06c8e34 Mon Sep 17 00:00:00 2001 From: Manuel Klimek Date: Tue, 28 Jul 2015 15:50:24 +0000 Subject: [PATCH] Do not force linebreaks when MaxEmptyLinesToKeep is 0. Previously we would format call( p); as call( p); with MaxEmptyLinesToKeep == 0. Now we format it as: call(p); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@243429 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/TokenAnnotator.cpp | 2 +- unittests/Format/FormatTest.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 36856eaeea..bd6fde0911 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -2065,7 +2065,7 @@ static bool isAllmanBrace(const FormatToken &Tok) { bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line, const FormatToken &Right) { const FormatToken &Left = *Right.Previous; - if (Right.NewlinesBefore > 1) + if (Right.NewlinesBefore > 1 && Style.MaxEmptyLinesToKeep > 0) return true; if (Style.Language == FormatStyle::LK_JavaScript) { diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 9cb1c31b05..ce7754dd44 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -7684,6 +7684,13 @@ TEST_F(FormatTest, BreaksStringLiterals) { format("#define A \"some text other\";", AlignLeft)); } +TEST_F(FormatTest, FullyRemoveEmptyLines) { + FormatStyle NoEmptyLines = getLLVMStyleWithColumns(80); + NoEmptyLines.MaxEmptyLinesToKeep = 0; + EXPECT_EQ("int i = a(b());", + format("int i=a(\n\n b(\n\n\n )\n\n);", NoEmptyLines)); +} + TEST_F(FormatTest, BreaksStringLiteralsWithTabs) { EXPECT_EQ( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" -- 2.40.0