nunit.analyzers icon indicating copy to clipboard operation
nunit.analyzers copied to clipboard

Add a rule informing that .Within is not valid for non-numeric types.

Open manfred-brands opened this issue 4 years ago • 3 comments

See https://github.com/nunit/nunit/issues/3736

The nunit syntax allows:

[Test]
public void RecordsEqualsMismatch()
{
    var a = new Data(1, 1.0);
    var b = new Data(1, 1.1);

    Assert.That(a, Is.EqualTo(b).Within(0.2), $"{a} != {b}");
}

private sealed record Data(int number, double Value);

But the .Within part is completely ignored. Only the NumericEquals and TupleEquals will use it.

Add a rule warning the user when the .Within constraint is not valid. Add a CodeFix to remove the constraint.

manfred-brands avatar Jan 20 '21 04:01 manfred-brands

I'll try to take care of this

Antash avatar Jan 20 '21 20:01 Antash

@Antash How are you going with this, need any help? You can raise a draft PR for us if you would like us to look at your work.

manfred-brands avatar Feb 11 '21 00:02 manfred-brands

@manfred-brands thanks for giving me a hand. I have almost zero experience with Roslyn and stuck a bit on the CodeFix. Most likely it will be very easy for you to advise how can I remove 'Within' node from the syntax tree. Also, need to add more test cases and documentation

Antash avatar Feb 14 '21 15:02 Antash