LibJS: Implement Intl.Locale.prototype.variants

This is a normative change in the ECMA-402 spec. See:
e8c995a
This commit is contained in:
Timothy Flynn 2025-06-04 10:20:10 -04:00 committed by Tim Flynn
commit 128675770c
Notes: github-actions[bot] 2025-06-04 21:12:35 +00:00
7 changed files with 123 additions and 7 deletions

View file

@ -0,0 +1,44 @@
describe("errors", () => {
test("called on non-Locale object", () => {
expect(() => {
Intl.Locale.prototype.variants;
}).toThrowWithMessage(TypeError, "Not an object of type Intl.Locale");
});
test("duplicate variants", () => {
expect(() => {
new Intl.Locale("en-abcde-abcde");
}).toThrowWithMessage(
RangeError,
"en-abcde-abcde is not a structurally valid language tag"
);
expect(() => {
new Intl.Locale("en", { variants: "abcde-abcde" });
}).toThrowWithMessage(RangeError, "abcde-abcde is not a valid value for option variants");
});
test("invalid variant", () => {
expect(() => {
new Intl.Locale("en-a");
}).toThrowWithMessage(RangeError, "en-a is not a structurally valid language tag");
expect(() => {
new Intl.Locale("en", { variants: "a" });
}).toThrowWithMessage(RangeError, "a is not a valid value for option variants");
expect(() => {
new Intl.Locale("en", { variants: "-" });
}).toThrowWithMessage(RangeError, "- is not a valid value for option variants");
});
});
describe("normal behavior", () => {
test("basic functionality", () => {
expect(new Intl.Locale("en").variants).toBeUndefined();
expect(new Intl.Locale("en-abcde").variants).toBe("abcde");
expect(new Intl.Locale("en-1234-abcde").variants).toBe("1234-abcde");
expect(new Intl.Locale("en", { variants: "abcde" }).variants).toBe("abcde");
expect(new Intl.Locale("en", { variants: "1234-abcde" }).variants).toBe("1234-abcde");
});
});