1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 05:47:34 +00:00

LibJS: Populate pluralCategories in Intl.PluralRules.resolvedOptions

This commit is contained in:
Timothy Flynn 2022-07-07 12:21:27 -04:00 committed by Linus Groh
parent 670bd066a5
commit f11cb7c075
2 changed files with 31 additions and 7 deletions

View file

@ -79,9 +79,29 @@ describe("correct behavior", () => {
});
test("plural categories", () => {
// FIXME: Write better tests when this is implemented.
const en = new Intl.PluralRules("en");
expect(en.resolvedOptions().pluralCategories).toBeDefined();
expect(en.resolvedOptions().pluralCategories).toEqual([]);
// The spec doesn't dictate an order of elements, and the generated CLDR data is ordered by
// hash map iteration. Instead of using toEqual(), just make sure all elements are the same.
const contains = (actual, expected) => {
if (actual.length !== expected.length) return false;
return expected.every(e => actual.includes(e));
};
const enCardinal = new Intl.PluralRules("en", { type: "cardinal" }).resolvedOptions();
expect(enCardinal.pluralCategories).toBeDefined();
expect(contains(enCardinal.pluralCategories, ["other", "one"])).toBeTrue();
const enOrdinal = new Intl.PluralRules("en", { type: "ordinal" }).resolvedOptions();
expect(enOrdinal.pluralCategories).toBeDefined();
expect(contains(enOrdinal.pluralCategories, ["other", "one", "two", "few"])).toBeTrue();
const gaCardinal = new Intl.PluralRules("ga", { type: "cardinal" }).resolvedOptions();
expect(gaCardinal.pluralCategories).toBeDefined();
expect(
contains(gaCardinal.pluralCategories, ["other", "one", "two", "few", "many"])
).toBeTrue();
const gaOrdinal = new Intl.PluralRules("ga", { type: "ordinal" }).resolvedOptions();
expect(gaOrdinal.pluralCategories).toBeDefined();
expect(contains(gaOrdinal.pluralCategories, ["other", "one"])).toBeTrue();
});
});