aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Format/FormatTestCSharp.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/unittests/Format/FormatTestCSharp.cpp')
-rw-r--r--clang/unittests/Format/FormatTestCSharp.cpp122
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);