Debian Codegraph @

js/src/tests/test262/built-ins/Temporal/PlainDateTime/from/argument-string-invalid.js

raw
1 // |reftest| shell-option(--enable-temporal) skip-if(!this.hasOwnProperty('Temporal')||!xulRuntime.shell) -- Temporal is not enabled unconditionally, requires shell-options
2 // Copyright (C) 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-temporal.plaindatetime.from
7 description: Reject string argument if it cannot be parsed
8 features: [Temporal]
9 ---*/
10
11 const invalidStrings = [
12 // invalid ISO strings:
13 "",
14 "obviously invalid",
15 "2020-01-00",
16 "2020-01-32",
17 "2020-02-30",
18 "2021-02-29",
19 "2020-00-01",
20 "2020-13-01",
21 "2020-01-01T",
22 "2020-01-01T25:00:00",
23 "2020-01-01T01:60:00",
24 "2020-01-01T01:60:61",
25 "2020-01-01junk",
26 "2020-01-01T00:00:00junk",
27 "2020-01-01T00:00:00+00:00junk",
28 "2020-01-01T00:00:00+00:00[UTC]junk",
29 "2020-01-01T00:00:00+00:00[UTC][u-ca=iso8601]junk",
30 "02020-01-01",
31 "2020-001-01",
32 "2020-01-001",
33 "2020-01-01T001",
34 "2020-01-01T01:001",
35 "2020-01-01T01:01:001",
36 // valid, but forms not supported in Temporal:
37 "2020-W01-1",
38 "2020-001",
39 "+0002020-01-01",
40 // valid, but this calendar must not exist:
41 "2020-01-01[u-ca=notexist]",
42 // may be valid in other contexts, but insufficient information for PlainDateTime:
43 "2020-01",
44 "+002020-01",
45 "01-01",
46 "2020-W01",
47 "P1Y",
48 "-P12Y",
49 // valid, but outside the supported range:
50 "-999999-01-01",
51 "+999999-01-01",
52 ];
53
54 invalidStrings.forEach((s) => {
55 assert.throws(
56 RangeError,
57 () => Temporal.PlainDateTime.from(s),
58 `invalid date-time string (${s})`
59 );
60 });
61
62 reportCompare(0, 0);