Debian Codegraph @

js/src/tests/test262/built-ins/RegExp/nullable-quantifier.js

raw
1 // Copyright (C) 2024 Aurèle Barrière. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 esid: sec-runtime-semantics-repeatmatcher-abstract-operation
6 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".
7 info: |
8 RepeatMatcher ( m, min, max, greedy, x, c, parenIndex, parenCount )
9
10 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:
11
12 b. If min = 0 and y.[[EndIndex]] = x.[[EndIndex]], return failure.
13 author: Aurèle Barrière
14 ---*/
15
16 let input = "ab";
17 let regex = /(a?b??)*/;
18 let match = regex.exec(input);
19 let expected = "ab";
20
21 assert.sameValue(match[0], expected, "The regex is expected to match the whole string");
22
23 reportCompare(0, 0);