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/test262/intl402/NumberFormat/test-option-currency.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/intl402/NumberFormat/test-option-currency.js')
-rw-r--r-- | js/src/tests/test262/intl402/NumberFormat/test-option-currency.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/js/src/tests/test262/intl402/NumberFormat/test-option-currency.js b/js/src/tests/test262/intl402/NumberFormat/test-option-currency.js new file mode 100644 index 0000000000..d1d786fab1 --- /dev/null +++ b/js/src/tests/test262/intl402/NumberFormat/test-option-currency.js @@ -0,0 +1,57 @@ +// Copyright 2012 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es5id: 11.1.1_17 +description: Tests that the option currency is processed correctly. +author: Norbert Lindenberg +---*/ + +var validValues = ["CNY", "USD", "EUR", "IDR", "jpy", {toString: function () {return "INR";}}]; +var invalidValues = ["$", "SFr.", "US$", "ßP", {toString: function () {return;}}]; + +var defaultLocale = new Intl.NumberFormat().resolvedOptions().locale; + +validValues.forEach(function (value) { + var format, actual, expected; + + // with currency style, we should get the upper case form back + format = new Intl.NumberFormat([defaultLocale], {style: "currency", currency: value}); + actual = format.resolvedOptions().currency; + expected = value.toString().toUpperCase(); + assert.sameValue(actual, expected, "Incorrect resolved currency with currency style."); + + // without currency style, we shouldn't get any currency back + format = new Intl.NumberFormat([defaultLocale], {currency: value}); + actual = format.resolvedOptions().currency; + expected = undefined; + assert.sameValue(actual, expected, "Incorrect resolved currency with non-currency style."); + + // currencies specified through the locale must be ignored + format = new Intl.NumberFormat([defaultLocale + "-u-cu-krw"], {style: "currency", currency: value}); + actual = format.resolvedOptions().currency; + expected = value.toString().toUpperCase(); + assert.sameValue(actual, expected, "Incorrect resolved currency with -u-cu- and currency style."); + + format = new Intl.NumberFormat([defaultLocale + "-u-cu-krw"], {currency: value}); + actual = format.resolvedOptions().currency; + expected = undefined; + assert.sameValue(actual, expected, "Incorrect resolved currency with -u-cu- and non-currency style."); +}); + +invalidValues.forEach(function (value) { + assert.throws(RangeError, function () { + return new Intl.NumberFormat([defaultLocale], {style: "currency", currency: value}); + }, "Invalid currency value " + value + " was not rejected."); + assert.throws(RangeError, function () { + return new Intl.NumberFormat([defaultLocale], {currency: value}); + }, "Invalid currency value " + value + " was not rejected."); + assert.throws(RangeError, function () { + return new Intl.NumberFormat([defaultLocale + "-u-cu-krw"], {style: "currency", currency: value}); + }, "Invalid currency value " + value + " was not rejected."); + assert.throws(RangeError, function () { + return new Intl.NumberFormat([defaultLocale + "-u-cu-krw"], {currency: value}); + }, "Invalid currency value " + value + " was not rejected."); +}); + +reportCompare(0, 0); |