test262/test/intl402/fallback-locales-are-supported.js
Frank Yung-Fong Tang 9997a26c7d
Fix tests on {localeMatcher: "lookup"} (#3008)
* Fix test for only {localeMatcher: "lookup"}

The expectation that "sr-Thai-RS" would be returned is only true with the 
9.2.2 BestAvailableLocale ( availableLocales, locale )
https://tc39.es/ecma402/#sec-bestavailablelocale
algorithm used by 9.2.3 LookupMatcher ( availableLocales, requestedLocales )
https://tc39.es/ecma402/#sec-lookupmatcher

The default for localeMatcher is "best fit" but not "lookup" for all Intl objects.

And for 9.2.4 BestFitMatcher ( availableLocales, requestedLocales )
https://tc39.es/ecma402/#sec-bestfitmatcher
It may not match "sr-Thai-RS" for "sr"  and return ["de", "zh-CN"] instead. Therefore, we need to change this test to only test on {localeMatcher: "lookup"}

* Add option to getLocaleSupportInfo

Needed to test different localeMatcher

* only test for "lookup" localeMatcher

* Get the info based on the localeMatcher

* pass in localeMatcher to getLocaleSupportInfo
2021-06-24 13:37:33 -04:00

35 lines
1.3 KiB
JavaScript

// Copyright 2012 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es5id: 9.1_b
description: >
Tests that appropriate fallback locales are provided for
supported locales.
author: Norbert Lindenberg
includes: [testIntl.js]
---*/
testWithIntlConstructors(function (Constructor) {
// The test is only valid under "lookup" localeMatcher
var info = getLocaleSupportInfo(Constructor, {localeMatcher: "lookup"});
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.");
}
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.");
}
}
});