Regex101 icon indicating copy to clipboard operation
Regex101 copied to clipboard

Unit test: add "substitution should match"

Open OnlineCop opened this issue 5 years ago • 2 comments

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)

OnlineCop avatar Jun 11 '19 17:06 OnlineCop

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.

OnlineCop avatar Jun 11 '19 18:06 OnlineCop

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

firasdib avatar Jun 18 '19 11:06 firasdib