[clang] [clang-format] Add `AllowShortNamespacesOnASingleLine` option (PR #105597)

Galen Elias via cfe-commits cfe-commits at lists.llvm.org
Sun Dec 29 21:16:59 PST 2024


================
@@ -4504,6 +4504,16 @@ TEST_F(FormatTest, FormatsCompactNamespaces) {
                "} // namespace bbbbbb\n"
                "} // namespace aaaaaa",
                Style);
+
+  verifyFormat("namespace a { namespace b { namespace c {\n"
+               "}}} // namespace a::b::c",
+               Style);
+
+  verifyFormat("namespace a { namespace b {\n"
+               "namespace cc {\n"
+               "}}} // namespace a::b::cc",
----------------
galenelias wrote:

I'll defer to your judgement, but I personally think it is helpful to test each side of these edge cases around line wrapping.  Having a test to verify things don't get wrapped at 'X' columns, but then having tests cases which are like X/2 long doesn't really validate the precision of the width calculations, as evidenced by this bug, and means we might be wrapping too aggressively, and won't catch that via any existing tests.  If we only verify lines significantly shorter or longer than the ColumnLimit then we it is easy for mistakes in the logic to sneak through.

https://github.com/llvm/llvm-project/pull/105597


More information about the cfe-commits mailing list