Skip to content

Commit

Permalink
Add failing test for sticky RegExp (minimally recreate zloirock#754)
Browse files Browse the repository at this point in the history
  • Loading branch information
x2764tech committed Mar 3, 2020
1 parent 4546ffe commit b99de7c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/tests/es.regexp.exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ if (DESCRIPTORS) {
assert.strictEqual(re.exec(str), null, '#15');
assert.strictEqual(re.lastIndex, 0, '#16');
});

QUnit.test('RegExp#exec sticky with alternation', assert => {
const re = new RegExp('a|b+', 'y');
const str = 'bbabaab';

assert.deepEqual(re.exec(str), Object.assign(['bb'], { index: 0 }), '#1 - start of string');
assert.deepEqual(re.exec(str), ['a'], '#2 - first a');
assert.deepEqual(re.exec(str), Object.assign(['b'], { index: 3 }), '#3 - next b');
assert.deepEqual(re.exec(str), ['a'], '#4');
assert.deepEqual(re.exec(str), ['a'], '#5');
assert.deepEqual(re.exec(str), ['b'], '#6');
assert.deepEqual(re.exec(str), null, '#7');
});

QUnit.test('RegExp#exec sticky anchored', assert => {
const regex = new RegExp('^foo', 'y');
assert.deepEqual(regex.exec('foo'), ['foo'], '#1');
Expand Down

0 comments on commit b99de7c

Please sign in to comment.