mirror of https://github.com/tc39/test262.git
Add tests for nullable quantifiers in RegExps (#4185)
* Add tests for nullable quantifiers in RegExps The JavaScript semantics for a quantifier matching the empty string are different from other regex languages. This adds a test that documents this JavaScript-specific behavior. This is part of my work at the SYSTEMF lab at EPFL. * Update nullable-quantifier.js
This commit is contained in:
parent
feb400c685
commit
ea37a19a4a
|
@ -0,0 +1,21 @@
|
|||
// Copyright (C) 2024 Aurèle Barrière. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-runtime-semantics-repeatmatcher-abstract-operation
|
||||
description: JavaScript nullable quantifiers have special semantics, optional iterations are not allowed to match the empty string. Point 2.b below shows that after each optional (min=0) iteration of a quantifier, if the iteration matched the empty string (y.[[EndIndex]] = x.[[EndIndex]]), then the iteration is discarded. In particular, for (a?b??)* on "ab", it is possible to do two iterations of the star, one matching "a" and the other matching "b".
|
||||
info: |
|
||||
RepeatMatcher ( m, min, max, greedy, x, c, parenIndex, parenCount )
|
||||
|
||||
2. Let d be a new MatcherContinuation with parameters (y) that captures m, min, max, greedy, x, c, parenIndex, and parenCount and performs the following steps when called:
|
||||
|
||||
b. If min = 0 and y.[[EndIndex]] = x.[[EndIndex]], return failure.
|
||||
author: Aurèle Barrière
|
||||
---*/
|
||||
|
||||
let input = "ab";
|
||||
let regex = /(a?b??)*/;
|
||||
let match = regex.exec(input);
|
||||
let expected = "ab";
|
||||
|
||||
assert.sameValue(match[0], expected, "The regex is expected to match the whole string");
|
Loading…
Reference in New Issue