From 4d32f38a76f81f77d6a19d39df3303c813c31f96 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Tue, 5 Jul 2022 12:28:21 -0400 Subject: 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. --- .../Intl/Locale/Locale.prototype.collations.js | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Userland/Libraries/LibJS/Tests/builtins/Intl/Locale/Locale.prototype.collations.js (limited to 'Userland/Libraries/LibJS/Tests') diff --git a/Userland/Libraries/LibJS/Tests/builtins/Intl/Locale/Locale.prototype.collations.js b/Userland/Libraries/LibJS/Tests/builtins/Intl/Locale/Locale.prototype.collations.js new file mode 100644 index 0000000000..e7732c2a58 --- /dev/null +++ b/Userland/Libraries/LibJS/Tests/builtins/Intl/Locale/Locale.prototype.collations.js @@ -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"]); + }); +}); -- cgit v1.2.3