diff --git a/test/built-ins/RegExp/prototype/exec/regexp-builtin-exec-v-flag.js b/test/built-ins/RegExp/prototype/exec/regexp-builtin-exec-v-flag.js deleted file mode 100644 index f326e5692c..0000000000 --- a/test/built-ins/RegExp/prototype/exec/regexp-builtin-exec-v-flag.js +++ /dev/null @@ -1,27 +0,0 @@ -// 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"); diff --git a/test/built-ins/RegExp/prototype/exec/regexp-builtin-exec-v-u-flag.js b/test/built-ins/RegExp/prototype/exec/regexp-builtin-exec-v-u-flag.js new file mode 100644 index 0000000000..d77df4b733 --- /dev/null +++ b/test/built-ins/RegExp/prototype/exec/regexp-builtin-exec-v-u-flag.js @@ -0,0 +1,47 @@ +// 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 'u' and 'v'flags +features: [regexp-v-flag, regexp-unicode-property-escapes] +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(/𠮷/u), ["𠮷", 0], "Exec with u flag"); +assert.compareArray(doExec(/\p{Script=Han}/u), ["𠮷", 0], "Unicode property escapes with u flag"); +assert.compareArray(doExec(/./u), ["𠮷", 0], "Dot with u 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.compareArray(doExec(/\p{ASCII}/u), ["a", 2], "ASCII with u flag"); +assert.compareArray(doExec(/\p{ASCII}/v), ["a", 2], "ASCII with v flag"); + +assert.sameValue(doExec(/x/u), null, "Non-matching regex with u flag"); +assert.sameValue(doExec(/x/v), null, "Non-matching regex with v flag"); + +const regexWithGroupsU = /(\p{Script=Han})(.)/u; +const resultWithGroupsU = regexWithGroupsU.exec(text); +assert.sameValue(resultWithGroupsU[1], "𠮷", "Capture group 1 with u flag"); +assert.sameValue(resultWithGroupsU[2], "a", "Capture group 2 with u flag"); +assert.sameValue(resultWithGroupsU.index, 0, "Match index for groups with u flag"); + +const regexWithGroupsV = /(\p{Script=Han})(.)/v; +const resultWithGroupsV = regexWithGroupsV.exec(text); +assert.sameValue(resultWithGroupsV[1], "𠮷", "Capture group 1 with v flag"); +assert.sameValue(resultWithGroupsV[2], "a", "Capture group 2 with v flag"); +assert.sameValue(resultWithGroupsV.index, 0, "Match index for groups with v flag"); + +const complexText = 'a\u{20BB7}b\u{10FFFF}c'; +assert.compareArray(/\P{ASCII}/u.exec(complexText), ["\u{20BB7}"], "Non-ASCII with u flag"); +assert.compareArray(/\P{ASCII}/v.exec(complexText), ["\u{20BB7}"], "Non-ASCII with v flag"); + +reportCompare(0, 0); diff --git a/test/built-ins/String/prototype/match/regexp-prototype-match-v-flag.js b/test/built-ins/String/prototype/match/regexp-prototype-match-v-flag.js deleted file mode 100644 index c324559f93..0000000000 --- a/test/built-ins/String/prototype/match/regexp-prototype-match-v-flag.js +++ /dev/null @@ -1,20 +0,0 @@ -// 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"); diff --git a/test/built-ins/String/prototype/match/regexp-prototype-match-v-u-flag.js b/test/built-ins/String/prototype/match/regexp-prototype-match-v-u-flag.js new file mode 100644 index 0000000000..acac5c7fbc --- /dev/null +++ b/test/built-ins/String/prototype/match/regexp-prototype-match-v-u-flag.js @@ -0,0 +1,32 @@ +// 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, comparing with 'u' flag +features: [Symbol.match, regexp-v-flag] +includes: [compareArray.js] +---*/ + +const text = '𠮷a𠮷b𠮷c👨‍👩‍👧‍👦d'; + +function doMatch(regex) { + return RegExp.prototype[Symbol.match].call(regex, text); +} + +assert.compareArray(doMatch(/𠮷/g), ["𠮷", "𠮷", "𠮷"], "Basic match with g flag"); +assert.compareArray(doMatch(/𠮷/u), ["𠮷"], "Match with u flag"); +assert.compareArray(doMatch(/𠮷/v), ["𠮷"], "Match with v flag"); + +assert.compareArray(doMatch(/\p{Script=Han}/gu), ["𠮷", "𠮷", "𠮷"], "Unicode property escapes with u flag"); +assert.compareArray(doMatch(/\p{Script=Han}/gv), ["𠮷", "𠮷", "𠮷"], "Unicode property escapes with v flag"); + +assert.compareArray(doMatch(/./g), ["\uD842", "\uDFB7", "a", "\uD842", "\uDFB7", "b", "\uD842", "\uDFB7", "c", "\uD83D", "\uDC68", "\u200D", "\uD83D", "\uDC69", "\u200D", "\uD83D", "\uDC67", "\u200D", "\uD83D", "\uDC66", "d"], "Dot without u or v flag"); +assert.compareArray(doMatch(/./gu), ["𠮷", "a", "𠮷", "b", "𠮷", "c", "👨", "‍", "👩", "‍", "👧", "‍", "👦", "d"], "Dot with u flag"); +assert.compareArray(doMatch(/./gv), ["𠮷", "a", "𠮷", "b", "𠮷", "c", "👨", "‍", "👩", "‍", "👧", "‍", "👦", "d"], "Dot with v flag"); + +assert.compareArray(doMatch(/[👨‍👩‍👧‍👦]/v), ["👨"], "Complex emoji sequence in set notation with v flag"); +assert.compareArray(doMatch(/[👨‍👩‍👧‍👦]/u), ["👨"], "Complex emoji sequence in set notation with u flag throws"); + +assert.sameValue(doMatch(/x/u), null, "Non-matching regex with u flag"); +assert.sameValue(doMatch(/x/v), null, "Non-matching regex with v flag"); +reportCompare(0, 0); diff --git a/test/built-ins/String/prototype/matchAll/regexp-prototype-matchAll-v-flag.js b/test/built-ins/String/prototype/matchAll/regexp-prototype-matchAll-v-flag.js deleted file mode 100644 index 2ab6b28284..0000000000 --- a/test/built-ins/String/prototype/matchAll/regexp-prototype-matchAll-v-flag.js +++ /dev/null @@ -1,43 +0,0 @@ -// 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" -); diff --git a/test/built-ins/String/prototype/matchAll/regexp-prototype-matchAll-v-u-flag.js b/test/built-ins/String/prototype/matchAll/regexp-prototype-matchAll-v-u-flag.js new file mode 100644 index 0000000000..6a70f7f137 --- /dev/null +++ b/test/built-ins/String/prototype/matchAll/regexp-prototype-matchAll-v-u-flag.js @@ -0,0 +1,83 @@ +// 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 'u'and 'v' flags. +features: [Symbol.matchAll, regexp-v-flag, regexp-unicode-property-escapes] +---*/ + +const text = '𠮷a𠮷b𠮷'; + +function doMatchAll(regex) { + const result = Array.from(RegExp.prototype[Symbol.matchAll].call(regex, text)); + const matches = result.map(m => m[0]); + const indices = result.map(m => m.index); + return matches.concat(indices); +} + +assert.sameValue( + assert.compareArray(doMatchAll(/𠮷/g), ['𠮷', '𠮷', '𠮷', 0, 3, 6]), + undefined, + "Basic matchAll with g flag" +); + +assert.sameValue( + assert.compareArray(doMatchAll(/𠮷/gu), ['𠮷', '𠮷', '𠮷', 0, 3, 6]), + undefined, + "matchAll with u flag" +); + +assert.sameValue( + assert.compareArray(doMatchAll(/𠮷/gv), ['𠮷', '𠮷', '𠮷', 0, 3, 6]), + undefined, + "matchAll with v flag" +); + +assert.sameValue( + assert.compareArray(doMatchAll(/\p{Script=Han}/gu), ['𠮷', '𠮷', '𠮷', 0, 3, 6]), + undefined, + "Unicode property escapes with u flag" +); + +assert.sameValue( + assert.compareArray(doMatchAll(/\p{Script=Han}/gv), ['𠮷', '𠮷', '𠮷', 0, 3, 6]), + undefined, + "Unicode property escapes with v flag" +); + +assert.sameValue( + assert.compareArray(doMatchAll(/./gu), ['𠮷', 'a', '𠮷', 'b', '𠮷', 0, 2, 3, 5, 6]), + undefined, + "Dot with u flag" +); + +assert.sameValue( + assert.compareArray(doMatchAll(/./gv), ['𠮷', 'a', '𠮷', 'b', '𠮷', 0, 2, 3, 5, 6]), + undefined, + "Dot with v flag" +); + +assert.sameValue( + doMatchAll(/(?:)/gu).length, + 6, + "Empty matches with u flag" +); + +assert.sameValue( + doMatchAll(/(?:)/gv).length, + 6, + "Empty matches with v flag" +); + +const complexText = 'a\u{20BB7}b\u{10FFFF}c'; +assert.sameValue( + assert.compareArray(Array.from(complexText.matchAll(/\P{ASCII}/gu), m => m[0]), ['\u{20BB7}', '\u{10FFFF}']), + undefined, + "Non-ASCII with u flag" +); +assert.sameValue( + assert.compareArray(Array.from(complexText.matchAll(/\P{ASCII}/gv), m => m[0]), ['\u{20BB7}', '\u{10FFFF}']), + undefined, + "Non-ASCII with v flag" +); +reportCompare(0, 0); diff --git a/test/built-ins/String/prototype/replace/regexp-prototype-replace-v-flag.js b/test/built-ins/String/prototype/replace/regexp-prototype-replace-v-u-flag.js similarity index 80% rename from test/built-ins/String/prototype/replace/regexp-prototype-replace-v-flag.js rename to test/built-ins/String/prototype/replace/regexp-prototype-replace-v-u-flag.js index 57d9e5db07..92b2fd5d75 100644 --- a/test/built-ins/String/prototype/replace/regexp-prototype-replace-v-flag.js +++ b/test/built-ins/String/prototype/replace/regexp-prototype-replace-v-u-flag.js @@ -21,3 +21,8 @@ assert.sameValue( "[𠮷:0][a:2][𠮷:3][b:5][𠮷:6]", "Replace with function" ); + +assert.sameValue(doReplace(/\p{Script=Han}/gu, 'X'), "XaXbX", "Unicode property escapes with u flag"); +assert.sameValue(doReplace(/\p{Script=Han}/gv, 'X'), "XaXbX", "Unicode property escapes with v flag"); + +reportCompare(0, 0); diff --git a/test/built-ins/String/prototype/search/regexp-prototype-search-v-flag.js.js b/test/built-ins/String/prototype/search/regexp-prototype-search-v-flag.js.js deleted file mode 100644 index e59d60dc1e..0000000000 --- a/test/built-ins/String/prototype/search/regexp-prototype-search-v-flag.js.js +++ /dev/null @@ -1,20 +0,0 @@ -// 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"); diff --git a/test/built-ins/String/prototype/search/regexp-prototype-search-v-u-flag.js.js b/test/built-ins/String/prototype/search/regexp-prototype-search-v-u-flag.js.js new file mode 100644 index 0000000000..aa31cead82 --- /dev/null +++ b/test/built-ins/String/prototype/search/regexp-prototype-search-v-u-flag.js.js @@ -0,0 +1,44 @@ +// 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, comparing with 'u' flag +features: [Symbol.search, regexp-v-flag] +---*/ + +const text = '𠮷a𠮷b𠮷c👨‍👩‍👧‍👦d'; + +function doSearch(regex) { + return RegExp.prototype[Symbol.search].call(regex, text); +} + +assert.sameValue(doSearch(/a/), 2, "Basic search without flags"); +assert.sameValue(doSearch(/a/u), 2, "Search with u flag"); +assert.sameValue(doSearch(/a/v), 2, "Search with v flag"); + +// Surrogate pair search +assert.sameValue(doSearch(/𠮷/), 0, "Search for surrogate pair without flags"); +assert.sameValue(doSearch(/𠮷/u), 0, "Search for surrogate pair with u flag"); +assert.sameValue(doSearch(/𠮷/v), 0, "Search for surrogate pair with v flag"); + +// Unicode property escapes +assert.sameValue(doSearch(/\p{Script=Han}/u), 0, "Unicode property escapes with u flag"); +assert.sameValue(doSearch(/\p{Script=Han}/v), 0, "Unicode property escapes with v flag"); + +// Dot behavior +assert.sameValue(doSearch(/c./), 8, "Dot without u or v flag"); +assert.sameValue(doSearch(/c./u), 8, "Dot with u flag"); +assert.sameValue(doSearch(/c./v), 8, "Dot with v flag"); + +// Complex emoji sequence +assert.sameValue(doSearch(/👨‍👩‍👧‍👦/u), 9, "Complex emoji sequence with u flag"); +assert.sameValue(doSearch(/👨‍👩‍👧‍👦/v), 9, "Complex emoji sequence with v flag"); + +// Set notation +assert.sameValue(doSearch(/[👨‍👩‍👧‍👦]/v), 9, "Complex emoji sequence in set notation with v flag"); +assert.sameValue(doSearch(/[👨‍👩‍👧‍👦]/u), 9, "Complex emoji sequence in set notation with u flag throws"); + +// Non-existent pattern +assert.sameValue(doSearch(/x/u), -1, "Search for non-existent pattern with u flag"); +assert.sameValue(doSearch(/x/v), -1, "Search for non-existent pattern with v flag"); +reportCompare(0, 0);