mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:37:35 +00:00
LibJS: Change Intl.Locale info APIs from property getters to methods
This is a normative change in the Intl Locale Info spec. See:
e550152
This commit is contained in:
parent
a357874c77
commit
1d76738dde
14 changed files with 191 additions and 185 deletions
|
@ -1,29 +0,0 @@
|
|||
describe("errors", () => {
|
||||
test("called on non-Locale object", () => {
|
||||
expect(() => {
|
||||
Intl.Locale.prototype.calendars;
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Intl.Locale");
|
||||
});
|
||||
});
|
||||
|
||||
describe("normal behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
expect(Array.isArray(new Intl.Locale("en").calendars)).toBeTrue();
|
||||
expect(new Intl.Locale("en").calendars).toEqual(["gregory"]);
|
||||
|
||||
expect(Array.isArray(new Intl.Locale("ar").calendars)).toBeTrue();
|
||||
expect(new Intl.Locale("ar").calendars).toEqual(["gregory"]);
|
||||
});
|
||||
|
||||
test("extension keyword overrides default data", () => {
|
||||
expect(new Intl.Locale("en-u-ca-islamicc").calendars).toEqual(["islamic-civil"]);
|
||||
expect(new Intl.Locale("en", { calendar: "dangi" }).calendars).toEqual(["dangi"]);
|
||||
|
||||
expect(new Intl.Locale("ar-u-ca-ethiopic-amete-alem").calendars).toEqual(["ethioaa"]);
|
||||
expect(new Intl.Locale("ar", { calendar: "hebrew" }).calendars).toEqual(["hebrew"]);
|
||||
|
||||
// Invalid calendars also take precedence.
|
||||
expect(new Intl.Locale("en-u-ca-ladybird").calendars).toEqual(["ladybird"]);
|
||||
expect(new Intl.Locale("en", { calendar: "ladybird" }).calendars).toEqual(["ladybird"]);
|
||||
});
|
||||
});
|
|
@ -1,29 +0,0 @@
|
|||
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"]);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,31 @@
|
|||
describe("errors", () => {
|
||||
test("called on non-Locale object", () => {
|
||||
expect(() => {
|
||||
Intl.Locale.prototype.getCalendars();
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Intl.Locale");
|
||||
});
|
||||
});
|
||||
|
||||
describe("normal behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
expect(Array.isArray(new Intl.Locale("en").getCalendars())).toBeTrue();
|
||||
expect(new Intl.Locale("en").getCalendars()).toEqual(["gregory"]);
|
||||
|
||||
expect(Array.isArray(new Intl.Locale("ar").getCalendars())).toBeTrue();
|
||||
expect(new Intl.Locale("ar").getCalendars()).toEqual(["gregory"]);
|
||||
});
|
||||
|
||||
test("extension keyword overrides default data", () => {
|
||||
expect(new Intl.Locale("en-u-ca-islamicc").getCalendars()).toEqual(["islamic-civil"]);
|
||||
expect(new Intl.Locale("en", { calendar: "dangi" }).getCalendars()).toEqual(["dangi"]);
|
||||
|
||||
expect(new Intl.Locale("ar-u-ca-ethiopic-amete-alem").getCalendars()).toEqual(["ethioaa"]);
|
||||
expect(new Intl.Locale("ar", { calendar: "hebrew" }).getCalendars()).toEqual(["hebrew"]);
|
||||
|
||||
// Invalid calendars also take precedence.
|
||||
expect(new Intl.Locale("en-u-ca-ladybird").getCalendars()).toEqual(["ladybird"]);
|
||||
expect(new Intl.Locale("en", { calendar: "ladybird" }).getCalendars()).toEqual([
|
||||
"ladybird",
|
||||
]);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,33 @@
|
|||
describe("errors", () => {
|
||||
test("called on non-Locale object", () => {
|
||||
expect(() => {
|
||||
Intl.Locale.prototype.getCollations();
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Intl.Locale");
|
||||
});
|
||||
});
|
||||
|
||||
describe("normal behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
expect(Array.isArray(new Intl.Locale("en").getCollations())).toBeTrue();
|
||||
expect(new Intl.Locale("en").getCollations()).toEqual(["default"]);
|
||||
|
||||
expect(Array.isArray(new Intl.Locale("ar").getCollations())).toBeTrue();
|
||||
expect(new Intl.Locale("ar").getCollations()).toEqual(["default"]);
|
||||
});
|
||||
|
||||
test("extension keyword overrides default data", () => {
|
||||
expect(new Intl.Locale("en-u-co-compat").getCollations()).toEqual(["compat"]);
|
||||
expect(new Intl.Locale("en", { collation: "compat" }).getCollations()).toEqual(["compat"]);
|
||||
|
||||
expect(new Intl.Locale("ar-u-co-reformed").getCollations()).toEqual(["reformed"]);
|
||||
expect(new Intl.Locale("ar", { collation: "reformed" }).getCollations()).toEqual([
|
||||
"reformed",
|
||||
]);
|
||||
|
||||
// Invalid getCollations() also take precedence.
|
||||
expect(new Intl.Locale("en-u-co-ladybird").getCollations()).toEqual(["ladybird"]);
|
||||
expect(new Intl.Locale("en", { collation: "ladybird" }).getCollations()).toEqual([
|
||||
"ladybird",
|
||||
]);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,29 @@
|
|||
describe("errors", () => {
|
||||
test("called on non-Locale object", () => {
|
||||
expect(() => {
|
||||
Intl.Locale.prototype.getHourCycles();
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Intl.Locale");
|
||||
});
|
||||
});
|
||||
|
||||
describe("normal behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
expect(Array.isArray(new Intl.Locale("en").getHourCycles())).toBeTrue();
|
||||
expect(new Intl.Locale("en").getHourCycles()).toContain("h12");
|
||||
|
||||
expect(Array.isArray(new Intl.Locale("ha").getHourCycles())).toBeTrue();
|
||||
expect(new Intl.Locale("ha").getHourCycles()).toContain("h23");
|
||||
});
|
||||
|
||||
test("extension keyword overrides default data", () => {
|
||||
expect(new Intl.Locale("en-u-hc-h24").getHourCycles()).toEqual(["h24"]);
|
||||
expect(new Intl.Locale("en", { hourCycle: "h24" }).getHourCycles()).toEqual(["h24"]);
|
||||
|
||||
expect(new Intl.Locale("ar-u-hc-h24").getHourCycles()).toEqual(["h24"]);
|
||||
expect(new Intl.Locale("ar", { hourCycle: "h24" }).getHourCycles()).toEqual(["h24"]);
|
||||
|
||||
// Invalid hourCycles also take precedence when specified in the locale string. Unlike other
|
||||
// properties, Locale("en", { hourCycle: "ladybird" }) will explicitly throw.
|
||||
expect(new Intl.Locale("en-u-hc-ladybird").getHourCycles()).toEqual(["ladybird"]);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,35 @@
|
|||
describe("errors", () => {
|
||||
test("called on non-Locale object", () => {
|
||||
expect(() => {
|
||||
Intl.Locale.prototype.getNumberingSystems();
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Intl.Locale");
|
||||
});
|
||||
});
|
||||
|
||||
describe("normal behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
expect(Array.isArray(new Intl.Locale("en").getNumberingSystems())).toBeTrue();
|
||||
expect(new Intl.Locale("en").getNumberingSystems()).toEqual(["latn"]);
|
||||
|
||||
expect(Array.isArray(new Intl.Locale("ar").getNumberingSystems())).toBeTrue();
|
||||
expect(new Intl.Locale("ar").getNumberingSystems()).toEqual(["arab", "latn"]);
|
||||
});
|
||||
|
||||
test("extension keyword overrides default data", () => {
|
||||
expect(new Intl.Locale("en-u-nu-deva").getNumberingSystems()).toEqual(["deva"]);
|
||||
expect(new Intl.Locale("en", { numberingSystem: "deva" }).getNumberingSystems()).toEqual([
|
||||
"deva",
|
||||
]);
|
||||
|
||||
expect(new Intl.Locale("ar-u-nu-bali").getNumberingSystems()).toEqual(["bali"]);
|
||||
expect(new Intl.Locale("ar", { numberingSystem: "bali" }).getNumberingSystems()).toEqual([
|
||||
"bali",
|
||||
]);
|
||||
|
||||
// Invalid numberingSystems also take precedence.
|
||||
expect(new Intl.Locale("en-u-nu-ladybird").getNumberingSystems()).toEqual(["ladybird"]);
|
||||
expect(
|
||||
new Intl.Locale("en", { numberingSystem: "ladybird" }).getNumberingSystems()
|
||||
).toEqual(["ladybird"]);
|
||||
});
|
||||
});
|
|
@ -1,14 +1,14 @@
|
|||
describe("errors", () => {
|
||||
test("called on non-Locale object", () => {
|
||||
expect(() => {
|
||||
Intl.Locale.prototype.textInfo;
|
||||
Intl.Locale.prototype.getTextInfo();
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Intl.Locale");
|
||||
});
|
||||
});
|
||||
|
||||
describe("normal behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const textInfo = new Intl.Locale("en").textInfo;
|
||||
const textInfo = new Intl.Locale("en").getTextInfo();
|
||||
|
||||
expect(textInfo).toBeDefined();
|
||||
expect(Object.getPrototypeOf(textInfo)).toBe(Object.prototype);
|
||||
|
@ -17,10 +17,10 @@ describe("normal behavior", () => {
|
|||
expect(Object.getPrototypeOf(textInfo.direction)).toBe(String.prototype);
|
||||
|
||||
expect(textInfo.direction).toBe("ltr");
|
||||
expect(new Intl.Locale("ar").textInfo.direction).toBe("rtl");
|
||||
expect(new Intl.Locale("ar").getTextInfo().direction).toBe("rtl");
|
||||
});
|
||||
|
||||
test("fallback to ltr", () => {
|
||||
expect(new Intl.Locale("xx").textInfo.direction).toBe("ltr");
|
||||
expect(new Intl.Locale("xx").getTextInfo().direction).toBe("ltr");
|
||||
});
|
||||
});
|
|
@ -1,34 +1,34 @@
|
|||
describe("errors", () => {
|
||||
test("called on non-Locale object", () => {
|
||||
expect(() => {
|
||||
Intl.Locale.prototype.timeZones;
|
||||
Intl.Locale.prototype.getTimeZones();
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Intl.Locale");
|
||||
});
|
||||
});
|
||||
|
||||
describe("normal behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
expect(new Intl.Locale("en").timeZones).toBeUndefined();
|
||||
expect(new Intl.Locale("ar-Latn").timeZones).toBeUndefined();
|
||||
expect(new Intl.Locale("en").getTimeZones()).toBeUndefined();
|
||||
expect(new Intl.Locale("ar-Latn").getTimeZones()).toBeUndefined();
|
||||
|
||||
const adZones = new Intl.Locale("en-AD").timeZones;
|
||||
const adZones = new Intl.Locale("en-AD").getTimeZones();
|
||||
expect(Array.isArray(adZones)).toBeTrue();
|
||||
expect(adZones).toEqual(["Europe/Andorra"]);
|
||||
|
||||
const esZones = new Intl.Locale("en-ES").timeZones;
|
||||
const esZones = new Intl.Locale("en-ES").getTimeZones();
|
||||
expect(Array.isArray(esZones)).toBeTrue();
|
||||
expect(esZones).toEqual(["Africa/Ceuta", "Atlantic/Canary", "Europe/Madrid"]);
|
||||
});
|
||||
|
||||
test("zone list is sorted", () => {
|
||||
const zones = new Intl.Locale("en-US").timeZones;
|
||||
const zones = new Intl.Locale("en-US").getTimeZones();
|
||||
const sortedZones = zones.toSorted();
|
||||
|
||||
expect(zones).toEqual(sortedZones);
|
||||
});
|
||||
|
||||
test("invalid region produces empty list", () => {
|
||||
const zones = new Intl.Locale("en-ZZ").timeZones;
|
||||
const zones = new Intl.Locale("en-ZZ").getTimeZones();
|
||||
expect(Array.isArray(zones)).toBeTrue();
|
||||
expect(zones).toEqual([]);
|
||||
});
|
|
@ -1,14 +1,14 @@
|
|||
describe("errors", () => {
|
||||
test("called on non-Locale object", () => {
|
||||
expect(() => {
|
||||
Intl.Locale.prototype.weekInfo;
|
||||
Intl.Locale.prototype.getWeekInfo();
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Intl.Locale");
|
||||
});
|
||||
});
|
||||
|
||||
describe("normal behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
const weekInfo = new Intl.Locale("en-US").weekInfo;
|
||||
const weekInfo = new Intl.Locale("en-US").getWeekInfo();
|
||||
|
||||
expect(weekInfo).toBeDefined();
|
||||
expect(Object.getPrototypeOf(weekInfo)).toBe(Object.prototype);
|
||||
|
@ -27,40 +27,40 @@ describe("normal behavior", () => {
|
|||
});
|
||||
|
||||
test("regions with CLDR-specified firstDay", () => {
|
||||
expect(new Intl.Locale("en-AG").weekInfo.firstDay).toBe(7);
|
||||
expect(new Intl.Locale("en-SY").weekInfo.firstDay).toBe(6);
|
||||
expect(new Intl.Locale("en-MV").weekInfo.firstDay).toBe(5);
|
||||
expect(new Intl.Locale("en-AG").getWeekInfo().firstDay).toBe(7);
|
||||
expect(new Intl.Locale("en-SY").getWeekInfo().firstDay).toBe(6);
|
||||
expect(new Intl.Locale("en-MV").getWeekInfo().firstDay).toBe(5);
|
||||
});
|
||||
|
||||
test("firstDay falls back to default region 001", () => {
|
||||
expect(new Intl.Locale("en-AC").weekInfo.firstDay).toBe(1);
|
||||
expect(new Intl.Locale("en-AC").getWeekInfo().firstDay).toBe(1);
|
||||
});
|
||||
|
||||
test("regions with CLDR-specified weekend", () => {
|
||||
expect(new Intl.Locale("en-AF").weekInfo.weekend).toEqual([4, 5]);
|
||||
expect(new Intl.Locale("en-IN").weekInfo.weekend).toEqual([7]);
|
||||
expect(new Intl.Locale("en-YE").weekInfo.weekend).toEqual([5, 6]);
|
||||
expect(new Intl.Locale("en-AF").getWeekInfo().weekend).toEqual([4, 5]);
|
||||
expect(new Intl.Locale("en-IN").getWeekInfo().weekend).toEqual([7]);
|
||||
expect(new Intl.Locale("en-YE").getWeekInfo().weekend).toEqual([5, 6]);
|
||||
});
|
||||
|
||||
test("weekend falls back to default region 001", () => {
|
||||
expect(new Intl.Locale("en-AC").weekInfo.weekend).toEqual([6, 7]);
|
||||
expect(new Intl.Locale("en-AC").getWeekInfo().weekend).toEqual([6, 7]);
|
||||
});
|
||||
|
||||
test("regions with CLDR-specified minimalDays", () => {
|
||||
expect(new Intl.Locale("en-AD").weekInfo.minimalDays).toBe(4);
|
||||
expect(new Intl.Locale("en-CZ").weekInfo.minimalDays).toBe(4);
|
||||
expect(new Intl.Locale("en-AD").getWeekInfo().minimalDays).toBe(4);
|
||||
expect(new Intl.Locale("en-CZ").getWeekInfo().minimalDays).toBe(4);
|
||||
});
|
||||
|
||||
test("minimalDays falls back to default region 001", () => {
|
||||
expect(new Intl.Locale("en-AC").weekInfo.minimalDays).toBe(1);
|
||||
expect(new Intl.Locale("en-AC").getWeekInfo().minimalDays).toBe(1);
|
||||
});
|
||||
|
||||
test("likely regional subtags are added to locales without a region", () => {
|
||||
const defaultRegion = new Intl.Locale("en-001").weekInfo;
|
||||
const defaultRegion = new Intl.Locale("en-001").getWeekInfo();
|
||||
|
||||
// "en" expands to "en-US" when likely subtags are added.
|
||||
const en = new Intl.Locale("en").weekInfo;
|
||||
const enUS = new Intl.Locale("en-US").weekInfo;
|
||||
const en = new Intl.Locale("en").getWeekInfo();
|
||||
const enUS = new Intl.Locale("en-US").getWeekInfo();
|
||||
|
||||
expect(en).toEqual(enUS);
|
||||
expect(en).not.toEqual(defaultRegion);
|
|
@ -1,29 +0,0 @@
|
|||
describe("errors", () => {
|
||||
test("called on non-Locale object", () => {
|
||||
expect(() => {
|
||||
Intl.Locale.prototype.hourCycles;
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Intl.Locale");
|
||||
});
|
||||
});
|
||||
|
||||
describe("normal behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
expect(Array.isArray(new Intl.Locale("en").hourCycles)).toBeTrue();
|
||||
expect(new Intl.Locale("en").hourCycles).toContain("h12");
|
||||
|
||||
expect(Array.isArray(new Intl.Locale("ha").hourCycles)).toBeTrue();
|
||||
expect(new Intl.Locale("ha").hourCycles).toContain("h23");
|
||||
});
|
||||
|
||||
test("extension keyword overrides default data", () => {
|
||||
expect(new Intl.Locale("en-u-hc-h24").hourCycles).toEqual(["h24"]);
|
||||
expect(new Intl.Locale("en", { hourCycle: "h24" }).hourCycles).toEqual(["h24"]);
|
||||
|
||||
expect(new Intl.Locale("ar-u-hc-h24").hourCycles).toEqual(["h24"]);
|
||||
expect(new Intl.Locale("ar", { hourCycle: "h24" }).hourCycles).toEqual(["h24"]);
|
||||
|
||||
// Invalid hourCycles also take precedence when specified in the locale string. Unlike other
|
||||
// properties, Locale("en", { hourCycle: "ladybird" }) will explicitly throw.
|
||||
expect(new Intl.Locale("en-u-hc-ladybird").hourCycles).toEqual(["ladybird"]);
|
||||
});
|
||||
});
|
|
@ -1,35 +0,0 @@
|
|||
describe("errors", () => {
|
||||
test("called on non-Locale object", () => {
|
||||
expect(() => {
|
||||
Intl.Locale.prototype.numberingSystems;
|
||||
}).toThrowWithMessage(TypeError, "Not an object of type Intl.Locale");
|
||||
});
|
||||
});
|
||||
|
||||
describe("normal behavior", () => {
|
||||
test("basic functionality", () => {
|
||||
expect(Array.isArray(new Intl.Locale("en").numberingSystems)).toBeTrue();
|
||||
expect(new Intl.Locale("en").numberingSystems).toEqual(["latn"]);
|
||||
|
||||
expect(Array.isArray(new Intl.Locale("ar").numberingSystems)).toBeTrue();
|
||||
expect(new Intl.Locale("ar").numberingSystems).toEqual(["arab", "latn"]);
|
||||
});
|
||||
|
||||
test("extension keyword overrides default data", () => {
|
||||
expect(new Intl.Locale("en-u-nu-deva").numberingSystems).toEqual(["deva"]);
|
||||
expect(new Intl.Locale("en", { numberingSystem: "deva" }).numberingSystems).toEqual([
|
||||
"deva",
|
||||
]);
|
||||
|
||||
expect(new Intl.Locale("ar-u-nu-bali").numberingSystems).toEqual(["bali"]);
|
||||
expect(new Intl.Locale("ar", { numberingSystem: "bali" }).numberingSystems).toEqual([
|
||||
"bali",
|
||||
]);
|
||||
|
||||
// Invalid numberingSystems also take precedence.
|
||||
expect(new Intl.Locale("en-u-nu-ladybird").numberingSystems).toEqual(["ladybird"]);
|
||||
expect(new Intl.Locale("en", { numberingSystem: "ladybird" }).numberingSystems).toEqual([
|
||||
"ladybird",
|
||||
]);
|
||||
});
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue