bestfit-supplemental-files.js 1.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
// 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");
  });

});