v8/test/intl/localematcher/bestfit-supportedLocalesOf-subset.js
Frank Tang 91d5cc2fa9 Reland "[intl] Improve test coverage of "best fit" localeMatcher"
This is a reland of dd8845cd74

Original change's description:
> [intl] Improve test coverage of "best fit" localeMatcher
>
> https: //docs.google.com/document/d/1cPGfiihn76yj2iAomKcspPFyLLcnk3WkCiqceBQPQyk/edit#heading=h.cc9tt7s0iwsd
> Bug: v8:7051
> Change-Id: I8c35e859062c5bdb009334dd1b725751e6df2123
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2965481
> Reviewed-by: Shu-yu Guo <syg@chromium.org>
> Commit-Queue: Frank Tang <ftang@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#75228}

Bug: v8:7051
Change-Id: I9af13b8fdf7ec3de2ac24050074d13fcdef981c7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2973648
Reviewed-by: Frank Tang <ftang@chromium.org>
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Frank Tang <ftang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75280}
2021-06-21 17:37:31 +00:00

39 lines
1.3 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 return list is subset of the request list.
// https://tc39.es/ecma402/#sec-bestfitsupportedlocales
// 9.2.9 BestFitSupportedLocales ( availableLocales, requestedLocales )
// The BestFitSupportedLocales abstract operation returns the SUBSET of the
// provided BCP 47 language priority list requestedLocales for which
// availableLocales has a matching locale when using the Best Fit Matcher
// algorithm. Locales appear in the same order in the returned list as in
// requestedLocales. The steps taken are implementation dependent.
function assertSubarray(a, b) {
assertTrue(a.every(val => b.includes(val)), ['returns:', a, 'requested:', b]);
}
function verifySupportedLocalesAreSubarray(f, ll) {
assertSubarray(f(ll), ll);
}
const intlObjs = [
Intl.Collator,
Intl.DateTimeFormat,
Intl.DisplayNames,
Intl.ListFormat,
Intl.NumberFormat,
Intl.PluralRules,
Intl.RelativeTimeFormat,
Intl.Segmenter,
];
intlObjs.forEach(function(obj) {
verifySupportedLocalesAreSubarray(obj.supportedLocalesOf, ['en', 'ceb']);
verifySupportedLocalesAreSubarray(obj.supportedLocalesOf, ['en', 'ceb', 'fil']);
});