diff options
author | Peter Stys <peterstys@google.com> | 2021-12-17 10:26:29 -0800 |
---|---|---|
committer | Owen Pan <owenpiano@gmail.com> | 2021-12-17 10:42:15 -0800 |
commit | 163c13fed9f68c31a14b3d2409b994909f0600bb (patch) | |
tree | 940c7bbc6334c27817b9281ec499d85f87524978 /clang/unittests/Format/FormatTestCSharp.cpp | |
parent | 2fefb66e53f7824c89b9524469a2d7c93f8d15eb (diff) | |
download | llvm-163c13fed9f68c31a14b3d2409b994909f0600bb.zip llvm-163c13fed9f68c31a14b3d2409b994909f0600bb.tar.gz llvm-163c13fed9f68c31a14b3d2409b994909f0600bb.tar.bz2 |
[clang-format] Fix formatting of the code that follows C# Lambda Expressions
The alignment fix introduced by https://reviews.llvm.org/D104388 caused a regression whereby formatting of code that follows the lambda block is incorrect i.e. separate expressions are put on the same line.
Differential Revision: https://reviews.llvm.org/D115738
Diffstat (limited to 'clang/unittests/Format/FormatTestCSharp.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTestCSharp.cpp | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/clang/unittests/Format/FormatTestCSharp.cpp b/clang/unittests/Format/FormatTestCSharp.cpp index 78547e0..2cfec61 100644 --- a/clang/unittests/Format/FormatTestCSharp.cpp +++ b/clang/unittests/Format/FormatTestCSharp.cpp @@ -759,6 +759,128 @@ class MyClass GoogleStyle); } +TEST_F(FormatTestCSharp, CSharpLambdasDontBreakFollowingCodeAlignment) { + FormatStyle GoogleStyle = getGoogleStyle(FormatStyle::LK_CSharp); + FormatStyle MicrosoftStyle = getMicrosoftStyle(FormatStyle::LK_CSharp); + + verifyFormat(R"(// +public class Sample +{ + public void Test() + { + while (true) + { + preBindEnumerators.RemoveAll(enumerator => !enumerator.MoveNext()); + CodeThatFollowsLambda(); + IsWellAligned(); + } + } +})", + MicrosoftStyle); + + verifyFormat(R"(// +public class Sample { + public void Test() { + while (true) { + preBindEnumerators.RemoveAll(enumerator => !enumerator.MoveNext()); + CodeThatFollowsLambda(); + IsWellAligned(); + } + } +})", + GoogleStyle); +} + +TEST_F(FormatTestCSharp, CSharpLambdasComplexLambdasDontBreakAlignment) { + FormatStyle GoogleStyle = getGoogleStyle(FormatStyle::LK_CSharp); + FormatStyle MicrosoftStyle = getMicrosoftStyle(FormatStyle::LK_CSharp); + + verifyFormat(R"(// +public class Test +{ + private static void ComplexLambda(BuildReport protoReport) + { + allSelectedScenes = + veryVeryLongCollectionNameThatPutsTheLineLenghtAboveTheThresholds.Where(scene => scene.enabled) + .Select(scene => scene.path) + .ToArray(); + if (allSelectedScenes.Count == 0) + { + return; + } + Functions(); + AreWell(); + Aligned(); + AfterLambdaBlock(); + } +})", + MicrosoftStyle); + + verifyFormat(R"(// +public class Test { + private static void ComplexLambda(BuildReport protoReport) { + allSelectedScenes = veryVeryLongCollectionNameThatPutsTheLineLenghtAboveTheThresholds + .Where(scene => scene.enabled) + .Select(scene => scene.path) + .ToArray(); + if (allSelectedScenes.Count == 0) { + return; + } + Functions(); + AreWell(); + Aligned(); + AfterLambdaBlock(); + } +})", + GoogleStyle); +} + +TEST_F(FormatTestCSharp, CSharpLambdasMulipleLambdasDontBreakAlignment) { + FormatStyle GoogleStyle = getGoogleStyle(FormatStyle::LK_CSharp); + FormatStyle MicrosoftStyle = getMicrosoftStyle(FormatStyle::LK_CSharp); + + verifyFormat(R"(// +public class Test +{ + private static void MultipleLambdas(BuildReport protoReport) + { + allSelectedScenes = + veryVeryLongCollectionNameThatPutsTheLineLenghtAboveTheThresholds.Where(scene => scene.enabled) + .Select(scene => scene.path) + .ToArray(); + preBindEnumerators.RemoveAll(enumerator => !enumerator.MoveNext()); + if (allSelectedScenes.Count == 0) + { + return; + } + Functions(); + AreWell(); + Aligned(); + AfterLambdaBlock(); + } +})", + MicrosoftStyle); + + verifyFormat(R"(// +public class Test { + private static void MultipleLambdas(BuildReport protoReport) { + allSelectedScenes = veryVeryLongCollectionNameThatPutsTheLineLenghtAboveTheThresholds + .Where(scene => scene.enabled) + .Select(scene => scene.path) + .ToArray(); + preBindEnumerators.RemoveAll(enumerator => !enumerator.MoveNext()); + if (allSelectedScenes.Count == 0) { + return; + } + Functions(); + AreWell(); + Aligned(); + AfterLambdaBlock(); + } +})", + GoogleStyle); +} + TEST_F(FormatTestCSharp, CSharpObjectInitializers) { FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp); |