diff options
author | mydeveloperday <mydeveloperday@gmail.com> | 2021-07-01 10:45:59 +0100 |
---|---|---|
committer | mydeveloperday <mydeveloperday@gmail.com> | 2021-07-01 10:46:43 +0100 |
commit | f9937106b7171eb1f4f8914e29c2be0c36ebc46d (patch) | |
tree | e85be34a33365a22dbeafc14b6f519df790be240 /clang/unittests/Format/FormatTestCSharp.cpp | |
parent | c32186038d6c581dcf5d12e16c47d003cd6fafff (diff) | |
download | llvm-f9937106b7171eb1f4f8914e29c2be0c36ebc46d.zip llvm-f9937106b7171eb1f4f8914e29c2be0c36ebc46d.tar.gz llvm-f9937106b7171eb1f4f8914e29c2be0c36ebc46d.tar.bz2 |
[clang-format] PR50727 C# Invoke Lamda Expression indentation incorrect
https://bugs.llvm.org/show_bug.cgi?id=50727
When processing C# Lambda expression in the indentation can goes a little wrong,
resulting the the closing } being at the wrong indentation level and meaning the remaining part of the file is
incorrectly indented.
This can be a fairly common pattern for when C# wants to peform a UI action from a thread,
and it wants to invoke that action on the main thread
Reviewed By: exv, jbcoe
Differential Revision: https://reviews.llvm.org/D104388
Diffstat (limited to 'clang/unittests/Format/FormatTestCSharp.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTestCSharp.cpp | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp index 651b54c..3c99033 100644 --- a/clang/unittests/Format/FormatTestCSharp.cpp +++ b/clang/unittests/Format/FormatTestCSharp.cpp @@ -640,6 +640,122 @@ class MyClass }; })", MicrosoftStyle); + + verifyFormat("void bar()\n" + "{\n" + " Function(Val, (Action)(() =>\n" + " {\n" + " lock (mylock)\n" + " {\n" + " if (true)\n" + " {\n" + " A.Remove(item);\n" + " }\n" + " }\n" + " }));\n" + "}", + MicrosoftStyle); + + verifyFormat("void baz()\n" + "{\n" + " Function(Val, (Action)(() =>\n" + " {\n" + " using (var a = new Lock())\n" + " {\n" + " if (true)\n" + " {\n" + " A.Remove(item);\n" + " }\n" + " }\n" + " }));\n" + "}", + MicrosoftStyle); + + verifyFormat("void baz()\n" + "{\n" + " Function(Val, (Action)(() =>\n" + " {\n" + " if (true)\n" + " {\n" + " A.Remove(item);\n" + " }\n" + " }));\n" + "}", + MicrosoftStyle); + + verifyFormat("void baz()\n" + "{\n" + " Function(Val, (Action)(() =>\n" + " {\n" + " do\n" + " {\n" + " A.Remove(item);\n" + " } while (true)\n" + " }));\n" + "}", + MicrosoftStyle); + + verifyFormat("void baz()\n" + "{\n" + " Function(Val, (Action)(() =>\n" + " { A.Remove(item); }));\n" + "}", + MicrosoftStyle); + + verifyFormat("void bar()\n" + "{\n" + " Function(Val, (() =>\n" + " {\n" + " lock (mylock)\n" + " {\n" + " if (true)\n" + " {\n" + " A.Remove(item);\n" + " }\n" + " }\n" + " }));\n" + "}", + MicrosoftStyle); + verifyFormat("void bar()\n" + "{\n" + " Function((() =>\n" + " {\n" + " lock (mylock)\n" + " {\n" + " if (true)\n" + " {\n" + " A.Remove(item);\n" + " }\n" + " }\n" + " }));\n" + "}", + MicrosoftStyle); + + MicrosoftStyle.IndentWidth = 2; + verifyFormat("void bar()\n" + "{\n" + " Function((() =>\n" + " {\n" + " lock (mylock)\n" + " {\n" + " if (true)\n" + " {\n" + " A.Remove(item);\n" + " }\n" + " }\n" + " }));\n" + "}", + MicrosoftStyle); + verifyFormat("void bar() {\n" + " Function((() => {\n" + " lock (mylock) {\n" + " if (true) {\n" + " A.Remove(item);\n" + " }\n" + " }\n" + " }));\n" + "}", + GoogleStyle); } TEST_F(FormatTestCSharp, CSharpObjectInitializers) { |