From 1991c24d914d95494f4d1838148988c602898765 Mon Sep 17 00:00:00 2001 From: Alexey Shvayka Date: Tue, 21 Apr 2020 14:49:42 +0300 Subject: [PATCH] Add valid Unicode test --- .../unicode-property-names-valid.js | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 test/built-ins/RegExp/named-groups/unicode-property-names-valid.js diff --git a/test/built-ins/RegExp/named-groups/unicode-property-names-valid.js b/test/built-ins/RegExp/named-groups/unicode-property-names-valid.js new file mode 100644 index 0000000000..316d68d567 --- /dev/null +++ b/test/built-ins/RegExp/named-groups/unicode-property-names-valid.js @@ -0,0 +1,100 @@ +// Copyright 2020 the Apple Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +author: Michael Saboff +description: Exotic named group names in Unicode RegExps +esid: prod-GroupSpecifier +features: [regexp-named-groups] +---*/ + +/* + Valid ID_Start / ID_Continue Unicode characters + + 𝑓 \u{1d453} \ud835 \udc53 + π‘œ \u{1d45c} \ud835 \udc5c + π‘₯ \u{id465} \ud835 \udc65 + + 𝓓 \u{1d4d3} \ud835 \udcd3 + 𝓸 \u{1d4f8} \ud835 \udcf8 + 𝓰 \u{1d4f0} \ud835 \udcf0 + + 𝓑 \u{1d4d1} \ud835 \udcd1 + 𝓻 \u{1d4fb} \ud835 \udcfb + 𝓸 \u{1d4f8} \ud835 \udcf8 + 𝔀 \u{1d500} \ud835 \udd00 + 𝓷 \u{1d4f7} \ud835 \udcf7 + + 𝖰 \u{1d5b0} \ud835 \uddb0 + 𝖑 \u{1d5a1} \ud835 \udda1 + π–₯ \u{1d5a5} \ud835 \udda5 + + (fox) η‹Έ \u{72f8} \u72f8 + (dog) η‹— \u{72d7} \u72d7 + + Valid ID_Continue Unicode characters (Can't be first identifier character.) + + 𝟚 \u{1d7da} \ud835 \udfda + + Invalid ID_Start / ID_Continue + + (fox face emoji) 🦊 \u{1f98a} \ud83e \udd8a + (dog emoji) πŸ• \u{1f415} \ud83d \udc15 +*/ + +var string = "The quick brown fox jumped over the lazy dog's back"; +var string2 = "It is a dog eat dog world."; + +let match = null; + +assert.sameValue(string.match(/(?fox|dog)/u).groups.animal, "fox"); +assert.sameValue(string.match(/(?the)/u).groups.the2, "the"); + +match = string.match(/(?<π‘“π‘œπ‘₯>fox).*(?<𝓓𝓸𝓰>dog)/u); +assert.sameValue(match.groups.π‘“π‘œπ‘₯, "fox"); +assert.sameValue(match.groups.𝓓𝓸𝓰, "dog"); +assert.sameValue(match[1], "fox"); +assert.sameValue(match[2], "dog"); + +match = string.match(/(?<η‹Έ>fox).*(?<η‹—>dog)/u); +assert.sameValue(match.groups.η‹Έ, "fox"); +assert.sameValue(match.groups.η‹—, "dog"); +assert.sameValue(match[1], "fox"); +assert.sameValue(match[2], "dog"); + +assert.sameValue(string.match(/(?<𝓑𝓻𝓸𝔀𝓷>brown)/u).groups.𝓑𝓻𝓸𝔀𝓷, "brown"); +assert.sameValue(string.match(/(?<𝓑𝓻𝓸𝔀𝓷>brown)/u).groups.\u{1d4d1}\u{1d4fb}\u{1d4f8}\u{1d500}\u{1d4f7}, "brown"); +assert.sameValue(string.match(/(?<\u{1d4d1}\u{1d4fb}\u{1d4f8}\u{1d500}\u{1d4f7}>brown)/u).groups.𝓑𝓻𝓸𝔀𝓷, "brown"); +assert.sameValue(string.match(/(?<\u{1d4d1}\u{1d4fb}\u{1d4f8}\u{1d500}\u{1d4f7}>brown)/u).groups.\u{1d4d1}\u{1d4fb}\u{1d4f8}\u{1d500}\u{1d4f7}, "brown"); +assert.sameValue(string.match(/(?<\ud835\udcd1\ud835\udcfb\ud835\udcf8\ud835\udd00\ud835\udcf7>brown)/u).groups.𝓑𝓻𝓸𝔀𝓷, "brown"); +assert.sameValue(string.match(/(?<\ud835\udcd1\ud835\udcfb\ud835\udcf8\ud835\udd00\ud835\udcf7>brown)/u).groups.\u{1d4d1}\u{1d4fb}\u{1d4f8}\u{1d500}\u{1d4f7}, "brown"); + +assert.sameValue(string.match(/(?<𝖰𝖑π–₯>q\w*\W\w*\W\w*)/u).groups.𝖰𝖑π–₯, "quick brown fox"); +assert.sameValue(string.match(/(?<𝖰𝖑\u{1d5a5}>q\w*\W\w*\W\w*)/u).groups.𝖰𝖑π–₯, "quick brown fox"); +assert.sameValue(string.match(/(?<𝖰\u{1d5a1}π–₯>q\w*\W\w*\W\w*)/u).groups.𝖰𝖑π–₯, "quick brown fox"); +assert.sameValue(string.match(/(?<𝖰\u{1d5a1}\u{1d5a5}>q\w*\W\w*\W\w*)/u).groups.𝖰𝖑π–₯, "quick brown fox"); +assert.sameValue(string.match(/(?<\u{1d5b0}𝖑π–₯>q\w*\W\w*\W\w*)/u).groups.𝖰𝖑π–₯, "quick brown fox"); +assert.sameValue(string.match(/(?<\u{1d5b0}𝖑\u{1d5a5}>q\w*\W\w*\W\w*)/u).groups.𝖰𝖑π–₯, "quick brown fox"); +assert.sameValue(string.match(/(?<\u{1d5b0}\u{1d5a1}π–₯>q\w*\W\w*\W\w*)/u).groups.𝖰𝖑π–₯, "quick brown fox"); +assert.sameValue(string.match(/(?<\u{1d5b0}\u{1d5a1}\u{1d5a5}>q\w*\W\w*\W\w*)/u).groups.𝖰𝖑π–₯, "quick brown fox"); + +assert.sameValue(string.match(/(?the)/u).groups.the𝟚, "the"); +assert.sameValue(string.match(/(?the)/u).groups.the𝟚, "the"); +assert.sameValue(string.match(/(?the)/u).groups.the𝟚, "the"); + +match = string2.match(/(?dog)(.*?)(\k)/u); +assert.sameValue(match.groups.dog, "dog"); +assert.sameValue(match[1], "dog"); +assert.sameValue(match[2], " eat "); +assert.sameValue(match[3], "dog"); + +match = string2.match(/(?<𝓓𝓸𝓰>dog)(.*?)(\k<𝓓𝓸𝓰>)/u); +assert.sameValue(match.groups.𝓓𝓸𝓰, "dog"); +assert.sameValue(match[1], "dog"); +assert.sameValue(match[2], " eat "); +assert.sameValue(match[3], "dog"); + +match = string2.match(/(?<η‹—>dog)(.*?)(\k<η‹—>)/u); +assert.sameValue(match.groups.η‹—, "dog"); +assert.sameValue(match[1], "dog"); +assert.sameValue(match[2], " eat "); +assert.sameValue(match[3], "dog");