Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for wrapping conditional expression in parenthesis for NUnit2050 #731

Merged
merged 1 commit into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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