aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Format/FormatTestCSharp.cpp
diff options
context:
space:
mode:
authorMarek Kurdej <marek.kurdej+llvm.org@gmail.com>2022-01-14 21:51:06 +0100
committerMarek Kurdej <marek.kurdej+llvm.org@gmail.com>2022-01-14 21:57:02 +0100
commit7af11989be21df00ad6a510a831ea2425e48fa90 (patch)
treee2a08f42bd98f3e9e84e861797700052f79fbb7c /clang/unittests/Format/FormatTestCSharp.cpp
parente0841f692017cad1edf866e9c6907bffda5ea02c (diff)
downloadllvm-7af11989be21df00ad6a510a831ea2425e48fa90.zip
llvm-7af11989be21df00ad6a510a831ea2425e48fa90.tar.gz
llvm-7af11989be21df00ad6a510a831ea2425e48fa90.tar.bz2
[clang-format] Fix short functions being considered as inline inside an indented namespace.
Fixes https://github.com/llvm/llvm-project/issues/24784. With config: ``` AllowShortFunctionsOnASingleLine: Inline NamespaceIndentation: All ``` The code: ``` namespace Test { void f() { return; } } ``` was incorrectly formatted to: ``` namespace Test { void f() { return; } } ``` since the function `f` was considered being inside a class/struct/record. That's because the check was simplistic and only checked for a non-zero indentation level of the line starting `f`. Reviewed By: MyDeveloperDay, HazardyKnusperkeks Differential Revision: https://reviews.llvm.org/D117142
Diffstat (limited to 'clang/unittests/Format/FormatTestCSharp.cpp')
-rw-r--r--clang/unittests/Format/FormatTestCSharp.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp
index 2cfec61..26c62c1 100644
--- a/clang/unittests/Format/FormatTestCSharp.cpp
+++ b/clang/unittests/Format/FormatTestCSharp.cpp
@@ -1518,5 +1518,32 @@ TEST_F(FormatTestCSharp, EmptyShortBlock) {
Style);
}
+TEST_F(FormatTestCSharp, ShortFunctions) {
+ FormatStyle Style = getLLVMStyle(FormatStyle::LK_CSharp);
+ Style.NamespaceIndentation = FormatStyle::NI_All;
+ Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline;
+ verifyFormat("interface Interface {\n"
+ " void f() { return; }\n"
+ "};",
+ Style);
+ verifyFormat("public interface Interface {\n"
+ " void f() { return; }\n"
+ "};",
+ Style);
+ verifyFormat("namespace {\n"
+ " void f() {\n"
+ " return;\n"
+ " }\n"
+ "};",
+ Style);
+ // "union" is not a keyword in C#.
+ verifyFormat("namespace union {\n"
+ " void f() {\n"
+ " return;\n"
+ " }\n"
+ "};",
+ Style);
+}
+
} // namespace format
} // end namespace clang