Debian Codegraph @

js/src/tests/test262/intl402/DateTimeFormat/constructor-options-dateStyle-valid.js

raw
1 // Copyright 2019 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-createdatetimeformat
6 description: >
7 Checks handling of the options argument to the DateTimeFormat constructor.
8 info: |
9 CreateDateTimeFormat ( dateTimeFormat, locales, options, required, defaults )
10
11 ...
12 39. Let dateStyle be ? GetOption(options, "dateStyle", "string", « "full", "long", "medium", "short" », undefined).
13 40. If dateStyle is not undefined, set dateTimeFormat.[[DateStyle]] to dateStyle.
14 features: [Intl.DateTimeFormat-datetimestyle]
15 ---*/
16
17
18 const validOptions = [
19 [undefined, undefined],
20 ["full", "full"],
21 ["long", "long"],
22 ["medium", "medium"],
23 ["short", "short"],
24 [{ toString() { return "full"; } }, "full"],
25 [{ valueOf() { return "long"; }, toString: undefined }, "long"],
26 ];
27 for (const [dateStyle, expected] of validOptions) {
28 const dtf = new Intl.DateTimeFormat("en", { dateStyle });
29 const options = dtf.resolvedOptions();
30 assert.sameValue(options.dateStyle, expected);
31 const propdesc = Object.getOwnPropertyDescriptor(options, "dateStyle");
32 if (expected === undefined) {
33 assert.sameValue(propdesc, undefined);
34 } else {
35 assert.sameValue(propdesc.value, expected);
36 }
37 }
38
39 reportCompare(0, 0);