aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Format
diff options
context:
space:
mode:
authorOwen Pan <owenpiano@gmail.com>2024-10-17 20:21:42 -0700
committerGitHub <noreply@github.com>2024-10-17 20:21:42 -0700
commitd989c2410eb883f464c3efa472ed026dc5fd9f88 (patch)
tree6a05d82d1fae029193811cd706028d4b665ed5c4 /clang/unittests/Format
parent67f576f31d661897c5da302b8611decb7e0f9237 (diff)
downloadllvm-d989c2410eb883f464c3efa472ed026dc5fd9f88.zip
llvm-d989c2410eb883f464c3efa472ed026dc5fd9f88.tar.gz
llvm-d989c2410eb883f464c3efa472ed026dc5fd9f88.tar.bz2
[clang-format] Add RemoveEmptyLinesInUnwrappedLines option (#112325)
Fixes #111340.
Diffstat (limited to 'clang/unittests/Format')
-rw-r--r--clang/unittests/Format/ConfigParseTest.cpp1
-rw-r--r--clang/unittests/Format/FormatTest.cpp77
2 files changed, 78 insertions, 0 deletions
diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp
index 318f08c..9e85290 100644
--- a/clang/unittests/Format/ConfigParseTest.cpp
+++ b/clang/unittests/Format/ConfigParseTest.cpp
@@ -184,6 +184,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) {
CHECK_PARSE_BOOL(ObjCSpaceBeforeProtocolList);
CHECK_PARSE_BOOL(Cpp11BracedListStyle);
CHECK_PARSE_BOOL(RemoveBracesLLVM);
+ CHECK_PARSE_BOOL(RemoveEmptyLinesInUnwrappedLines);
CHECK_PARSE_BOOL(RemoveSemicolon);
CHECK_PARSE_BOOL(SkipMacroDefinitionBody);
CHECK_PARSE_BOOL(SpacesInSquareBrackets);
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 43513f1..8f4c921 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -28135,6 +28135,83 @@ TEST_F(FormatTest, BreakBinaryOperations) {
Style);
}
+TEST_F(FormatTest, RemovesEmptyLinesInUnwrappedLines) {
+ auto Style = getLLVMStyle();
+ Style.RemoveEmptyLinesInUnwrappedLines = true;
+
+ verifyFormat("int c = a + b;",
+ "int c\n"
+ "\n"
+ " = a + b;",
+ Style);
+
+ verifyFormat("enum : unsigned { AA = 0, BB } myEnum;",
+ "enum : unsigned\n"
+ "\n"
+ "{\n"
+ " AA = 0,\n"
+ " BB\n"
+ "} myEnum;",
+ Style);
+
+ verifyFormat("class B : public E {\n"
+ "private:\n"
+ "};",
+ "class B : public E\n"
+ "\n"
+ "{\n"
+ "private:\n"
+ "};",
+ Style);
+
+ verifyFormat(
+ "struct AAAAAAAAAAAAAAA test[3] = {{56, 23, \"hello\"}, {7, 5, \"!!\"}};",
+ "struct AAAAAAAAAAAAAAA test[3] = {{56,\n"
+ "\n"
+ " 23, \"hello\"},\n"
+ " {7, 5, \"!!\"}};",
+ Style);
+
+ verifyFormat("int myFunction(int aaaaaaaaaaaaa, int ccccccccccccc, int d);",
+ "int myFunction(\n"
+ "\n"
+ " int aaaaaaaaaaaaa,\n"
+ "\n"
+ " int ccccccccccccc, int d);",
+ Style);
+
+ verifyFormat("switch (e) {\n"
+ "case 1:\n"
+ " return e;\n"
+ "case 2:\n"
+ " return 2;\n"
+ "}",
+ "switch (\n"
+ "\n"
+ " e) {\n"
+ "case 1:\n"
+ " return e;\n"
+ "case 2:\n"
+ " return 2;\n"
+ "}",
+ Style);
+
+ verifyFormat("while (true) {\n"
+ "}",
+ "while (\n"
+ "\n"
+ " true) {\n"
+ "}",
+ Style);
+
+ verifyFormat("void loooonFunctionIsVeryLongButNotAsLongAsJavaTypeNames(\n"
+ " std::map<int, std::string> *outputMap);",
+ "void loooonFunctionIsVeryLongButNotAsLongAsJavaTypeNames\n"
+ "\n"
+ " (std::map<int, std::string> *outputMap);",
+ Style);
+}
+
} // namespace
} // namespace test
} // namespace format