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
StringAssertions - Count regex matches #1868
Comments
You can achieve it using the a.LongLongString.Should().Match(subject => Regex.Matches(subject, @"(.*\(\d+,\d{2}€\))+").Count == 2); |
Ok, thank you I will take that for the moment to be able to go further in development. Helps a lot :) |
If you have a small hint for me how to start I would give it a shot |
@IT-VBFK Have a look at how the |
Ok will try to implement this :) Should this be an extra overload for both of the |
Yes please. |
If it's of any help |
Description
I am using the FA string assertions
MatchRegex()
to check strings. But because the regex pattern have to be really generic to match all future strings, it turned out to be a test case that will mostly ever pass (and therefore is useless).Now if I could restrict the assertion to a predictable count of regex matches, this could be (for me) a better solution.
Complete minimal example reproducing the issue
Expected behavior:
I think an overload like the
string.Contains("bla", AtLeast.Once())
should be good, so:a.LongLongString().Should().MatchRegex("bla", Exactly.Twice());
Actual behavior:
Cannot be done (except I am missing some way to achieve this)
Versions
Additional Information
Unfortunately
string.Contains("bla", AtLeast.Once())
and similar assertions can not be done, because I am trying to match price values inside the text.The text was updated successfully, but these errors were encountered: