// followed by a curly.
if (FormatTok->is(TT_JsFatArrow)) {
nextToken();
- if (FormatTok->is(tok::l_brace))
+ if (FormatTok->is(tok::l_brace)) {
+ // C# may break after => if the next character is a newline.
+ if (Style.isCSharp() && Style.BraceWrapping.AfterFunction == true) {
+ // calling `addUnwrappedLine()` here causes odd parsing errors.
+ FormatTok->MustBreakBefore = true;
+ }
parseChildBlock();
+ }
break;
}
EXPECT_EQ(Code, format(Code, Style));
}
+TEST_F(FormatTestCSharp, CSharpLambdas) {
+ FormatStyle GoogleStyle = getGoogleStyle(FormatStyle::LK_CSharp);
+ FormatStyle MicrosoftStyle = getMicrosoftStyle(FormatStyle::LK_CSharp);
+
+ verifyFormat(R"(//
+class MyClass {
+ Action<string> greet = name => {
+ string greeting = $"Hello {name}!";
+ Console.WriteLine(greeting);
+ };
+})",
+ GoogleStyle);
+
+ // Microsoft Style:
+ // https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions#statement-lambdas
+ verifyFormat(R"(//
+class MyClass
+{
+ Action<string> greet = name =>
+ {
+ string greeting = $"Hello {name}!";
+ Console.WriteLine(greeting);
+ };
+})",
+ MicrosoftStyle);
+}
+
TEST_F(FormatTestCSharp, CSharpObjectInitializers) {
FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp);