Skip to content

Commit

Permalink
More code review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
manfred-brands committed Oct 29, 2023
1 parent ecdf110 commit be7fe62
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ public void ConvertWhenMinimumParametersIsTwo()
{
var code = TestUtility.WrapInTestMethod(@"
const int actual = 42;
↓Assert.That(actual, Is.EqualTo(42), ""Expected actual value to be 42, but was: {0}"", actual);
↓Assert.That(actual, Is.EqualTo(42), ""Expected actual value to be 42, but was: {0} at time {1:HH:mm:ss}"", actual, DateTime.Now);
");
var fixedCode = TestUtility.WrapInTestMethod(@"
const int actual = 42;
Assert.That(actual, Is.EqualTo(42), $""Expected actual value to be 42, but was: {actual}"");
Assert.That(actual, Is.EqualTo(42), $""Expected actual value to be 42, but was: {actual} at time {DateTime.Now:HH:mm:ss}"");
");
RoslynAssert.CodeFix(analyzer, fix, expectedDiagnostic, code, fixedCode);
}
Expand All @@ -82,6 +82,31 @@ public void TestConvertWithEmbeddedSpecialCharacters(string text)

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

[TestCase("")]
[TestCase(":N1")]
[TestCase(",5")]
[TestCase(",-5")]
[TestCase(",5:N1")]
public void TestFormatModifiers(string modifier)
{
string argument = "1.23";
var code = TestUtility.WrapInTestMethod($"↓Assert.Pass(\"{{0{modifier}}}\", {argument});");

var fixedCode = TestUtility.WrapInTestMethod($"Assert.Pass($\"{{{argument}{modifier}}}\");");

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

[Test]
public void TestEscapedBraces()
{
var code = TestUtility.WrapInTestMethod("↓Assert.Pass(\"{{{0}}}\", 42);");

var fixedCode = TestUtility.WrapInTestMethod("Assert.Pass($\"{{{42}}}\");");

RoslynAssert.CodeFix(analyzer, fix, expectedDiagnostic, code, fixedCode);
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public void TestMethod()
{{
var instance = new UserDefinedType(1, 1.1, ""1.1"");
Assert.That(new UserDefinedType(1, 1.2, ""1.1""), Is.EqualTo(instance).Within(0.1));
Assert.That(new UserDefinedType(1, 1.2, ""1.1""), Is.EqualTo(instance).Within(0.1));
}}
private {kind} UserDefinedType
Expand Down Expand Up @@ -419,7 +419,7 @@ public void TestMethod()
{
var instance = new SomeRecord(1, 1.1, ""1.1"");
Assert.That(new SomeRecord(1, 1.2, ""1.1""), Is.EqualTo(instance).Within(0.1));
Assert.That(new SomeRecord(1, 1.2, ""1.1""), Is.EqualTo(instance).Within(0.1));
}
private sealed record SomeRecord
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 @@ -159,7 +159,7 @@ internal static IEnumerable<InterpolatedStringContentSyntax> UpdateStringFormatT
string formatClause = formatSpecification.Substring(++argumentFormatSpecification, argumentSpecificationEnd - argumentFormatSpecification);
interpolationFormat = SyntaxFactory.InterpolationFormatClause(
SyntaxFactory.Token(SyntaxKind.ColonToken),
SyntaxFactory.Literal(formatClause));
InterpolatedStringTextToken(formatClause));
}

yield return SyntaxFactory.Interpolation(formatArgument, interpolationAlignment, interpolationFormat);
Expand Down
2 changes: 1 addition & 1 deletion src/nunit.analyzers/Helpers/Constraints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace NUnit.Analyzers.Helpers
{
internal sealed class Constraints
{
public Constraints(string staticClass, string? modifier, string? constraintMethod, string? property1 = default, string? property2 = null)
public Constraints(string staticClass, string? modifier, string? constraintMethod, string? property1 = null, string? property2 = null)
{
this.StaticClass = staticClass;
this.Modifier = modifier;
Expand Down

0 comments on commit be7fe62

Please sign in to comment.