-
Notifications
You must be signed in to change notification settings - Fork 475
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
Add tests for RegExp u
flag
#352
Conversation
|
||
var r = /(𝌆)?/ug; | ||
r[Symbol.match]('𝌆'); | ||
assert.sameValue(r.lastIndex, 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lastIndex
is reset to 0
in 21.2.5.2.2 RegExpBuiltinExec, step 15.a.i when the loop in 21.2.5.6, step 8.g is executed the third (and last) time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, okay. So I think this behavior can't be externally verified through inspection of the lastIndex
property. What about this instead:
test/built-ins/RegExp/prototype/Symbol.match/u-lastindex.js
, renamed to test/built-ins/RegExp/prototype/Symbol.match/u-advance-after-empty.js
var match = /^|\udf06/ug[Symbol.match]('\ud834\udf06');
assert(match !== null);
assert.sameValue(match.length, 1);
assert.sameValue(match[0], '');
test/built-ins/RegExp/prototype/Symbol.replace/u-lastindex.js
, renamed to test/built-ins/RegExp/prototype/Symbol.replace/u-advance-after-empty.js
var str = /^|\udf06/ug[Symbol.replace]('\ud834\udf06', 'XXX');
assert.sameValue(str, 'XXX\ud834\udf06');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that should work. Alternatively it's also possible to use /\b/
and /\B/
assertions to execute those steps. Like in: https://github.com/anba/es6draft/blob/master/src/test/scripts/suite/regress/bug4159.js
I've fixed the bugs that @anba identified in a fixup commit |
These are good tests @jugglinmike. It might be better to add the following tests to improve coverage:
|
Sounds good to me. I've added tests for those three behaviors |
You could also add a test to see if running |
Hey Mathias! That test actually describes to distinct expectations:
I think it will be more clear (and maintainable) to test |
So I think this is good for 🍆? |
dd5f324
to
9068608
Compare
Done and done |
Add tests for RegExp `u` flag
I'd like to draw attention to two tests in particular since they both concern a very specific condition (for example, good ol' step 8.g.iv.5.d):
Despite a careful reading, I'm still not convinced those test cases properly express the detail documented in their info/description. I decided I may have looked at it for too long and that some fresh perspective would help
@mathiasbynens Would you mind taking a look?