Fix Regex Character Class Escape Tests #4195
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Character class escape tests for \d, \D, \s, \S, \w, \W are not testing what they should.
Consider the escape
\d
.We should test two things:
This is not what the auto-generated tests are currently doing.
character-class-digit-class-escape.js
only checks that\d
finds a match in"0123456789"
.And
character-class-digit-class-escape-plus-quantifier.js
only checks that\d+
finds a match in"0123456789"
.First, these two tests are equivalent.
But also, they do not check that
\d
matches all digits, only one.And they never check that non-digits are not matched.
It seems that an implementation where
\d
matches only "3" and "z" would pass all the current tests.I suggest the following:
^\d+$
(with anchors) on the string"0123456789"
.\d
on the string that contains all code points except digits.Thanks to Noé De Santo @Ef55 for realizing that these tests were probably not what they were intended to be, while working on the Warblre project.