forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LibJS: Implement Intl.ListFormat.supportedLocalesOf
- Loading branch information
Showing
3 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
Userland/Libraries/LibJS/Tests/builtins/Intl/ListFormat/ListFormat.supportedLocalesOf.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
describe("correct behavior", () => { | ||
test("length is 1", () => { | ||
expect(Intl.ListFormat.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.ListFormat.supportedLocalesOf(input)).toEqual(expected); | ||
// "best fit" (implementation defined) just uses the same implementation as "lookup" at the moment | ||
expect( | ||
Intl.ListFormat.supportedLocalesOf(input, { localeMatcher: "best fit" }) | ||
).toEqual(Intl.ListFormat.supportedLocalesOf(input, { localeMatcher: "lookup" })); | ||
} | ||
}); | ||
}); | ||
|
||
describe("errors", () => { | ||
test("invalid value for localeMatcher option", () => { | ||
expect(() => { | ||
Intl.ListFormat.supportedLocalesOf([], { localeMatcher: "foo" }); | ||
}).toThrowWithMessage(RangeError, "foo is not a valid value for option localeMatcher"); | ||
}); | ||
|
||
test("invalid language tag", () => { | ||
expect(() => { | ||
Intl.ListFormat.supportedLocalesOf(["aaaaaaaaa"]); | ||
}).toThrowWithMessage(RangeError, "aaaaaaaaa is not a structurally valid language tag"); | ||
}); | ||
}); |