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 a rule informing that .Within is not valid for non-numeric types. #344

Closed
manfred-brands opened this issue Jan 20, 2021 · 3 comments · Fixed by #537
Closed

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

manfred-brands opened this issue Jan 20, 2021 · 3 comments · Fixed by #537

Comments

@manfred-brands
Copy link
Member

See nunit/nunit#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.

@Antash
Copy link
Contributor

Antash commented Jan 20, 2021

I'll try to take care of this

@manfred-brands
Copy link
Member Author

@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.

@Antash
Copy link
Contributor

Antash commented Feb 14, 2021

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants