Add helper functions to retrieve all calendars, collations, numberingSystems, and simple sanctioned units

And then use these helpers to replace hard-coded lists in other tests.
This commit is contained in:
André Bargull 2021-09-07 05:44:06 -07:00 committed by Rick Waldron
parent 4a7830beec
commit 71460edfeb
8 changed files with 150 additions and 262 deletions

View File

@ -19,7 +19,12 @@ defines:
- getInvalidLocaleArguments
- testOption
- testForUnwantedRegExpChanges
- allCalendars
- allCollations
- allNumberingSystems
- isValidNumberingSystem
- numberingSystemDigits
- allSimpleSanctionedUnits
- testNumberFormat
- getDateTimeComponents
- getDateTimeComponentValues
@ -2029,17 +2034,71 @@ function testForUnwantedRegExpChanges(testFunc) {
/**
* Tests whether name is a valid BCP 47 numbering system name
* and not excluded from use in the ECMAScript Internationalization API.
* @param {string} name the name to be tested.
* @return {boolean} whether name is a valid BCP 47 numbering system name and
* allowed for use in the ECMAScript Internationalization API.
* Returns an array of all known calendars.
*/
function allCalendars() {
// source: CLDR file common/bcp47/number.xml; version CLDR 39.
// https://github.com/unicode-org/cldr/blob/master/common/bcp47/calendar.xml
return [
"buddhist",
"chinese",
"coptic",
"dangi",
"ethioaa",
"ethiopic",
"gregory",
"hebrew",
"indian",
"islamic",
"islamic-umalqura",
"islamic-tbla",
"islamic-civil",
"islamic-rgsa",
"iso8601",
"japanese",
"persian",
"roc",
];
}
function isValidNumberingSystem(name) {
// source: CLDR file common/bcp47/number.xml; version CLDR 36.1.
var numberingSystems = [
/**
* Returns an array of all known collations.
*/
function allCollations() {
// source: CLDR file common/bcp47/collation.xml; version CLDR 39.
// https://github.com/unicode-org/cldr/blob/master/common/bcp47/collation.xml
return [
"big5han",
"compat",
"dict",
"direct",
"ducet",
"emoji",
"eor",
"gb2312",
"phonebk",
"phonetic",
"pinyin",
"reformed",
"search",
"searchjl",
"standard",
"stroke",
"trad",
"unihan",
"zhuyin",
];
}
/**
* Returns an array of all known numbering systems.
*/
function allNumberingSystems() {
// source: CLDR file common/bcp47/number.xml; version CLDR 39.
// https://github.com/unicode-org/cldr/blob/master/common/bcp47/number.xml
return [
"adlm",
"ahom",
"arab",
@ -2128,6 +2187,20 @@ function isValidNumberingSystem(name) {
"wara",
"wcho",
];
}
/**
* Tests whether name is a valid BCP 47 numbering system name
* and not excluded from use in the ECMAScript Internationalization API.
* @param {string} name the name to be tested.
* @return {boolean} whether name is a valid BCP 47 numbering system name and
* allowed for use in the ECMAScript Internationalization API.
*/
function isValidNumberingSystem(name) {
var numberingSystems = allNumberingSystems();
var excluded = [
"finance",
@ -2215,6 +2288,59 @@ var numberingSystemDigits = {
};
/**
* Returns an array of all simple, sanctioned unit identifiers.
*/
function allSimpleSanctionedUnits() {
// https://tc39.es/ecma402/#table-sanctioned-simple-unit-identifiers
return [
"acre",
"bit",
"byte",
"celsius",
"centimeter",
"day",
"degree",
"fahrenheit",
"fluid-ounce",
"foot",
"gallon",
"gigabit",
"gigabyte",
"gram",
"hectare",
"hour",
"inch",
"kilobit",
"kilobyte",
"kilogram",
"kilometer",
"liter",
"megabit",
"megabyte",
"meter",
"mile",
"mile-scandinavian",
"milliliter",
"millimeter",
"millisecond",
"minute",
"month",
"ounce",
"percent",
"petabyte",
"pound",
"second",
"stone",
"terabit",
"terabyte",
"week",
"yard",
"year",
];
}
/**
* Tests that number formatting is handled correctly. The function checks that the
* digit sequences in formatted output are as specified, converted to the

View File

@ -15,29 +15,7 @@ var actual = new Intl.Collator().resolvedOptions();
var actual2 = new Intl.Collator().resolvedOptions();
assert.notSameValue(actual2, actual, "resolvedOptions returned the same object twice.");
// source: CLDR file common/bcp47/collation.xml; version CLDR 32.
var collations = [
"default", // added
"big5han",
"compat",
"dict",
"direct",
"ducet",
"emoji",
"eor",
"gb2312",
"phonebk",
"phonetic",
"pinyin",
"reformed",
// "search", // excluded
"searchjl",
// "standard", // excluded
"stroke",
"trad",
"unihan",
"zhuyin",
];
var collations = ["default", ...allCollations()];
// this assumes the default values where the specification provides them
assert(isCanonicalizedStructurallyValidLanguageTag(actual.locale),
@ -45,6 +23,8 @@ assert(isCanonicalizedStructurallyValidLanguageTag(actual.locale),
assert.sameValue(actual.usage, "sort");
assert.sameValue(actual.sensitivity, "variant");
assert.sameValue(actual.ignorePunctuation, false);
assert.notSameValue(actual.collation, "search");
assert.notSameValue(actual.collation, "standard");
assert.notSameValue(collations.indexOf(actual.collation), -1,
"Invalid collation: " + actual.collation);

View File

@ -6,29 +6,12 @@ esid: sec-initializedatetimeformat
description: >
Checks the DateTimeFormat choose different patterns based
on calendar.
includes: [testIntl.js]
features: [Intl.DateTimeFormat-formatRange]
locale: [en]
---*/
let calendars = [
"buddhist",
"chinese",
"coptic",
"dangi",
"ethiopic",
"ethioaa",
"gregory",
"hebrew",
"indian",
"islamic",
"islamic-civil",
"islamic-rgsa",
"islamic-tbla",
"islamic-umalqura",
"japanese",
"persian",
"roc"
];
let calendars = allCalendars();
let date1 = new Date(2017, 3, 12);
let date2 = new Date();

View File

@ -6,28 +6,11 @@ esid: sec-initializedatetimeformat
description: >
Checks the DateTimeFormat choose different patterns based
on calendar.
includes: [testIntl.js]
locale: [en]
---*/
let calendars = [
"buddhist",
"chinese",
"coptic",
"dangi",
"ethiopic",
"ethioaa",
"gregory",
"hebrew",
"indian",
"islamic",
"islamic-civil",
"islamic-rgsa",
"islamic-tbla",
"islamic-umalqura",
"japanese",
"persian",
"roc"
];
let calendars = allCalendars();
let date = new Date();
// serialize parts to a string by considering only the type and literal.

View File

@ -16,29 +16,7 @@ var actual = new Intl.DateTimeFormat().resolvedOptions();
var actual2 = new Intl.DateTimeFormat().resolvedOptions();
assert.notSameValue(actual2, actual, "resolvedOptions returned the same object twice.");
// source: CLDR file common/bcp47/calendar.xml; version CLDR 32.
var calendars = [
"buddhist",
"chinese",
"coptic",
"dangi",
"ethioaa",
"ethiopic-amete-alem",
"ethiopic",
"gregory",
"hebrew",
"indian",
"islamic",
"islamic-umalqura",
"islamic-tbla",
"islamic-civil",
"islamic-rgsa",
"iso8601",
"japanese",
"persian",
"roc",
"islamicc",
];
var calendars = allCalendars();
// this assumes the default values where the specification provides them
assert(isCanonicalizedStructurallyValidLanguageTag(actual.locale),

View File

@ -4,6 +4,7 @@
/*---
esid: sec-initializenumberformat
description: Checks handling of the unit style.
includes: [testIntl.js]
features: [Intl.NumberFormat-unified]
---*/
@ -51,51 +52,7 @@ function check(unit) {
assert.sameValue(options.unit, unit);
}
const units = [
"acre",
"bit",
"byte",
"celsius",
"centimeter",
"day",
"degree",
"fahrenheit",
"fluid-ounce",
"foot",
"gallon",
"gigabit",
"gigabyte",
"gram",
"hectare",
"hour",
"inch",
"kilobit",
"kilobyte",
"kilogram",
"kilometer",
"liter",
"megabit",
"megabyte",
"meter",
"mile",
"mile-scandinavian",
"millimeter",
"milliliter",
"millisecond",
"minute",
"month",
"ounce",
"percent",
"petabyte",
"pound",
"second",
"stone",
"terabit",
"terabyte",
"week",
"yard",
"year",
];
const units = allSimpleSanctionedUnits();
for (const simpleUnit of units) {
check(simpleUnit);

View File

@ -7,93 +7,17 @@ description: >
Tests that Intl.NumberFormat.prototype.format supports all
numbering systems with simple digit mappings.
author: Roozbeh Pournader
includes: [testIntl.js]
---*/
const numberingSystems = {
adlm: 0x1E950,
ahom: 0x11730,
arab: 0x0660,
arabext: 0x06F0,
bali: 0x1B50,
beng: 0x09E6,
bhks: 0x11C50,
brah: 0x11066,
cakm: 0x11136,
cham: 0xAA50,
deva: 0x0966,
diak: 0x11950,
fullwide: 0xFF10,
gong: 0x11DA0,
gonm: 0x11D50,
gujr: 0x0AE6,
guru: 0x0A66,
hanidec: [0x3007, 0x4E00, 0x4E8C, 0x4E09, 0x56DB,
0x4E94, 0x516D, 0x4E03, 0x516B, 0x4E5D],
hmng: 0x16B50,
hmnp: 0x1E140,
java: 0xA9D0,
kali: 0xA900,
khmr: 0x17E0,
knda: 0x0CE6,
lana: 0x1A80,
lanatham: 0x1A90,
laoo: 0x0ED0,
latn: 0x0030,
lepc: 0x1C40,
limb: 0x1946,
mathbold: 0x1D7CE,
mathdbl: 0x1D7D8,
mathmono: 0x1D7F6,
mathsanb: 0x1D7EC,
mathsans: 0x1D7E2,
mlym: 0x0D66,
modi: 0x11650,
mong: 0x1810,
mroo: 0x16A60,
mtei: 0xABF0,
mymr: 0x1040,
mymrshan: 0x1090,
mymrtlng: 0xA9F0,
newa: 0x11450,
nkoo: 0x07C0,
olck: 0x1C50,
orya: 0x0B66,
osma: 0x104A0,
rohg: 0x10D30,
saur: 0xA8D0,
segment: 0x1FBF0,
shrd: 0x111D0,
sind: 0x112F0,
sinh: 0x0DE6,
sora: 0x110F0,
sund: 0x1BB0,
takr: 0x116C0,
talu: 0x19D0,
tamldec: 0x0BE6,
telu: 0x0C66,
thai: 0x0E50,
tibt: 0x0F20,
tirh: 0x114D0,
vaii: 0xA620,
wara: 0x118E0,
wcho: 0x1E2F0,
};
for (let [numberingSystem, digitList] of Object.entries(numberingSystems)) {
if (typeof digitList === 'number') {
let zeroCode = digitList;
digitList = [];
for (let i = 0; i <= 9; ++i) {
digitList[i] = zeroCode + i;
}
}
for (let [numberingSystem, digits] of Object.entries(numberingSystemDigits)) {
let digitList = [...digits];
assert.sameValue(digitList.length, 10);
let nf = new Intl.NumberFormat(undefined, {numberingSystem});
for (let i = 0; i <= 9; ++i) {
assert.sameValue(nf.format(i), String.fromCodePoint(digitList[i]),
assert.sameValue(nf.format(i), digitList[i],
`numberingSystem: ${numberingSystem}, digit: ${i}`);
}
}

View File

@ -4,6 +4,7 @@
/*---
esid: sec-intl.numberformat.prototype.format
description: Checks handling of units.
includes: [testIntl.js]
features: [Intl.NumberFormat-unified]
---*/
@ -13,51 +14,7 @@ function check(unit) {
assert.notSameValue(s1, s2);
}
const units = [
"acre",
"bit",
"byte",
"celsius",
"centimeter",
"day",
"degree",
"fahrenheit",
"fluid-ounce",
"foot",
"gallon",
"gigabit",
"gigabyte",
"gram",
"hectare",
"hour",
"inch",
"kilobit",
"kilobyte",
"kilogram",
"kilometer",
"liter",
"megabit",
"megabyte",
"meter",
"mile",
"mile-scandinavian",
"millimeter",
"milliliter",
"millisecond",
"minute",
"month",
"ounce",
"percent",
"petabyte",
"pound",
"second",
"stone",
"terabit",
"terabyte",
"week",
"yard",
"year",
];
const units = allSimpleSanctionedUnits();
for (const simpleUnit of units) {
check(simpleUnit);