summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Intl/NumberFormat/currency-sign-accounting.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 14:29:10 +0000
commit2aa4a82499d4becd2284cdb482213d541b8804dd (patch)
treeb80bf8bf13c3766139fbacc530efd0dd9d54394c /js/src/tests/non262/Intl/NumberFormat/currency-sign-accounting.js
parentInitial commit. (diff)
downloadfirefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz
firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/Intl/NumberFormat/currency-sign-accounting.js')
-rw-r--r--js/src/tests/non262/Intl/NumberFormat/currency-sign-accounting.js192
1 files changed, 192 insertions, 0 deletions
diff --git a/js/src/tests/non262/Intl/NumberFormat/currency-sign-accounting.js b/js/src/tests/non262/Intl/NumberFormat/currency-sign-accounting.js
new file mode 100644
index 0000000000..6f91d6edd4
--- /dev/null
+++ b/js/src/tests/non262/Intl/NumberFormat/currency-sign-accounting.js
@@ -0,0 +1,192 @@
+// |reftest| skip-if(!this.hasOwnProperty("Intl"))
+
+const {
+ Nan, Inf, Integer, MinusSign, PlusSign, Decimal, Fraction,
+ Currency, Literal,
+} = NumberFormatParts;
+
+const testcases = [
+ // "auto": Show the sign on negative numbers only.
+ {
+ locale: "en",
+ options: {
+ style: "currency",
+ currency: "USD",
+ currencySign: "accounting",
+ signDisplay: "auto",
+ },
+ values: [
+ {value: +0, string: "$0.00",
+ parts: [Currency("$"), Integer("0"), Decimal("."), Fraction("00")]},
+ {value: -0, string: "($0.00)",
+ parts: [Literal("("), Currency("$"), Integer("0"), Decimal("."), Fraction("00"), Literal(")")]},
+
+ {value: 1, string: "$1.00",
+ parts: [Currency("$"), Integer("1"), Decimal("."), Fraction("00")]},
+ {value: -1, string: "($1.00)",
+ parts: [Literal("("), Currency("$"), Integer("1"), Decimal("."), Fraction("00"), Literal(")")]},
+
+ {value: Infinity, string: "$∞", parts: [Currency("$"), Inf("∞")]},
+ {value: -Infinity, string: "($∞)", parts: [Literal("("), Currency("$"), Inf("∞"), Literal(")")]},
+
+ {value: NaN, string: "$NaN", parts: [Currency("$"), Nan("NaN")]},
+ {value: -NaN, string: "$NaN", parts: [Currency("$"), Nan("NaN")]},
+ ],
+ },
+
+ // "never": Show the sign on neither positive nor negative numbers.
+ {
+ locale: "en",
+ options: {
+ style: "currency",
+ currency: "USD",
+ currencySign: "accounting",
+ signDisplay: "never",
+ },
+ values: [
+ {value: +0, string: "$0.00", parts: [Currency("$"), Integer("0"), Decimal("."), Fraction("00")]},
+ {value: -0, string: "$0.00", parts: [Currency("$"), Integer("0"), Decimal("."), Fraction("00")]},
+
+ {value: 1, string: "$1.00", parts: [Currency("$"), Integer("1"), Decimal("."), Fraction("00")]},
+ {value: -1, string: "$1.00", parts: [Currency("$"), Integer("1"), Decimal("."), Fraction("00")]},
+
+ {value: Infinity, string: "$∞", parts: [Currency("$"), Inf("∞")]},
+ {value: -Infinity, string: "$∞", parts: [Currency("$"), Inf("∞")]},
+
+ {value: NaN, string: "$NaN", parts: [Currency("$"), Nan("NaN")]},
+ {value: -NaN, string: "$NaN", parts: [Currency("$"), Nan("NaN")]},
+ ],
+ },
+
+ // "always": Show the sign on positive and negative numbers including zero.
+ {
+ locale: "en",
+ options: {
+ style: "currency",
+ currency: "USD",
+ currencySign: "accounting",
+ signDisplay: "always",
+ },
+ values: [
+ {value: +0, string: "+$0.00",
+ parts: [PlusSign("+"), Currency("$"), Integer("0"), Decimal("."), Fraction("00")]},
+ {value: -0, string: "($0.00)",
+ parts: [Literal("("), Currency("$"), Integer("0"), Decimal("."), Fraction("00"), Literal(")")]},
+
+ {value: 1, string: "+$1.00",
+ parts: [PlusSign("+"), Currency("$"), Integer("1"), Decimal("."), Fraction("00")]},
+ {value: -1, string: "($1.00)",
+ parts: [Literal("("), Currency("$"), Integer("1"), Decimal("."), Fraction("00"), Literal(")")]},
+
+ {value: Infinity, string: "+$∞", parts: [PlusSign("+"), Currency("$"), Inf("∞")]},
+ {value: -Infinity, string: "($∞)", parts: [Literal("("), Currency("$"), Inf("∞"), Literal(")")]},
+
+ {value: NaN, string: "+$NaN", parts: [PlusSign("+"), Currency("$"), Nan("NaN")]},
+ {value: -NaN, string: "+$NaN", parts: [PlusSign("+"), Currency("$"), Nan("NaN")]},
+ ],
+ },
+
+ // "exceptZero": Show the sign on positive and negative numbers but not zero.
+ {
+ locale: "en",
+ options: {
+ style: "currency",
+ currency: "USD",
+ currencySign: "accounting",
+ signDisplay: "exceptZero",
+ },
+ values: [
+ {value: +0, string: "$0.00",
+ parts: [Currency("$"), Integer("0"), Decimal("."), Fraction("00")]},
+ {value: -0, string: "$0.00",
+ parts: [Currency("$"), Integer("0"), Decimal("."), Fraction("00")]},
+
+ {value: 1, string: "+$1.00",
+ parts: [PlusSign("+"), Currency("$"), Integer("1"), Decimal("."), Fraction("00")]},
+ {value: -1, string: "($1.00)",
+ parts: [Literal("("), Currency("$"), Integer("1"), Decimal("."), Fraction("00"), Literal(")")]},
+
+ {value: Infinity, string: "+$∞", parts: [PlusSign("+"), Currency("$"), Inf("∞")]},
+ {value: -Infinity, string: "($∞)", parts: [Literal("("), Currency("$"), Inf("∞"), Literal(")")]},
+
+ {value: NaN, string: "$NaN", parts: [Currency("$"), Nan("NaN")]},
+ {value: -NaN, string: "$NaN", parts: [Currency("$"), Nan("NaN")]},
+ ],
+ },
+
+ // Tests with suppressed fractional digits.
+
+ // "auto": Show the sign on negative numbers only.
+ {
+ locale: "en",
+ options: {
+ style: "currency",
+ currency: "USD",
+ currencySign: "accounting",
+ signDisplay: "auto",
+ minimumFractionDigits: 0,
+ maximumFractionDigits: 0,
+ },
+ values: [
+ {value: +0.1, string: "$0", parts: [Currency("$"), Integer("0")]},
+ {value: -0.1, string: "($0)", parts: [Literal("("), Currency("$"), Integer("0"), Literal(")")]},
+ ],
+ },
+
+ // "never": Show the sign on neither positive nor negative numbers.
+ {
+ locale: "en",
+ options: {
+ style: "currency",
+ currency: "USD",
+ currencySign: "accounting",
+ signDisplay: "never",
+ minimumFractionDigits: 0,
+ maximumFractionDigits: 0,
+ },
+ values: [
+ {value: +0.1, string: "$0", parts: [Currency("$"), Integer("0")]},
+ {value: -0.1, string: "$0", parts: [Currency("$"), Integer("0")]},
+ ],
+ },
+
+ // "always": Show the sign on positive and negative numbers including zero.
+ {
+ locale: "en",
+ options: {
+ style: "currency",
+ currency: "USD",
+ currencySign: "accounting",
+ signDisplay: "always",
+ minimumFractionDigits: 0,
+ maximumFractionDigits: 0,
+ },
+ values: [
+ {value: +0.1, string: "+$0", parts: [PlusSign("+"), Currency("$"), Integer("0")]},
+ {value: -0.1, string: "($0)", parts: [Literal("("), Currency("$"), Integer("0"), Literal(")")]},
+ ],
+ },
+
+ // "exceptZero": Show the sign on positive and negative numbers but not zero.
+ {
+ locale: "en",
+ options: {
+ style: "currency",
+ currency: "USD",
+ currencySign: "accounting",
+ signDisplay: "exceptZero",
+ minimumFractionDigits: 0,
+ maximumFractionDigits: 0,
+ },
+
+ values: [
+ {value: +0.1, string: "$0", parts: [Currency("$"), Integer("0")]},
+ {value: -0.1, string: "$0", parts: [Currency("$"), Integer("0")]},
+ ],
+ }
+];
+
+runNumberFormattingTestcases(testcases);
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);