From afce1b3fde39abfb825da518971fc18423068e94 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Mon, 18 Apr 2022 11:16:54 -0700 Subject: [PATCH] Test conversion of Number to Temporal objects Adds tests for conversion of a Number whose corresponding toString() value is a valid ISO string. For some Temporal types this is possible, with a number like 20220418. Especially for Temporal.Calendar, we have to take into account the case where the number is provided as the value for the 'calendar' property in a property bag, and the case of up to one level of nested property bag as well. Regularizes and expands existing tests for this case. --- .../Temporal/Calendar/from/calendar-number.js | 27 +++++++++ .../prototype/dateAdd/argument-number.js | 30 ++++++++++ .../argument-propertybag-calendar-number.js | 42 ++++++++++++++ .../prototype/dateUntil/argument-number.js | 37 ++++++++++++ .../argument-propertybag-calendar-number.js | 56 +++++++++++++++++++ .../Calendar/prototype/day/argument-number.js | 29 ++++++++++ .../argument-propertybag-calendar-number.js | 41 ++++++++++++++ .../prototype/dayOfWeek/argument-number.js | 29 ++++++++++ .../argument-propertybag-calendar-number.js | 41 ++++++++++++++ .../prototype/dayOfYear/argument-number.js | 29 ++++++++++ .../argument-propertybag-calendar-number.js | 41 ++++++++++++++ .../prototype/daysInMonth/argument-number.js | 29 ++++++++++ .../argument-propertybag-calendar-number.js | 41 ++++++++++++++ .../prototype/daysInWeek/argument-number.js | 29 ++++++++++ .../argument-propertybag-calendar-number.js | 41 ++++++++++++++ .../prototype/daysInYear/argument-number.js | 29 ++++++++++ .../argument-propertybag-calendar-number.js | 41 ++++++++++++++ .../prototype/inLeapYear/argument-number.js | 29 ++++++++++ .../argument-propertybag-calendar-number.js | 41 ++++++++++++++ .../prototype/month/argument-number.js | 29 ++++++++++ .../argument-propertybag-calendar-number.js | 41 ++++++++++++++ .../prototype/monthCode/argument-number.js | 29 ++++++++++ .../argument-propertybag-calendar-number.js | 41 ++++++++++++++ .../prototype/monthsInYear/argument-number.js | 29 ++++++++++ .../argument-propertybag-calendar-number.js | 41 ++++++++++++++ .../prototype/weekOfYear/argument-number.js | 29 ++++++++++ .../argument-propertybag-calendar-number.js | 41 ++++++++++++++ .../prototype/year/argument-number.js | 29 ++++++++++ .../argument-propertybag-calendar-number.js | 41 ++++++++++++++ .../prototype/add/relativeto-number.js | 30 ++++++++++ .../relativeto-propertybag-calendar-number.js | 42 ++++++++++++++ .../prototype/round/relativeto-number.js | 30 ++++++++++ .../relativeto-propertybag-calendar-number.js | 42 ++++++++++++++ .../prototype/subtract/relativeto-number.js | 30 ++++++++++ .../relativeto-propertybag-calendar-number.js | 42 ++++++++++++++ .../prototype/total/relativeto-number.js | 29 ++++++++++ .../relativeto-propertybag-calendar-number.js | 41 ++++++++++++++ .../toZonedDateTime/calendar-number.js | 29 ++++++++++ .../Temporal/Now/plainDate/calendar-number.js | 27 +++++++++ .../Now/plainDateTime/calendar-number.js | 27 +++++++++ .../Now/zonedDateTime/calendar-number.js | 27 +++++++++ .../Temporal/PlainDate/calendar-number.js | 27 +++++++++ .../PlainDate/compare/argument-number.js | 34 +++++++++++ .../argument-propertybag-calendar-number.js | 53 ++++++++++++++++++ .../PlainDate/from/argument-number.js | 22 +++++++- .../argument-propertybag-calendar-number.js | 40 +++++++++++++ .../prototype/equals/argument-number.js | 29 ++++++++++ .../argument-propertybag-calendar-number.js | 41 ++++++++++++++ .../prototype/since/argument-number.js | 30 ++++++++++ .../argument-propertybag-calendar-number.js | 42 ++++++++++++++ .../toPlainDateTime/argument-number.js | 31 ++++++++++ .../toZonedDateTime/argument-number.js | 30 ++++++++++ .../prototype/until/argument-number.js | 30 ++++++++++ .../argument-propertybag-calendar-number.js | 42 ++++++++++++++ .../prototype/withCalendar/calendar-number.js | 29 ++++++++++ .../Temporal/PlainDateTime/calendar-number.js | 27 +++++++++ .../PlainDateTime/compare/argument-number.js | 34 +++++++++++ .../argument-propertybag-calendar-number.js | 53 ++++++++++++++++++ .../PlainDateTime/from/argument-number.js | 35 ++++++------ .../argument-propertybag-calendar-number.js | 40 +++++++++++++ .../prototype/equals/argument-number.js | 29 ++++++++++ .../argument-propertybag-calendar-number.js | 41 ++++++++++++++ .../prototype/since/argument-number.js | 30 ++++++++++ .../argument-propertybag-calendar-number.js | 42 ++++++++++++++ .../prototype/until/argument-number.js | 30 ++++++++++ .../argument-propertybag-calendar-number.js | 42 ++++++++++++++ .../prototype/withCalendar/calendar-number.js | 29 ++++++++++ .../withPlainDate/argument-number.js | 30 ++++++++++ .../argument-propertybag-calendar-number.js | 42 ++++++++++++++ .../withPlainTime/argument-number.js | 31 ++++++++++ .../Temporal/PlainMonthDay/calendar-number.js | 27 +++++++++ .../PlainMonthDay/from/argument-number.js | 28 ++++++++++ .../argument-propertybag-calendar-number.js | 40 +++++++++++++ .../prototype/equals/argument-number.js | 29 ++++++++++ .../argument-propertybag-calendar-number.js | 41 ++++++++++++++ .../PlainTime/compare/argument-number.js | 35 ++++++++++++ .../PlainTime/from/argument-number.js | 25 +++++++-- .../prototype/equals/argument-number.js | 30 ++++++++++ .../prototype/since/argument-number.js | 31 ++++++++++ .../toPlainDateTime/argument-number.js | 30 ++++++++++ .../argument-propertybag-calendar-number.js | 42 ++++++++++++++ .../toZonedDateTime/argument-number.js | 29 ++++++++++ .../argument-propertybag-calendar-number.js | 41 ++++++++++++++ .../prototype/until/argument-number.js | 31 ++++++++++ .../PlainYearMonth/calendar-number.js | 27 +++++++++ .../PlainYearMonth/compare/argument-number.js | 34 +++++++++++ .../argument-propertybag-calendar-number.js | 53 ++++++++++++++++++ .../PlainYearMonth/from/argument-number.js | 27 ++++++--- .../argument-propertybag-calendar-number.js | 40 +++++++++++++ .../prototype/equals/argument-number.js | 29 ++++++++++ .../argument-propertybag-calendar-number.js | 41 ++++++++++++++ .../prototype/since/argument-number.js | 30 ++++++++++ .../argument-propertybag-calendar-number.js | 42 ++++++++++++++ .../prototype/until/argument-number.js | 30 ++++++++++ .../argument-propertybag-calendar-number.js | 42 ++++++++++++++ .../getInstantFor/argument-number.js | 29 ++++++++++ .../argument-propertybag-calendar-number.js | 41 ++++++++++++++ .../getPlainDateTimeFor/calendar-number.js | 29 ++++++++++ .../getPossibleInstantsFor/argument-number.js | 30 ++++++++++ .../argument-propertybag-calendar-number.js | 42 ++++++++++++++ .../Temporal/ZonedDateTime/calendar-number.js | 27 +++++++++ .../argument-propertybag-calendar-number.js | 56 +++++++++++++++++++ .../argument-propertybag-calendar-number.js | 41 ++++++++++++++ .../argument-propertybag-calendar-number.js | 42 ++++++++++++++ .../argument-propertybag-calendar-number.js | 43 ++++++++++++++ .../argument-propertybag-calendar-number.js | 43 ++++++++++++++ .../prototype/withCalendar/calendar-number.js | 29 ++++++++++ .../withPlainDate/argument-number.js | 29 ++++++++++ .../argument-propertybag-calendar-number.js | 41 ++++++++++++++ .../withPlainTime/argument-number.js | 30 ++++++++++ .../Calendar/prototype/era/argument-number.js | 29 ++++++++++ .../argument-propertybag-calendar-number.js | 41 ++++++++++++++ .../prototype/eraYear/argument-number.js | 29 ++++++++++ .../argument-propertybag-calendar-number.js | 41 ++++++++++++++ 114 files changed, 3957 insertions(+), 32 deletions(-) create mode 100644 test/built-ins/Temporal/Calendar/from/calendar-number.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-number.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-number.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/day/argument-number.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/day/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-number.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-number.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-number.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-number.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-number.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-number.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/month/argument-number.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/month/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/monthCode/argument-number.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/monthCode/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-number.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-number.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/year/argument-number.js create mode 100644 test/built-ins/Temporal/Calendar/prototype/year/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-number.js create mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/Duration/prototype/round/relativeto-number.js create mode 100644 test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-number.js create mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/Duration/prototype/total/relativeto-number.js create mode 100644 test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/Instant/prototype/toZonedDateTime/calendar-number.js create mode 100644 test/built-ins/Temporal/Now/plainDate/calendar-number.js create mode 100644 test/built-ins/Temporal/Now/plainDateTime/calendar-number.js create mode 100644 test/built-ins/Temporal/Now/zonedDateTime/calendar-number.js create mode 100644 test/built-ins/Temporal/PlainDate/calendar-number.js create mode 100644 test/built-ins/Temporal/PlainDate/compare/argument-number.js create mode 100644 test/built-ins/Temporal/PlainDate/compare/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/PlainDate/from/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/equals/argument-number.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/equals/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/since/argument-number.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/since/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-number.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-number.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/until/argument-number.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-number.js create mode 100644 test/built-ins/Temporal/PlainDateTime/calendar-number.js create mode 100644 test/built-ins/Temporal/PlainDateTime/compare/argument-number.js create mode 100644 test/built-ins/Temporal/PlainDateTime/compare/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/PlainDateTime/from/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-number.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/since/argument-number.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/until/argument-number.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-number.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-number.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-number.js create mode 100644 test/built-ins/Temporal/PlainMonthDay/calendar-number.js create mode 100644 test/built-ins/Temporal/PlainMonthDay/from/argument-number.js create mode 100644 test/built-ins/Temporal/PlainMonthDay/from/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-number.js create mode 100644 test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/PlainTime/compare/argument-number.js create mode 100644 test/built-ins/Temporal/PlainTime/prototype/equals/argument-number.js create mode 100644 test/built-ins/Temporal/PlainTime/prototype/since/argument-number.js create mode 100644 test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-number.js create mode 100644 test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-number.js create mode 100644 test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/PlainTime/prototype/until/argument-number.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/calendar-number.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/compare/argument-number.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/compare/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/from/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-number.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-number.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-number.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-number.js create mode 100644 test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/calendar-number.js create mode 100644 test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-number.js create mode 100644 test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/calendar-number.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-number.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-number.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-number.js create mode 100644 test/intl402/Temporal/Calendar/prototype/era/argument-number.js create mode 100644 test/intl402/Temporal/Calendar/prototype/era/argument-propertybag-calendar-number.js create mode 100644 test/intl402/Temporal/Calendar/prototype/eraYear/argument-number.js create mode 100644 test/intl402/Temporal/Calendar/prototype/eraYear/argument-propertybag-calendar-number.js diff --git a/test/built-ins/Temporal/Calendar/from/calendar-number.js b/test/built-ins/Temporal/Calendar/from/calendar-number.js new file mode 100644 index 0000000000..b6977f2f5a --- /dev/null +++ b/test/built-ins/Temporal/Calendar/from/calendar-number.js @@ -0,0 +1,27 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.from +description: A number is converted to a string, then to Temporal.Calendar +features: [Temporal] +---*/ + +const arg = 19761118; + +const result = Temporal.Calendar.from(arg); +assert.sameValue(result.id, "iso8601", "19761118 is a valid ISO string for Calendar"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => Temporal.Calendar.from(arg), + `Number ${arg} does not convert to a valid ISO string for Calendar` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-number.js b/test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-number.js new file mode 100644 index 0000000000..d1ff94276d --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-number.js @@ -0,0 +1,30 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.dateadd +description: A number is converted to a string, then to Temporal.PlainDate +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const arg = 19761118; + +const result = instance.dateAdd(arg, new Temporal.Duration()); +TemporalHelpers.assertPlainDate(result, 1976, 11, "M11", 18, "19761118 is a valid ISO string for PlainDate"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.dateAdd(arg, new Temporal.Duration()), + `Number ${arg} does not convert to a valid ISO string for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..4d585142dc --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/dateAdd/argument-propertybag-calendar-number.js @@ -0,0 +1,42 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.dateadd +description: A number as calendar in a property bag is converted to a string, then to a calendar +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = instance.dateAdd(arg, new Temporal.Duration()); +TemporalHelpers.assertPlainDate(result1, 1976, 11, "M11", 18, "19970327 is a valid ISO string for calendar"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = instance.dateAdd(arg, new Temporal.Duration()); +TemporalHelpers.assertPlainDate(result2, 1976, 11, "M11", 18, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.dateAdd(arg, new Temporal.Duration()), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.dateAdd(arg, new Temporal.Duration()), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-number.js b/test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-number.js new file mode 100644 index 0000000000..343b06553b --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-number.js @@ -0,0 +1,37 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.dateuntil +description: A number is converted to a string, then to Temporal.PlainDate +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const arg = 19761118; + +const result1 = instance.dateUntil(arg, new Temporal.PlainDate(1976, 11, 19)); +TemporalHelpers.assertDuration(result1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "19761118 is a valid ISO string for PlainDate (first argument)"); +const result2 = instance.dateUntil(new Temporal.PlainDate(1976, 11, 19), arg); +TemporalHelpers.assertDuration(result2, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, "19761118 is a valid ISO string for PlainDate (second argument)"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 18)), + `Number ${arg} does not convert to a valid ISO string for PlainDate (first argument)` + ); + assert.throws( + RangeError, + () => instance.dateUntil(new Temporal.PlainDate(1977, 11, 18), arg), + `Number ${arg} does not convert to a valid ISO string for PlainDate (second argument)` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..a9fd223616 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/dateUntil/argument-propertybag-calendar-number.js @@ -0,0 +1,56 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.dateuntil +description: A number as calendar in a property bag is converted to a string, then to a calendar +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = instance.dateUntil(arg, new Temporal.PlainDate(1976, 11, 19)); +TemporalHelpers.assertDuration(result1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar (first argument)"); +const result2 = instance.dateUntil(new Temporal.PlainDate(1976, 11, 19), arg); +TemporalHelpers.assertDuration(result2, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar (second argument)"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result3 = instance.dateUntil(arg, new Temporal.PlainDate(1976, 11, 19)); +TemporalHelpers.assertDuration(result3, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar (nested property, first argument)"); +const result4 = instance.dateUntil(new Temporal.PlainDate(1976, 11, 19), arg); +TemporalHelpers.assertDuration(result4, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar (nested property, second argument)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)), + `Number ${calendar} does not convert to a valid ISO string for calendar (first argument)` + ); + assert.throws( + RangeError, + () => instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (second argument)` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.dateUntil(arg, new Temporal.PlainDate(1977, 11, 19)), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property, first argument)` + ); + assert.throws( + RangeError, + () => instance.dateUntil(new Temporal.PlainDate(1977, 11, 19), arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property, second argument)` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/day/argument-number.js b/test/built-ins/Temporal/Calendar/prototype/day/argument-number.js new file mode 100644 index 0000000000..61562a4da6 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/day/argument-number.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.day +description: A number is converted to a string, then to Temporal.PlainDate +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const arg = 19761118; + +const result = instance.day(arg); +assert.sameValue(result, 18, "19761118 is a valid ISO string for PlainDate"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.day(arg), + `Number ${arg} does not convert to a valid ISO string for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/day/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/Calendar/prototype/day/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..403ca7f06d --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/day/argument-propertybag-calendar-number.js @@ -0,0 +1,41 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.day +description: A number as calendar in a property bag is converted to a string, then to a calendar +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = instance.day(arg); +assert.sameValue(result1, 18, "19970327 is a valid ISO string for calendar"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = instance.day(arg); +assert.sameValue(result2, 18, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.day(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.day(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-number.js b/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-number.js new file mode 100644 index 0000000000..026642fdee --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-number.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.dayofweek +description: A number is converted to a string, then to Temporal.PlainDate +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const arg = 19761118; + +const result = instance.dayOfWeek(arg); +assert.sameValue(result, 4, "19761118 is a valid ISO string for PlainDate"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.dayOfWeek(arg), + `Number ${arg} does not convert to a valid ISO string for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..bc4d21ea1c --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/dayOfWeek/argument-propertybag-calendar-number.js @@ -0,0 +1,41 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.dayofweek +description: A number as calendar in a property bag is converted to a string, then to a calendar +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = instance.dayOfWeek(arg); +assert.sameValue(result1, 4, "19970327 is a valid ISO string for calendar"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = instance.dayOfWeek(arg); +assert.sameValue(result2, 4, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.dayOfWeek(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.dayOfWeek(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-number.js b/test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-number.js new file mode 100644 index 0000000000..0794df0f4c --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-number.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.dayofyear +description: A number is converted to a string, then to Temporal.PlainDate +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const arg = 19761118; + +const result = instance.dayOfYear(arg); +assert.sameValue(result, 323, "19761118 is a valid ISO string for PlainDate"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.dayOfYear(arg), + `Number ${arg} does not convert to a valid ISO string for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..f0447e0c1c --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/dayOfYear/argument-propertybag-calendar-number.js @@ -0,0 +1,41 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.dayofyear +description: A number as calendar in a property bag is converted to a string, then to a calendar +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = instance.dayOfYear(arg); +assert.sameValue(result1, 323, "19970327 is a valid ISO string for calendar"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = instance.dayOfYear(arg); +assert.sameValue(result2, 323, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.dayOfYear(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.dayOfYear(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-number.js b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-number.js new file mode 100644 index 0000000000..5020046bf4 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-number.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.daysinmonth +description: A number is converted to a string, then to Temporal.PlainDate +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const arg = 19761118; + +const result = instance.daysInMonth(arg); +assert.sameValue(result, 30, "19761118 is a valid ISO string for PlainDate"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.daysInMonth(arg), + `Number ${arg} does not convert to a valid ISO string for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..2987dc0b11 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/daysInMonth/argument-propertybag-calendar-number.js @@ -0,0 +1,41 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.daysinmonth +description: A number as calendar in a property bag is converted to a string, then to a calendar +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = instance.daysInMonth(arg); +assert.sameValue(result1, 30, "19970327 is a valid ISO string for calendar"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = instance.daysInMonth(arg); +assert.sameValue(result2, 30, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.daysInMonth(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.daysInMonth(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-number.js b/test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-number.js new file mode 100644 index 0000000000..889f44f8ba --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-number.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.daysinweek +description: A number is converted to a string, then to Temporal.PlainDate +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const arg = 19761118; + +const result = instance.daysInWeek(arg); +assert.sameValue(result, 7, "19761118 is a valid ISO string for PlainDate"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.daysInWeek(arg), + `Number ${arg} does not convert to a valid ISO string for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..473cd6a433 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/daysInWeek/argument-propertybag-calendar-number.js @@ -0,0 +1,41 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.daysinweek +description: A number as calendar in a property bag is converted to a string, then to a calendar +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = instance.daysInWeek(arg); +assert.sameValue(result1, 7, "19970327 is a valid ISO string for calendar"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = instance.daysInWeek(arg); +assert.sameValue(result2, 7, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.daysInWeek(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.daysInWeek(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-number.js b/test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-number.js new file mode 100644 index 0000000000..84492ddf2b --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-number.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.daysinyear +description: A number is converted to a string, then to Temporal.PlainDate +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const arg = 19761118; + +const result = instance.daysInYear(arg); +assert.sameValue(result, 366, "19761118 is a valid ISO string for PlainDate"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.daysInYear(arg), + `Number ${arg} does not convert to a valid ISO string for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..de1bdcfccd --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/daysInYear/argument-propertybag-calendar-number.js @@ -0,0 +1,41 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.daysinyear +description: A number as calendar in a property bag is converted to a string, then to a calendar +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = instance.daysInYear(arg); +assert.sameValue(result1, 366, "19970327 is a valid ISO string for calendar"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = instance.daysInYear(arg); +assert.sameValue(result2, 366, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.daysInYear(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.daysInYear(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-number.js b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-number.js new file mode 100644 index 0000000000..1b9f0dde66 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-number.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.inleapyear +description: A number is converted to a string, then to Temporal.PlainDate +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const arg = 19761118; + +const result = instance.inLeapYear(arg); +assert.sameValue(result, true, "19761118 is a valid ISO string for PlainDate"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.inLeapYear(arg), + `Number ${arg} does not convert to a valid ISO string for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..f3ba12a322 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/inLeapYear/argument-propertybag-calendar-number.js @@ -0,0 +1,41 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.inleapyear +description: A number as calendar in a property bag is converted to a string, then to a calendar +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = instance.inLeapYear(arg); +assert.sameValue(result1, true, "19970327 is a valid ISO string for calendar"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = instance.inLeapYear(arg); +assert.sameValue(result2, true, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.inLeapYear(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.inLeapYear(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/month/argument-number.js b/test/built-ins/Temporal/Calendar/prototype/month/argument-number.js new file mode 100644 index 0000000000..f63c215e3d --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/month/argument-number.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.month +description: A number is converted to a string, then to Temporal.PlainDate +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const arg = 19761118; + +const result = instance.month(arg); +assert.sameValue(result, 11, "19761118 is a valid ISO string for PlainDate"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.month(arg), + `Number ${arg} does not convert to a valid ISO string for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/month/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/Calendar/prototype/month/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..1d8351bc8d --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/month/argument-propertybag-calendar-number.js @@ -0,0 +1,41 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.month +description: A number as calendar in a property bag is converted to a string, then to a calendar +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = instance.month(arg); +assert.sameValue(result1, 11, "19970327 is a valid ISO string for calendar"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = instance.month(arg); +assert.sameValue(result2, 11, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.month(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.month(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/monthCode/argument-number.js b/test/built-ins/Temporal/Calendar/prototype/monthCode/argument-number.js new file mode 100644 index 0000000000..dfd779c38b --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/monthCode/argument-number.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.monthcode +description: A number is converted to a string, then to Temporal.PlainDate +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const arg = 19761118; + +const result = instance.monthCode(arg); +assert.sameValue(result, "M11", "19761118 is a valid ISO string for PlainDate"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.monthCode(arg), + `Number ${arg} does not convert to a valid ISO string for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/monthCode/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/Calendar/prototype/monthCode/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..d7ac6bebdc --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/monthCode/argument-propertybag-calendar-number.js @@ -0,0 +1,41 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.monthcode +description: A number as calendar in a property bag is converted to a string, then to a calendar +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = instance.monthCode(arg); +assert.sameValue(result1, "M11", "19970327 is a valid ISO string for calendar"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = instance.monthCode(arg); +assert.sameValue(result2, "M11", "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.monthCode(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.monthCode(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-number.js b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-number.js new file mode 100644 index 0000000000..9e2513cc76 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-number.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.monthsinyear +description: A number is converted to a string, then to Temporal.PlainDate +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const arg = 19761118; + +const result = instance.monthsInYear(arg); +assert.sameValue(result, 12, "19761118 is a valid ISO string for PlainDate"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.monthsInYear(arg), + `Number ${arg} does not convert to a valid ISO string for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..b2ce9cd8d5 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/monthsInYear/argument-propertybag-calendar-number.js @@ -0,0 +1,41 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.monthsinyear +description: A number as calendar in a property bag is converted to a string, then to a calendar +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = instance.monthsInYear(arg); +assert.sameValue(result1, 12, "19970327 is a valid ISO string for calendar"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = instance.monthsInYear(arg); +assert.sameValue(result2, 12, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.monthsInYear(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.monthsInYear(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-number.js b/test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-number.js new file mode 100644 index 0000000000..d0259e9038 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-number.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.weekofyear +description: A number is converted to a string, then to Temporal.PlainDate +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const arg = 19761118; + +const result = instance.weekOfYear(arg); +assert.sameValue(result, 47, "19761118 is a valid ISO string for PlainDate"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.weekOfYear(arg), + `Number ${arg} does not convert to a valid ISO string for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..cd5069188c --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/weekOfYear/argument-propertybag-calendar-number.js @@ -0,0 +1,41 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.weekofyear +description: A number as calendar in a property bag is converted to a string, then to a calendar +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = instance.weekOfYear(arg); +assert.sameValue(result1, 47, "19970327 is a valid ISO string for calendar"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = instance.weekOfYear(arg); +assert.sameValue(result2, 47, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.weekOfYear(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.weekOfYear(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/year/argument-number.js b/test/built-ins/Temporal/Calendar/prototype/year/argument-number.js new file mode 100644 index 0000000000..212c2ac82e --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/year/argument-number.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.year +description: A number is converted to a string, then to Temporal.PlainDate +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const arg = 19761118; + +const result = instance.year(arg); +assert.sameValue(result, 1976, "19761118 is a valid ISO string for PlainDate"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.year(arg), + `Number ${arg} does not convert to a valid ISO string for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/Calendar/prototype/year/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/Calendar/prototype/year/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..3030c5ed26 --- /dev/null +++ b/test/built-ins/Temporal/Calendar/prototype/year/argument-propertybag-calendar-number.js @@ -0,0 +1,41 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.year +description: A number as calendar in a property bag is converted to a string, then to a calendar +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = instance.year(arg); +assert.sameValue(result1, 1976, "19970327 is a valid ISO string for calendar"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = instance.year(arg); +assert.sameValue(result2, 1976, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.year(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.year(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-number.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-number.js new file mode 100644 index 0000000000..ecdce2d3eb --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/add/relativeto-number.js @@ -0,0 +1,30 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.add +description: A number as relativeTo option is converted to a string, then to Temporal.PlainDate +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.Duration(1, 0, 0, 1); + +const relativeTo = 20191101; + +const result = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); +TemporalHelpers.assertDuration(result, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "20191101 is a valid ISO string for relativeTo"); + +const numbers = [ + 1, + -20191101, + 1234567890, +]; + +for (const relativeTo of numbers) { + assert.throws( + RangeError, + () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), + `Number ${relativeTo} does not convert to a valid ISO string for relativeTo` + ); +} diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-calendar-number.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-calendar-number.js new file mode 100644 index 0000000000..b2ff180cb5 --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-calendar-number.js @@ -0,0 +1,42 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.add +description: A number as calendar in relativeTo property bag is converted to a string, then to a calendar +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.Duration(1, 0, 0, 1); + +const calendar = 19970327; + +let relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; +const result1 = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); +TemporalHelpers.assertDuration(result1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for relativeTo.calendar"); + +relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar } }; +const result2 = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); +TemporalHelpers.assertDuration(result2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for relativeTo.calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; + assert.throws( + RangeError, + () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), + `Number ${calendar} does not convert to a valid ISO string for relativeTo.calendar` + ); + relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), + `Number ${calendar} does not convert to a valid ISO string for relativeTo.calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/Duration/prototype/round/relativeto-number.js b/test/built-ins/Temporal/Duration/prototype/round/relativeto-number.js new file mode 100644 index 0000000000..9ec36f6775 --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/round/relativeto-number.js @@ -0,0 +1,30 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.round +description: A number as relativeTo option is converted to a string, then to Temporal.PlainDate +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.Duration(1, 0, 0, 0, 24); + +const relativeTo = 20191101; + +const result = instance.round({ largestUnit: "years", relativeTo }); +TemporalHelpers.assertDuration(result, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, "20191101 is a valid ISO string for relativeTo"); + +const numbers = [ + 1, + -20191101, + 1234567890, +]; + +for (const relativeTo of numbers) { + assert.throws( + RangeError, + () => instance.round({ largestUnit: "years", relativeTo }), + `Number ${relativeTo} does not convert to a valid ISO string for relativeTo` + ); +} diff --git a/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-calendar-number.js b/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-calendar-number.js new file mode 100644 index 0000000000..6aee637fc1 --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-calendar-number.js @@ -0,0 +1,42 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.round +description: A number as calendar in relativeTo property bag is converted to a string, then to a calendar +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.Duration(1, 0, 0, 0, 24); + +const calendar = 19970327; + +let relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; +const result1 = instance.round({ largestUnit: "years", relativeTo }); +TemporalHelpers.assertDuration(result1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for relativeTo.calendar"); + +relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar } }; +const result2 = instance.round({ largestUnit: "years", relativeTo }); +TemporalHelpers.assertDuration(result2, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for relativeTo.calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; + assert.throws( + RangeError, + () => instance.round({ largestUnit: "years", relativeTo }), + `Number ${calendar} does not convert to a valid ISO string for relativeTo.calendar` + ); + relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.round({ largestUnit: "years", relativeTo }), + `Number ${calendar} does not convert to a valid ISO string for relativeTo.calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-number.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-number.js new file mode 100644 index 0000000000..40d1170665 --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-number.js @@ -0,0 +1,30 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.subtract +description: A number as relativeTo option is converted to a string, then to Temporal.PlainDate +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.Duration(1, 0, 0, 1); + +const relativeTo = 20191101; + +const result = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); +TemporalHelpers.assertDuration(result, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "20191101 is a valid ISO string for relativeTo"); + +const numbers = [ + 1, + -20191101, + 1234567890, +]; + +for (const relativeTo of numbers) { + assert.throws( + RangeError, + () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), + `Number ${relativeTo} does not convert to a valid ISO string for relativeTo` + ); +} diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-number.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-number.js new file mode 100644 index 0000000000..d00e30568f --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-number.js @@ -0,0 +1,42 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.subtract +description: A number as calendar in relativeTo property bag is converted to a string, then to a calendar +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.Duration(1, 0, 0, 1); + +const calendar = 19970327; + +let relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; +const result1 = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); +TemporalHelpers.assertDuration(result1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for relativeTo.calendar"); + +relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar } }; +const result2 = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); +TemporalHelpers.assertDuration(result2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for relativeTo.calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; + assert.throws( + RangeError, + () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), + `Number ${calendar} does not convert to a valid ISO string for relativeTo.calendar` + ); + relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), + `Number ${calendar} does not convert to a valid ISO string for relativeTo.calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/Duration/prototype/total/relativeto-number.js b/test/built-ins/Temporal/Duration/prototype/total/relativeto-number.js new file mode 100644 index 0000000000..6825c00ce4 --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/total/relativeto-number.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.total +description: A number as relativeTo option is converted to a string, then to Temporal.PlainDate +features: [Temporal] +---*/ + +const instance = new Temporal.Duration(1, 0, 0, 0, 24); + +const relativeTo = 20191101; + +const result = instance.total({ unit: "days", relativeTo }); +assert.sameValue(result, 367, "20191101 is a valid ISO string for relativeTo"); + +const numbers = [ + 1, + -20191101, + 1234567890, +]; + +for (const relativeTo of numbers) { + assert.throws( + RangeError, + () => instance.total({ unit: "days", relativeTo }), + `Number ${relativeTo} does not convert to a valid ISO string for relativeTo` + ); +} diff --git a/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-calendar-number.js b/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-calendar-number.js new file mode 100644 index 0000000000..773e2f03bb --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-calendar-number.js @@ -0,0 +1,41 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.total +description: A number as calendar in relativeTo property bag is converted to a string, then to a calendar +features: [Temporal] +---*/ + +const instance = new Temporal.Duration(1, 0, 0, 0, 24); + +const calendar = 19970327; + +let relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; +const result1 = instance.total({ unit: "days", relativeTo }); +assert.sameValue(result1, 367, "19970327 is a valid ISO string for relativeTo.calendar"); + +relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar } }; +const result2 = instance.total({ unit: "days", relativeTo }); +assert.sameValue(result2, 367, "19970327 is a valid ISO string for relativeTo.calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; + assert.throws( + RangeError, + () => instance.total({ unit: "days", relativeTo }), + `Number ${calendar} does not convert to a valid ISO string for relativeTo.calendar` + ); + relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.total({ unit: "days", relativeTo }), + `Number ${calendar} does not convert to a valid ISO string for relativeTo.calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/Instant/prototype/toZonedDateTime/calendar-number.js b/test/built-ins/Temporal/Instant/prototype/toZonedDateTime/calendar-number.js new file mode 100644 index 0000000000..b66e68c75c --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/toZonedDateTime/calendar-number.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.prototype.tozoneddatetime +description: A number is converted to a string, then to Temporal.Calendar +features: [Temporal] +---*/ + +const instance = new Temporal.Instant(1_000_000_000_000_000_000n); + +const arg = 19761118; + +const result = instance.toZonedDateTime({ calendar: arg, timeZone: "UTC" }); +assert.sameValue(result.calendar.id, "iso8601", "19761118 is a valid ISO string for Calendar"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.toZonedDateTime({ calendar: arg, timeZone: "UTC" }), + `Number ${arg} does not convert to a valid ISO string for Calendar` + ); +} diff --git a/test/built-ins/Temporal/Now/plainDate/calendar-number.js b/test/built-ins/Temporal/Now/plainDate/calendar-number.js new file mode 100644 index 0000000000..8586672bdd --- /dev/null +++ b/test/built-ins/Temporal/Now/plainDate/calendar-number.js @@ -0,0 +1,27 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.now.plaindate +description: A number is converted to a string, then to Temporal.Calendar +features: [Temporal] +---*/ + +const arg = 19761118; + +const result = Temporal.Now.plainDate(arg); +assert.sameValue(result.calendar.id, "iso8601", "19761118 is a valid ISO string for Calendar"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => Temporal.Now.plainDate(arg), + `Number ${arg} does not convert to a valid ISO string for Calendar` + ); +} diff --git a/test/built-ins/Temporal/Now/plainDateTime/calendar-number.js b/test/built-ins/Temporal/Now/plainDateTime/calendar-number.js new file mode 100644 index 0000000000..5d226c703e --- /dev/null +++ b/test/built-ins/Temporal/Now/plainDateTime/calendar-number.js @@ -0,0 +1,27 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.now.plaindatetime +description: A number is converted to a string, then to Temporal.Calendar +features: [Temporal] +---*/ + +const arg = 19761118; + +const result = Temporal.Now.plainDateTime(arg); +assert.sameValue(result.calendar.id, "iso8601", "19761118 is a valid ISO string for Calendar"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => Temporal.Now.plainDateTime(arg), + `Number ${arg} does not convert to a valid ISO string for Calendar` + ); +} diff --git a/test/built-ins/Temporal/Now/zonedDateTime/calendar-number.js b/test/built-ins/Temporal/Now/zonedDateTime/calendar-number.js new file mode 100644 index 0000000000..296ed87aa0 --- /dev/null +++ b/test/built-ins/Temporal/Now/zonedDateTime/calendar-number.js @@ -0,0 +1,27 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.now.zoneddatetime +description: A number is converted to a string, then to Temporal.Calendar +features: [Temporal] +---*/ + +const arg = 19761118; + +const result = Temporal.Now.zonedDateTime(arg); +assert.sameValue(result.calendar.id, "iso8601", "19761118 is a valid ISO string for Calendar"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => Temporal.Now.zonedDateTime(arg), + `Number ${arg} does not convert to a valid ISO string for Calendar` + ); +} diff --git a/test/built-ins/Temporal/PlainDate/calendar-number.js b/test/built-ins/Temporal/PlainDate/calendar-number.js new file mode 100644 index 0000000000..8fdba70164 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/calendar-number.js @@ -0,0 +1,27 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate +description: A number is converted to a string, then to Temporal.Calendar +features: [Temporal] +---*/ + +const arg = 19761118; + +const result = new Temporal.PlainDate(2000, 5, 2, arg); +assert.sameValue(result.calendar.id, "iso8601", "19761118 is a valid ISO string for Calendar"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => new Temporal.PlainDate(2000, 5, 2, arg), + `Number ${arg} does not convert to a valid ISO string for Calendar` + ); +} diff --git a/test/built-ins/Temporal/PlainDate/compare/argument-number.js b/test/built-ins/Temporal/PlainDate/compare/argument-number.js new file mode 100644 index 0000000000..cf93daf7a1 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/compare/argument-number.js @@ -0,0 +1,34 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.compare +description: A number is converted to a string, then to Temporal.PlainDate +features: [Temporal] +---*/ + +const arg = 19761118; + +const result1 = Temporal.PlainDate.compare(arg, new Temporal.PlainDate(1976, 11, 18)); +assert.sameValue(result1, 0, "19761118 is a valid ISO string for PlainDate (first argument)"); +const result2 = Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg); +assert.sameValue(result2, 0, "19761118 is a valid ISO string for PlainDate (second argument)"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => Temporal.PlainDate.compare(arg, new Temporal.PlainDate(1976, 11, 18)), + `Number ${arg} does not convert to a valid ISO string for PlainDate (first argument)` + ); + assert.throws( + RangeError, + () => Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg), + `Number ${arg} does not convert to a valid ISO string for PlainDate (second argument)` + ); +} diff --git a/test/built-ins/Temporal/PlainDate/compare/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainDate/compare/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..debcfec9c1 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/compare/argument-propertybag-calendar-number.js @@ -0,0 +1,53 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.compare +description: A number as calendar in a property bag is converted to a string, then to a calendar +features: [Temporal] +---*/ + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = Temporal.PlainDate.compare(arg, new Temporal.PlainDate(1976, 11, 18)); +assert.sameValue(result1, 0, "19970327 is a valid ISO string for calendar (first argument)"); +const result2 = Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg); +assert.sameValue(result2, 0, "19970327 is a valid ISO string for calendar (first argument)"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result3 = Temporal.PlainDate.compare(arg, new Temporal.PlainDate(1976, 11, 18)); +assert.sameValue(result3, 0, "19970327 is a valid ISO string for calendar (nested property, first argument)"); +const result4 = Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg); +assert.sameValue(result4, 0, "19970327 is a valid ISO string for calendar (nested property, first argument)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => Temporal.PlainDate.compare(arg, new Temporal.PlainDate(1976, 11, 18)), + `Number ${calendar} does not convert to a valid ISO string for calendar (first argument)` + ); + assert.throws( + RangeError, + () => Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (second argument)` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => Temporal.PlainDate.compare(arg, new Temporal.PlainDate(1976, 11, 18)), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property, first argument)` + ); + assert.throws( + RangeError, + () => Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property, second argument)` + ); +} diff --git a/test/built-ins/Temporal/PlainDate/from/argument-number.js b/test/built-ins/Temporal/PlainDate/from/argument-number.js index 0b1741613c..519b3ba7f3 100644 --- a/test/built-ins/Temporal/PlainDate/from/argument-number.js +++ b/test/built-ins/Temporal/PlainDate/from/argument-number.js @@ -3,10 +3,26 @@ /*--- esid: sec-temporal.plaindate.from -description: various interesting string arguments. +description: A number is converted to a string, then to Temporal.PlainDate includes: [temporalHelpers.js] features: [Temporal] ---*/ -const result = Temporal.PlainDate.from(19761118); -TemporalHelpers.assertPlainDate(result, 1976, 11, "M11", 18); +const arg = 19761118; + +const result = Temporal.PlainDate.from(arg); +TemporalHelpers.assertPlainDate(result, 1976, 11, "M11", 18, "19761118 is a valid ISO string for PlainDate"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => Temporal.PlainDate.from(arg), + `Number ${arg} does not convert to a valid ISO string for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/PlainDate/from/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainDate/from/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..634405c734 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/from/argument-propertybag-calendar-number.js @@ -0,0 +1,40 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.from +description: A number as calendar in a property bag is converted to a string, then to a calendar +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = Temporal.PlainDate.from(arg); +TemporalHelpers.assertPlainDate(result1, 1976, 11, "M11", 18, "19970327 is a valid ISO string for calendar"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = Temporal.PlainDate.from(arg); +TemporalHelpers.assertPlainDate(result2, 1976, 11, "M11", 18, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => Temporal.PlainDate.from(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => Temporal.PlainDate.from(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/PlainDate/prototype/equals/argument-number.js b/test/built-ins/Temporal/PlainDate/prototype/equals/argument-number.js new file mode 100644 index 0000000000..2f06b86c7f --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/equals/argument-number.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.equals +description: A number is converted to a string, then to Temporal.PlainDate +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDate(1976, 11, 18); + +const arg = 19761118; + +const result = instance.equals(arg); +assert.sameValue(result, true, "19761118 is a valid ISO string for PlainDate"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.equals(arg), + `Number ${arg} does not convert to a valid ISO string for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/PlainDate/prototype/equals/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainDate/prototype/equals/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..22e505924f --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/equals/argument-propertybag-calendar-number.js @@ -0,0 +1,41 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.equals +description: A number as calendar in a property bag is converted to a string, then to a calendar +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDate(1976, 11, 18); + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = instance.equals(arg); +assert.sameValue(result1, true, "19970327 is a valid ISO string for calendar"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = instance.equals(arg); +assert.sameValue(result2, true, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.equals(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.equals(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/argument-number.js b/test/built-ins/Temporal/PlainDate/prototype/since/argument-number.js new file mode 100644 index 0000000000..734eec3be3 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/since/argument-number.js @@ -0,0 +1,30 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.since +description: A number is converted to a string, then to Temporal.PlainDate +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDate(1976, 11, 18); + +const arg = 19761118; + +const result = instance.since(arg); +TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19761118 is a valid ISO string for PlainDate"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.since(arg), + `Number ${arg} does not convert to a valid ISO string for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainDate/prototype/since/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..c1156c06dc --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/since/argument-propertybag-calendar-number.js @@ -0,0 +1,42 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.since +description: A number as calendar in a property bag is converted to a string, then to a calendar +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDate(1976, 11, 18); + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = instance.since(arg); +TemporalHelpers.assertDuration(result1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = instance.since(arg); +TemporalHelpers.assertDuration(result2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.since(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.since(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-number.js b/test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-number.js new file mode 100644 index 0000000000..79d13f0b7f --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/toPlainDateTime/argument-number.js @@ -0,0 +1,31 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.toplaindatetime +description: A number is converted to a string, then to Temporal.PlainTime +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDate(2000, 5, 2); + +const arg = 123456.987654321; + +const result = instance.toPlainDateTime(arg); +TemporalHelpers.assertPlainDateTime(result, 2000, 5, "M05", 2, 12, 34, 56, 987, 654, 321, "123456.987654321 is a valid ISO string for PlainTime"); + +const numbers = [ + 1, + -123456.987654321, + 1234567, + 123456.9876543219, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.toPlainDateTime(arg), + `Number ${arg} does not convert to a valid ISO string for PlainTime` + ); +} diff --git a/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-number.js b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-number.js new file mode 100644 index 0000000000..b25efbb22b --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-number.js @@ -0,0 +1,30 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.tozoneddatetime +description: A number is converted to a string, then to Temporal.PlainTime +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDate(2000, 5, 2); + +const arg = 123456.987654321; + +const result = instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" }); +assert.sameValue(result.epochNanoseconds, 957270896_987_654_321n, "123456.987654321 is a valid ISO string for PlainTime"); + +const numbers = [ + 1, + -123456.987654321, + 1234567, + 123456.9876543219, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.toZonedDateTime({ plainTime: arg, timeZone: "UTC" }), + `Number ${arg} does not convert to a valid ISO string for PlainTime` + ); +} diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/argument-number.js b/test/built-ins/Temporal/PlainDate/prototype/until/argument-number.js new file mode 100644 index 0000000000..04e1567d76 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/until/argument-number.js @@ -0,0 +1,30 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.until +description: A number is converted to a string, then to Temporal.PlainDate +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDate(1976, 11, 18); + +const arg = 19761118; + +const result = instance.until(arg); +TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19761118 is a valid ISO string for PlainDate"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.until(arg), + `Number ${arg} does not convert to a valid ISO string for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..2a73bffd8d --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-number.js @@ -0,0 +1,42 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.until +description: A number as calendar in a property bag is converted to a string, then to a calendar +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDate(1976, 11, 18); + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = instance.until(arg); +TemporalHelpers.assertDuration(result1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = instance.until(arg); +TemporalHelpers.assertDuration(result2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.until(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.until(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-number.js b/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-number.js new file mode 100644 index 0000000000..1ff8a50d69 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-number.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.withcalendar +description: A number is converted to a string, then to Temporal.Calendar +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDate(1976, 11, 18, { id: "replace-me" }); + +const arg = 19761118; + +const result = instance.withCalendar(arg); +assert.sameValue(result.calendar.id, "iso8601", "19761118 is a valid ISO string for Calendar"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.withCalendar(arg), + `Number ${arg} does not convert to a valid ISO string for Calendar` + ); +} diff --git a/test/built-ins/Temporal/PlainDateTime/calendar-number.js b/test/built-ins/Temporal/PlainDateTime/calendar-number.js new file mode 100644 index 0000000000..c44989eaeb --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/calendar-number.js @@ -0,0 +1,27 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime +description: A number is converted to a string, then to Temporal.Calendar +features: [Temporal] +---*/ + +const arg = 19761118; + +const result = new Temporal.PlainDateTime(2000, 5, 2, 15, 23, 30, 987, 654, 321, arg); +assert.sameValue(result.calendar.id, "iso8601", "19761118 is a valid ISO string for Calendar"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => new Temporal.PlainDateTime(2000, 5, 2, 15, 23, 30, 987, 654, 321, arg), + `Number ${arg} does not convert to a valid ISO string for Calendar` + ); +} diff --git a/test/built-ins/Temporal/PlainDateTime/compare/argument-number.js b/test/built-ins/Temporal/PlainDateTime/compare/argument-number.js new file mode 100644 index 0000000000..8bf6b2caac --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/compare/argument-number.js @@ -0,0 +1,34 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.compare +description: A number is converted to a string, then to Temporal.PlainDateTime +features: [Temporal] +---*/ + +let arg = 19761118; + +const result1 = Temporal.PlainDateTime.compare(arg, new Temporal.PlainDateTime(1976, 11, 18)); +assert.sameValue(result1, 0, "19761118 is a valid ISO string for PlainDateTime (first argument)"); +const result2 = Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg); +assert.sameValue(result2, 0, "19761118 is a valid ISO string for PlainDateTime (second argument)"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => Temporal.PlainDateTime.compare(arg, new Temporal.PlainDateTime(1976, 11, 18)), + `Number ${arg} does not convert to a valid ISO string for PlainDateTime (first argument)` + ); + assert.throws( + RangeError, + () => Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg), + `Number ${arg} does not convert to a valid ISO string for PlainDateTime (second argument)` + ); +} diff --git a/test/built-ins/Temporal/PlainDateTime/compare/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainDateTime/compare/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..eb830da34f --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/compare/argument-propertybag-calendar-number.js @@ -0,0 +1,53 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.compare +description: A number as calendar in a property bag is converted to a string, then to a calendar +features: [Temporal] +---*/ + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = Temporal.PlainDateTime.compare(arg, new Temporal.PlainDateTime(1976, 11, 18)); +assert.sameValue(result1, 0, "19970327 is a valid ISO string for calendar (first argument)"); +const result2 = Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg); +assert.sameValue(result2, 0, "19970327 is a valid ISO string for calendar (second argument)"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result3 = Temporal.PlainDateTime.compare(arg, new Temporal.PlainDateTime(1976, 11, 18)); +assert.sameValue(result3, 0, "19970327 is a valid ISO string for calendar (nested property, first argument)"); +const result4 = Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg); +assert.sameValue(result4, 0, "19970327 is a valid ISO string for calendar (nested property, second argument)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => Temporal.PlainDateTime.compare(arg, new Temporal.PlainDateTime(1976, 11, 18)), + `Number ${calendar} does not convert to a valid ISO string for calendar (first argument)` + ); + assert.throws( + RangeError, + () => Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (second argument)` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => Temporal.PlainDateTime.compare(arg, new Temporal.PlainDateTime(1976, 11, 18)), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property, first argument)` + ); + assert.throws( + RangeError, + () => Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property, second argument)` + ); +} diff --git a/test/built-ins/Temporal/PlainDateTime/from/argument-number.js b/test/built-ins/Temporal/PlainDateTime/from/argument-number.js index cce1107e7c..0c1d2a5fdf 100644 --- a/test/built-ins/Temporal/PlainDateTime/from/argument-number.js +++ b/test/built-ins/Temporal/PlainDateTime/from/argument-number.js @@ -3,25 +3,26 @@ /*--- esid: sec-temporal.plaindatetime.from -description: A number is converted to a string, which may be a valid ISO string -features: [Temporal] +description: A number is converted to a string, then to Temporal.PlainDateTime includes: [temporalHelpers.js] +features: [Temporal] ---*/ -TemporalHelpers.assertPlainDateTime( - Temporal.PlainDateTime.from(19761118), - 1976, 11, "M11", 18, 0, 0, 0, 0, 0, 0, - "Number may be an acceptable argument" -); +let arg = 19761118; -assert.throws( - RangeError, - () => Temporal.PlainDateTime.from(1), - "number, in decimal, has the wrong format (too few digits)" -); +const result = Temporal.PlainDateTime.from(arg); +TemporalHelpers.assertPlainDateTime(result, 1976, 11, "M11", 18, 0, 0, 0, 0, 0, 0, "19761118 is a valid ISO string for PlainDateTime"); -assert.throws( - RangeError, - () => Temporal.PlainDateTime.from(1234567890), - "number, in decimal, has the wrong format (too many digits)" -); +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => Temporal.PlainDateTime.from(arg), + `Number ${arg} does not convert to a valid ISO string for PlainDateTime` + ); +} diff --git a/test/built-ins/Temporal/PlainDateTime/from/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainDateTime/from/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..ae00e596a0 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/from/argument-propertybag-calendar-number.js @@ -0,0 +1,40 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.from +description: A number as calendar in a property bag is converted to a string, then to a calendar +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = Temporal.PlainDateTime.from(arg); +TemporalHelpers.assertPlainDateTime(result1, 1976, 11, "M11", 18, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = Temporal.PlainDateTime.from(arg); +TemporalHelpers.assertPlainDateTime(result2, 1976, 11, "M11", 18, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => Temporal.PlainDateTime.from(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => Temporal.PlainDateTime.from(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-number.js b/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-number.js new file mode 100644 index 0000000000..3b5f54af88 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-number.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.equals +description: A number is converted to a string, then to Temporal.PlainDateTime +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(1976, 11, 18); + +let arg = 19761118; + +const result = instance.equals(arg); +assert.sameValue(result, true, "19761118 is a valid ISO string for PlainDateTime"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.equals(arg), + `Number ${arg} does not convert to a valid ISO string for PlainDateTime` + ); +} diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..347888b944 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-number.js @@ -0,0 +1,41 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.equals +description: A number as calendar in a property bag is converted to a string, then to a calendar +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(1976, 11, 18); + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = instance.equals(arg); +assert.sameValue(result1, true, "19970327 is a valid ISO string for calendar"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = instance.equals(arg); +assert.sameValue(result2, true, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.equals(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.equals(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-number.js b/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-number.js new file mode 100644 index 0000000000..5c0179d5a5 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-number.js @@ -0,0 +1,30 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.since +description: A number is converted to a string, then to Temporal.PlainDateTime +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(1976, 11, 18); + +let arg = 19761118; + +const result = instance.since(arg); +TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19761118 is a valid ISO string for PlainDateTime"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.since(arg), + `Number ${arg} does not convert to a valid ISO string for PlainDateTime` + ); +} diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..e12a26b735 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-number.js @@ -0,0 +1,42 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.since +description: A number as calendar in a property bag is converted to a string, then to a calendar +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(1976, 11, 18); + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = instance.since(arg); +TemporalHelpers.assertDuration(result1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = instance.since(arg); +TemporalHelpers.assertDuration(result2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.since(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.since(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-number.js b/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-number.js new file mode 100644 index 0000000000..e6c05841d8 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-number.js @@ -0,0 +1,30 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.until +description: A number is converted to a string, then to Temporal.PlainDateTime +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(1976, 11, 18); + +let arg = 19761118; + +const result = instance.until(arg); +TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19761118 is a valid ISO string for PlainDateTime"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.until(arg), + `Number ${arg} does not convert to a valid ISO string for PlainDateTime` + ); +} diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..8cf4915c7f --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-number.js @@ -0,0 +1,42 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.until +description: A number as calendar in a property bag is converted to a string, then to a calendar +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(1976, 11, 18); + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = instance.until(arg); +TemporalHelpers.assertDuration(result1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = instance.until(arg); +TemporalHelpers.assertDuration(result2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.until(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.until(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-number.js b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-number.js new file mode 100644 index 0000000000..3289014fc4 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-number.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.withcalendar +description: A number is converted to a string, then to Temporal.Calendar +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, { id: "replace-me" }); + +const arg = 19761118; + +const result = instance.withCalendar(arg); +assert.sameValue(result.calendar.id, "iso8601", "19761118 is a valid ISO string for Calendar"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.withCalendar(arg), + `Number ${arg} does not convert to a valid ISO string for Calendar` + ); +} diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-number.js b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-number.js new file mode 100644 index 0000000000..cb2c9337a3 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-number.js @@ -0,0 +1,30 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.withplaindate +description: A number is converted to a string, then to Temporal.PlainDate +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321); + +const arg = 19761118; + +const result = instance.withPlainDate(arg); +TemporalHelpers.assertPlainDateTime(result, 1976, 11, "M11", 18, 12, 34, 56, 987, 654, 321, "19761118 is a valid ISO string for PlainDate"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.withPlainDate(arg), + `Number ${arg} does not convert to a valid ISO string for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..c9ae966915 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainDate/argument-propertybag-calendar-number.js @@ -0,0 +1,42 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.withplaindate +description: A number as calendar in a property bag is converted to a string, then to a calendar +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321); + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = instance.withPlainDate(arg); +TemporalHelpers.assertPlainDateTime(result1, 1976, 11, "M11", 18, 12, 34, 56, 987, 654, 321, "19970327 is a valid ISO string for calendar"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = instance.withPlainDate(arg); +TemporalHelpers.assertPlainDateTime(result2, 1976, 11, "M11", 18, 12, 34, 56, 987, 654, 321, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.withPlainDate(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.withPlainDate(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-number.js b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-number.js new file mode 100644 index 0000000000..a2dc97347d --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withPlainTime/argument-number.js @@ -0,0 +1,31 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.withplaintime +description: A number is converted to a string, then to Temporal.PlainTime +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(2000, 5, 2); + +const arg = 123456.987654321; + +const result = instance.withPlainTime(arg); +TemporalHelpers.assertPlainDateTime(result, 2000, 5, "M05", 2, 12, 34, 56, 987, 654, 321, "123456.987654321 is a valid ISO string for PlainTime"); + +const numbers = [ + 1, + -123456.987654321, + 1234567, + 123456.9876543219, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.withPlainTime(arg), + `Number ${arg} does not convert to a valid ISO string for PlainTime` + ); +} diff --git a/test/built-ins/Temporal/PlainMonthDay/calendar-number.js b/test/built-ins/Temporal/PlainMonthDay/calendar-number.js new file mode 100644 index 0000000000..bc2edac62f --- /dev/null +++ b/test/built-ins/Temporal/PlainMonthDay/calendar-number.js @@ -0,0 +1,27 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainmonthday +description: A number is converted to a string, then to Temporal.Calendar +features: [Temporal] +---*/ + +const arg = 19761118; + +const result = new Temporal.PlainMonthDay(12, 15, arg, 1972); +assert.sameValue(result.calendar.id, "iso8601", "19761118 is a valid ISO string for Calendar"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => new Temporal.PlainMonthDay(12, 15, arg, 1972), + `Number ${arg} does not convert to a valid ISO string for Calendar` + ); +} diff --git a/test/built-ins/Temporal/PlainMonthDay/from/argument-number.js b/test/built-ins/Temporal/PlainMonthDay/from/argument-number.js new file mode 100644 index 0000000000..e9b0edcbf4 --- /dev/null +++ b/test/built-ins/Temporal/PlainMonthDay/from/argument-number.js @@ -0,0 +1,28 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainmonthday.from +description: A number is converted to a string, then to Temporal.PlainMonthDay +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const arg = 1118; + +const result = Temporal.PlainMonthDay.from(arg); +TemporalHelpers.assertPlainMonthDay(result, "M11", 18, "1118 is a valid ISO string for PlainMonthDay"); + +const numbers = [ + 1, + -1118, + 12345, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => Temporal.PlainMonthDay.from(arg), + `Number ${arg} does not convert to a valid ISO string for PlainMonthDay` + ); +} diff --git a/test/built-ins/Temporal/PlainMonthDay/from/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainMonthDay/from/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..56eec0c427 --- /dev/null +++ b/test/built-ins/Temporal/PlainMonthDay/from/argument-propertybag-calendar-number.js @@ -0,0 +1,40 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainmonthday.from +description: A number as calendar in a property bag is converted to a string, then to a calendar +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const calendar = 19970327; + +let arg = { monthCode: "M11", day: 18, calendar }; +const result1 = Temporal.PlainMonthDay.from(arg); +TemporalHelpers.assertPlainMonthDay(result1, "M11", 18, "19970327 is a valid ISO string for calendar"); + +arg = { monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = Temporal.PlainMonthDay.from(arg); +TemporalHelpers.assertPlainMonthDay(result2, "M11", 18, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => Temporal.PlainMonthDay.from(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => Temporal.PlainMonthDay.from(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-number.js b/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-number.js new file mode 100644 index 0000000000..b24f80790f --- /dev/null +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-number.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainmonthday.prototype.equals +description: A number is converted to a string, then to Temporal.PlainMonthDay +features: [Temporal] +---*/ + +const instance = new Temporal.PlainMonthDay(11, 18); + +const arg = 1118; + +const result = instance.equals(arg); +assert.sameValue(result, true, "1118 is a valid ISO string for PlainMonthDay"); + +const numbers = [ + 1, + -1118, + 12345, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.equals(arg), + `Number ${arg} does not convert to a valid ISO string for PlainMonthDay` + ); +} diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..be40e79001 --- /dev/null +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-propertybag-calendar-number.js @@ -0,0 +1,41 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainmonthday.prototype.equals +description: A number as calendar in a property bag is converted to a string, then to a calendar +features: [Temporal] +---*/ + +const instance = new Temporal.PlainMonthDay(11, 18); + +const calendar = 19970327; + +let arg = { monthCode: "M11", day: 18, calendar }; +const result1 = instance.equals(arg); +assert.sameValue(result1, true, "19970327 is a valid ISO string for calendar"); + +arg = { monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = instance.equals(arg); +assert.sameValue(result2, true, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.equals(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.equals(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/PlainTime/compare/argument-number.js b/test/built-ins/Temporal/PlainTime/compare/argument-number.js new file mode 100644 index 0000000000..aedb3f9b84 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/compare/argument-number.js @@ -0,0 +1,35 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaintime.compare +description: A number is converted to a string, then to Temporal.PlainTime +features: [Temporal] +---*/ + +const arg = 123456.987654321; + +const result1 = Temporal.PlainTime.compare(arg, new Temporal.PlainTime(12, 34, 56, 987, 654, 321)); +assert.sameValue(result1, 0, "123456.987654321 is a valid ISO string for PlainTime (first argument)"); +const result2 = Temporal.PlainTime.compare(new Temporal.PlainTime(12, 34, 56, 987, 654, 321), arg); +assert.sameValue(result2, 0, "123456.987654321 is a valid ISO string for PlainTime (second argument)"); + +const numbers = [ + 1, + -123456.987654321, + 1234567, + 123456.9876543219, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => Temporal.PlainTime.compare(arg, new Temporal.PlainTime(12, 34, 56, 987, 654, 321)), + `Number ${arg} does not convert to a valid ISO string for PlainTime (first argument)` + ); + assert.throws( + RangeError, + () => Temporal.PlainTime.compare(new Temporal.PlainTime(12, 34, 56, 987, 654, 321), arg), + `Number ${arg} does not convert to a valid ISO string for PlainTime (second argument)` + ); +} diff --git a/test/built-ins/Temporal/PlainTime/from/argument-number.js b/test/built-ins/Temporal/PlainTime/from/argument-number.js index 6f215a4e4a..bc83036e0f 100644 --- a/test/built-ins/Temporal/PlainTime/from/argument-number.js +++ b/test/built-ins/Temporal/PlainTime/from/argument-number.js @@ -3,10 +3,27 @@ /*--- esid: sec-temporal.plaintime.from -description: Number argument is converted to string -includes: [compareArray.js, temporalHelpers.js] +description: A number is converted to a string, then to Temporal.PlainTime +includes: [temporalHelpers.js] features: [Temporal] ---*/ -const result = Temporal.PlainTime.from(1523); -TemporalHelpers.assertPlainTime(result, 15, 23, 0, 0, 0, 0); +const arg = 123456.987654321; + +const result = Temporal.PlainTime.from(arg); +TemporalHelpers.assertPlainTime(result, 12, 34, 56, 987, 654, 321, "123456.987654321 is a valid ISO string for PlainTime"); + +const numbers = [ + 1, + -123456.987654321, + 1234567, + 123456.9876543219, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => Temporal.PlainTime.from(arg), + `Number ${arg} does not convert to a valid ISO string for PlainTime` + ); +} diff --git a/test/built-ins/Temporal/PlainTime/prototype/equals/argument-number.js b/test/built-ins/Temporal/PlainTime/prototype/equals/argument-number.js new file mode 100644 index 0000000000..4894d5934e --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/equals/argument-number.js @@ -0,0 +1,30 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaintime.prototype.equals +description: A number is converted to a string, then to Temporal.PlainTime +features: [Temporal] +---*/ + +const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); + +const arg = 123456.987654321; + +const result = instance.equals(arg); +assert.sameValue(result, true, "123456.987654321 is a valid ISO string for PlainTime"); + +const numbers = [ + 1, + -123456.987654321, + 1234567, + 123456.9876543219, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.equals(arg), + `Number ${arg} does not convert to a valid ISO string for PlainTime` + ); +} diff --git a/test/built-ins/Temporal/PlainTime/prototype/since/argument-number.js b/test/built-ins/Temporal/PlainTime/prototype/since/argument-number.js new file mode 100644 index 0000000000..3ca4003a0b --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/since/argument-number.js @@ -0,0 +1,31 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaintime.prototype.since +description: A number is converted to a string, then to Temporal.PlainTime +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); + +const arg = 123456.987654321; + +const result = instance.since(arg); +TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "123456.987654321 is a valid ISO string for PlainTime"); + +const numbers = [ + 1, + -123456.987654321, + 1234567, + 123456.9876543219, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.since(arg), + `Number ${arg} does not convert to a valid ISO string for PlainTime` + ); +} diff --git a/test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-number.js b/test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-number.js new file mode 100644 index 0000000000..1742c9a9d3 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-number.js @@ -0,0 +1,30 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaintime.prototype.toplaindatetime +description: A number is converted to a string, then to Temporal.PlainDate +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); + +const arg = 19761118; + +const result = instance.toPlainDateTime(arg); +TemporalHelpers.assertPlainDateTime(result, 1976, 11, "M11", 18, 12, 34, 56, 987, 654, 321, "19761118 is a valid ISO string for PlainDate"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.toPlainDateTime(arg), + `Number ${arg} does not convert to a valid ISO string for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..1353b30b99 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/toPlainDateTime/argument-propertybag-calendar-number.js @@ -0,0 +1,42 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaintime.prototype.toplaindatetime +description: A number as calendar in a property bag is converted to a string, then to a calendar +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = instance.toPlainDateTime(arg); +TemporalHelpers.assertPlainDateTime(result1, 1976, 11, "M11", 18, 12, 34, 56, 987, 654, 321, "19970327 is a valid ISO string for calendar"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = instance.toPlainDateTime(arg); +TemporalHelpers.assertPlainDateTime(result2, 1976, 11, "M11", 18, 12, 34, 56, 987, 654, 321, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.toPlainDateTime(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.toPlainDateTime(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-number.js b/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-number.js new file mode 100644 index 0000000000..e466ad4e48 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-number.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaintime.prototype.tozoneddatetime +description: A number is converted to a string, then to Temporal.PlainDate +features: [Temporal] +---*/ + +const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); + +const arg = 19761118; + +const result = instance.toZonedDateTime({ plainDate: arg, timeZone: "UTC" }); +assert.sameValue(result.epochNanoseconds, 217_168_496_987_654_321n, "19761118 is a valid ISO string for PlainDate"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.toZonedDateTime({ plainDate: arg, timeZone: "UTC" }), + `Number ${arg} does not convert to a valid ISO string for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..1f40ffa0dc --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/toZonedDateTime/argument-propertybag-calendar-number.js @@ -0,0 +1,41 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaintime.prototype.tozoneddatetime +description: A number as calendar in a property bag is converted to a string, then to a calendar +features: [Temporal] +---*/ + +const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = instance.toZonedDateTime({ plainDate: arg, timeZone: "UTC" }); +assert.sameValue(result1.epochNanoseconds, 217_168_496_987_654_321n, "19970327 is a valid ISO string for calendar"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = instance.toZonedDateTime({ plainDate: arg, timeZone: "UTC" }); +assert.sameValue(result2.epochNanoseconds, 217_168_496_987_654_321n, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.toZonedDateTime({ plainDate: arg, timeZone: "UTC" }), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.toZonedDateTime({ plainDate: arg, timeZone: "UTC" }), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/PlainTime/prototype/until/argument-number.js b/test/built-ins/Temporal/PlainTime/prototype/until/argument-number.js new file mode 100644 index 0000000000..0ce8dcf294 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/until/argument-number.js @@ -0,0 +1,31 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaintime.prototype.until +description: A number is converted to a string, then to Temporal.PlainTime +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainTime(12, 34, 56, 987, 654, 321); + +const arg = 123456.987654321; + +const result = instance.until(arg); +TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "123456.987654321 is a valid ISO string for PlainTime"); + +const numbers = [ + 1, + -123456.987654321, + 1234567, + 123456.9876543219, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.until(arg), + `Number ${arg} does not convert to a valid ISO string for PlainTime` + ); +} diff --git a/test/built-ins/Temporal/PlainYearMonth/calendar-number.js b/test/built-ins/Temporal/PlainYearMonth/calendar-number.js new file mode 100644 index 0000000000..cf7d4142a5 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/calendar-number.js @@ -0,0 +1,27 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth +description: A number is converted to a string, then to Temporal.Calendar +features: [Temporal] +---*/ + +const arg = 19761118; + +const result = new Temporal.PlainYearMonth(2000, 5, arg, 1); +assert.sameValue(result.calendar.id, "iso8601", "19761118 is a valid ISO string for Calendar"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => new Temporal.PlainYearMonth(2000, 5, arg, 1), + `Number ${arg} does not convert to a valid ISO string for Calendar` + ); +} diff --git a/test/built-ins/Temporal/PlainYearMonth/compare/argument-number.js b/test/built-ins/Temporal/PlainYearMonth/compare/argument-number.js new file mode 100644 index 0000000000..c34aa67e14 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/compare/argument-number.js @@ -0,0 +1,34 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.compare +description: A number is converted to a string, then to Temporal.PlainYearMonth +features: [Temporal] +---*/ + +const arg = 201906; + +const result1 = Temporal.PlainYearMonth.compare(arg, new Temporal.PlainYearMonth(2019, 6)); +assert.sameValue(result1, 0, "201906 is a valid ISO string for PlainYearMonth (first argument)"); +const result2 = Temporal.PlainYearMonth.compare(new Temporal.PlainYearMonth(2019, 6), arg); +assert.sameValue(result2, 0, "201906 is a valid ISO string for PlainYearMonth (second argument)"); + +const numbers = [ + 1, + -201906, + 1234567, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => Temporal.PlainYearMonth.compare(arg, new Temporal.PlainYearMonth(2019, 6)), + `Number ${arg} does not convert to a valid ISO string for PlainYearMonth (first argument)` + ); + assert.throws( + RangeError, + () => Temporal.PlainYearMonth.compare(new Temporal.PlainYearMonth(2019, 6), arg), + `Number ${arg} does not convert to a valid ISO string for PlainYearMonth (first argument)` + ); +} diff --git a/test/built-ins/Temporal/PlainYearMonth/compare/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainYearMonth/compare/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..e153ce98fc --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/compare/argument-propertybag-calendar-number.js @@ -0,0 +1,53 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.compare +description: A number as calendar in a property bag is converted to a string, then to a calendar +features: [Temporal] +---*/ + +const calendar = 19970327; + +let arg = { year: 2019, monthCode: "M06", calendar }; +const result1 = Temporal.PlainYearMonth.compare(arg, new Temporal.PlainYearMonth(2019, 6)); +assert.sameValue(result1, 0, "19970327 is a valid ISO string for calendar (first argument)"); +const result2 = Temporal.PlainYearMonth.compare(new Temporal.PlainYearMonth(2019, 6), arg); +assert.sameValue(result2, 0, "19970327 is a valid ISO string for calendar (second argument)"); + +arg = { year: 2019, monthCode: "M06", calendar: { calendar } }; +const result3 = Temporal.PlainYearMonth.compare(arg, new Temporal.PlainYearMonth(2019, 6)); +assert.sameValue(result3, 0, "19970327 is a valid ISO string for calendar (nested property, first argument)"); +const result4 = Temporal.PlainYearMonth.compare(new Temporal.PlainYearMonth(2019, 6), arg); +assert.sameValue(result4, 0, "19970327 is a valid ISO string for calendar (nested property, second argument)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 2019, monthCode: "M06", calendar }; + assert.throws( + RangeError, + () => Temporal.PlainYearMonth.compare(arg, new Temporal.PlainYearMonth(2019, 6)), + `Number ${calendar} does not convert to a valid ISO string for calendar (first argument)` + ); + assert.throws( + RangeError, + () => Temporal.PlainYearMonth.compare(new Temporal.PlainYearMonth(2019, 6), arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (second argument)` + ); + arg = { year: 2019, monthCode: "M06", calendar: { calendar } }; + assert.throws( + RangeError, + () => Temporal.PlainYearMonth.compare(arg, new Temporal.PlainYearMonth(2019, 6)), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property, first argument)` + ); + assert.throws( + RangeError, + () => Temporal.PlainYearMonth.compare(new Temporal.PlainYearMonth(2019, 6), arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property, second argument)` + ); +} diff --git a/test/built-ins/Temporal/PlainYearMonth/from/argument-number.js b/test/built-ins/Temporal/PlainYearMonth/from/argument-number.js index 90a720fac0..4c9e3196c6 100644 --- a/test/built-ins/Temporal/PlainYearMonth/from/argument-number.js +++ b/test/built-ins/Temporal/PlainYearMonth/from/argument-number.js @@ -3,15 +3,26 @@ /*--- esid: sec-temporal.plainyearmonth.from -description: A number argument is stringified +description: A number is converted to a string, then to Temporal.PlainYearMonth includes: [temporalHelpers.js] features: [Temporal] ---*/ -const plainYearMonth = Temporal.PlainYearMonth.from(201906); -TemporalHelpers.assertPlainYearMonth(plainYearMonth, 2019, 6, "M06"); -const fields = plainYearMonth.getISOFields(); -assert.sameValue(fields.calendar.id, "iso8601"); -assert.sameValue(fields.isoDay, 1, "isoDay"); -assert.sameValue(fields.isoMonth, 6, "isoMonth"); -assert.sameValue(fields.isoYear, 2019, "isoYear"); +const arg = 201906; + +const result = Temporal.PlainYearMonth.from(arg); +TemporalHelpers.assertPlainYearMonth(result, 2019, 6, "M06", "201906 is a valid ISO string for PlainYearMonth"); + +const numbers = [ + 1, + -201906, + 1234567, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => Temporal.PlainYearMonth.from(arg), + `Number ${arg} does not convert to a valid ISO string for PlainYearMonth` + ); +} diff --git a/test/built-ins/Temporal/PlainYearMonth/from/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainYearMonth/from/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..ecead4225c --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/from/argument-propertybag-calendar-number.js @@ -0,0 +1,40 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.from +description: A number as calendar in a property bag is converted to a string, then to a calendar +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const calendar = 19970327; + +let arg = { year: 2019, monthCode: "M06", calendar }; +const result1 = Temporal.PlainYearMonth.from(arg); +TemporalHelpers.assertPlainYearMonth(result1, 2019, 6, "M06", "19970327 is a valid ISO string for calendar"); + +arg = { year: 2019, monthCode: "M06", calendar: { calendar } }; +const result2 = Temporal.PlainYearMonth.from(arg); +TemporalHelpers.assertPlainYearMonth(result2, 2019, 6, "M06", "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 2019, monthCode: "M06", calendar }; + assert.throws( + RangeError, + () => Temporal.PlainYearMonth.from(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 2019, monthCode: "M06", calendar: { calendar } }; + assert.throws( + RangeError, + () => Temporal.PlainYearMonth.from(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-number.js b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-number.js new file mode 100644 index 0000000000..11cbfd5e07 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-number.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.prototype.equals +description: A number is converted to a string, then to Temporal.PlainYearMonth +features: [Temporal] +---*/ + +const instance = new Temporal.PlainYearMonth(2019, 6); + +const arg = 201906; + +const result = instance.equals(arg); +assert.sameValue(result, true, "201906 is a valid ISO string for PlainYearMonth"); + +const numbers = [ + 1, + -201906, + 1234567, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.equals(arg), + `Number ${arg} does not convert to a valid ISO string for PlainYearMonth` + ); +} diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..cd1ea7b30d --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-propertybag-calendar-number.js @@ -0,0 +1,41 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.prototype.equals +description: A number as calendar in a property bag is converted to a string, then to a calendar +features: [Temporal] +---*/ + +const instance = new Temporal.PlainYearMonth(2019, 6); + +const calendar = 19970327; + +let arg = { year: 2019, monthCode: "M06", calendar }; +const result1 = instance.equals(arg); +assert.sameValue(result1, true, "19970327 is a valid ISO string for calendar"); + +arg = { year: 2019, monthCode: "M06", calendar: { calendar } }; +const result2 = instance.equals(arg); +assert.sameValue(result2, true, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 2019, monthCode: "M06", calendar }; + assert.throws( + RangeError, + () => instance.equals(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 2019, monthCode: "M06", calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.equals(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-number.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-number.js new file mode 100644 index 0000000000..f9116301e5 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-number.js @@ -0,0 +1,30 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.prototype.since +description: A number is converted to a string, then to Temporal.PlainYearMonth +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainYearMonth(2019, 6); + +const arg = 201906; + +const result = instance.since(arg); +TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "201906 is a valid ISO string for PlainYearMonth"); + +const numbers = [ + 1, + -201906, + 1234567, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.since(arg), + `Number ${arg} does not convert to a valid ISO string for PlainYearMonth` + ); +} diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..ab573e785a --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-propertybag-calendar-number.js @@ -0,0 +1,42 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.prototype.since +description: A number as calendar in a property bag is converted to a string, then to a calendar +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainYearMonth(2019, 6); + +const calendar = 19970327; + +let arg = { year: 2019, monthCode: "M06", calendar }; +const result1 = instance.since(arg); +TemporalHelpers.assertDuration(result1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar"); + +arg = { year: 2019, monthCode: "M06", calendar: { calendar } }; +const result2 = instance.since(arg); +TemporalHelpers.assertDuration(result2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 2019, monthCode: "M06", calendar }; + assert.throws( + RangeError, + () => instance.since(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 2019, monthCode: "M06", calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.since(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-number.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-number.js new file mode 100644 index 0000000000..b056e5aebe --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-number.js @@ -0,0 +1,30 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.prototype.until +description: A number is converted to a string, then to Temporal.PlainYearMonth +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainYearMonth(2019, 6); + +const arg = 201906; + +const result = instance.until(arg); +TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "201906 is a valid ISO string for PlainYearMonth"); + +const numbers = [ + 1, + -201906, + 1234567, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.until(arg), + `Number ${arg} does not convert to a valid ISO string for PlainYearMonth` + ); +} diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..2dedd8fe55 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-propertybag-calendar-number.js @@ -0,0 +1,42 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.prototype.until +description: A number as calendar in a property bag is converted to a string, then to a calendar +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainYearMonth(2019, 6); + +const calendar = 19970327; + +let arg = { year: 2019, monthCode: "M06", calendar }; +const result1 = instance.until(arg); +TemporalHelpers.assertDuration(result1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar"); + +arg = { year: 2019, monthCode: "M06", calendar: { calendar } }; +const result2 = instance.until(arg); +TemporalHelpers.assertDuration(result2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 2019, monthCode: "M06", calendar }; + assert.throws( + RangeError, + () => instance.until(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 2019, monthCode: "M06", calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.until(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-number.js b/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-number.js new file mode 100644 index 0000000000..d2d0589882 --- /dev/null +++ b/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-number.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.timezone.prototype.getinstantfor +description: A number is converted to a string, then to Temporal.PlainDateTime +features: [Temporal] +---*/ + +const instance = new Temporal.TimeZone("UTC"); + +let arg = 19761118; + +const result = instance.getInstantFor(arg); +assert.sameValue(result.epochNanoseconds, 217_123_200_000_000_000n, "19761118 is a valid ISO string for PlainDateTime"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.getInstantFor(arg), + `Number ${arg} does not convert to a valid ISO string for PlainDateTime` + ); +} diff --git a/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..2d14c50ee3 --- /dev/null +++ b/test/built-ins/Temporal/TimeZone/prototype/getInstantFor/argument-propertybag-calendar-number.js @@ -0,0 +1,41 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.timezone.prototype.getinstantfor +description: A number as calendar in a property bag is converted to a string, then to a calendar +features: [Temporal] +---*/ + +const instance = new Temporal.TimeZone("UTC"); + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = instance.getInstantFor(arg); +assert.sameValue(result1.epochNanoseconds, 217_123_200_000_000_000n, "19970327 is a valid ISO string for calendar"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = instance.getInstantFor(arg); +assert.sameValue(result2.epochNanoseconds, 217_123_200_000_000_000n, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.getInstantFor(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.getInstantFor(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/calendar-number.js b/test/built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/calendar-number.js new file mode 100644 index 0000000000..97a6429cd5 --- /dev/null +++ b/test/built-ins/Temporal/TimeZone/prototype/getPlainDateTimeFor/calendar-number.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.timezone.prototype.getplaindatetimefor +description: A number is converted to a string, then to Temporal.Calendar +features: [Temporal] +---*/ + +const instance = new Temporal.TimeZone("UTC"); + +const arg = 19761118; + +const result = instance.getPlainDateTimeFor(new Temporal.Instant(0n), arg); +assert.sameValue(result.calendar.id, "iso8601", "19761118 is a valid ISO string for Calendar"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.getPlainDateTimeFor(new Temporal.Instant(0n), arg), + `Number ${arg} does not convert to a valid ISO string for Calendar` + ); +} diff --git a/test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-number.js b/test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-number.js new file mode 100644 index 0000000000..a5894c8bf0 --- /dev/null +++ b/test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-number.js @@ -0,0 +1,30 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.timezone.prototype.getpossibleinstantsfor +description: A number is converted to a string, then to Temporal.PlainDateTime +includes: [compareArray.js] +features: [Temporal] +---*/ + +const instance = new Temporal.TimeZone("UTC"); + +let arg = 19761118; + +const result = instance.getPossibleInstantsFor(arg); +assert.compareArray(result.map(i => i.epochNanoseconds), [217_123_200_000_000_000n], "19761118 is a valid ISO string for PlainDateTime"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.getPossibleInstantsFor(arg), + `Number ${arg} does not convert to a valid ISO string for PlainDateTime` + ); +} diff --git a/test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..bee5a08198 --- /dev/null +++ b/test/built-ins/Temporal/TimeZone/prototype/getPossibleInstantsFor/argument-propertybag-calendar-number.js @@ -0,0 +1,42 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.timezone.prototype.getpossibleinstantsfor +description: A number as calendar in a property bag is converted to a string, then to a calendar +includes: [compareArray.js] +features: [Temporal] +---*/ + +const instance = new Temporal.TimeZone("UTC"); + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = instance.getPossibleInstantsFor(arg); +assert.compareArray(result1.map(i => i.epochNanoseconds), [217_123_200_000_000_000n], "19970327 is a valid ISO string for calendar"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = instance.getPossibleInstantsFor(arg); +assert.compareArray(result2.map(i => i.epochNanoseconds), [217_123_200_000_000_000n], "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.getPossibleInstantsFor(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.getPossibleInstantsFor(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/ZonedDateTime/calendar-number.js b/test/built-ins/Temporal/ZonedDateTime/calendar-number.js new file mode 100644 index 0000000000..889bf726c8 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/calendar-number.js @@ -0,0 +1,27 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime +description: A number is converted to a string, then to Temporal.Calendar +features: [Temporal] +---*/ + +const arg = 19761118; + +const result = new Temporal.ZonedDateTime(0n, "UTC", arg); +assert.sameValue(result.calendar.id, "iso8601", "19761118 is a valid ISO string for Calendar"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => new Temporal.ZonedDateTime(0n, "UTC", arg), + `Number ${arg} does not convert to a valid ISO string for Calendar` + ); +} diff --git a/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..e753410243 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-calendar-number.js @@ -0,0 +1,56 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.compare +description: A number as calendar in a property bag is converted to a string, then to a calendar +features: [Temporal] +---*/ + +const calendar = 19970327; + +const timeZone = new Temporal.TimeZone("UTC"); +const datetime = new Temporal.ZonedDateTime(0n, timeZone); + +let arg = { year: 1970, monthCode: "M01", day: 1, calendar, timeZone }; +const result1 = Temporal.ZonedDateTime.compare(arg, datetime); +assert.sameValue(result1, 0, "19970327 is a valid ISO string for calendar (first argument)"); +const result2 = Temporal.ZonedDateTime.compare(datetime, arg); +assert.sameValue(result2, 0, "19970327 is a valid ISO string for calendar (second argument)"); + +arg = { year: 1970, monthCode: "M01", day: 1, calendar: { calendar }, timeZone }; +const result3 = Temporal.ZonedDateTime.compare(arg, datetime); +assert.sameValue(result3, 0, "19970327 is a valid ISO string for calendar (nested property, first argument)"); +const result4 = Temporal.ZonedDateTime.compare(datetime, arg); +assert.sameValue(result4, 0, "19970327 is a valid ISO string for calendar (nested property, second argument)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1970, monthCode: "M01", day: 1, calendar, timeZone }; + assert.throws( + RangeError, + () => Temporal.ZonedDateTime.compare(arg, datetime), + `Number ${calendar} does not convert to a valid ISO string for calendar (first argument)` + ); + assert.throws( + RangeError, + () => Temporal.ZonedDateTime.compare(datetime, arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (second argument)` + ); + arg = { year: 1970, monthCode: "M01", day: 1, calendar: { calendar }, timeZone }; + assert.throws( + RangeError, + () => Temporal.ZonedDateTime.compare(arg, datetime), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property, first argument)` + ); + assert.throws( + RangeError, + () => Temporal.ZonedDateTime.compare(datetime, arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property, second argument)` + ); +} diff --git a/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..82c4337cc0 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-calendar-number.js @@ -0,0 +1,41 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.from +description: A number as calendar in a property bag is converted to a string, then to a calendar +features: [Temporal] +---*/ + +const calendar = 19970327; + +const timeZone = new Temporal.TimeZone("UTC"); + +let arg = { year: 1970, monthCode: "M01", day: 1, calendar, timeZone }; +const result1 = Temporal.ZonedDateTime.from(arg); +assert.sameValue(result1.calendar.id, "iso8601", "19970327 is a valid ISO string for calendar"); + +arg = { year: 1970, monthCode: "M01", day: 1, calendar: { calendar }, timeZone }; +const result2 = Temporal.ZonedDateTime.from(arg); +assert.sameValue(result2.calendar.id, "iso8601", "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1970, monthCode: "M01", day: 1, calendar, timeZone }; + assert.throws( + RangeError, + () => Temporal.ZonedDateTime.from(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1970, monthCode: "M01", day: 1, calendar: { calendar }, timeZone }; + assert.throws( + RangeError, + () => Temporal.ZonedDateTime.from(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..63105a259a --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-calendar-number.js @@ -0,0 +1,42 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.equals +description: A number as calendar in a property bag is converted to a string, then to a calendar +features: [Temporal] +---*/ + +const timeZone = new Temporal.TimeZone("UTC"); +const instance = new Temporal.ZonedDateTime(0n, timeZone); + +const calendar = 19970327; + +let arg = { year: 1970, monthCode: "M01", day: 1, calendar, timeZone }; +const result1 = instance.equals(arg); +assert.sameValue(result1, true, "19970327 is a valid ISO string for calendar"); + +arg = { year: 1970, monthCode: "M01", day: 1, calendar: { calendar }, timeZone }; +const result2 = instance.equals(arg); +assert.sameValue(result2, true, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1970, monthCode: "M01", day: 1, calendar, timeZone }; + assert.throws( + RangeError, + () => instance.equals(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1970, monthCode: "M01", day: 1, calendar: { calendar }, timeZone }; + assert.throws( + RangeError, + () => instance.equals(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..4cf765900d --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-calendar-number.js @@ -0,0 +1,43 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.since +description: A number as calendar in a property bag is converted to a string, then to a calendar +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const timeZone = new Temporal.TimeZone("UTC"); +const instance = new Temporal.ZonedDateTime(0n, timeZone); + +const calendar = 19970327; + +let arg = { year: 1970, monthCode: "M01", day: 1, calendar, timeZone }; +const result1 = instance.since(arg); +TemporalHelpers.assertDuration(result1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar"); + +arg = { year: 1970, monthCode: "M01", day: 1, calendar: { calendar }, timeZone }; +const result2 = instance.since(arg); +TemporalHelpers.assertDuration(result2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1970, monthCode: "M01", day: 1, calendar, timeZone }; + assert.throws( + RangeError, + () => instance.since(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1970, monthCode: "M01", day: 1, calendar: { calendar }, timeZone }; + assert.throws( + RangeError, + () => instance.since(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..cb4b7ee17b --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-calendar-number.js @@ -0,0 +1,43 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.until +description: A number as calendar in a property bag is converted to a string, then to a calendar +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const timeZone = new Temporal.TimeZone("UTC"); +const instance = new Temporal.ZonedDateTime(0n, timeZone); + +const calendar = 19970327; + +let arg = { year: 1970, monthCode: "M01", day: 1, calendar, timeZone }; +const result1 = instance.until(arg); +TemporalHelpers.assertDuration(result1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar"); + +arg = { year: 1970, monthCode: "M01", day: 1, calendar: { calendar }, timeZone }; +const result2 = instance.until(arg); +TemporalHelpers.assertDuration(result2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1970, monthCode: "M01", day: 1, calendar, timeZone }; + assert.throws( + RangeError, + () => instance.until(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1970, monthCode: "M01", day: 1, calendar: { calendar }, timeZone }; + assert.throws( + RangeError, + () => instance.until(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-number.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-number.js new file mode 100644 index 0000000000..0a299d540f --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-number.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.withcalendar +description: A number is converted to a string, then to Temporal.Calendar +features: [Temporal] +---*/ + +const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", { id: "replace-me" }); + +const arg = 19761118; + +const result = instance.withCalendar(arg); +assert.sameValue(result.calendar.id, "iso8601", "19761118 is a valid ISO string for Calendar"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.withCalendar(arg), + `Number ${arg} does not convert to a valid ISO string for Calendar` + ); +} diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-number.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-number.js new file mode 100644 index 0000000000..f251b281fd --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-number.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.withplaindate +description: A number is converted to a string, then to Temporal.PlainDate +features: [Temporal] +---*/ + +const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC"); + +const arg = 19761118; + +const result = instance.withPlainDate(arg); +assert.sameValue(result.epochNanoseconds, 217_129_600_000_000_000n, "19761118 is a valid ISO string for PlainDate"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.withPlainDate(arg), + `Number ${arg} does not convert to a valid ISO string for PlainDate` + ); +} diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..4320436738 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainDate/argument-propertybag-calendar-number.js @@ -0,0 +1,41 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.withplaindate +description: A number as calendar in a property bag is converted to a string, then to a calendar +features: [Temporal] +---*/ + +const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC"); + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = instance.withPlainDate(arg); +assert.sameValue(result1.epochNanoseconds, 217_129_600_000_000_000n, "19970327 is a valid ISO string for calendar"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = instance.withPlainDate(arg); +assert.sameValue(result2.epochNanoseconds, 217_129_600_000_000_000n, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.withPlainDate(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.withPlainDate(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-number.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-number.js new file mode 100644 index 0000000000..13dc510e5b --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withPlainTime/argument-number.js @@ -0,0 +1,30 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.withplaintime +description: A number is converted to a string, then to Temporal.PlainTime +features: [Temporal] +---*/ + +const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC"); + +const arg = 123456.987654321; + +const result = instance.withPlainTime(arg); +assert.sameValue(result.epochNanoseconds, 1000038896_987_654_321n, "123456.987654321 is a valid ISO string for PlainTime"); + +const numbers = [ + 1, + -123456.987654321, + 1234567, + 123456.9876543219, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.withPlainTime(arg), + `Number ${arg} does not convert to a valid ISO string for PlainTime` + ); +} diff --git a/test/intl402/Temporal/Calendar/prototype/era/argument-number.js b/test/intl402/Temporal/Calendar/prototype/era/argument-number.js new file mode 100644 index 0000000000..1fde733db5 --- /dev/null +++ b/test/intl402/Temporal/Calendar/prototype/era/argument-number.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.era +description: A number is converted to a string, then to Temporal.PlainDate +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const arg = 19761118; + +const result = instance.era(arg); +assert.sameValue(result, undefined, "19761118 is a valid ISO string for PlainDate"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.era(arg), + `Number ${arg} does not convert to a valid ISO string for PlainDate` + ); +} diff --git a/test/intl402/Temporal/Calendar/prototype/era/argument-propertybag-calendar-number.js b/test/intl402/Temporal/Calendar/prototype/era/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..e355b70e95 --- /dev/null +++ b/test/intl402/Temporal/Calendar/prototype/era/argument-propertybag-calendar-number.js @@ -0,0 +1,41 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.era +description: A number as calendar in a property bag is converted to a string, then to a calendar +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = instance.era(arg); +assert.sameValue(result1, undefined, "19970327 is a valid ISO string for calendar"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = instance.era(arg); +assert.sameValue(result2, undefined, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.era(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.era(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +} diff --git a/test/intl402/Temporal/Calendar/prototype/eraYear/argument-number.js b/test/intl402/Temporal/Calendar/prototype/eraYear/argument-number.js new file mode 100644 index 0000000000..9cecd5ed35 --- /dev/null +++ b/test/intl402/Temporal/Calendar/prototype/eraYear/argument-number.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.erayear +description: A number is converted to a string, then to Temporal.PlainDate +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const arg = 19761118; + +const result = instance.eraYear(arg); +assert.sameValue(result, undefined, "19761118 is a valid ISO string for PlainDate"); + +const numbers = [ + 1, + -19761118, + 1234567890, +]; + +for (const arg of numbers) { + assert.throws( + RangeError, + () => instance.eraYear(arg), + `Number ${arg} does not convert to a valid ISO string for PlainDate` + ); +} diff --git a/test/intl402/Temporal/Calendar/prototype/eraYear/argument-propertybag-calendar-number.js b/test/intl402/Temporal/Calendar/prototype/eraYear/argument-propertybag-calendar-number.js new file mode 100644 index 0000000000..e1640061d8 --- /dev/null +++ b/test/intl402/Temporal/Calendar/prototype/eraYear/argument-propertybag-calendar-number.js @@ -0,0 +1,41 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.calendar.prototype.erayear +description: A number as calendar in a property bag is converted to a string, then to a calendar +features: [Temporal] +---*/ + +const instance = new Temporal.Calendar("iso8601"); + +const calendar = 19970327; + +let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; +const result1 = instance.eraYear(arg); +assert.sameValue(result1, undefined, "19970327 is a valid ISO string for calendar"); + +arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; +const result2 = instance.eraYear(arg); +assert.sameValue(result2, undefined, "19970327 is a valid ISO string for calendar (nested property)"); + +const numbers = [ + 1, + -19970327, + 1234567890, +]; + +for (const calendar of numbers) { + let arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.eraYear(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar` + ); + arg = { year: 1976, monthCode: "M11", day: 18, calendar: { calendar } }; + assert.throws( + RangeError, + () => instance.eraYear(arg), + `Number ${calendar} does not convert to a valid ISO string for calendar (nested property)` + ); +}