summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Tests
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2022-07-16 12:46:14 -0400
committerLinus Groh <mail@linusgroh.de>2022-07-18 08:51:07 +0100
commit37ab7cc694df2b1608945a9f8b04c6776cd58d04 (patch)
tree989afd7bf2d9b1a1373ba22d4c4d9ee86ec90a8b /Userland/Libraries/LibJS/Tests
parenta712c7b5e171f6b57ef7e02be2b0d41a725464c3 (diff)
downloadserenity-37ab7cc694df2b1608945a9f8b04c6776cd58d04.zip
LibJS: Implement Intl.NumberFormat V3's [[TrailingZeroDisplay]] changes
Diffstat (limited to 'Userland/Libraries/LibJS/Tests')
-rw-r--r--Userland/Libraries/LibJS/Tests/builtins/Intl/NumberFormat/NumberFormat.prototype.format.js44
1 files changed, 44 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Tests/builtins/Intl/NumberFormat/NumberFormat.prototype.format.js b/Userland/Libraries/LibJS/Tests/builtins/Intl/NumberFormat/NumberFormat.prototype.format.js
index 5e9a135e0a..508636af02 100644
--- a/Userland/Libraries/LibJS/Tests/builtins/Intl/NumberFormat/NumberFormat.prototype.format.js
+++ b/Userland/Libraries/LibJS/Tests/builtins/Intl/NumberFormat/NumberFormat.prototype.format.js
@@ -567,6 +567,50 @@ describe("style=decimal", () => {
expect(nf("ar", undefined, 2, undefined, 2).format(1.23)).toBe("\u0661\u066b\u0662\u0663");
expect(nf("ar", undefined, 3, undefined, 1).format(1.23)).toBe("\u0661\u066b\u0662\u0663");
});
+
+ test("trailingZeroDisplay=auto", () => {
+ const en = new Intl.NumberFormat("en", {
+ trailingZeroDisplay: "auto",
+ minimumSignificantDigits: 5,
+ });
+ expect(en.format(1)).toBe("1.0000");
+ expect(en.format(1n)).toBe("1.0000");
+ expect(en.format(12)).toBe("12.000");
+ expect(en.format(12n)).toBe("12.000");
+ expect(en.format(1.2)).toBe("1.2000");
+
+ const ar = new Intl.NumberFormat("ar", {
+ trailingZeroDisplay: "auto",
+ minimumSignificantDigits: 5,
+ });
+ expect(ar.format(1)).toBe("\u0661\u066b\u0660\u0660\u0660\u0660");
+ expect(ar.format(1n)).toBe("\u0661\u066b\u0660\u0660\u0660\u0660");
+ expect(ar.format(12)).toBe("\u0661\u0662\u066b\u0660\u0660\u0660");
+ expect(ar.format(12n)).toBe("\u0661\u0662\u066b\u0660\u0660\u0660");
+ expect(ar.format(1.2)).toBe("\u0661\u066b\u0662\u0660\u0660\u0660");
+ });
+
+ test("trailingZeroDisplay=stripIfInteger", () => {
+ const en = new Intl.NumberFormat("en", {
+ trailingZeroDisplay: "stripIfInteger",
+ minimumSignificantDigits: 5,
+ });
+ expect(en.format(1)).toBe("1");
+ expect(en.format(1n)).toBe("1");
+ expect(en.format(12)).toBe("12");
+ expect(en.format(12n)).toBe("12");
+ expect(en.format(1.2)).toBe("1.2000");
+
+ const ar = new Intl.NumberFormat("ar", {
+ trailingZeroDisplay: "stripIfInteger",
+ minimumSignificantDigits: 5,
+ });
+ expect(ar.format(1)).toBe("\u0661");
+ expect(ar.format(1n)).toBe("\u0661");
+ expect(ar.format(12)).toBe("\u0661\u0662");
+ expect(ar.format(12n)).toBe("\u0661\u0662");
+ expect(ar.format(1.2)).toBe("\u0661\u066b\u0662\u0660\u0660\u0660");
+ });
});
describe("style=percent", () => {