[clang] [clang-format] Add new option: WrapNamespaceBodyWithNewlines (PR #106145)
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 30 17:26:37 PST 2024
================
@@ -28104,6 +28104,138 @@ TEST_F(FormatTest, BreakBinaryOperations) {
Style);
}
+TEST_F(FormatTest, WrapNamespaceBodyWithEmptyLinesNever) {
+ auto Style = getLLVMStyle();
+ Style.FixNamespaceComments = false;
+ Style.WrapNamespaceBodyWithEmptyLines = FormatStyle::WNBWELS_Never;
+
+ // Empty namespace.
+ verifyFormat("namespace N {}", Style);
+
+ // Single namespace.
+ verifyFormat("namespace N {\n"
+ "int f1(int a) { return 2 * a; }\n"
+ "}",
+ Style);
+
+ // Nested namespace.
+ verifyFormat("namespace N1 {\n"
+ "namespace N2 {\n"
+ "int a = 1;\n"
+ "}\n"
+ "}",
+ Style);
+
+ Style.CompactNamespaces = true;
+
+ verifyFormat("namespace N1 { namespace N2 {\n"
+ "int a = 1;\n"
+ "}}",
+ Style);
+
+ // Removing empty lines.
+ verifyFormat("namespace N {\n"
+ "\n"
+ "int a = 1;\n"
+ "\n"
----------------
owenca wrote:
```suggestion
"int a = 1;\n"
```
https://github.com/llvm/llvm-project/pull/106145
More information about the cfe-commits
mailing list