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/formatRange-BigInt.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/formatRange-BigInt.js | 150 |
1 files changed, 150 insertions, 0 deletions
diff --git a/js/src/tests/non262/Intl/NumberFormat/formatRange-BigInt.js b/js/src/tests/non262/Intl/NumberFormat/formatRange-BigInt.js new file mode 100644 index 0000000000..36ccdf59e3 --- /dev/null +++ b/js/src/tests/non262/Intl/NumberFormat/formatRange-BigInt.js @@ -0,0 +1,150 @@ +// |reftest| skip-if(!this.hasOwnProperty("Intl")||release_or_beta) + +// Int64-BigInts which can be exactly represented as doubles receive a fast-path. + +const tests = { + "en": { + options: {}, + ranges: [ + // BigInt around Number.MIN_SAFE_INTEGER. + { + start: -0x20000000000001n, + end: -0x20000000000000n, + result: "-9,007,199,254,740,993 – -9,007,199,254,740,992", + }, + { + start: -0x20000000000000n, + end: -0x20000000000000n, + result: "~-9,007,199,254,740,992", + }, + { + start: -0x20000000000000n, + end: -0x1fffffffffffffn, + result: "-9,007,199,254,740,992 – -9,007,199,254,740,991", + }, + { + start: -0x1fffffffffffffn, + end: -0x1fffffffffffffn, + result: "~-9,007,199,254,740,991", + }, + { + start: -0x1fffffffffffffn, + end: -0x1ffffffffffffen, + result: "-9,007,199,254,740,991 – -9,007,199,254,740,990", + }, + { + start: -0x1ffffffffffffen, + end: -0x1ffffffffffffen, + result: "~-9,007,199,254,740,990", + }, + + // BigInt around Number.MAX_SAFE_INTEGER. + { + start: 0x1ffffffffffffen, + end: 0x1ffffffffffffen, + result: "~9,007,199,254,740,990", + }, + { + start: 0x1ffffffffffffen, + end: 0x1fffffffffffffn, + result: "9,007,199,254,740,990–9,007,199,254,740,991", + }, + { + start: 0x1fffffffffffffn, + end: 0x1fffffffffffffn, + result: "~9,007,199,254,740,991", + }, + { + start: 0x1fffffffffffffn, + end: 0x20000000000000n, + result: "9,007,199,254,740,991–9,007,199,254,740,992", + }, + { + start: 0x20000000000000n, + end: 0x20000000000000n, + result: "~9,007,199,254,740,992", + }, + { + start: 0x20000000000000n, + end: 0x20000000000001n, + result: "9,007,199,254,740,992–9,007,199,254,740,993", + }, + + // BigInt around INT64_MIN. + { + start: -0x8000000000000002n, + end: -0x8000000000000001n, + result: "-9,223,372,036,854,775,810 – -9,223,372,036,854,775,809", + }, + { + start: -0x8000000000000001n, + end: -0x8000000000000001n, + result: "~-9,223,372,036,854,775,809", + }, + { + start: -0x8000000000000001n, + end: -0x8000000000000000n, + result: "-9,223,372,036,854,775,809 – -9,223,372,036,854,775,808", + }, + { + start: -0x8000000000000000n, + end: -0x8000000000000000n, + result: "~-9,223,372,036,854,775,808", + }, + { + start: -0x8000000000000000n, + end: -0x7fffffffffffffffn, + result: "-9,223,372,036,854,775,808 – -9,223,372,036,854,775,807", + }, + { + start: -0x7fffffffffffffffn, + end: -0x7fffffffffffffffn, + result: "~-9,223,372,036,854,775,807", + }, + + // BigInt around INT64_MAX. + { + start: 0x7ffffffffffffffen, + end: 0x7ffffffffffffffen, + result: "~9,223,372,036,854,775,806", + }, + { + start: 0x7ffffffffffffffen, + end: 0x7fffffffffffffffn, + result: "9,223,372,036,854,775,806–9,223,372,036,854,775,807", + }, + { + start: 0x7fffffffffffffffn, + end: 0x7fffffffffffffffn, + result: "~9,223,372,036,854,775,807", + }, + { + start: 0x7fffffffffffffffn, + end: 0x8000000000000000n, + result: "9,223,372,036,854,775,807–9,223,372,036,854,775,808", + }, + { + start: 0x8000000000000000n, + end: 0x8000000000000000n, + result: "~9,223,372,036,854,775,808", + }, + { + start: 0x8000000000000000n, + end: 0x8000000000000001n, + result: "9,223,372,036,854,775,808–9,223,372,036,854,775,809", + }, + ], + }, +}; + +for (let [locale, {options, ranges}] of Object.entries(tests)) { + let nf = new Intl.NumberFormat(locale, options); + for (let {start, end, result} of ranges) { + assertEq(nf.formatRange(start, end), result, `${start}-${end}`); + assertEq(nf.formatRangeToParts(start, end).reduce((acc, part) => acc + part.value, ""), + result, `${start}-${end}`); + } +} + +if (typeof reportCompare === "function") + reportCompare(true, true); |