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