mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 19:27:35 +00:00
LibJS: Move resolution of some Intl.NumberFormat options to a common AO
This is a normative change in the Intl.NumberFormat V3 spec. See:
29acfc6
This is to allow Intl.PluralRules to use these options, as they were in-
effect required by later AOs anyways.
This commit is contained in:
parent
093cf428a3
commit
5b3b14be0a
5 changed files with 197 additions and 63 deletions
|
@ -125,6 +125,57 @@ describe("errors", () => {
|
|||
"hello! is not a valid value for option roundingPriority"
|
||||
);
|
||||
});
|
||||
|
||||
test("roundingMode option is invalid", () => {
|
||||
expect(() => {
|
||||
new Intl.PluralRules("en", { roundingMode: "hello!" });
|
||||
}).toThrowWithMessage(RangeError, "hello! is not a valid value for option roundingMode");
|
||||
});
|
||||
|
||||
test("roundingIncrement option is invalid", () => {
|
||||
expect(() => {
|
||||
new Intl.PluralRules("en", { roundingIncrement: "hello!" });
|
||||
}).toThrowWithMessage(RangeError, "Value NaN is NaN or is not between 1 and 5000");
|
||||
|
||||
expect(() => {
|
||||
new Intl.PluralRules("en", { roundingIncrement: 0 });
|
||||
}).toThrowWithMessage(RangeError, "Value 0 is NaN or is not between 1 and 5000");
|
||||
|
||||
expect(() => {
|
||||
new Intl.PluralRules("en", { roundingIncrement: 5001 });
|
||||
}).toThrowWithMessage(RangeError, "Value 5001 is NaN or is not between 1 and 5000");
|
||||
|
||||
expect(() => {
|
||||
new Intl.PluralRules("en", { roundingIncrement: 3 });
|
||||
}).toThrowWithMessage(RangeError, "3 is not a valid rounding increment");
|
||||
|
||||
expect(() => {
|
||||
new Intl.PluralRules("en", { roundingIncrement: 5, minimumSignificantDigits: 1 });
|
||||
}).toThrowWithMessage(
|
||||
TypeError,
|
||||
"5 is not a valid rounding increment for rounding type significantDigits"
|
||||
);
|
||||
|
||||
expect(() => {
|
||||
new Intl.PluralRules("en", {
|
||||
roundingIncrement: 5,
|
||||
minimumFractionDigits: 2,
|
||||
maximumFractionDigits: 3,
|
||||
});
|
||||
}).toThrowWithMessage(
|
||||
RangeError,
|
||||
"5 is not a valid rounding increment for inequal min/max fraction digits"
|
||||
);
|
||||
});
|
||||
|
||||
test("trailingZeroDisplay option is invalid", () => {
|
||||
expect(() => {
|
||||
new Intl.PluralRules("en", { trailingZeroDisplay: "hello!" });
|
||||
}).toThrowWithMessage(
|
||||
RangeError,
|
||||
"hello! is not a valid value for option trailingZeroDisplay"
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("normal behavior", () => {
|
||||
|
@ -195,4 +246,40 @@ describe("normal behavior", () => {
|
|||
}).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
test("all valid roundingMode options", () => {
|
||||
[
|
||||
"ceil",
|
||||
"floor",
|
||||
"expand",
|
||||
"trunc",
|
||||
"halfCeil",
|
||||
"halfFloor",
|
||||
"halfExpand",
|
||||
"halfTrunc",
|
||||
"halfEven",
|
||||
].forEach(roundingMode => {
|
||||
expect(() => {
|
||||
new Intl.PluralRules("en", { roundingMode: roundingMode });
|
||||
}).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
test("all valid roundingIncrement options", () => {
|
||||
[1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000, 2500, 5000].forEach(
|
||||
roundingIncrement => {
|
||||
expect(() => {
|
||||
new Intl.PluralRules("en", { roundingIncrement: roundingIncrement });
|
||||
}).not.toThrow();
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test("all valid trailingZeroDisplay options", () => {
|
||||
["auto", "stripIfInteger"].forEach(trailingZeroDisplay => {
|
||||
expect(() => {
|
||||
new Intl.PluralRules("en", { trailingZeroDisplay: trailingZeroDisplay });
|
||||
}).not.toThrow();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -114,4 +114,46 @@ describe("correct behavior", () => {
|
|||
expect(en2.resolvedOptions().roundingPriority).toBe(roundingPriority);
|
||||
});
|
||||
});
|
||||
|
||||
test("rounding mode", () => {
|
||||
const en1 = new Intl.PluralRules("en");
|
||||
expect(en1.resolvedOptions().roundingMode).toBe("halfExpand");
|
||||
|
||||
[
|
||||
"ceil",
|
||||
"floor",
|
||||
"expand",
|
||||
"trunc",
|
||||
"halfCeil",
|
||||
"halfFloor",
|
||||
"halfExpand",
|
||||
"halfTrunc",
|
||||
"halfEven",
|
||||
].forEach(roundingMode => {
|
||||
const en2 = new Intl.PluralRules("en", { roundingMode: roundingMode });
|
||||
expect(en2.resolvedOptions().roundingMode).toBe(roundingMode);
|
||||
});
|
||||
});
|
||||
|
||||
test("rounding increment", () => {
|
||||
const en1 = new Intl.PluralRules("en");
|
||||
expect(en1.resolvedOptions().roundingIncrement).toBe(1);
|
||||
|
||||
[1, 2, 5, 10, 20, 25, 50, 100, 200, 250, 500, 1000, 2000, 2500, 5000].forEach(
|
||||
roundingIncrement => {
|
||||
const en2 = new Intl.PluralRules("en", { roundingIncrement: roundingIncrement });
|
||||
expect(en2.resolvedOptions().roundingIncrement).toBe(roundingIncrement);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
test("trailing zero display", () => {
|
||||
const en1 = new Intl.PluralRules("en");
|
||||
expect(en1.resolvedOptions().trailingZeroDisplay).toBe("auto");
|
||||
|
||||
["auto", "stripIfInteger"].forEach(trailingZeroDisplay => {
|
||||
const en2 = new Intl.PluralRules("en", { trailingZeroDisplay: trailingZeroDisplay });
|
||||
expect(en2.resolvedOptions().trailingZeroDisplay).toBe(trailingZeroDisplay);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue