1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 23:58:11 +00:00

LibJS: Partially implement Intl.Locale.prototype.collations property

We do not yet parse collation data from the CLDR. This stubs out the
collations property, analogous to Intl.supportedValuesOf.
This commit is contained in:
Timothy Flynn 2022-07-05 12:28:21 -04:00 committed by Linus Groh
parent e9bc35d805
commit 4d32f38a76
7 changed files with 57 additions and 2 deletions

View file

@ -0,0 +1,29 @@
describe("errors", () => {
test("called on non-Locale object", () => {
expect(() => {
Intl.Locale.prototype.collations;
}).toThrowWithMessage(TypeError, "Not an object of type Intl.Locale");
});
});
describe("normal behavior", () => {
test("basic functionality", () => {
expect(Array.isArray(new Intl.Locale("en").collations)).toBeTrue();
expect(new Intl.Locale("en").collations).toEqual(["default"]);
expect(Array.isArray(new Intl.Locale("ar").collations)).toBeTrue();
expect(new Intl.Locale("ar").collations).toEqual(["default"]);
});
test("extension keyword overrides default data", () => {
expect(new Intl.Locale("en-u-co-compat").collations).toEqual(["compat"]);
expect(new Intl.Locale("en", { collation: "compat" }).collations).toEqual(["compat"]);
expect(new Intl.Locale("ar-u-co-reformed").collations).toEqual(["reformed"]);
expect(new Intl.Locale("ar", { collation: "reformed" }).collations).toEqual(["reformed"]);
// Invalid collations also take precedence.
expect(new Intl.Locale("en-u-co-ladybird").collations).toEqual(["ladybird"]);
expect(new Intl.Locale("en", { collation: "ladybird" }).collations).toEqual(["ladybird"]);
});
});