node/deps/v8/test/intl/localematcher/bestfit-supplemental-files.js
Michaël Zasso 50930a0fa0
deps: update V8 to 9.3.345.16
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>
2021-08-30 21:02:51 +02:00

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");
});
});