-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
test/built-ins/RegExp/prototype/exec/regexp-builtin-exec-v-flag.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// 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] | ||
---*/ | ||
|
||
const text = '𠮷a𠮷b𠮷'; | ||
|
||
function doExec(regex) { | ||
const result = regex.exec(text); | ||
return result ? [result[0], result.index] : null; | ||
} | ||
|
||
assert.sameValue(doExec(/𠮷/).toString(), "𠮷,0", "Basic exec without v flag"); | ||
assert.sameValue(doExec(/𠮷/v).toString(), "𠮷,0", "Exec with v flag"); | ||
assert.sameValue(doExec(/\p{Script=Han}/v).toString(), "𠮷,0", "Unicode property escapes with v flag"); | ||
assert.sameValue(doExec(/./v).toString(), "𠮷,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"); |
19 changes: 19 additions & 0 deletions
19
test/built-ins/String/prototype/match/regexp-prototype-match-v-flag.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// 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] | ||
---*/ | ||
|
||
const text = '𠮷a𠮷b𠮷'; | ||
|
||
function doMatch(regex) { | ||
return RegExp.prototype[Symbol.match].call(regex, text); | ||
} | ||
|
||
assert.sameValue(doMatch(/𠮷/g).toString(), "𠮷,𠮷,𠮷", "Basic match with g flag"); | ||
assert.sameValue(doMatch(/𠮷/v).toString(), "𠮷", "Match with v flag"); | ||
assert.sameValue(doMatch(/\p{Script=Han}/gv).toString(), "𠮷,𠮷,𠮷", "Unicode property escapes with v flag"); | ||
assert.sameValue(doMatch(/./gv).toString(), "𠮷,a,𠮷,b,𠮷", "Dot with v flag"); | ||
assert.sameValue(doMatch(/x/v), null, "Non-matching regex"); |
43 changes: 43 additions & 0 deletions
43
test/built-ins/String/prototype/matchAll/regexp-prototype-matchAll-v-flag.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
); |
23 changes: 23 additions & 0 deletions
23
test/built-ins/String/prototype/replace/regexp-prototype-replace-v-flag.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
); |
20 changes: 20 additions & 0 deletions
20
test/built-ins/String/prototype/search/regexp-prototype-search-v-flag.js.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); |