mirror of
https://github.com/nodejs/node.git
synced 2025-05-17 08:05:29 +00:00

PR-URL: https://github.com/nodejs/node/pull/39469 Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
// Copyright 2021 the V8 project authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
// Flags: --harmony_intl_best_fit_matcher
|
|
//
|
|
// Test the supportedLocales and resolvedOptions based on
|
|
// https://github.com/unicode-org/cldr/blob/master/common/supplemental/languageInfo.xml
|
|
|
|
const intlObjs = [
|
|
Intl.Collator,
|
|
Intl.DateTimeFormat,
|
|
Intl.DisplayNames,
|
|
Intl.ListFormat,
|
|
Intl.NumberFormat,
|
|
Intl.RelativeTimeFormat,
|
|
Intl.PluralRules,
|
|
Intl.Segmenter,
|
|
];
|
|
|
|
|
|
function verifyResolvedLocale(obj, opt, l1, l2) {
|
|
let options = {}
|
|
options = Object.assign(options, opt);
|
|
if (obj == Intl.DisplayNames) {
|
|
options['type'] = "language";
|
|
}
|
|
let resolvedLocale = (new obj(l1, options)).resolvedOptions().locale;
|
|
assertTrue((l1 == resolvedLocale) ||
|
|
(l2 == resolvedLocale.substring(0, l2.length)));
|
|
}
|
|
|
|
let bestFitOpt = {localeMatcher: "best fit"};
|
|
let defaultLocale = (new Intl.NumberFormat()).resolvedOptions().locale;
|
|
intlObjs.forEach(function(obj) {
|
|
[{}, bestFitOpt].forEach(function(opt) {
|
|
print(obj);
|
|
verifyResolvedLocale(obj, opt, "co", "fr");
|
|
verifyResolvedLocale(obj, opt, "crs", "fr");
|
|
verifyResolvedLocale(obj, opt, "lb", "de");
|
|
verifyResolvedLocale(obj, opt, "gsw", "de");
|
|
verifyResolvedLocale(obj, opt, "btj", "ms");
|
|
verifyResolvedLocale(obj, opt, "bjn", "ms");
|
|
});
|
|
|
|
});
|