[PATCH] D104044: [clang-format] Fix the issue of no empty line after namespace
Darwin Xu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 10 09:47:28 PDT 2021
darwin created this revision.
darwin added a project: clang-format.
darwin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
This a bug fix of https://bugs.llvm.org/show_bug.cgi?id=50116
First revision only contains the change of the test code. I would like to have someone review the expected result. If it is OK. Then I can fix it.
Here is the output of the test case without fixing yet:
darwin at Darwins-iMac build % /Volumes/silo/Projects/open-source/llvm-project/build/tools/clang/unittests/Format/./FormatTests --gtest_filter=FormatTest.RemovesEmptyLines
Note: Google Test filter = FormatTest.RemovesEmptyLines
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from FormatTest
[ RUN ] FormatTest.RemovesEmptyLines
/Volumes/silo/Projects/open-source/llvm-project/clang/unittests/Format/FormatTest.cpp:279: Failure
Expected equality of these values:
"namespace N\n" "{\n" "\n" "int i;\n" "}"
Which is: "namespace N\n{\n\nint i;\n}"
format("namespace N\n" "{\n" "\n" "\n" "int i;\n" "}", GoogleWrapBraceAfterNamespace)
Which is: "namespace N\n{\nint i;\n}"
With diff:
@@ -1,5 @@
namespace N
{
-
int i;
}
/Volumes/silo/Projects/open-source/llvm-project/clang/unittests/Format/FormatTest.cpp:290: Failure
Expected equality of these values:
"/* something */ namespace N\n" "{\n" "\n" "int i;\n" "}"
Which is: "/* something */ namespace N\n{\n\nint i;\n}"
format("/* something */ namespace N {\n" "\n" "\n" "int i;\n" "}", GoogleWrapBraceAfterNamespace)
Which is: "/* something */ namespace N\n{\nint i;\n}"
With diff:
@@ -1,5 @@
/* something */ namespace N
{
-
int i;
}
/Volumes/silo/Projects/open-source/llvm-project/clang/unittests/Format/FormatTest.cpp:302: Failure
Expected equality of these values:
"inline namespace N\n" "{\n" "\n" "int i;\n" "}"
Which is: "inline namespace N\n{\n\nint i;\n}"
format("inline namespace N\n" "{\n" "\n" "\n" "int i;\n" "}", GoogleWrapBraceAfterNamespace)
Which is: "inline namespace N\n{\nint i;\n}"
With diff:
@@ -1,5 @@
inline namespace N
{
-
int i;
}
/Volumes/silo/Projects/open-source/llvm-project/clang/unittests/Format/FormatTest.cpp:313: Failure
Expected equality of these values:
"/* something */ inline namespace N\n" "{\n" "\n" "int i;\n" "}"
Which is: "/* something */ inline namespace N\n{\n\nint i;\n}"
format("/* something */ inline namespace N\n" "{\n" "\n" "int i;\n" "}", GoogleWrapBraceAfterNamespace)
Which is: "/* something */ inline namespace N\n{\nint i;\n}"
With diff:
@@ -1,5 @@
/* something */ inline namespace N
{
-
int i;
}
/Volumes/silo/Projects/open-source/llvm-project/clang/unittests/Format/FormatTest.cpp:324: Failure
Expected equality of these values:
"export namespace N\n" "{\n" "\n" "int i;\n" "}"
Which is: "export namespace N\n{\n\nint i;\n}"
format("export namespace N\n" "{\n" "\n" "int i;\n" "}", GoogleWrapBraceAfterNamespace)
Which is: "export namespace N\n{\nint i;\n}"
With diff:
@@ -1,5 @@
export namespace N
{
-
int i;
}
/Volumes/silo/Projects/open-source/llvm-project/clang/unittests/Format/FormatTest.cpp:345: Failure
Expected equality of these values:
"namespace a\n" "{\n" "namespace b\n" "{\n" "\n" "class AA {};\n" "\n" "} // namespace b\n" "} // namespace a\n"
Which is: "namespace a\n{\nnamespace b\n{\n\nclass 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)
Which is: "namespace a\n{\nnamespace b\n{\nclass AA {};\n\n} // namespace b\n} // namespace a\n"
With diff:
@@ -3,5 @@
namespace b
{
-
class AA {};
[ FAILED ] FormatTest.RemovesEmptyLines (41 ms)
[----------] 1 test from FormatTest (41 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (41 ms total)
[ PASSED ] 0 tests.
[ FAILED ] 1 test, listed below:
[ FAILED ] FormatTest.RemovesEmptyLines
1 FAILED TEST
darwin at Darwins-iMac build %
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D104044
Files:
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ 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());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104044.351203.patch
Type: text/x-patch
Size: 2955 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210610/880ff3fd/attachment.bin>
More information about the cfe-commits
mailing list