diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -262,6 +262,88 @@ "}", getGoogleStyle())); + auto GoogleWrapBraceAfterNamespace = getGoogleStyle(); + GoogleWrapBraceAfterNamespace.BreakBeforeBraces = FormatStyle::BS_Custom; + GoogleWrapBraceAfterNamespace.BraceWrapping.AfterNamespace = true; + EXPECT_EQ("namespace N\n" + "{\n" + "\n" + "int i;\n" + "}", + format("namespace N\n" + "{\n" + "\n" + "\n" + "int i;\n" + "}", + GoogleWrapBraceAfterNamespace)); + EXPECT_EQ("/* something */ namespace N\n" + "{\n" + "\n" + "int i;\n" + "}", + format("/* something */ namespace N {\n" + "\n" + "\n" + "int i;\n" + "}", + GoogleWrapBraceAfterNamespace)); + EXPECT_EQ("inline namespace N\n" + "{\n" + "\n" + "int i;\n" + "}", + format("inline namespace N\n" + "{\n" + "\n" + "\n" + "int i;\n" + "}", + GoogleWrapBraceAfterNamespace)); + EXPECT_EQ("/* something */ inline namespace N\n" + "{\n" + "\n" + "int i;\n" + "}", + format("/* something */ inline namespace N\n" + "{\n" + "\n" + "int i;\n" + "}", + GoogleWrapBraceAfterNamespace)); + EXPECT_EQ("export namespace N\n" + "{\n" + "\n" + "int i;\n" + "}", + format("export namespace N\n" + "{\n" + "\n" + "int i;\n" + "}", + GoogleWrapBraceAfterNamespace)); + EXPECT_EQ("namespace a\n" + "{\n" + "namespace b\n" + "{\n" + "\n" + "class AA {};\n" + "\n" + "} // namespace b\n" + "} // namespace a\n", + format("namespace a\n" + "{\n" + "namespace b\n" + "{\n" + "\n" + "\n" + "class AA {};\n" + "\n" + "\n" + "}\n" + "}\n", + GoogleWrapBraceAfterNamespace)); + // ...but do keep inlining and removing empty lines for non-block extern "C" // functions. verifyFormat("extern \"C\" int f() { return 42; }", getGoogleStyle());