Debian Codegraph @

js/src/tests/test262/intl402/DurationFormat/constructor-locales-valid.js

raw
1 // |reftest| skip-if(!Intl.hasOwnProperty('DurationFormat')) -- Intl.DurationFormat is not enabled unconditionally
2 // Copyright 2022 Igalia, S.L. All rights reserved.
3 // This code is governed by the BSD license found in the LICENSE file.
4
5 /*---
6 esid: sec-Intl.DurationFormat
7 description: Checks cases for the locales argument to the DurationFormat constructor.
8 info: |
9 Intl.DurationFormat ( [ locales [ , options ] ] )
10 (...)
11 3. Let _requestedLocales_ be ? CanonicalizeLocaleList(_locales_).
12 features: [Intl.DurationFormat]
13 ---*/
14
15 const defaultLocale = new Intl.DurationFormat().resolvedOptions().locale;
16
17 const matchers = ["lookup", "best fit"]
18
19 const tests = [
20 [undefined, defaultLocale, "undefined"],
21 ["EN", "en", "Single value"],
22 [[], defaultLocale, "Empty array"],
23 [["en", "EN"], "en", "Duplicate value (canonical first)"],
24 [["EN", "en"], "en", "Duplicate value (canonical last)"],
25 [{ 0: "DE", length: 0 }, defaultLocale, "Object with zero length"],
26 [{ 0: "DE", length: 1 }, "de", "Object with length"],
27 ];
28
29
30 for (const [locales, expected, name] of tests) {
31 matchers.forEach((matcher)=>{
32 const drf = new Intl.DurationFormat(locales, {localeMatcher: matcher});
33 assert.sameValue(drf.resolvedOptions().locale, expected, name);
34 });
35 };
36
37 reportCompare(0, 0);