[clang] clang-format: Add "AllowShortNamespacesOnASingleLine" option (PR #105597)
Owen Pan via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 6 23:46:30 PDT 2024
================
@@ -27981,6 +27981,118 @@ TEST_F(FormatTest, BreakBinaryOperations) {
Style);
}
+TEST_F(FormatTest, ShortNamespacesOption) {
+ FormatStyle Style = getLLVMStyle();
+ Style.AllowShortNamespacesOnASingleLine = true;
+ Style.FixNamespaceComments = false;
+
+ // Basic functionality.
+ verifyFormat("namespace foo { class bar; }", Style);
+ verifyFormat("namespace foo::bar { class baz; }", Style);
+ verifyFormat("namespace { class bar; }", Style);
+ verifyFormat("namespace foo {\n"
+ "class bar;\n"
+ "class baz;\n"
+ "}",
+ Style);
+
+ // Trailing comments prevent merging.
+ verifyFormat("namespace foo {\n"
+ "namespace baz { class qux; } // comment\n"
+ "}",
+ Style);
+
+ // Make sure code doesn't walk to far on unbalanced code.
----------------
owenca wrote:
```suggestion
// Make sure code doesn't walk too far on unbalanced code.
```
https://github.com/llvm/llvm-project/pull/105597
More information about the cfe-commits
mailing list