mirror of https://github.com/tc39/test262.git
Add more tests for v flag
This commit is contained in:
parent
dc7a22dd28
commit
474af83250
|
@ -0,0 +1,27 @@
|
|||
// Copyright (C) 2024 Tan Meng. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-regexpbuiltinexec
|
||||
description: RegExpBuiltinExec behavior with 'v' flag
|
||||
features: [regexp-v-flag]
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
const text = '𠮷a𠮷b𠮷';
|
||||
|
||||
function doExec(regex) {
|
||||
const result = regex.exec(text);
|
||||
return result ? [result[0], result.index] : null;
|
||||
}
|
||||
|
||||
assert.compareArray(doExec(/𠮷/), ["𠮷", 0], "Basic exec without v flag");
|
||||
assert.compareArray(doExec(/𠮷/v), ["𠮷", 0], "Exec with v flag");
|
||||
assert.compareArray(doExec(/\p{Script=Han}/v), ["𠮷", 0], "Unicode property escapes with v flag");
|
||||
assert.compareArray(doExec(/./v), ["𠮷", 0], "Dot with v flag");
|
||||
assert.sameValue(doExec(/x/v), null, "Non-matching regex");
|
||||
|
||||
const regexWithGroups = /(\p{Script=Han})(.)/v;
|
||||
const resultWithGroups = regexWithGroups.exec(text);
|
||||
assert.sameValue(resultWithGroups[1], "𠮷", "Capture group 1");
|
||||
assert.sameValue(resultWithGroups[2], "a", "Capture group 2");
|
||||
assert.sameValue(resultWithGroups.index, 0, "Match index for groups");
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2024 Tan Meng. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-regexp.prototype-@@match
|
||||
description: RegExp.prototype[@@match] behavior with 'v' flag
|
||||
features: [Symbol.match, regexp-v-flag]
|
||||
includes: [compareArray.js]
|
||||
---*/
|
||||
|
||||
const text = '𠮷a𠮷b𠮷';
|
||||
|
||||
function doMatch(regex) {
|
||||
return RegExp.prototype[Symbol.match].call(regex, text);
|
||||
}
|
||||
|
||||
assert.compareArray(doMatch(/𠮷/g), ["𠮷", "𠮷", "𠮷"], "Basic match with g flag");
|
||||
assert.compareArray(doMatch(/𠮷/v), ["𠮷"], "Match with v flag");
|
||||
assert.compareArray(doMatch(/\p{Script=Han}/gv), ["𠮷", "𠮷", "𠮷"], "Unicode property escapes with v flag");
|
||||
assert.compareArray(doMatch(/./gv), ["𠮷", "a", "𠮷", "b", "𠮷"], "Dot with v flag");
|
||||
assert.sameValue(doMatch(/x/v), null, "Non-matching regex");
|
43
test/built-ins/String/prototype/matchAll/regexp-prototype-matchAll-v-flag.js
vendored
Normal file
43
test/built-ins/String/prototype/matchAll/regexp-prototype-matchAll-v-flag.js
vendored
Normal file
|
@ -0,0 +1,43 @@
|
|||
// Copyright (C) 2024 Tan Meng. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-regexp.prototype-@@matchall
|
||||
description: RegExp.prototype[@@matchAll] behavior with 'v' flag
|
||||
features: [Symbol.matchAll, regexp-v-flag]
|
||||
---*/
|
||||
|
||||
const text = '𠮷a𠮷b𠮷';
|
||||
|
||||
function doMatchAll(regex) {
|
||||
return Array.from(RegExp.prototype[Symbol.matchAll].call(regex, text), m => [m[0], m.index]);
|
||||
}
|
||||
|
||||
assert.sameValue(
|
||||
doMatchAll(/𠮷/g).toString(),
|
||||
"𠮷,0,𠮷,3,𠮷,6",
|
||||
"Basic matchAll with g flag"
|
||||
);
|
||||
|
||||
assert.sameValue(
|
||||
doMatchAll(/𠮷/gv).toString(),
|
||||
"𠮷,0,𠮷,3,𠮷,6",
|
||||
"matchAll with v flag"
|
||||
);
|
||||
|
||||
assert.sameValue(
|
||||
doMatchAll(/\p{Script=Han}/gv).toString(),
|
||||
"𠮷,0,𠮷,3,𠮷,6",
|
||||
"Unicode property escapes with v flag"
|
||||
);
|
||||
|
||||
assert.sameValue(
|
||||
doMatchAll(/./gv).toString(),
|
||||
"𠮷,0,a,2,𠮷,3,b,5,𠮷,6",
|
||||
"Dot with v flag"
|
||||
);
|
||||
|
||||
assert.sameValue(
|
||||
doMatchAll(/(?:)/gv).length,
|
||||
6,
|
||||
"Empty matches with v flag"
|
||||
);
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright (C) 2024 Tan Meng. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-regexp.prototype-@@replace
|
||||
description: RegExp.prototype[@@replace] behavior with 'v' flag
|
||||
features: [Symbol.replace, regexp-v-flag]
|
||||
---*/
|
||||
|
||||
const text = '𠮷a𠮷b𠮷';
|
||||
|
||||
function doReplace(regex, replacement) {
|
||||
return RegExp.prototype[Symbol.replace].call(regex, text, replacement);
|
||||
}
|
||||
|
||||
assert.sameValue(doReplace(/𠮷/g, '-'), "-a-b-", "Basic replace with g flag");
|
||||
assert.sameValue(doReplace(/𠮷/v, '-'), "-a𠮷b𠮷", "Replace with v flag");
|
||||
assert.sameValue(doReplace(/\p{Script=Han}/gv, 'X'), "XaXbX", "Unicode property escapes with v flag");
|
||||
assert.sameValue(doReplace(/./gv, '$&$&'), "𠮷𠮷aa𠮷𠮷bb𠮷𠮷", "Dot with v flag");
|
||||
assert.sameValue(
|
||||
doReplace(/./gv, (match, index) => `[${match}:${index}]`),
|
||||
"[𠮷:0][a:2][𠮷:3][b:5][𠮷:6]",
|
||||
"Replace with function"
|
||||
);
|
|
@ -0,0 +1,20 @@
|
|||
// Copyright (C) 2024 Tan Meng. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
/*---
|
||||
esid: sec-regexp.prototype-@@search
|
||||
description: RegExp.prototype[@@search] behavior with 'v' flag
|
||||
features: [Symbol.search, regexp-v-flag]
|
||||
---*/
|
||||
|
||||
const text = '𠮷a𠮷b𠮷';
|
||||
|
||||
function doSearch(regex) {
|
||||
return RegExp.prototype[Symbol.search].call(regex, text);
|
||||
}
|
||||
|
||||
assert.sameValue(doSearch(/a/), 2, "Basic search without v flag");
|
||||
assert.sameValue(doSearch(/a/v), 2, "Search with v flag");
|
||||
assert.sameValue(doSearch(/𠮷/), 0, "Search for surrogate pair without v flag");
|
||||
assert.sameValue(doSearch(/𠮷/v), 0, "Search for surrogate pair with v flag");
|
||||
assert.sameValue(doSearch(/\p{Script=Han}/v), 0, "Unicode property escapes with v flag");
|
||||
assert.sameValue(doSearch(/b./v), 5, "Dot with v flag");
|
Loading…
Reference in New Issue