1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 10:38:13 +00:00

LibJS: Populate roundingPriority in Intl.PluralRules.resolvedOptions

This is inherited from Intl.NumberFormat.
This commit is contained in:
Timothy Flynn 2022-07-12 13:23:21 -04:00 committed by Linus Groh
parent 33698b9615
commit cd4ee46b70
3 changed files with 47 additions and 1 deletions

View file

@ -116,6 +116,15 @@ describe("errors", () => {
new Intl.PluralRules("en", { maximumSignificantDigits: 22 });
}).toThrowWithMessage(RangeError, "Value 22 is NaN or is not between 1 and 21");
});
test("roundingPriority option is invalid", () => {
expect(() => {
new Intl.PluralRules("en", { roundingPriority: "hello!" });
}).toThrowWithMessage(
RangeError,
"hello! is not a valid value for option roundingPriority"
);
});
});
describe("normal behavior", () => {
@ -178,4 +187,12 @@ describe("normal behavior", () => {
}).not.toThrow();
}
});
test("all valid roundingPriority options", () => {
["auto", "morePrecision", "lessPrecision"].forEach(roundingPriority => {
expect(() => {
new Intl.PluralRules("en", { roundingPriority: roundingPriority });
}).not.toThrow();
});
});
});

View file

@ -104,4 +104,14 @@ describe("correct behavior", () => {
expect(gaOrdinal.pluralCategories).toBeDefined();
expect(contains(gaOrdinal.pluralCategories, ["other", "one"])).toBeTrue();
});
test("rounding priority", () => {
const en1 = new Intl.PluralRules("en");
expect(en1.resolvedOptions().roundingPriority).toBe("auto");
["auto", "morePrecision", "lessPrecision"].forEach(roundingPriority => {
const en2 = new Intl.PluralRules("en", { roundingPriority: roundingPriority });
expect(en2.resolvedOptions().roundingPriority).toBe(roundingPriority);
});
});
});