monthcode-invalid.js (2174B)
1 // |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally 2 // Copyright (C) 2021 the V8 project authors. All rights reserved. 3 // This code is governed by the BSD license found in the LICENSE file. 4 5 /*--- 6 esid: sec-temporal.plainmonthday.from 7 description: Throw RangeError for an out-of-range, conflicting, or ill-formed monthCode 8 features: [Temporal] 9 ---*/ 10 11 ["m1", "M1", "m01"].forEach((monthCode) => { 12 assert.throws(RangeError, () => Temporal.PlainMonthDay.from({ monthCode, day: 17 }), 13 `monthCode '${monthCode}' is not well-formed (without numeric month)`); 14 assert.throws(RangeError, () => Temporal.PlainMonthDay.from({ month: 1, monthCode, day: 17 }), 15 `monthCode '${monthCode}' is not well-formed (with numeric month)`); 16 }); 17 18 assert.throws(RangeError, () => Temporal.PlainMonthDay.from({ year: 2021, month: 12, monthCode: "M11", day: 17 }), 19 "monthCode and month conflict"); 20 21 ["M00", "M19", "M99", "M13", "M00L", "M05L", "M13L"].forEach((monthCode) => { 22 assert.throws(RangeError, () => Temporal.PlainMonthDay.from({ monthCode, day: 17 }), 23 `monthCode '${monthCode}' is not valid for ISO 8601 calendar (without numeric month)`); 24 var monthNumber = Number(monthCode.slice(1, 3)) + (monthCode.length - 3); 25 assert.throws( 26 RangeError, 27 () => Temporal.PlainMonthDay.from({ month: monthNumber, monthCode, day: 17 }), 28 `monthCode '${monthCode}' is not valid for ISO 8601 calendar (with numeric month)` 29 ); 30 var clampedMonthNumber = monthNumber < 1 ? 1 : monthNumber > 12 ? 12 : monthNumber; 31 assert.throws( 32 RangeError, 33 () => Temporal.PlainMonthDay.from({ month: clampedMonthNumber, monthCode, day: 17 }), 34 `monthCode '${monthCode}' is not valid for ISO 8601 calendar (with clamped numeric month)` 35 ); 36 }); 37 38 assert.throws( 39 RangeError, 40 () => Temporal.PlainMonthDay.from({ day: 1, monthCode: "L99M", year: Symbol() }), 41 "Month code syntax is validated before year type is validated" 42 ); 43 44 assert.throws( 45 TypeError, 46 () => Temporal.PlainMonthDay.from({ day: 1, monthCode: "M99L", year: Symbol() }), 47 "Month code suitability is validated after year type is validated" 48 ); 49 50 reportCompare(0, 0);