From 1edeb484b8080b2709fce0911a9dcb01a4cef1a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Mon, 22 Jul 2019 02:12:05 -0700 Subject: [PATCH] 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. --- harness/testIntl.js | 4 +-- .../intl402/fallback-locales-are-supported.js | 27 +++++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/harness/testIntl.js b/harness/testIntl.js index 87ee1647d6..08008419be 100644 --- a/harness/testIntl.js +++ b/harness/testIntl.js @@ -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; diff --git a/test/intl402/fallback-locales-are-supported.js b/test/intl402/fallback-locales-are-supported.js index 9850926452..2044fd9dd8 100644 --- a/test/intl402/fallback-locales-are-supported.js +++ b/test/intl402/fallback-locales-are-supported.js @@ -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."); } - }); + } });