Regex101
Regex101 copied to clipboard
Unit test: add "substitution should match"
Add an option to the TARGET dropdown ("regex", "full match"): "substitution".
Add a new suboption for the ASSERTION dropdown with values:
- "replaced text matches"
- "replaced text does not match".
Add a "comparison string" field for user-supplied text to match/not match against (similar to the comparison string for the "full match" target).
Example: regex should substitute /foo/ with /bar/ within the text "food".
User may specify whether the resulting string:
- SHOULD MATCH "bard" (substitution succeeded)
- SHOULD NOT MATCH "bard" (substitution failed)
- SHOULD MATCH "food" (substitution failed)
- SHOULD NOT MATCH "food" (substitution succeeded)
This request comes to ensure that a non-regex user could theoretically design all the "replacing A should leave me with B" tests and hand that off to someone else to come up with a passing regular expression.
For example: https://regex101.com/r/8UelRU/3 may get new requirements, such as the bottom Given:/Wanted: line to replace "keys with spaces" the same as "keysWithoutSpaces".
Instead of eyeballing that the SUBSTITUTION has the same before/after, it could be done via unit tests.
One issue I see with this is that the substitution is not modifiable in the unit test view.
The intention was just to test the regex using this feature, but I do see some value in this.
I guess this would relate to #1090