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/NumberFormat/use-grouping.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/NumberFormat/use-grouping.js | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/js/src/tests/non262/Intl/NumberFormat/use-grouping.js b/js/src/tests/non262/Intl/NumberFormat/use-grouping.js new file mode 100644 index 0000000000..8fcb2fb51e --- /dev/null +++ b/js/src/tests/non262/Intl/NumberFormat/use-grouping.js @@ -0,0 +1,97 @@ +// |reftest| skip-if(!this.hasOwnProperty("Intl")||release_or_beta) + +const tests = { + // minimumGroupingDigits is one for "en" (English). + "en": { + values: [ + { + value: 1000, + useGroupings: { + auto: "1,000", + always: "1,000", + min2: "1000", + "": "1000", + }, + }, + { + value: 10000, + useGroupings: { + auto: "10,000", + always: "10,000", + min2: "10,000", + "": "10000", + }, + }, + ], + }, + + // minimumGroupingDigits is two for "pl" (Polish). + "pl": { + values: [ + { + value: 1000, + useGroupings: { + auto: "1000", + always: "1 000", + min2: "1000", + "": "1000", + }, + }, + { + value: 10000, + useGroupings: { + auto: "10 000", + always: "10 000", + min2: "10 000", + "": "10000", + }, + }, + ], + }, +}; + +for (let [locale, {options = {}, values}] of Object.entries(tests)) { + for (let {value, useGroupings} of values) { + for (let [useGrouping, expected] of Object.entries(useGroupings)) { + let nf = new Intl.NumberFormat(locale, {...options, useGrouping}); + assertEq(nf.format(value), expected, `locale=${locale}, value=${value}, useGrouping=${useGrouping}`); + } + } +} + +// Resolved options. +for (let [useGrouping, expected] of [ + [false, false], + ["", false], + [0, false], + [null, false], + + ["auto", "auto"], + [undefined, "auto"], + + ["always", "always"], + [true, "always"], + + ["min2", "min2"], + + // Unsupported values fallback to "auto" + ["true", "auto"], + ["false", "auto"], + ["none", "auto"], + ["yes", "auto"], + ["no", "auto"], + [{}, "auto"], + [123, "auto"], + [123n, "auto"], +]) { + let nf = new Intl.NumberFormat("en", {useGrouping}); + assertEq(nf.resolvedOptions().useGrouping , expected); +} + +// Throws a TypeError if ToString fails. +for (let useGrouping of [Object.create(null), Symbol()]) { + assertThrowsInstanceOf(() => new Intl.NumberFormat("en", {useGrouping}), TypeError); +} + +if (typeof reportCompare === "function") + reportCompare(true, true); |