diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/Intl/resolved-locale-sorted-unicode-extension-keys.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | js/src/tests/non262/Intl/resolved-locale-sorted-unicode-extension-keys.js | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/js/src/tests/non262/Intl/resolved-locale-sorted-unicode-extension-keys.js b/js/src/tests/non262/Intl/resolved-locale-sorted-unicode-extension-keys.js new file mode 100644 index 0000000000..400f7f0f63 --- /dev/null +++ b/js/src/tests/non262/Intl/resolved-locale-sorted-unicode-extension-keys.js @@ -0,0 +1,109 @@ +// |reftest| skip-if(!this.hasOwnProperty("Intl")) + +function IsIntlService(c) { + return typeof c === "function" && + c.hasOwnProperty("prototype") && + c.prototype.hasOwnProperty("resolvedOptions"); +} + +const IntlServices = Object.getOwnPropertyNames(Intl).map(name => Intl[name]).filter(IsIntlService); + +// Examples for all possible Unicode extension keys (with the exception of deprecated "vt"). +const unicodeExtensions = [ + // calendar + "ca-gregory", + "fw-mon", + "hc-h23", + + // collation + "co-phonebk", + "ka-noignore", + "kb-false", + "kc-false", + "kf-false", + "kh-false", + "kk-false", + "kn-false", + "kr-space", + "ks-level1", + "kv-space", + + // currency + "cf-standard", + "cu-eur", + + // measure + "ms-metric", + + // number + "nu-latn", + + // segmentation + "lb-strict", + "lw-normal", + "ss-none", + + // timezone + "tz-atvie", + + // variant + "em-default", + "rg-atzzzz", + "sd-atat1", + "va-posix", +]; + +function reverse(a, b) { + if (a < b) { + return 1; + } + if (a > b) { + return -1; + } + return 0; +} + +function findUnicodeExtensionKeys(locale) { + // Find the Unicode extension key subtag. + var extension = locale.match(/.*-u-(.*)/); + if (extension === null) { + return []; + } + + // Replace all types in the Unicode extension keywords. + return extension[1].replace(/-\w{3,}/g, "").split("-"); +} + +// Test all Intl service constructors and ensure the Unicode extension keys in +// the resolved locale are sorted alphabetically. + +for (let IntlService of IntlServices) { + let options = undefined; + if (IntlService === Intl.DisplayNames) { + // Intl.DisplayNames requires the "type" option to be set. + options = {type: "language"}; + } + + // sort() modifies the input array, so create a copy. + let ext = unicodeExtensions.slice(0); + + let locale, keys; + + // Input keys unsorted. + locale = new IntlService(`de-u-${ext.join("-")}`, options).resolvedOptions().locale; + keys = findUnicodeExtensionKeys(locale); + assertEqArray(keys, keys.slice(0).sort()); + + // Input keys sorted alphabetically. + locale = new IntlService(`de-u-${ext.sort().join("-")}`, options).resolvedOptions().locale; + keys = findUnicodeExtensionKeys(locale); + assertEqArray(keys, keys.slice(0).sort()); + + // Input keys sorted alphabetically in reverse order. + locale = new IntlService(`de-u-${ext.sort(reverse).join("-")}`, options).resolvedOptions().locale; + keys = findUnicodeExtensionKeys(locale); + assertEqArray(keys, keys.slice(0).sort()); +} + +if (typeof reportCompare === "function") + reportCompare(0, 0); |