Debian Codegraph @

js/src/tests/test262/intl402/DurationFormat/constructor-options-style-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 handling of valid values for the style option to the DurationFormat constructor.
8 info: |
9 InitializeDurationFormat (DurationFormat, locales, options)
10 (...)
11 13. Let style be ? GetOption(options, "style", "string", « "long", "short", "narrow", "digital" », "short").
12 14. Set durationFormat.[[Style]] to style.
13 features: [Intl.DurationFormat]
14 ---*/
15
16 const validOptions = [
17 [undefined, "short"],
18 ["long", "long"],
19 ["short", "short"],
20 ["narrow", "narrow"],
21 ["digital", "digital"],
22 [{ toString() { return "short"; } }, "short"],
23 [{ toString() { return "long"; } }, "long"],
24 [{ toString() { return "narrow"; } }, "narrow"],
25 [{ toString() { return "digital"; } }, "digital"],
26 ];
27
28 for (const [validOption, expected] of validOptions) {
29 const df = new Intl.DurationFormat([], {"style": validOption});
30 const resolvedOptions = df.resolvedOptions();
31 assert.sameValue(resolvedOptions.style, expected);
32 }
33
34 reportCompare(0, 0);