node/deps/v8/test/intl/localematcher/bestfit-macrolanguages.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

57 lines
1.8 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 handle macrolanguages
// documented in https://unicode.org/reports/tr35/#Field_Definitions
const intlObjs = [
Intl.Collator,
Intl.DateTimeFormat,
Intl.DisplayNames,
Intl.ListFormat,
Intl.NumberFormat,
Intl.PluralRules,
Intl.RelativeTimeFormat,
Intl.Segmenter,
];
// Macrolanguages in
// https://unicode.org/reports/tr35/#Field_Definitionsk
const macroLanguageMap = {
'cmn': 'zh',
'arb': 'ar',
'zsm': 'ms',
'swh': 'sw',
'uzn': 'uz',
// 'knn': 'kok', // chrome does not ship data for kok locale
'kmr': 'ku',
};
let bestFitOpt = {localeMatcher: "best fit"};
let defaultLocale = (new Intl.NumberFormat()).resolvedOptions().locale;
intlObjs.forEach(function(obj) {
for (const [macro, lang] of Object.entries(macroLanguageMap)) {
const justMacro = [macro];
// Test the macro language will be persist in the supportedLocalesOf
assertEquals([lang], obj.supportedLocalesOf(justMacro));
assertEquals([lang], obj.supportedLocalesOf(justMacro, bestFitOpt));
// Test the macro language would be resolved to a locale other than the
// default locale.
if (obj == Intl.DisplayNames) {
assertTrue(defaultLocale != (new obj(macro, {type: "language"}))
.resolvedOptions().locale);
assertTrue(defaultLocale !=
(new obj(macro, {type: "language", localeMatcher: "best fit"}))
.resolvedOptions().locale);
} else {
assertTrue(defaultLocale != (new obj(macro)).resolvedOptions().locale);
assertTrue(defaultLocale != (new obj(macro, bestFitOpt))
.resolvedOptions().locale);
}
}
});