-
Notifications
You must be signed in to change notification settings - Fork 464
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
Fix Regex Character Class Escape Tests #4195
base: main
Are you sure you want to change the base?
Conversation
For each character class escape (\d, \D, \s, \S, \w, \W), check positive cases (the escape matches all characters it's supposed to match) and negative cases (the escape doesn't match any of the characters it should not match). Each of these checks is also done in Unicode mode. This is part of my work at the SYSTEMF lab at EPFL.
cc @mathiasbynens, you might be interested in this. |
CC @leobalter as the original author of these tests. Thanks for kicking this off! Since these are generated tests, could you please update the source script that generates these files rather than editing them directly? It would be easier to review that patch. |
I'll give it a try in the next few days! |
I no longer have the code on any of my machines, the diff information points out to https://github.com/bocoup/test262-regexp-generator. I hope that helps. |
Hi, So I believe these generator tests correctly check positive and negative cases! It seems to me like the reason for the differences between the two sets of tests is due to this commit, optimizing the tests by removing this I see two ways forward:
What do you think? |
IMHO this is the way to go. |
Hello, To generate the correct strings, I've used the regenerate.js file from this repo: https://github.com/mathiasbynens/unicode-property-escapes-tests/ I've also added a configuration with the v flag. Best, |
We are considering copying bocoup/test262-regexp-generator into this repo. I'm not sure Bocoup is still maintaining it. |
Makes sense! Let me know and I can update this PR when the generator is copied here. |
I've copied and updated the generator script in #4303. I had to make some modifications to it, to implement some changes that had been made directly to the test files and weren't reflected in the script. So any extra review is appreciated! |
@Aurele-Barriere The generator script has landed in test262 now, so you can bring the improvements to the generator script into this PR. I'm afraid it will need a certain amount of rebasing, but at least now you can be certain that the script output matches the tests in the repo. |
Great news thanks, I'll give it a try soon! |
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.