clang-format: Keep empty lines and format 1-line nested blocks.
Let clang-format consistently keep up to one empty line (configured via
FormatStyle::MaxEmptyLinesToKeep) in nested blocks, e.g. lambdas. Also,
actually format single statements in nested blocks.
Before:
DEBUG({ int i; });
DEBUG({
int i;
// an empty line here would just be removed.
int j;
});
After:
DEBUG({ int i; });
DEBUG({
int i;
int j;
});
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@190278 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 10a6316..ef7d63c 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -2276,6 +2276,19 @@
" somethingElse();\n"
"});",
getLLVMStyleWithColumns(29)));
+ EXPECT_EQ("DEBUG({ int i; });", format("DEBUG({ int i; });"));
+ EXPECT_EQ("DEBUG({\n"
+ " int i;\n"
+ "\n"
+ " // comment\n"
+ " int j;\n"
+ "});",
+ format("DEBUG({\n"
+ " int i;\n"
+ "\n"
+ " // comment\n"
+ " int j;\n"
+ "});"));
}
TEST_F(FormatTest, PutEmptyBlocksIntoOneLine) {
@@ -6395,7 +6408,7 @@
verifyFormat("auto c = { [&a, &a, a] {\n"
" [=, a, b, &c] { return b++; }();\n"
"} }\n");
- verifyFormat("auto c = { [&a, &a, a] { [=, a, b, &c] { }(); } }\n");
+ verifyFormat("auto c = { [&a, &a, a] { [=, a, b, &c] {}(); } }\n");
verifyFormat("void f() {\n"
" other(x.begin(), x.end(), [&](int, int) { return 1; });\n"
"}\n");