Skip to content

Commit

Permalink
Improve Normalize Whitespace for block lambdas (#46661)
Browse files Browse the repository at this point in the history
  • Loading branch information
YairHalberstadt authored Aug 17, 2020
1 parent e69b451 commit 1919454
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Compilers/CSharp/Portable/Syntax/SyntaxNormalizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ private static int LineBreaksAfterOpenBrace(SyntaxToken currentToken, SyntaxToke
private static int LineBreaksAfterCloseBrace(SyntaxToken currentToken, SyntaxToken nextToken)
{
if (currentToken.Parent is InitializerExpressionSyntax ||
currentToken.Parent.IsKind(SyntaxKind.Interpolation))
currentToken.Parent.IsKind(SyntaxKind.Interpolation) ||
currentToken.Parent?.Parent is AnonymousFunctionExpressionSyntax)
{
return 0;
}
Expand Down
12 changes: 12 additions & 0 deletions src/Compilers/CSharp/Test/Syntax/Syntax/SyntaxNormalizerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,18 @@ public void TestNormalizeTuples()
TestNormalizeDeclaration("public (string prefix,string uri)Foo()", "public (string prefix, string uri) Foo()");
}

[Theory]
[InlineData("_=()=>{};", "_ = () =>\r\n{\r\n};")]
[InlineData("_=x=>{};", "_ = x =>\r\n{\r\n};")]
[InlineData("Add(()=>{});", "Add(() =>\r\n{\r\n});")]
[InlineData("Add(delegate(){});", "Add(delegate ()\r\n{\r\n});")]
[InlineData("Add(()=>{{_=x=>{};}});", "Add(() =>\r\n{\r\n {\r\n _ = x =>\r\n {\r\n };\r\n }\r\n});")]
[WorkItem(46656, "https://github.com/dotnet/roslyn/issues/46656")]
public void TestNormalizeBlockAnonymousFunctions(string actual, string expected)
{
TestNormalizeStatement(actual, expected);
}

private void TestNormalize(CSharpSyntaxNode node, string expected)
{
var actual = node.NormalizeWhitespace(" ").ToFullString();
Expand Down

0 comments on commit 1919454

Please sign in to comment.