Skip to content

Commit

Permalink
Code review changes for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
manfred-brands committed May 1, 2023
1 parent ce4c363 commit 136fb27
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,11 @@ private sealed class Configuration
RoslynAssert.FixAll(analyzer, fix, expectedDiagnostic, code, fixedCode);
}

[TestCase(" // ", "")]
[TestCase("\r\n // ", "")]
[TestCase("\r\n ", "")]
[TestCase("\r\n ", " // Same line Comment")]
[TestCase("\r\n ", "\r\n // Final Comment on next line")]
public void VerifyKeepsTrivia(string separation, string comment)
[Test]
public void VerifyKeepsTrivia(
[Values("", "\r\n")] string newline,
[Values("", "// ")] string preComment,
[Values("", "// Same line Comment", "\r\n // Final Comment on next line")] string postComment)
{
var code = TestUtility.WrapMethodInClassNamespaceAndAddUsings(@$"
public void TestMethod()
Expand All @@ -150,8 +149,8 @@ public void TestMethod()
// Verify that our bool constants are correct
↓Assert.That(True, Is.True);
Assert.That(False, Is.False);
{separation}Console.WriteLine(""Next Statement"");{comment}
Assert.That(False, Is.False);{newline}
{preComment}Console.WriteLine(""Next Statement"");{postComment}
}}");
var fixedCode = TestUtility.WrapMethodInClassNamespaceAndAddUsings(@$"
public void TestMethod()
Expand All @@ -164,8 +163,8 @@ public void TestMethod()
// Verify that our bool constants are correct
Assert.That(True, Is.True);
Assert.That(False, Is.False);
}});
{separation}Console.WriteLine(""Next Statement"");{comment}
}});{newline}
{preComment}Console.WriteLine(""Next Statement"");{postComment}
}}");
RoslynAssert.CodeFix(analyzer, fix, expectedDiagnostic, code, fixedCode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,16 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)
SyntaxFactory.SeparatedList(new[]
{
SyntaxFactory.Argument(parenthesizedLambdaExpression)
})))).WithAdditionalAnnotations(Formatter.Annotation);
}))))
.WithTrailingTrivia(SyntaxFactory.CarriageReturnLineFeed)
.WithAdditionalAnnotations(Formatter.Annotation);

if (endOfLineTrivia is not null)
{
// Add the remembered blank line.
// Add the remembered blank line to go before the Assert.Multiple statement.
assertMultiple = assertMultiple.WithLeadingTrivia(endOfLineTrivia.Value);
}

// Add new line after the Assert.Multiple statement.
assertMultiple = assertMultiple.WithTrailingTrivia(SyntaxFactory.CarriageReturnLineFeed);

// Comments at the end of a block are not associated with the last statement but with the closing brace
// Keep the exising block's open and close braces with associated trivia in our updated block.
var updatedBlock = SyntaxFactory.Block(
Expand Down

0 comments on commit 136fb27

Please sign in to comment.