[clang] 6e58d14 - [clang-format] [PR52228] clang-format csharp inconsistant nested namespace indentation
via cfe-commits
cfe-commits at lists.llvm.org
Sat Nov 13 06:14:12 PST 2021
Author: mydeveloperday
Date: 2021-11-13T14:13:51Z
New Revision: 6e58d14e5b012215007ae375006f5e847a9b61bc
URL: https://github.com/llvm/llvm-project/commit/6e58d14e5b012215007ae375006f5e847a9b61bc
DIFF: https://github.com/llvm/llvm-project/commit/6e58d14e5b012215007ae375006f5e847a9b61bc.diff
LOG: [clang-format] [PR52228] clang-format csharp inconsistant nested namespace indentation
https://bugs.llvm.org/show_bug.cgi?id=52228
For multilevel namespaces in C# get their content indented when NamespaceIndentation: None is set, where as single level namespaces are formatted correctly.
Reviewed By: HazardyKnusperkeks, jbcoe
Differential Revision: https://reviews.llvm.org/D112887
Added:
Modified:
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTestCSharp.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index ae38e387f1df2..5ed25f6e27982 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -2216,7 +2216,7 @@ void UnwrappedLineParser::parseNamespace() {
parseParens();
} else {
while (FormatTok->isOneOf(tok::identifier, tok::coloncolon, tok::kw_inline,
- tok::l_square)) {
+ tok::l_square, tok::period)) {
if (FormatTok->is(tok::l_square))
parseSquare();
else
diff --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp
index b7ea8d3672a2a..bb91cd6cf2b06 100644
--- a/clang/unittests/Format/FormatTestCSharp.cpp
+++ b/clang/unittests/Format/FormatTestCSharp.cpp
@@ -1314,5 +1314,60 @@ TEST_F(FormatTestCSharp, CSharpAfterClass) {
Style);
}
+TEST_F(FormatTestCSharp, NamespaceIndentation) {
+ FormatStyle Style = getMicrosoftStyle(FormatStyle::LK_CSharp);
+ Style.NamespaceIndentation = FormatStyle::NI_None;
+
+ verifyFormat("namespace A\n"
+ "{\n"
+ "public interface Name1\n"
+ "{\n"
+ "}\n"
+ "}\n",
+ Style);
+
+ verifyFormat("namespace A.B\n"
+ "{\n"
+ "public interface Name1\n"
+ "{\n"
+ "}\n"
+ "}\n",
+ Style);
+
+ Style.NamespaceIndentation = FormatStyle::NI_Inner;
+
+ verifyFormat("namespace A\n"
+ "{\n"
+ "namespace B\n"
+ "{\n"
+ " public interface Name1\n"
+ " {\n"
+ " }\n"
+ "}\n"
+ "}\n",
+ Style);
+
+ Style.NamespaceIndentation = FormatStyle::NI_All;
+
+ verifyFormat("namespace A.B\n"
+ "{\n"
+ " public interface Name1\n"
+ " {\n"
+ " }\n"
+ "}\n",
+ Style);
+
+ verifyFormat("namespace A\n"
+ "{\n"
+ " namespace B\n"
+ " {\n"
+ " public interface Name1\n"
+ " {\n"
+ " }\n"
+ " }\n"
+ "}\n",
+ Style);
+}
+
} // namespace format
} // end namespace clang
More information about the cfe-commits
mailing list