r243429 - Do not force linebreaks when MaxEmptyLinesToKeep is 0.
Manuel Klimek
klimek at google.com
Tue Jul 28 08:50:24 PDT 2015
Author: klimek
Date: Tue Jul 28 10:50:24 2015
New Revision: 243429
URL: http://llvm.org/viewvc/llvm-project?rev=243429&view=rev
Log:
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);
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=243429&r1=243428&r2=243429&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Jul 28 10:50:24 2015
@@ -2065,7 +2065,7 @@ static bool isAllmanBrace(const FormatTo
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) {
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=243429&r1=243428&r2=243429&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Tue Jul 28 10:50:24 2015
@@ -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"
More information about the cfe-commits
mailing list