Skip to content

Commit

Permalink
Fix trivia for NUnit2007
Browse files Browse the repository at this point in the history
  • Loading branch information
verdie-g authored and manfred-brands committed Sep 12, 2024
1 parent 90602b4 commit 8b2e749
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,32 @@ public void Test()
fixTitle: ConstActualValueUsageCodeFix.SwapArgumentsDescription);
}

[TestCase(nameof(ClassicAssert.AreEqual))]
[TestCase(nameof(ClassicAssert.AreNotEqual))]
[TestCase(nameof(ClassicAssert.AreSame))]
[TestCase(nameof(ClassicAssert.AreNotSame))]
public void LiteralArgumentIsProvidedForClassicAssertCodeFixWithNewLine(string classicAssertMethod)
{
var code = TestUtility.WrapMethodInClassNamespaceAndAddUsings($@"
public void Test()
{{
int expected = 5;
ClassicAssert.{classicAssertMethod}(expected,
↓1);
}}");

var fixedCode = TestUtility.WrapMethodInClassNamespaceAndAddUsings($@"
public void Test()
{{
int expected = 5;
ClassicAssert.{classicAssertMethod}(1,
expected);
}}");

RoslynAssert.CodeFix(analyzer, fix, expectedDiagnostic, code, fixedCode,
fixTitle: ConstActualValueUsageCodeFix.SwapArgumentsDescription);
}

[TestCase(nameof(ClassicAssert.AreEqual))]
public void LiteralArgumentIsProvidedForClassicAssertWithDeltaCodeFix(string classicAssertMethod)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)

var newRoot = root
.ReplaceNodes(new[] { expectedArgument, actualArgument },
(node, _) => node == actualArgument ? expectedArgument : actualArgument);
(node, _) => node == actualArgument
? expectedArgument.WithTriviaFrom(actualArgument)
: actualArgument.WithTriviaFrom(expectedArgument));

var codeAction = CodeAction.Create(
SwapArgumentsDescription,
Expand Down

0 comments on commit 8b2e749

Please sign in to comment.