mirror of
https://github.com/tc39/test262.git
synced 2025-07-03 20:24:38 +02:00
Include locales supported through fallback when testing fallbacks
This test started failing when updating to ICU 64, because ICU supports "zh" and "zh-Hans-CN", but not explicitly also "zh-Hans", which is required for this test to pass. The same kind of error is reproducible with ICU <64 when "Guru" is added to the list of script codes in 'testIntl.js', because ICU supports "pa-Guru-IN", but "pa-IN" isn't explicitly supported, too. So, change this test to also check 'byFallback' to see if a locale is supported. Drive-by change: - Modernise the test to make it more readable how subtags are combined. - Also add "419" to the list of region codes to cover the digit region syntax.
This commit is contained in:
parent
f7e8dba39b
commit
1edeb484b8
@ -116,8 +116,8 @@ function taintArray() {
|
|||||||
*/
|
*/
|
||||||
function getLocaleSupportInfo(Constructor) {
|
function getLocaleSupportInfo(Constructor) {
|
||||||
var languages = ["zh", "es", "en", "hi", "ur", "ar", "ja", "pa"];
|
var languages = ["zh", "es", "en", "hi", "ur", "ar", "ja", "pa"];
|
||||||
var scripts = ["Latn", "Hans", "Deva", "Arab", "Jpan", "Hant"];
|
var scripts = ["Latn", "Hans", "Deva", "Arab", "Jpan", "Hant", "Guru"];
|
||||||
var countries = ["CN", "IN", "US", "PK", "JP", "TW", "HK", "SG"];
|
var countries = ["CN", "IN", "US", "PK", "JP", "TW", "HK", "SG", "419"];
|
||||||
|
|
||||||
var allTags = [];
|
var allTags = [];
|
||||||
var i, j, k;
|
var i, j, k;
|
||||||
|
@ -12,17 +12,22 @@ includes: [testIntl.js]
|
|||||||
|
|
||||||
testWithIntlConstructors(function (Constructor) {
|
testWithIntlConstructors(function (Constructor) {
|
||||||
var info = getLocaleSupportInfo(Constructor);
|
var info = getLocaleSupportInfo(Constructor);
|
||||||
var fallback;
|
for (var locale of info.supported) {
|
||||||
info.supported.forEach(function (locale) {
|
var match = /^([a-z]{2,3})(-[A-Z][a-z]{3})?(-(?:[A-Z]{2}|[0-9]{3}))?$/.exec(locale);
|
||||||
var pos = locale.lastIndexOf("-");
|
assert.notSameValue(match, null, "Locale " + locale + " is supported, but can't be parsed.")
|
||||||
if (pos !== -1) {
|
|
||||||
fallback = locale.substring(0, pos);
|
var [language, script, region] = match.slice(1);
|
||||||
assert.notSameValue(info.supported.indexOf(fallback), -1, "Locale " + locale + " is supported, but fallback " + fallback + " isn't.");
|
|
||||||
|
if (script !== undefined) {
|
||||||
|
var fallback = language + script;
|
||||||
|
assert(info.supported.includes(fallback) || info.byFallback.includes(fallback),
|
||||||
|
"Locale " + locale + " is supported, but fallback " + fallback + " isn't.");
|
||||||
}
|
}
|
||||||
var match = /([a-z]{2,3})(-[A-Z][a-z]{3})(-[A-Z]{2})/.exec(locale);
|
|
||||||
if (match !== null) {
|
if (region !== undefined) {
|
||||||
fallback = match[1] + match[3];
|
var fallback = language + region;
|
||||||
assert.notSameValue(info.supported.indexOf(fallback), -1, "Locale " + locale + " is supported, but fallback " + fallback + " isn't.");
|
assert(info.supported.includes(fallback) || info.byFallback.includes(fallback),
|
||||||
|
"Locale " + locale + " is supported, but fallback " + fallback + " isn't.");
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user