argument-string-invalid.js (1635B)
1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally 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.plaindate.from 7 description: > 8 RangeError thrown if an invalid ISO string (or syntactically valid ISO string 9 that is not supported) is used as a PlainDate 10 features: [Temporal, arrow-function] 11 ---*/ 12 13 const invalidStrings = [ 14 // invalid ISO strings: 15 "", 16 "invalid iso8601", 17 "2020-01-00", 18 "2020-01-32", 19 "2020-02-30", 20 "2021-02-29", 21 "2020-00-01", 22 "2020-13-01", 23 "2020-01-01T", 24 "2020-01-01T25:00:00", 25 "2020-01-01T01:60:00", 26 "2020-01-01T01:60:61", 27 "2020-01-01junk", 28 "2020-01-01T00:00:00junk", 29 "2020-01-01T00:00:00+00:00junk", 30 "2020-01-01T00:00:00+00:00[UTC]junk", 31 "2020-01-01T00:00:00+00:00[UTC][u-ca=iso8601]junk", 32 "02020-01-01", 33 "2020-001-01", 34 "2020-01-001", 35 "2020-01-01T001", 36 "2020-01-01T01:001", 37 "2020-01-01T01:01:001", 38 // valid, but forms not supported in Temporal: 39 "2020-W01-1", 40 "2020-001", 41 "+0002020-01-01", 42 // valid, but this calendar must not exist: 43 "2020-01-01[u-ca=notexist]", 44 // may be valid in other contexts, but insufficient information for PlainDate: 45 "2020-01", 46 "+002020-01", 47 "01-01", 48 "2020-W01", 49 "P1Y", 50 "-P12Y", 51 // valid, but outside the supported range: 52 "-999999-01-01", 53 "+999999-01-01", 54 ]; 55 for (const arg of invalidStrings) { 56 assert.throws( 57 RangeError, 58 () => Temporal.PlainDate.from(arg), 59 `"${arg}" should not be a valid ISO string for a PlainDate` 60 ); 61 } 62 63 reportCompare(0, 0);