mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:47:35 +00:00
LibJS: Implement Intl.NumberFormat V3's [[TrailingZeroDisplay]] changes
This commit is contained in:
parent
a712c7b5e1
commit
37ab7cc694
2 changed files with 68 additions and 5 deletions
|
@ -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", () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue