mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:47:37 +00:00
LibJS: Implement Intl.PluralRules.supportedLocalesOf
This commit is contained in:
parent
624fad3821
commit
8b3f49ff84
3 changed files with 65 additions and 0 deletions
|
@ -0,0 +1,43 @@
|
|||
describe("correct behavior", () => {
|
||||
test("length is 1", () => {
|
||||
expect(Intl.PluralRules.supportedLocalesOf).toHaveLength(1);
|
||||
});
|
||||
|
||||
test("basic functionality", () => {
|
||||
// prettier-ignore
|
||||
const values = [
|
||||
[[], []],
|
||||
[undefined, []],
|
||||
["en", ["en"]],
|
||||
[new Intl.Locale("en"), ["en"]],
|
||||
[["en"], ["en"]],
|
||||
[["en", "en-gb", "en-us"], ["en", "en-GB", "en-US"]],
|
||||
[["en", "de", "fr"], ["en", "de", "fr"]],
|
||||
[["en-foobar"], ["en-foobar"]],
|
||||
[["en-foobar-u-abc"], ["en-foobar-u-abc"]],
|
||||
[["aa", "zz"], []],
|
||||
[["en", "aa", "zz"], ["en"]],
|
||||
];
|
||||
for (const [input, expected] of values) {
|
||||
expect(Intl.PluralRules.supportedLocalesOf(input)).toEqual(expected);
|
||||
// "best fit" (implementation defined) just uses the same implementation as "lookup" at the moment
|
||||
expect(
|
||||
Intl.PluralRules.supportedLocalesOf(input, { localeMatcher: "best fit" })
|
||||
).toEqual(Intl.PluralRules.supportedLocalesOf(input, { localeMatcher: "lookup" }));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("errors", () => {
|
||||
test("invalid value for localeMatcher option", () => {
|
||||
expect(() => {
|
||||
Intl.PluralRules.supportedLocalesOf([], { localeMatcher: "foo" });
|
||||
}).toThrowWithMessage(RangeError, "foo is not a valid value for option localeMatcher");
|
||||
});
|
||||
|
||||
test("invalid language tag", () => {
|
||||
expect(() => {
|
||||
Intl.PluralRules.supportedLocalesOf(["aaaaaaaaa"]);
|
||||
}).toThrowWithMessage(RangeError, "aaaaaaaaa is not a structurally valid language tag");
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue