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:
André Bargull 2019-07-22 02:12:05 -07:00
parent f7e8dba39b
commit 1edeb484b8
2 changed files with 18 additions and 13 deletions

View File

@ -116,8 +116,8 @@ function taintArray() {
*/
function getLocaleSupportInfo(Constructor) {
var languages = ["zh", "es", "en", "hi", "ur", "ar", "ja", "pa"];
var scripts = ["Latn", "Hans", "Deva", "Arab", "Jpan", "Hant"];
var countries = ["CN", "IN", "US", "PK", "JP", "TW", "HK", "SG"];
var scripts = ["Latn", "Hans", "Deva", "Arab", "Jpan", "Hant", "Guru"];
var countries = ["CN", "IN", "US", "PK", "JP", "TW", "HK", "SG", "419"];
var allTags = [];
var i, j, k;

View File

@ -12,17 +12,22 @@ includes: [testIntl.js]
testWithIntlConstructors(function (Constructor) {
var info = getLocaleSupportInfo(Constructor);
var fallback;
info.supported.forEach(function (locale) {
var pos = locale.lastIndexOf("-");
if (pos !== -1) {
fallback = locale.substring(0, pos);
assert.notSameValue(info.supported.indexOf(fallback), -1, "Locale " + locale + " is supported, but fallback " + fallback + " isn't.");
for (var locale of info.supported) {
var match = /^([a-z]{2,3})(-[A-Z][a-z]{3})?(-(?:[A-Z]{2}|[0-9]{3}))?$/.exec(locale);
assert.notSameValue(match, null, "Locale " + locale + " is supported, but can't be parsed.")
var [language, script, region] = match.slice(1);
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) {
fallback = match[1] + match[3];
assert.notSameValue(info.supported.indexOf(fallback), -1, "Locale " + locale + " is supported, but fallback " + fallback + " isn't.");
if (region !== undefined) {
var fallback = language + region;
assert(info.supported.includes(fallback) || info.byFallback.includes(fallback),
"Locale " + locale + " is supported, but fallback " + fallback + " isn't.");
}
});
}
});