Skip to content

Commit

Permalink
Merge pull request #731 from manfred-brands/Issue729
Browse files Browse the repository at this point in the history
Add test for wrapping conditional expression in parenthesis for NUnit2050
  • Loading branch information
mikkelbu authored Apr 14, 2024
2 parents d14cc57 + acb700b commit f9cac1d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,22 @@ public void TestEscapedBraces()

RoslynAssert.CodeFix(analyzer, fix, expectedDiagnostic, code, fixedCode);
}

[Test]
public void TestConditionalExpressionArgument()
{
var code = TestUtility.WrapInTestMethod(@"
string? someValue = ""Value"";
↓Assert.Pass(""Value is {0}"", someValue is null ? ""null"" : someValue);
");

var fixedCode = TestUtility.WrapInTestMethod(@"
string? someValue = ""Value"";
Assert.Pass($""Value is {(someValue is null ? ""null"" : someValue)}"");
");

RoslynAssert.CodeFix(analyzer, fix, expectedDiagnostic, code, fixedCode);
}
#endif

}
Expand Down
2 changes: 1 addition & 1 deletion src/nunit.analyzers/Helpers/CodeFixHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ internal static IEnumerable<InterpolatedStringContentSyntax> UpdateStringFormatT
.OfType<ConditionalExpressionSyntax>()
.Any())
{
// Colon is not allowed in an Interpolation, wrap expression in parenthesis: (expession).
// Colon is not allowed in an Interpolation, wrap expression in parenthesis: (expression).
formatArgument = SyntaxFactory.ParenthesizedExpression(formatArgument);
}

Expand Down

0 comments on commit f9cac1d

Please sign in to comment.