You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, I have, AFAIK, no cool way to match the actual groups of the RegEx.
My motivation behind this here is validating the syntax of a code generator. It should, under some circumstances, e.g. return "123" as the second group in the RegEx. Note, as this assertion needs to target the middle of the string, it is very hard to match and assert without using RegEx (and arguably maybe as ugly, e.g. if as in my case the start and end could be different lengths...).
More complex use cases are possible, of course.
...or similar. (Indexers probably need to be used, as potentially many matches are possible).
Alternative Designs
maybe make RegexAssertions specifically? I dunno how exactly implementing it would be best.
Current solution would be (Chaining is also not really possible here):
resultOfSystemUnderTest.Match(result).Groups[2].Value.Should().Be("123");// etc.
Risks
IMHO/AFAIK no breaking changes, performance should also be the same as the existing matches, because AFAIK the groups are anyway evaluated by C# if you match it, but I am not sure.
Are you willing to help with a proof-of-concept (as PR in that or a separate repo) first and as pull-request later on?
No
The text was updated successfully, but these errors were encountered:
One microscopic downside is that MatchRegex will need to switch from the lighter Regex.IsMatch to Regex.Match, but I don't think that will be noticeable from test.
Background and motivation
Suppose I have the following rgeular expression (regex):
(abc)(\d{3})([X-Z]*)
(https://regex101.com/r/Aszkcm/1)I can write it like this, and this is fine:
However, I have, AFAIK, no cool way to match the actual groups of the RegEx.
My motivation behind this here is validating the syntax of a code generator. It should, under some circumstances, e.g. return "123" as the second group in the RegEx. Note, as this assertion needs to target the middle of the string, it is very hard to match and assert without using RegEx (and arguably maybe as ugly, e.g. if as in my case the start and end could be different lengths...).
More complex use cases are possible, of course.
API Proposal
Maybe
MatchRegex
just needs to be expanded to return an extendedTAssertions
that can handle the regex then?API Usage
...or similar. (Indexers probably need to be used, as potentially many matches are possible).
Alternative Designs
RegexAssertions
specifically? I dunno how exactly implementing it would be best.Current solution would be (Chaining is also not really possible here):
Risks
IMHO/AFAIK no breaking changes, performance should also be the same as the existing matches, because AFAIK the groups are anyway evaluated by C# if you match it, but I am not sure.
Are you willing to help with a proof-of-concept (as PR in that or a separate repo) first and as pull-request later on?
No
The text was updated successfully, but these errors were encountered: