summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Format/FormatTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r--clang/unittests/Format/FormatTest.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 2dea38f7908..80072b5ab57 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -192,6 +192,53 @@ TEST_F(FormatTest, RemovesWhitespaceWhenTriggeredOnEmptyLine) {
format("int a;\n \n\n int b;", 9, 0, getLLVMStyle()));
}
+TEST_F(FormatTest, RemovesEmptyLines) {
+ EXPECT_EQ("class C {\n"
+ " int i;\n"
+ "};",
+ format("class C {\n"
+ " int i;\n"
+ "\n"
+ "};"));
+
+ // Don't remove empty lines in more complex control statements.
+ EXPECT_EQ("void f() {\n"
+ " if (a) {\n"
+ " f();\n"
+ "\n"
+ " } else if (b) {\n"
+ " f();\n"
+ " }\n"
+ "}",
+ format("void f() {\n"
+ " if (a) {\n"
+ " f();\n"
+ "\n"
+ " } else if (b) {\n"
+ " f();\n"
+ "\n"
+ " }\n"
+ "\n"
+ "}"));
+
+ // FIXME: This is slightly inconsistent.
+ EXPECT_EQ("namespace {\n"
+ "int i;\n"
+ "}",
+ format("namespace {\n"
+ "int i;\n"
+ "\n"
+ "}"));
+ EXPECT_EQ("namespace {\n"
+ "int i;\n"
+ "\n"
+ "} // namespace",
+ format("namespace {\n"
+ "int i;\n"
+ "\n"
+ "} // namespace"));
+}
+
TEST_F(FormatTest, ReformatsMovedLines) {
EXPECT_EQ(
"template <typename T> T *getFETokenInfo() const {\n"
OpenPOWER on IntegriCloud