diff --git a/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/overflow-constrain.js b/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/overflow-constrain.js new file mode 100644 index 00000000000..dd843bb090f --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/overflow-constrain.js @@ -0,0 +1,46 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.yearmonthfromfields +description: Temporal.Calendar.prototype.yearMonthFromFields will return correctly with data and overflow set to 'constrain'. +info: | + 1. Let calendar be the this value. + 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). + 3. Assert: calendar.[[Identifier]] is "iso8601". + 4. If Type(fields) is not Object, throw a TypeError exception. + 5. Set options to ? GetOptionsObject(options). + 6. Let result be ? ISOYearMonthFromFields(fields, options). + 7. Return ? CreateTemporalYearMonth(result.[[Year]], result.[[Month]], calendar, result.[[ReferenceISODay]]). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601") + +let opt = {overflow: "constrain"}; +// Test overflow: "constrain" work properly +assert.sameValue("2021-01", cal.yearMonthFromFields({year: 2021, month: 1}, opt).toJSON()); +assert.sameValue("2021-02", cal.yearMonthFromFields({year: 2021, month: 2}, opt).toJSON()); +assert.sameValue("2021-03", cal.yearMonthFromFields({year: 2021, month: 3}, opt).toJSON()); +assert.sameValue("2021-04", cal.yearMonthFromFields({year: 2021, month: 4}, opt).toJSON()); +assert.sameValue("2021-05", cal.yearMonthFromFields({year: 2021, month: 5}, opt).toJSON()); +assert.sameValue("2021-06", cal.yearMonthFromFields({year: 2021, month: 6}, opt).toJSON()); +assert.sameValue("2021-07", cal.yearMonthFromFields({year: 2021, month: 7}, opt).toJSON()); +assert.sameValue("2021-08", cal.yearMonthFromFields({year: 2021, month: 8}, opt).toJSON()); +assert.sameValue("2021-09", cal.yearMonthFromFields({year: 2021, month: 9}, opt).toJSON()); +assert.sameValue("2021-10", cal.yearMonthFromFields({year: 2021, month: 10}, opt).toJSON()); +assert.sameValue("2021-11", cal.yearMonthFromFields({year: 2021, month: 11}, opt).toJSON()); +assert.sameValue("2021-12", cal.yearMonthFromFields({year: 2021, month: 12}, opt).toJSON()); +assert.sameValue("2021-12", cal.yearMonthFromFields({year: 2021, month: 13}, opt).toJSON()); +assert.sameValue("2021-12", cal.yearMonthFromFields({year: 2021, month: 999999}, opt).toJSON()); +assert.sameValue("2021-01", cal.yearMonthFromFields({year: 2021, monthCode: "M01"}, opt).toJSON()); +assert.sameValue("2021-02", cal.yearMonthFromFields({year: 2021, monthCode: "M02"}, opt).toJSON()); +assert.sameValue("2021-03", cal.yearMonthFromFields({year: 2021, monthCode: "M03"}, opt).toJSON()); +assert.sameValue("2021-04", cal.yearMonthFromFields({year: 2021, monthCode: "M04"}, opt).toJSON()); +assert.sameValue("2021-05", cal.yearMonthFromFields({year: 2021, monthCode: "M05"}, opt).toJSON()); +assert.sameValue("2021-06", cal.yearMonthFromFields({year: 2021, monthCode: "M06"}, opt).toJSON()); +assert.sameValue("2021-07", cal.yearMonthFromFields({year: 2021, monthCode: "M07"}, opt).toJSON()); +assert.sameValue("2021-08", cal.yearMonthFromFields({year: 2021, monthCode: "M08"}, opt).toJSON()); +assert.sameValue("2021-09", cal.yearMonthFromFields({year: 2021, monthCode: "M09"}, opt).toJSON()); +assert.sameValue("2021-10", cal.yearMonthFromFields({year: 2021, monthCode: "M10"}, opt).toJSON()); +assert.sameValue("2021-11", cal.yearMonthFromFields({year: 2021, monthCode: "M11"}, opt).toJSON()); +assert.sameValue("2021-12", cal.yearMonthFromFields({year: 2021, monthCode: "M12"}, opt).toJSON()); diff --git a/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/overflow-undefined.js b/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/overflow-undefined.js new file mode 100644 index 00000000000..35b7726c290 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/overflow-undefined.js @@ -0,0 +1,44 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.yearmonthfromfields +description: Temporal.Calendar.prototype.yearMonthFromFields will return correctly with default overflow which constrain date range. +info: | + 1. Let calendar be the this value. + 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). + 3. Assert: calendar.[[Identifier]] is "iso8601". + 4. If Type(fields) is not Object, throw a TypeError exception. + 5. Set options to ? GetOptionsObject(options). + 6. Let result be ? ISOYearMonthFromFields(fields, options). + 7. Return ? CreateTemporalYearMonth(result.[[Year]], result.[[Month]], calendar, result.[[ReferenceISODay]]). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601") + +assert.sameValue("2021-01", cal.yearMonthFromFields({year: 2021, month: 1}).toJSON()); +assert.sameValue("2021-02", cal.yearMonthFromFields({year: 2021, month: 2}).toJSON()); +assert.sameValue("2021-03", cal.yearMonthFromFields({year: 2021, month: 3}).toJSON()); +assert.sameValue("2021-04", cal.yearMonthFromFields({year: 2021, month: 4}).toJSON()); +assert.sameValue("2021-05", cal.yearMonthFromFields({year: 2021, month: 5}).toJSON()); +assert.sameValue("2021-06", cal.yearMonthFromFields({year: 2021, month: 6}).toJSON()); +assert.sameValue("2021-07", cal.yearMonthFromFields({year: 2021, month: 7}).toJSON()); +assert.sameValue("2021-08", cal.yearMonthFromFields({year: 2021, month: 8}).toJSON()); +assert.sameValue("2021-09", cal.yearMonthFromFields({year: 2021, month: 9}).toJSON()); +assert.sameValue("2021-10", cal.yearMonthFromFields({year: 2021, month: 10}).toJSON()); +assert.sameValue("2021-11", cal.yearMonthFromFields({year: 2021, month: 11}).toJSON()); +assert.sameValue("2021-12", cal.yearMonthFromFields({year: 2021, month: 12}).toJSON()); +assert.sameValue("2021-12", cal.yearMonthFromFields({year: 2021, month: 13}).toJSON()); +assert.sameValue("2021-12", cal.yearMonthFromFields({year: 2021, month: 999999}).toJSON()); +assert.sameValue("2021-01", cal.yearMonthFromFields({year: 2021, monthCode: "M01"}).toJSON()); +assert.sameValue("2021-02", cal.yearMonthFromFields({year: 2021, monthCode: "M02"}).toJSON()); +assert.sameValue("2021-03", cal.yearMonthFromFields({year: 2021, monthCode: "M03"}).toJSON()); +assert.sameValue("2021-04", cal.yearMonthFromFields({year: 2021, monthCode: "M04"}).toJSON()); +assert.sameValue("2021-05", cal.yearMonthFromFields({year: 2021, monthCode: "M05"}).toJSON()); +assert.sameValue("2021-06", cal.yearMonthFromFields({year: 2021, monthCode: "M06"}).toJSON()); +assert.sameValue("2021-07", cal.yearMonthFromFields({year: 2021, monthCode: "M07"}).toJSON()); +assert.sameValue("2021-08", cal.yearMonthFromFields({year: 2021, monthCode: "M08"}).toJSON()); +assert.sameValue("2021-09", cal.yearMonthFromFields({year: 2021, monthCode: "M09"}).toJSON()); +assert.sameValue("2021-10", cal.yearMonthFromFields({year: 2021, monthCode: "M10"}).toJSON()); +assert.sameValue("2021-11", cal.yearMonthFromFields({year: 2021, monthCode: "M11"}).toJSON()); +assert.sameValue("2021-12", cal.yearMonthFromFields({year: 2021, monthCode: "M12"}).toJSON()); diff --git a/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/simple.js b/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/simple.js new file mode 100644 index 00000000000..0c009d01a3f --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/simple.js @@ -0,0 +1,31 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.yearmonthfromfields +description: Temporal.Calendar.prototype.yearMonthFromFields return correctly with valid data. +info: | + 1. Let calendar be the this value. + 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). + 3. Assert: calendar.[[Identifier]] is "iso8601". + 4. If Type(fields) is not Object, throw a TypeError exception. + 5. Set options to ? GetOptionsObject(options). + 6. Let result be ? ISOYearMonthFromFields(fields, options). + 7. Return ? CreateTemporalYearMonth(result.[[Year]], result.[[Month]], calendar, result.[[ReferenceISODay]]). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601") + + +assert.sameValue("2021-07", cal.yearMonthFromFields({year: 2021, month: 7}).toJSON()); +assert.sameValue("2021-12", cal.yearMonthFromFields({year: 2021, month: 12}).toJSON()); +assert.sameValue("2021-07", cal.yearMonthFromFields({year: 2021, monthCode: "M07"}).toJSON()); +assert.sameValue("2021-12", cal.yearMonthFromFields({year: 2021, monthCode: "M12"}).toJSON()); + +["constrain", "reject"].forEach(function(overflow) { + let opt = {overflow}; + assert.sameValue("2021-07", cal.yearMonthFromFields({year: 2021, month: 7}, opt).toJSON()); + assert.sameValue("2021-12", cal.yearMonthFromFields({year: 2021, month: 12}, opt).toJSON()); + assert.sameValue("2021-07", cal.yearMonthFromFields({year: 2021, monthCode: "M07"}, opt).toJSON()); + assert.sameValue("2021-12", cal.yearMonthFromFields({year: 2021, monthCode: "M12"}, opt).toJSON()); +}) diff --git a/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/throw-range-error.js b/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/throw-range-error.js new file mode 100644 index 00000000000..b51ff65575d --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/throw-range-error.js @@ -0,0 +1,65 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.yearmonthfromfields +description: Temporal.Calendar.prototype.yearMonthFromFields will throw RangeError while the input data value is out of range. +info: | + 1. Let calendar be the this value. + 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). + 3. Assert: calendar.[[Identifier]] is "iso8601". + 4. If Type(fields) is not Object, throw a TypeError exception. + 5. Set options to ? GetOptionsObject(options). + 6. Let result be ? ISOYearMonthFromFields(fields, options). + 7. Return ? CreateTemporalYearMonth(result.[[Year]], result.[[Month]], calendar, result.[[ReferenceISODay]]). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601") + +assert.throws(RangeError, () => cal.yearMonthFromFields({year: 2021, monthCode: "m1"}), + "monthCode value is out of range."); +assert.throws(RangeError, () => cal.yearMonthFromFields({year: 2021, monthCode: "M1"}), + "monthCode value is out of range."); +assert.throws(RangeError, () => cal.yearMonthFromFields({year: 2021, monthCode: "m01"}), + "monthCode value is out of range."); + +assert.throws(RangeError, () => cal.yearMonthFromFields({year: 2021, month: 12, monthCode: "M11"}), + "monthCode value is out of range."); +assert.throws(RangeError, () => cal.yearMonthFromFields({year: 2021, monthCode: "M00"}), + "monthCode value is out of range."); +assert.throws(RangeError, () => cal.yearMonthFromFields({year: 2021, monthCode: "M19"}), + "monthCode value is out of range."); +assert.throws(RangeError, () => cal.yearMonthFromFields({year: 2021, monthCode: "M99"}), + "monthCode value is out of range."); +assert.throws(RangeError, () => cal.yearMonthFromFields({year: 2021, monthCode: "M13"}), + "monthCode value is out of range."); + +assert.throws(RangeError, () => cal.yearMonthFromFields({year: 2021, month: -1}), + "Invalid time value"); +assert.throws(RangeError, () => cal.yearMonthFromFields({year: 2021, month: -Infinity}), + "Invalid time value"); + +assert.throws(RangeError, () => cal.yearMonthFromFields({year: 2021, month: 0, day: 5}, {overflow: "reject"}), + "Invalid time value"); +assert.throws(RangeError, () => cal.yearMonthFromFields({year: 2021, month: 13, day: 5}, {overflow: "reject"}), + "Invalid time value"); + +assert.throws(RangeError, () => cal.yearMonthFromFields( + {year: 2021, monthCode: "M00"}, {overflow: "reject"}), + "monthCode value is out of range."); +assert.throws(RangeError, () => cal.yearMonthFromFields( + {year: 2021, monthCode: "M13"}, {overflow: "reject"}), + "monthCode value is out of range."); + +assert.throws(RangeError, () => cal.yearMonthFromFields( + {year: 2021, month: 0}), "Invalid time value"); + +// Check throw for the second arg +assert.throws(RangeError, () => cal.yearMonthFromFields( + {year: 2021, month: 7}, {overflow: "invalid"}), + "Value invalid out of range for Temporal.Calendar.prototype.yearMonthFromFields options property overflow"); + +assert.throws(RangeError, () => cal.yearMonthFromFields( + {year: 2021, month: 13}, {overflow: "reject"}), "Invalid time value"); +assert.throws(RangeError, () => cal.yearMonthFromFields( + {year: 2021, month: 9995}, {overflow: "reject"}), "Invalid time value"); diff --git a/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/throw-type-error-fields-is-not-object.js b/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/throw-type-error-fields-is-not-object.js new file mode 100644 index 00000000000..a39ab953b34 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/throw-type-error-fields-is-not-object.js @@ -0,0 +1,19 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.yearmonthfromfields +description: Temporal.Calendar.prototype.yearMonthFromFields will throw TypeError when fields is not object. + no [[InitializedTemporalCalendar]] in calendar. +info: | + 4. If Type(fields) is not Object, throw a TypeError exception. +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601") + +let notObjectList = [ + null, undefined, "string", Symbol('efg'), true, false, Infinity, NaN, 123, 456n]; +notObjectList.forEach(function(fields) { + assert.throws(TypeError, () => cal.yearMonthFromFields(fields), + "fields is not object"); +}) diff --git a/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/throw-type-error-from-GetOptionsObject.js b/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/throw-type-error-from-GetOptionsObject.js new file mode 100644 index 00000000000..0d82322a343 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/throw-type-error-from-GetOptionsObject.js @@ -0,0 +1,19 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.yearmonthfromfields +description: Temporal.Calendar.prototype.yearMonthFromFields will throw TypeError from GetOptionsObject. + no [[InitializedTemporalCalendar]] in calendar. +info: | + 5. Set options to ? GetOptionsObject(options). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601") + +let notObjectList = [ + null, "string", Symbol('efg'), true, false, Infinity, NaN, 123, 456n]; +notObjectList.forEach(function(options) { + assert.throws(TypeError, () => cal.yearMonthFromFields({year: 2021, month:7}, options), + "options is not object"); +}) diff --git a/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/throw-type-error-from-RequireInternalSlot.js b/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/throw-type-error-from-RequireInternalSlot.js new file mode 100644 index 00000000000..0109ba3382e --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/throw-type-error-from-RequireInternalSlot.js @@ -0,0 +1,17 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.yearmonthfromfields +description: Temporal.Calendar.prototype.yearMonthFromFields will throw TypeError from RequireInternalSlot if there are + no [[InitializedTemporalCalendar]] in calendar. +info: | + 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601") + +let badCal = {yearMonthFromFields: cal.yearMonthFromFields}; +// Check throw for first arg +assert.throws(TypeError, () => badCal.yearMonthFromFields({year: 2021, month: 1), + "calendar does not have [[InitializedTemporalCalendar]]"); diff --git a/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/throw-type-error.js b/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/throw-type-error.js new file mode 100644 index 00000000000..3d56d708d28 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/throw-type-error.js @@ -0,0 +1,37 @@ +// Copyright (C) 2021 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.yearmonthfromfields +description: Temporal.Calendar.prototype.yearMonthFromFields will throw TypeError with incorrect input data type. +info: | + 1. Let calendar be the this value. + 2. Perform ? RequireInternalSlot(calendar, [[InitializedTemporalCalendar]]). + 3. Assert: calendar.[[Identifier]] is "iso8601". + 4. If Type(fields) is not Object, throw a TypeError exception. + 5. Set options to ? GetOptionsObject(options). + 6. Let result be ? ISOYearMonthFromFields(fields, options). + 7. Return ? CreateTemporalYearMonth(result.[[Year]], result.[[Month]], calendar, result.[[ReferenceISODay]]). +features: [Temporal] +---*/ +let cal = new Temporal.Calendar("iso8601") + +// Check throw for first arg +assert.throws(TypeError, () => cal.yearMonthFromFields(), + "Temporal.Calendar.prototype.yearMonthFromFields called on non-object"); +[undefined, true, false, 123, 456n, Symbol(), "string"].forEach( + function(fields) { + assert.throws(TypeError, () => cal.yearMonthFromFields(fields), + "Temporal.Calendar.prototype.yearMonthFromFields called on non-object"); + assert.throws(TypeError, () => cal.yearMonthFromFields(fields, undefined), + "Temporal.Calendar.prototype.yearMonthFromFields called on non-object"); + assert.throws(TypeError, () => cal.yearMonthFromFields(fields, {overflow: "constrain"}), + "Temporal.Calendar.prototype.yearMonthFromFields called on non-object"); + assert.throws(TypeError, () => cal.yearMonthFromFields(fields, {overflow: "reject"}), + "Temporal.Calendar.prototype.yearMonthFromFields called on non-object"); + }); + +assert.throws(TypeError, () => cal.yearMonthFromFields({month: 1}), + "invalid_argument"); +assert.throws(TypeError, () => cal.yearMonthFromFields({year: 2021}), + "invalid_argument");