From 443f0d2e7faf033b0d65586ef86e2601e774cd7c Mon Sep 17 00:00:00 2001 From: brageh01 Date: Thu, 24 Apr 2025 01:04:15 +0200 Subject: [PATCH] Temporal: Reorganize calendar and wrong-type tests (#4415) Changes made to: - PlainDate - PlainYearMonth - ZonedDateTime - PlainDateTime - PlainMonthDay Merged calendar-number.js and calendar-wrong-type.js, due to no special behaviour of number to be tested. Extracted string tests to calendar-iso-string.js and renamed the file to calendar-invalid-iso-string.js, due to the contents of the file initially testing invalid ISO strings. Closes #3873 --- ...ropertybag-calendar-invalid-iso-string.js} | 18 ++++---- ...ativeto-propertybag-calendar-wrong-type.js | 27 +++++------- ...ropertybag-calendar-invalid-iso-string.js} | 17 ++++---- ...ativeto-propertybag-calendar-wrong-type.js | 29 +++++-------- .../PlainDate/calendar-invalid-iso-string.js | 21 ++++++++++ .../Temporal/PlainDate/calendar-iso-string.js | 14 ------- .../Temporal/PlainDate/calendar-number.js | 23 ----------- .../Temporal/PlainDate/calendar-wrong-type.js | 27 +++++------- ...ropertybag-calendar-invalid-iso-string.js} | 23 +++++------ ...rgument-propertybag-calendar-wrong-type.js | 39 ++++++++---------- ...propertybag-calendar-invalid-iso-string.js | 21 ++++++++++ .../argument-propertybag-calendar-number.js | 24 ----------- ...rgument-propertybag-calendar-wrong-type.js | 28 +++++-------- ...propertybag-calendar-invalid-iso-string.js | 23 +++++++++++ .../argument-propertybag-calendar-number.js | 26 ------------ ...rgument-propertybag-calendar-wrong-type.js | 31 ++++++-------- ...propertybag-calendar-invalid-iso-string.js | 23 +++++++++++ .../argument-propertybag-calendar-number.js | 25 ----------- ...rgument-propertybag-calendar-wrong-type.js | 32 ++++++--------- ...propertybag-calendar-invalid-iso-string.js | 23 +++++++++++ .../argument-propertybag-calendar-number.js | 25 ----------- ...rgument-propertybag-calendar-wrong-type.js | 31 ++++++-------- .../calendar-invalid-iso-string.js | 22 ++++++++++ .../prototype/withCalendar/calendar-number.js | 25 ----------- .../withCalendar/calendar-wrong-type.js | 27 +++++------- .../calendar-invalid-iso-string.js | 21 ++++++++++ .../PlainDateTime/calendar-iso-string.js | 14 ------- .../Temporal/PlainDateTime/calendar-number.js | 23 ----------- .../PlainDateTime/calendar-wrong-type.js | 27 +++++------- ...ropertybag-calendar-invalid-iso-string.js} | 23 +++++------ ...rgument-propertybag-calendar-wrong-type.js | 39 ++++++++---------- ...propertybag-calendar-invalid-iso-string.js | 21 ++++++++++ .../argument-propertybag-calendar-number.js | 24 ----------- ...rgument-propertybag-calendar-wrong-type.js | 28 +++++-------- ...propertybag-calendar-invalid-iso-string.js | 23 +++++++++++ .../argument-propertybag-calendar-number.js | 26 ------------ ...rgument-propertybag-calendar-wrong-type.js | 31 ++++++-------- ...propertybag-calendar-invalid-iso-string.js | 23 +++++++++++ .../argument-propertybag-calendar-number.js | 26 ------------ ...rgument-propertybag-calendar-wrong-type.js | 30 ++++++-------- ...propertybag-calendar-invalid-iso-string.js | 23 +++++++++++ .../argument-propertybag-calendar-number.js | 26 ------------ ...rgument-propertybag-calendar-wrong-type.js | 31 ++++++-------- ...mber.js => calendar-invalid-iso-string.js} | 17 ++++---- .../withCalendar/calendar-wrong-type.js | 25 +++++------ .../calendar-invalid-iso-string.js | 21 ++++++++++ .../PlainMonthDay/calendar-iso-string.js | 14 ------- .../Temporal/PlainMonthDay/calendar-number.js | 23 ----------- .../PlainMonthDay/calendar-wrong-type.js | 27 +++++------- ...propertybag-calendar-invalid-iso-string.js | 21 ++++++++++ ...rgument-propertybag-calendar-iso-string.js | 2 +- .../argument-propertybag-calendar-number.js | 24 ----------- ...rgument-propertybag-calendar-wrong-type.js | 30 ++++++-------- ...propertybag-calendar-invalid-iso-string.js | 24 +++++++++++ .../argument-propertybag-calendar-number.js | 26 ------------ ...rgument-propertybag-calendar-wrong-type.js | 27 +++++------- .../calendar-invalid-iso-string.js | 21 ++++++++++ .../PlainYearMonth/calendar-iso-string.js | 14 ------- .../PlainYearMonth/calendar-number.js | 23 ----------- .../PlainYearMonth/calendar-wrong-type.js | 27 +++++------- ...ropertybag-calendar-invalid-iso-string.js} | 23 +++++------ ...rgument-propertybag-calendar-wrong-type.js | 41 ++++++++----------- ...propertybag-calendar-invalid-iso-string.js | 21 ++++++++++ .../argument-propertybag-calendar-number.js | 24 ----------- ...rgument-propertybag-calendar-wrong-type.js | 30 ++++++-------- ...propertybag-calendar-invalid-iso-string.js | 25 +++++++++++ .../argument-propertybag-calendar-number.js | 26 ------------ ...rgument-propertybag-calendar-wrong-type.js | 27 +++++------- ...propertybag-calendar-invalid-iso-string.js | 24 +++++++++++ .../argument-propertybag-calendar-number.js | 26 ------------ ...rgument-propertybag-calendar-wrong-type.js | 26 +++++------- ...propertybag-calendar-invalid-iso-string.js | 24 +++++++++++ .../argument-propertybag-calendar-number.js | 26 ------------ ...rgument-propertybag-calendar-wrong-type.js | 27 +++++------- .../calendar-invalid-iso-string.js | 21 ++++++++++ .../ZonedDateTime/calendar-iso-string.js | 14 ------- .../Temporal/ZonedDateTime/calendar-number.js | 23 ----------- .../ZonedDateTime/calendar-wrong-type.js | 27 +++++------- ...propertybag-calendar-invalid-iso-string.js | 28 +++++++++++++ .../argument-propertybag-calendar-number.js | 32 --------------- ...rgument-propertybag-calendar-wrong-type.js | 41 ++++++++----------- ...propertybag-calendar-invalid-iso-string.js | 23 +++++++++++ .../argument-propertybag-calendar-number.js | 25 ----------- ...rgument-propertybag-calendar-wrong-type.js | 31 ++++++-------- ...propertybag-calendar-invalid-iso-string.js | 25 +++++++++++ .../argument-propertybag-calendar-number.js | 27 ------------ ...rgument-propertybag-calendar-wrong-type.js | 24 ++++------- ...propertybag-calendar-invalid-iso-string.js | 25 +++++++++++ .../argument-propertybag-calendar-number.js | 27 ------------ ...rgument-propertybag-calendar-wrong-type.js | 26 +++++------- ...propertybag-calendar-invalid-iso-string.js | 25 +++++++++++ .../argument-propertybag-calendar-number.js | 27 ------------ ...rgument-propertybag-calendar-wrong-type.js | 26 +++++------- .../calendar-invalid-iso-string.js | 23 +++++++++++ .../prototype/withCalendar/calendar-number.js | 25 ----------- .../withCalendar/calendar-wrong-type.js | 28 +++++-------- 96 files changed, 1023 insertions(+), 1369 deletions(-) rename test/built-ins/Temporal/Duration/prototype/round/{relativeto-propertybag-calendar-number.js => relativeto-propertybag-calendar-invalid-iso-string.js} (53%) rename test/built-ins/Temporal/Duration/prototype/total/{relativeto-propertybag-calendar-number.js => relativeto-propertybag-calendar-invalid-iso-string.js} (53%) create mode 100644 test/built-ins/Temporal/PlainDate/calendar-invalid-iso-string.js delete mode 100644 test/built-ins/Temporal/PlainDate/calendar-iso-string.js delete mode 100644 test/built-ins/Temporal/PlainDate/calendar-number.js rename test/built-ins/Temporal/PlainDate/compare/{argument-propertybag-calendar-number.js => argument-propertybag-calendar-invalid-iso-string.js} (50%) create mode 100644 test/built-ins/Temporal/PlainDate/from/argument-propertybag-calendar-invalid-iso-string.js delete mode 100644 test/built-ins/Temporal/PlainDate/from/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/equals/argument-propertybag-calendar-invalid-iso-string.js delete 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-propertybag-calendar-invalid-iso-string.js delete mode 100644 test/built-ins/Temporal/PlainDate/prototype/since/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-invalid-iso-string.js delete 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-invalid-iso-string.js delete mode 100644 test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-number.js create mode 100644 test/built-ins/Temporal/PlainDateTime/calendar-invalid-iso-string.js delete mode 100644 test/built-ins/Temporal/PlainDateTime/calendar-iso-string.js delete mode 100644 test/built-ins/Temporal/PlainDateTime/calendar-number.js rename test/built-ins/Temporal/PlainDateTime/compare/{argument-propertybag-calendar-number.js => argument-propertybag-calendar-invalid-iso-string.js} (51%) create mode 100644 test/built-ins/Temporal/PlainDateTime/from/argument-propertybag-calendar-invalid-iso-string.js delete mode 100644 test/built-ins/Temporal/PlainDateTime/from/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-invalid-iso-string.js delete 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-propertybag-calendar-invalid-iso-string.js delete 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-propertybag-calendar-invalid-iso-string.js delete mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-number.js rename test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/{calendar-number.js => calendar-invalid-iso-string.js} (51%) create mode 100644 test/built-ins/Temporal/PlainMonthDay/calendar-invalid-iso-string.js delete mode 100644 test/built-ins/Temporal/PlainMonthDay/calendar-iso-string.js delete mode 100644 test/built-ins/Temporal/PlainMonthDay/calendar-number.js create mode 100644 test/built-ins/Temporal/PlainMonthDay/from/argument-propertybag-calendar-invalid-iso-string.js delete mode 100644 test/built-ins/Temporal/PlainMonthDay/from/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-propertybag-calendar-invalid-iso-string.js delete mode 100644 test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/calendar-invalid-iso-string.js delete mode 100644 test/built-ins/Temporal/PlainYearMonth/calendar-iso-string.js delete mode 100644 test/built-ins/Temporal/PlainYearMonth/calendar-number.js rename test/built-ins/Temporal/PlainYearMonth/compare/{argument-propertybag-calendar-number.js => argument-propertybag-calendar-invalid-iso-string.js} (50%) create mode 100644 test/built-ins/Temporal/PlainYearMonth/from/argument-propertybag-calendar-invalid-iso-string.js delete mode 100644 test/built-ins/Temporal/PlainYearMonth/from/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-propertybag-calendar-invalid-iso-string.js delete 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-propertybag-calendar-invalid-iso-string.js delete 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-propertybag-calendar-invalid-iso-string.js delete mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-propertybag-calendar-number.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/calendar-invalid-iso-string.js delete mode 100644 test/built-ins/Temporal/ZonedDateTime/calendar-iso-string.js delete mode 100644 test/built-ins/Temporal/ZonedDateTime/calendar-number.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-calendar-invalid-iso-string.js delete 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-invalid-iso-string.js delete 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-invalid-iso-string.js delete 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-invalid-iso-string.js delete 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-invalid-iso-string.js delete 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-invalid-iso-string.js delete mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-number.js 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-invalid-iso-string.js similarity index 53% rename from test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-calendar-number.js rename to test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-calendar-invalid-iso-string.js index 4d36ffa8e7..7febd19837 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-calendar-invalid-iso-string.js @@ -1,26 +1,24 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// Copyright (C) 2025 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 invalid +description: > + An ISO string that cannot be converted to a calendar ID should throw a RangeError features: [Temporal] ---*/ const instance = new Temporal.Duration(1, 0, 0, 0, 24); -const numbers = [ - 1, - 19970327, - -19970327, - 1234567890, +const invalidStrings = [ + ["", "empty string"] ]; -for (const calendar of numbers) { +for (const [calendar, description] of invalidStrings) { const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; assert.throws( - TypeError, + RangeError, () => instance.round({ largestUnit: "years", relativeTo }), - `A number (${calendar}) is not a valid ISO string for relativeTo.calendar` + `${description} is not a valid calendar ID` ); } diff --git a/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-calendar-wrong-type.js index ffd9706346..2c28d1a313 100644 --- a/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-calendar-wrong-type.js @@ -9,27 +9,16 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const timeZone = "UTC"; const instance = new Temporal.Duration(1, 0, 0, 0, 24); -const primitiveTests = [ +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], [1, "number that doesn't convert to a valid ISO string"], [1n, "bigint"], -]; - -for (const [calendar, description] of primitiveTests) { - const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws( - typeof calendar === 'string' ? RangeError : TypeError, - () => instance.round({ largestUnit: "years", relativeTo }), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ + [19970327, "large number"], + [-19970327, "negative number"], + [1234567890, "very large integer"], [Symbol(), "symbol"], [{}, "object"], [Temporal.PlainDate, "Temporal.PlainDate, object"], @@ -38,7 +27,11 @@ const typeErrorTests = [ [Temporal.ZonedDateTime.prototype, "Temporal.ZonedDateTime.prototype, object"], ]; -for (const [calendar, description] of typeErrorTests) { +for (const [calendar, description] of wrongTypeTests) { const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(TypeError, () => instance.round({ largestUnit: "years", relativeTo }), `${description} is not a valid property bag and does not convert to a string`); + assert.throws( + TypeError, + () => instance.round({ largestUnit: "years", relativeTo }), + `${description} does not convert to a valid ISO string` + ); } 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-invalid-iso-string.js similarity index 53% rename from test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-calendar-number.js rename to test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-calendar-invalid-iso-string.js index c84815264f..3469ba89e4 100644 --- a/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-calendar-invalid-iso-string.js @@ -1,26 +1,23 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// Copyright (C) 2025 Brage Hogstad, University of Bergen. 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 invalid +description: Various invalid ISO string values for relativeTo.calendar features: [Temporal] ---*/ const instance = new Temporal.Duration(1, 0, 0, 0, 24); -const numbers = [ - 1, - 19970327, - -19970327, - 1234567890, +const invalidStrings = [ + ["", "empty string"], ]; -for (const calendar of numbers) { +for (const [calendar, description] of invalidStrings) { const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; assert.throws( - TypeError, + RangeError, () => instance.total({ unit: "days", relativeTo }), - `A number (${calendar}) is not a valid ISO string for relativeTo.calendar` + `${description} is not a valid calendar ID` ); } diff --git a/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-calendar-wrong-type.js index 3e2b8a7a4a..f2d7411fd7 100644 --- a/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-calendar-wrong-type.js @@ -9,27 +9,16 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const timeZone = "UTC"; const instance = new Temporal.Duration(1, 0, 0, 0, 24); -const primitiveTests = [ +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], - [1, "number that doesn't convert to a valid ISO string"], + [1, "number"], [1n, "bigint"], -]; - -for (const [calendar, description] of primitiveTests) { - const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws( - typeof calendar === 'string' ? RangeError : TypeError, - () => instance.total({ unit: "days", relativeTo }), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ + [19970327, "large number"], + [-19970327, "negative number"], + [1234567890, "very large integer"], [Symbol(), "symbol"], [{}, "object"], [Temporal.PlainDate, "Temporal.PlainDate, object"], @@ -38,7 +27,11 @@ const typeErrorTests = [ [Temporal.ZonedDateTime.prototype, "Temporal.ZonedDateTime.prototype, object"], ]; -for (const [calendar, description] of typeErrorTests) { +for (const [calendar, description] of wrongTypeTests) { const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(TypeError, () => instance.total({ unit: "days", relativeTo }), `${description} is not a valid property bag and does not convert to a string`); + assert.throws( + TypeError, + () => instance.total({ unit: "days", relativeTo }), + `${description} is not a valid calendar` + ); } diff --git a/test/built-ins/Temporal/PlainDate/calendar-invalid-iso-string.js b/test/built-ins/Temporal/PlainDate/calendar-invalid-iso-string.js new file mode 100644 index 0000000000..c7309ae765 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/calendar-invalid-iso-string.js @@ -0,0 +1,21 @@ +// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.constructor +description: Various invalid ISO string values for calendar +features: [Temporal] +---*/ + +const invalidStrings = [ + ["", "empty string"], + ["1997-12-04[u-ca=iso8601]", "ISO string with calendar annotation"], +]; + +for (const [arg, description] of invalidStrings) { + assert.throws( + RangeError, + () => new Temporal.PlainDate(2000, 5, 2, arg), + `${description} is not a valid calendar ID` + ); +} diff --git a/test/built-ins/Temporal/PlainDate/calendar-iso-string.js b/test/built-ins/Temporal/PlainDate/calendar-iso-string.js deleted file mode 100644 index 444815b189..0000000000 --- a/test/built-ins/Temporal/PlainDate/calendar-iso-string.js +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (C) 2024 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.plaindate.constructor -description: An ISO string is not valid input for a constructor's calendar param -features: [Temporal] ----*/ - -assert.throws( - RangeError, - () => new Temporal.PlainDate(2000, 5, 2, "1997-12-04[u-ca=iso8601]"), - "An ISO string is not a valid calendar ID for constructor parameter" -); diff --git a/test/built-ins/Temporal/PlainDate/calendar-number.js b/test/built-ins/Temporal/PlainDate/calendar-number.js deleted file mode 100644 index 59ccc26614..0000000000 --- a/test/built-ins/Temporal/PlainDate/calendar-number.js +++ /dev/null @@ -1,23 +0,0 @@ -// 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 not allowed to be a calendar -features: [Temporal] ----*/ - -const numbers = [ - 1, - -19761118, - 19761118, - 1234567890, -]; - -for (const arg of numbers) { - assert.throws( - TypeError, - () => new Temporal.PlainDate(2000, 5, 2, arg), - "A number is not a valid ISO string for Calendar" - ); -} diff --git a/test/built-ins/Temporal/PlainDate/calendar-wrong-type.js b/test/built-ins/Temporal/PlainDate/calendar-wrong-type.js index 0555387dc0..5bd53ac7d3 100644 --- a/test/built-ins/Temporal/PlainDate/calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDate/calendar-wrong-type.js @@ -9,28 +9,23 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const primitiveTests = [ +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], - [1, "number that doesn't convert to a valid ISO string"], + [1, "number"], [1n, "bigint"], -]; - -for (const [arg, description] of primitiveTests) { - assert.throws( - typeof arg === 'string' ? RangeError : TypeError, - () => new Temporal.PlainDate(2000, 5, 2, arg), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ + [-19761118, "negative number"], + [19761118, "large positive number"], + [1234567890, "large integer"], [Symbol(), "symbol"], [{}, "object"], [new Temporal.Duration(), "duration instance"], ]; -for (const [arg, description] of typeErrorTests) { - assert.throws(TypeError, () => new Temporal.PlainDate(2000, 5, 2, arg), `${description} is not a valid object and does not convert to a string`); +for (const [arg, description] of wrongTypeTests) { + assert.throws( + TypeError, + () => new Temporal.PlainDate(2000, 5, 2, arg), + `${description} is not a valid calendar` + ); } diff --git a/test/built-ins/Temporal/PlainDate/compare/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainDate/compare/argument-propertybag-calendar-invalid-iso-string.js similarity index 50% rename from test/built-ins/Temporal/PlainDate/compare/argument-propertybag-calendar-number.js rename to test/built-ins/Temporal/PlainDate/compare/argument-propertybag-calendar-invalid-iso-string.js index 12475bcdb9..7ff0119ec7 100644 --- a/test/built-ins/Temporal/PlainDate/compare/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/PlainDate/compare/argument-propertybag-calendar-invalid-iso-string.js @@ -1,29 +1,26 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// Copyright (C) 2025 Brage Hogstad, University of Bergen. 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 not accepted +description: Invalid ISO string as calendar should throw RangeError features: [Temporal] ---*/ -const numbers = [ - 1, - 19970327, - -19970327, - 1234567890, +const invalidStrings = [ + ["", "empty string"], ]; - -for (const calendar of numbers) { + +for (const [calendar, description] of invalidStrings) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - TypeError, + RangeError, () => Temporal.PlainDate.compare(arg, new Temporal.PlainDate(1976, 11, 18)), - "A number is not a valid ISO string for calendar (first argument)" + `${description} is not a valid calendar ID (first argument)` ); assert.throws( - TypeError, + RangeError, () => Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg), - "A number is not a valid ISO string for calendar (second argument)" + `${description} is not a valid calendar ID (second argument)` ); } diff --git a/test/built-ins/Temporal/PlainDate/compare/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainDate/compare/argument-propertybag-calendar-wrong-type.js index 2c74354e9d..afaaef0165 100644 --- a/test/built-ins/Temporal/PlainDate/compare/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDate/compare/argument-propertybag-calendar-wrong-type.js @@ -9,36 +9,29 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const primitiveTests = [ +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], - [1, "number that doesn't convert to a valid ISO string"], + [1, "number"], [1n, "bigint"], -]; - -for (const [calendar, description] of primitiveTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws( - typeof calendar === "string" ? RangeError : TypeError, - () => Temporal.PlainDate.compare(arg, new Temporal.PlainDate(1976, 11, 18)), - `${description} does not convert to a valid ISO string (first argument)` - ); - assert.throws( - typeof calendar === "string" ? RangeError : TypeError, - () => Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg), - `${description} does not convert to a valid ISO string (second argument)` - ); -} - -const typeErrorTests = [ + [19970327, "large number"], + [-19970327, "negative number"], + [1234567890, "very large integer"], [Symbol(), "symbol"], [{}, "object"], [new Temporal.Duration(), "duration instance"], ]; -for (const [calendar, description] of typeErrorTests) { +for (const [calendar, description] of wrongTypeTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(TypeError, () => Temporal.PlainDate.compare(arg, new Temporal.PlainDate(1976, 11, 18)), `${description} is not a valid property bag and does not convert to a string (first argument)`); - assert.throws(TypeError, () => Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg), `${description} is not a valid property bag and does not convert to a string (second argument)`); + assert.throws( + TypeError, + () => Temporal.PlainDate.compare(arg, new Temporal.PlainDate(1976, 11, 18)), + `${description} is not a valid property bag and does not convert to a string (first argument)` + ); + assert.throws( + TypeError, + () => Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg), + `${description} is not a valid property bag and does not convert to a string (second argument)` + ); } diff --git a/test/built-ins/Temporal/PlainDate/from/argument-propertybag-calendar-invalid-iso-string.js b/test/built-ins/Temporal/PlainDate/from/argument-propertybag-calendar-invalid-iso-string.js new file mode 100644 index 0000000000..eac62aa42f --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/from/argument-propertybag-calendar-invalid-iso-string.js @@ -0,0 +1,21 @@ +// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.from +description: Various invalid ISO string values for calendar in a property bag +features: [Temporal] +---*/ + +const invalidStrings = [ + ["", "empty string"], +]; + +for (const [calendar, description] of invalidStrings) { + const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; + assert.throws( + RangeError, + () => Temporal.PlainDate.from(arg), + `${description} is not a valid calendar ID` + ); +} 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 deleted file mode 100644 index 6e8f9cef37..0000000000 --- a/test/built-ins/Temporal/PlainDate/from/argument-propertybag-calendar-number.js +++ /dev/null @@ -1,24 +0,0 @@ -// 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 not accepted -features: [Temporal] ----*/ - -const numbers = [ - 1, - 19970327, - -19970327, - 1234567890, -]; - -for (const calendar of numbers) { - const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; - assert.throws( - TypeError, - () => Temporal.PlainDate.from(arg), - "Numbers cannot be used as a calendar" - ); -} diff --git a/test/built-ins/Temporal/PlainDate/from/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainDate/from/argument-propertybag-calendar-wrong-type.js index c6a2bdfc9b..8e1da6df60 100644 --- a/test/built-ins/Temporal/PlainDate/from/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDate/from/argument-propertybag-calendar-wrong-type.js @@ -9,30 +9,24 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const primitiveTests = [ +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], - [1, "number that doesn't convert to a valid ISO string"], + [1, "number"], [1n, "bigint"], -]; - -for (const [calendar, description] of primitiveTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws( - typeof calendar === 'string' ? RangeError : TypeError, - () => Temporal.PlainDate.from(arg), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ + [19970327, "large number"], + [-19970327, "negative number"], + [1234567890, "very large integer"], [Symbol(), "symbol"], [{}, "object"], [new Temporal.Duration(), "duration instance"], ]; -for (const [calendar, description] of typeErrorTests) { +for (const [calendar, description] of wrongTypeTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(TypeError, () => Temporal.PlainDate.from(arg), `${description} is not a valid property bag and does not convert to a string`); + assert.throws( + TypeError, + () => Temporal.PlainDate.from(arg), + `${description} is not a valid calendar` + ); } diff --git a/test/built-ins/Temporal/PlainDate/prototype/equals/argument-propertybag-calendar-invalid-iso-string.js b/test/built-ins/Temporal/PlainDate/prototype/equals/argument-propertybag-calendar-invalid-iso-string.js new file mode 100644 index 0000000000..badabe640c --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/equals/argument-propertybag-calendar-invalid-iso-string.js @@ -0,0 +1,23 @@ +// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.equals +description: Invalid ISO string as calendar should throw RangeError +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDate(2000, 5, 2); + +const invalidStrings = [ + ["", "empty string"], +]; + +for (const [calendar, description] of invalidStrings) { + const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.equals(arg), + `${description} is not a valid calendar ID` + ); +} 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 deleted file mode 100644 index c835461bc5..0000000000 --- a/test/built-ins/Temporal/PlainDate/prototype/equals/argument-propertybag-calendar-number.js +++ /dev/null @@ -1,26 +0,0 @@ -// 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 not accepted -features: [Temporal] ----*/ - -const instance = new Temporal.PlainDate(1976, 11, 18); - -const numbers = [ - 1, - 19970327, - -19970327, - 1234567890, -]; - -for (const calendar of numbers) { - const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; - assert.throws( - TypeError, - () => instance.equals(arg), - "Numbers cannot be used as a calendar" - ); -} diff --git a/test/built-ins/Temporal/PlainDate/prototype/equals/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainDate/prototype/equals/argument-propertybag-calendar-wrong-type.js index 0172fc4adf..7b9dae8cab 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/equals/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDate/prototype/equals/argument-propertybag-calendar-wrong-type.js @@ -9,33 +9,26 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const timeZone = "UTC"; const instance = new Temporal.PlainDate(2000, 5, 2); -const primitiveTests = [ +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], - [1, "number that doesn't convert to a valid ISO string"], + [1, "number"], [1n, "bigint"], -]; - -for (const [calendar, description] of primitiveTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws( - typeof calendar === 'string' ? RangeError : TypeError, - () => instance.equals(arg), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ + [19970327, "large number"], + [-19970327, "negative number"], + [1234567890, "very large integer"], [Symbol(), "symbol"], [{}, "object"], [new Temporal.Duration(), "duration instance"], ]; -for (const [calendar, description] of typeErrorTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(TypeError, () => instance.equals(arg), `${description} is not a valid property bag and does not convert to a string`); +for (const [calendar, description] of wrongTypeTests) { + const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + TypeError, + () => instance.equals(arg), + `${description} is not a valid calendar` + ); } diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/argument-propertybag-calendar-invalid-iso-string.js b/test/built-ins/Temporal/PlainDate/prototype/since/argument-propertybag-calendar-invalid-iso-string.js new file mode 100644 index 0000000000..42ad23219f --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/since/argument-propertybag-calendar-invalid-iso-string.js @@ -0,0 +1,23 @@ +// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.since +description: Invalid ISO string as calendar should throw RangeError +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDate(2000, 5, 2); + +const invalidStrings = [ + ["", "empty string"], +]; + +for (const [calendar, description] of invalidStrings) { + const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.since(arg), + `${description} is not a valid calendar ID` + ); +} 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 deleted file mode 100644 index 2a05d60d01..0000000000 --- a/test/built-ins/Temporal/PlainDate/prototype/since/argument-propertybag-calendar-number.js +++ /dev/null @@ -1,25 +0,0 @@ -// 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 not accepted -features: [Temporal] ----*/ - -const instance = new Temporal.PlainDate(1976, 11, 18); - -const numbers = [ - 1, - 19970327, - -19970327, - 1234567890, -]; -for (const calendar of numbers) { - const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; - assert.throws( - TypeError, - () => instance.since(arg), - "Numbers cannot be used as a calendar" - ); -} diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainDate/prototype/since/argument-propertybag-calendar-wrong-type.js index 043ff19894..cb85f0a258 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/since/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDate/prototype/since/argument-propertybag-calendar-wrong-type.js @@ -5,36 +5,30 @@ esid: sec-temporal.plaindate.prototype.since description: > Appropriate error thrown when a calendar property from a property bag cannot - be converted to a calendar object or string + be converted to a calendar object features: [BigInt, Symbol, Temporal] ---*/ const instance = new Temporal.PlainDate(2000, 5, 2); -const primitiveTests = [ +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], - [1, "number that doesn't convert to a valid ISO string"], + [1, "number"], [1n, "bigint"], -]; - -for (const [calendar, description] of primitiveTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws( - typeof calendar === 'string' ? RangeError : TypeError, - () => instance.since(arg), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ + [19970327, "large number"], + [-19970327, "negative number"], + [1234567890, "very large integer"], [Symbol(), "symbol"], [{}, "object"], [new Temporal.Duration(), "duration instance"], ]; -for (const [calendar, description] of typeErrorTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(TypeError, () => instance.since(arg), `${description} is not a valid property bag and does not convert to a string`); +for (const [calendar, description] of wrongTypeTests) { + const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + TypeError, + () => instance.since(arg), + `${description} is not a valid calendar` + ); } diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-invalid-iso-string.js b/test/built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-invalid-iso-string.js new file mode 100644 index 0000000000..d763d1dd79 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-invalid-iso-string.js @@ -0,0 +1,23 @@ +// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.until +description: Invalid ISO string as calendar should throw RangeError +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDate(2000, 5, 2); + +const invalidStrings = [ + ["", "empty string"], +]; + +for (const [calendar, description] of invalidStrings) { + const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.until(arg), + `${description} is not a valid calendar ID` + ); +} 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 deleted file mode 100644 index a1af7e8ef9..0000000000 --- a/test/built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-number.js +++ /dev/null @@ -1,25 +0,0 @@ -// 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 not accepted -features: [Temporal] ----*/ - -const instance = new Temporal.PlainDate(1976, 11, 18); - -const numbers = [ - 1, - 19970327, - -19970327, - 1234567890, -]; -for (const calendar of numbers) { - const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; - assert.throws( - TypeError, - () => instance.until(arg), - "Numbers cannot be used as a calendar" - ); -} diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-wrong-type.js index 023184f7f7..d6ebfa7104 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-wrong-type.js @@ -9,33 +9,26 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const timeZone = "UTC"; const instance = new Temporal.PlainDate(2000, 5, 2); -const primitiveTests = [ +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], - [1, "number that doesn't convert to a valid ISO string"], + [1, "number"], [1n, "bigint"], -]; - -for (const [calendar, description] of primitiveTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws( - typeof calendar === 'string' ? RangeError : TypeError, - () => instance.until(arg), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ + [19970327, "large number"], + [-19970327, "negative number"], + [1234567890, "very large integer"], [Symbol(), "symbol"], [{}, "object"], [new Temporal.Duration(), "duration instance"], ]; -for (const [calendar, description] of typeErrorTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(TypeError, () => instance.until(arg), `${description} is not a valid property bag and does not convert to a string`); +for (const [calendar, description] of wrongTypeTests) { + const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + TypeError, + () => instance.until(arg), + `${description} is not a valid calendar` + ); } diff --git a/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-invalid-iso-string.js b/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-invalid-iso-string.js new file mode 100644 index 0000000000..fc31f54f59 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-invalid-iso-string.js @@ -0,0 +1,22 @@ +// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.withcalendar +description: Invalid ISO string as calendar should throw RangeError +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDate(1976, 11, 18, "iso8601"); + +const invalidStrings = [ + ["", "empty string"], +]; + +for (const [arg, description] of invalidStrings) { + assert.throws( + RangeError, + () => instance.withCalendar(arg), + `${description} is not a valid calendar ID` + ); +} diff --git a/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-number.js b/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-number.js deleted file mode 100644 index e0cfb96795..0000000000 --- a/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-number.js +++ /dev/null @@ -1,25 +0,0 @@ -// 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 not allowed to be a calendar -features: [Temporal] ----*/ - -const instance = new Temporal.PlainDate(1976, 11, 18, "iso8601"); - -const numbers = [ - 1, - -19761118, - 19761118, - 1234567890, -]; - -for (const arg of numbers) { - assert.throws( - TypeError, - () => instance.withCalendar(arg), - "A number is not a valid ISO string for Calendar" - ); -} diff --git a/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-wrong-type.js b/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-wrong-type.js index 944eec4a60..a8e7cb8f10 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-wrong-type.js @@ -11,28 +11,23 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.PlainDate(1976, 11, 18, "iso8601"); -const primitiveTests = [ +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], - [1, "number that doesn't convert to a valid ISO string"], + [1, "number"], [1n, "bigint"], -]; - -for (const [arg, description] of primitiveTests) { - assert.throws( - typeof arg === 'string' ? RangeError : TypeError, - () => instance.withCalendar(arg), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ + [-19761118, "negative number"], + [19761118, "large positive number"], + [1234567890, "very large integer"], [Symbol(), "symbol"], [{}, "object"], [new Temporal.Duration(), "duration instance"], ]; -for (const [arg, description] of typeErrorTests) { - assert.throws(TypeError, () => instance.withCalendar(arg), `${description} is not a valid object and does not convert to a string`); +for (const [arg, description] of wrongTypeTests) { + assert.throws( + TypeError, + () => instance.withCalendar(arg), + `${description} is not a valid calendar` + ); } diff --git a/test/built-ins/Temporal/PlainDateTime/calendar-invalid-iso-string.js b/test/built-ins/Temporal/PlainDateTime/calendar-invalid-iso-string.js new file mode 100644 index 0000000000..83d273376c --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/calendar-invalid-iso-string.js @@ -0,0 +1,21 @@ +// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.constructor +description: Various invalid ISO string values for calendar +features: [Temporal] +---*/ + +const invalidStrings = [ + ["", "empty string"], + ["1997-12-04[u-ca=iso8601]", "ISO string with calendar annotation"], +]; + +for (const [arg, description] of invalidStrings) { + assert.throws( + RangeError, + () => new Temporal.PlainDateTime(2000, 5, 2, 15, 23, 30, 987, 654, 321, arg), + `${description} is not a valid calendar ID` + ); +} diff --git a/test/built-ins/Temporal/PlainDateTime/calendar-iso-string.js b/test/built-ins/Temporal/PlainDateTime/calendar-iso-string.js deleted file mode 100644 index 4bc1431607..0000000000 --- a/test/built-ins/Temporal/PlainDateTime/calendar-iso-string.js +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (C) 2024 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.plaindatetime.constructor -description: An ISO string is not valid input for a constructor's calendar param -features: [Temporal] ----*/ - -assert.throws( - RangeError, - () => new Temporal.PlainDateTime(2000, 5, 2, 15, 23, 30, 987, 654, 321, "1997-12-04[u-ca=iso8601]"), - "An ISO string is not a valid calendar ID for constructor parameter" -); diff --git a/test/built-ins/Temporal/PlainDateTime/calendar-number.js b/test/built-ins/Temporal/PlainDateTime/calendar-number.js deleted file mode 100644 index 0c80c0d759..0000000000 --- a/test/built-ins/Temporal/PlainDateTime/calendar-number.js +++ /dev/null @@ -1,23 +0,0 @@ -// 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 not allowed to be a calendar -features: [Temporal] ----*/ - -const numbers = [ - 1, - -19761118, - 19761118, - 1234567890, -]; - -for (const arg of numbers) { - assert.throws( - TypeError, - () => new Temporal.PlainDateTime(2000, 5, 2, 15, 23, 30, 987, 654, 321, arg), - "A number is not a valid ISO string for Calendar" - ); -} diff --git a/test/built-ins/Temporal/PlainDateTime/calendar-wrong-type.js b/test/built-ins/Temporal/PlainDateTime/calendar-wrong-type.js index b76c42f717..986ede5c8f 100644 --- a/test/built-ins/Temporal/PlainDateTime/calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDateTime/calendar-wrong-type.js @@ -9,28 +9,23 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const primitiveTests = [ +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], - [1, "number that doesn't convert to a valid ISO string"], + [1, "number"], [1n, "bigint"], -]; - -for (const [arg, description] of primitiveTests) { - assert.throws( - typeof arg === 'string' ? RangeError : TypeError, - () => new Temporal.PlainDateTime(2000, 5, 2, 15, 23, 30, 987, 654, 321, arg), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ + [-19761118, "negative number"], + [19761118, "large positive number"], + [1234567890, "large integer"], [Symbol(), "symbol"], [{}, "object"], [new Temporal.Duration(), "duration instance"], ]; -for (const [arg, description] of typeErrorTests) { - assert.throws(TypeError, () => new Temporal.PlainDateTime(2000, 5, 2, 15, 23, 30, 987, 654, 321, arg), `${description} is not a valid object and does not convert to a string`); +for (const [arg, description] of wrongTypeTests) { + assert.throws( + TypeError, + () => new Temporal.PlainDateTime(2000, 5, 2, 15, 23, 30, 987, 654, 321, arg), + `${description} is not a valid calendar` + ); } diff --git a/test/built-ins/Temporal/PlainDateTime/compare/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainDateTime/compare/argument-propertybag-calendar-invalid-iso-string.js similarity index 51% rename from test/built-ins/Temporal/PlainDateTime/compare/argument-propertybag-calendar-number.js rename to test/built-ins/Temporal/PlainDateTime/compare/argument-propertybag-calendar-invalid-iso-string.js index 46de71cba4..5afccbfd00 100644 --- a/test/built-ins/Temporal/PlainDateTime/compare/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/PlainDateTime/compare/argument-propertybag-calendar-invalid-iso-string.js @@ -1,29 +1,26 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// Copyright (C) 2025 Brage Hogstad, University of Bergen. 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 not accepted +description: Invalid ISO string as calendar should throw RangeError features: [Temporal] ---*/ -const numbers = [ - 1, - 19970327, - -19970327, - 1234567890, +const invalidStrings = [ + ["", "empty string"], ]; - -for (const calendar of numbers) { + +for (const [calendar, description] of invalidStrings) { const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; assert.throws( - TypeError, + RangeError, () => Temporal.PlainDateTime.compare(arg, new Temporal.PlainDateTime(1976, 11, 18)), - "A number is not a valid ISO string for calendar (first argument)" + `${description} is not a valid calendar ID (first argument)` ); assert.throws( - TypeError, + RangeError, () => Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg), - "A number is not a valid ISO string for calendar (second argument)" + `${description} is not a valid calendar ID (second argument)` ); } diff --git a/test/built-ins/Temporal/PlainDateTime/compare/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainDateTime/compare/argument-propertybag-calendar-wrong-type.js index fae20dd9f1..45027c0247 100644 --- a/test/built-ins/Temporal/PlainDateTime/compare/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDateTime/compare/argument-propertybag-calendar-wrong-type.js @@ -9,36 +9,29 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const primitiveTests = [ +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], - [1, "number that doesn't convert to a valid ISO string"], + [1, "number"], [1n, "bigint"], -]; - -for (const [calendar, description] of primitiveTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws( - typeof calendar === "string" ? RangeError : TypeError, - () => Temporal.PlainDateTime.compare(arg, new Temporal.PlainDateTime(1976, 11, 18)), - `${description} does not convert to a valid ISO string (first argument)` - ); - assert.throws( - typeof calendar === "string" ? RangeError : TypeError, - () => Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg), - `${description} does not convert to a valid ISO string (second argument)` - ); -} - -const typeErrorTests = [ + [19970327, "large number"], + [-19970327, "negative number"], + [1234567890, "very large integer"], [Symbol(), "symbol"], [{}, "object"], [new Temporal.Duration(), "duration instance"], ]; -for (const [calendar, description] of typeErrorTests) { +for (const [calendar, description] of wrongTypeTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(TypeError, () => Temporal.PlainDateTime.compare(arg, new Temporal.PlainDateTime(1976, 11, 18)), `${description} is not a valid property bag and does not convert to a string (first argument)`); - assert.throws(TypeError, () => Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg), `${description} is not a valid property bag and does not convert to a string (second argument)`); + assert.throws( + TypeError, + () => Temporal.PlainDateTime.compare(arg, new Temporal.PlainDateTime(1976, 11, 18)), + `${description} is not a valid calendar (first argument)` + ); + assert.throws( + TypeError, + () => Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg), + `${description} is not a valid calendar (second argument)` + ); } diff --git a/test/built-ins/Temporal/PlainDateTime/from/argument-propertybag-calendar-invalid-iso-string.js b/test/built-ins/Temporal/PlainDateTime/from/argument-propertybag-calendar-invalid-iso-string.js new file mode 100644 index 0000000000..f1f56484fb --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/from/argument-propertybag-calendar-invalid-iso-string.js @@ -0,0 +1,21 @@ +// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.from +description: Various invalid ISO string values for calendar in a property bag +features: [Temporal] +---*/ + +const invalidStrings = [ + ["", "empty string"], +]; + +for (const [calendar, description] of invalidStrings) { + const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; + assert.throws( + RangeError, + () => Temporal.PlainDateTime.from(arg), + `${description} is not a valid calendar ID` + ); +} 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 deleted file mode 100644 index fad7828da9..0000000000 --- a/test/built-ins/Temporal/PlainDateTime/from/argument-propertybag-calendar-number.js +++ /dev/null @@ -1,24 +0,0 @@ -// 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 not accepted -features: [Temporal] ----*/ - -const numbers = [ - 1, - 19970327, - -19970327, - 1234567890, -]; - -for (const calendar of numbers) { - const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; - assert.throws( - TypeError, - () => Temporal.PlainDateTime.from(arg), - "Numbers cannot be used as a calendar" - ); -} diff --git a/test/built-ins/Temporal/PlainDateTime/from/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainDateTime/from/argument-propertybag-calendar-wrong-type.js index 092c83c9ea..91dba629ce 100644 --- a/test/built-ins/Temporal/PlainDateTime/from/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDateTime/from/argument-propertybag-calendar-wrong-type.js @@ -9,30 +9,24 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const primitiveTests = [ +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], - [1, "number that doesn't convert to a valid ISO string"], + [1, "number"], [1n, "bigint"], -]; - -for (const [calendar, description] of primitiveTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws( - typeof calendar === 'string' ? RangeError : TypeError, - () => Temporal.PlainDateTime.from(arg), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ + [19970327, "large number"], + [-19970327, "negative number"], + [1234567890, "very large integer"], [Symbol(), "symbol"], [{}, "object"], [new Temporal.Duration(), "duration instance"], ]; -for (const [calendar, description] of typeErrorTests) { +for (const [calendar, description] of wrongTypeTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(TypeError, () => Temporal.PlainDateTime.from(arg), `${description} is not a valid property bag and does not convert to a string`); + assert.throws( + TypeError, + () => Temporal.PlainDateTime.from(arg), + `${description} is not a valid calendar` + ); } diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-invalid-iso-string.js b/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-invalid-iso-string.js new file mode 100644 index 0000000000..93a37e8529 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-invalid-iso-string.js @@ -0,0 +1,23 @@ +// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.equals +description: Invalid ISO string as calendar should throw RangeError +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321); + +const invalidStrings = [ + ["", "empty string"], +]; + +for (const [calendar, description] of invalidStrings) { + const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.equals(arg), + `${description} is not a valid calendar ID` + ); +} 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 deleted file mode 100644 index beecb8c0f5..0000000000 --- a/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-number.js +++ /dev/null @@ -1,26 +0,0 @@ -// 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 not accepted -features: [Temporal] ----*/ - -const instance = new Temporal.PlainDateTime(1976, 11, 18); - -const numbers = [ - 1, - 19970327, - -19970327, - 1234567890, -]; - -for (const calendar of numbers) { - const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; - assert.throws( - TypeError, - () => instance.equals(arg), - "Numbers cannot be used as a calendar" - ); -} diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-wrong-type.js index 46f88bcd58..9e9690f241 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-wrong-type.js @@ -9,33 +9,26 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const timeZone = "UTC"; const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321); -const primitiveTests = [ +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], - [1, "number that doesn't convert to a valid ISO string"], + [1, "number"], [1n, "bigint"], -]; - -for (const [calendar, description] of primitiveTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws( - typeof calendar === 'string' ? RangeError : TypeError, - () => instance.equals(arg), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ + [19970327, "large number"], + [-19970327, "negative number"], + [1234567890, "very large integer"], [Symbol(), "symbol"], [{}, "object"], [new Temporal.Duration(), "duration instance"], ]; -for (const [calendar, description] of typeErrorTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(TypeError, () => instance.equals(arg), `${description} is not a valid property bag and does not convert to a string`); +for (const [calendar, description] of wrongTypeTests) { + const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + TypeError, + () => instance.equals(arg), + `${description} is not a valid calendar` + ); } diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-invalid-iso-string.js b/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-invalid-iso-string.js new file mode 100644 index 0000000000..e0cfcac102 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-invalid-iso-string.js @@ -0,0 +1,23 @@ +// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.since +description: Invalid ISO string as calendar should throw RangeError +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321); + +const invalidStrings = [ + ["", "empty string"], +]; + +for (const [calendar, description] of invalidStrings) { + const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.since(arg), + `${description} is not a valid calendar ID` + ); +} 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 deleted file mode 100644 index 866053f489..0000000000 --- a/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-number.js +++ /dev/null @@ -1,26 +0,0 @@ -// 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 not accepted -features: [Temporal] ----*/ - -const instance = new Temporal.PlainDateTime(1976, 11, 18); - -const numbers = [ - 1, - 19970327, - -19970327, - 1234567890, -]; - -for (const calendar of numbers) { - const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; - assert.throws( - TypeError, - () => instance.since(arg), - "Numbers cannot be used as a calendar" - ); -} diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-wrong-type.js index 745ea669a3..e98f60befc 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-wrong-type.js @@ -11,30 +11,24 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321); -const primitiveTests = [ +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], - [1, "number that doesn't convert to a valid ISO string"], + [1, "number"], [1n, "bigint"], -]; - -for (const [calendar, description] of primitiveTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws( - typeof calendar === 'string' ? RangeError : TypeError, - () => instance.since(arg), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ + [19970327, "large number"], + [-19970327, "negative number"], + [1234567890, "very large integer"], [Symbol(), "symbol"], [{}, "object"], [new Temporal.Duration(), "duration instance"], ]; -for (const [calendar, description] of typeErrorTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(TypeError, () => instance.since(arg), `${description} is not a valid property bag and does not convert to a string`); +for (const [calendar, description] of wrongTypeTests) { + const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + TypeError, + () => instance.since(arg), + `${description} is not a valid calendar` + ); } diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-invalid-iso-string.js b/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-invalid-iso-string.js new file mode 100644 index 0000000000..1276091226 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-invalid-iso-string.js @@ -0,0 +1,23 @@ +// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.until +description: Invalid ISO string as calendar should throw RangeError +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321); + +const invalidStrings = [ + ["", "empty string"], +]; + +for (const [calendar, description] of invalidStrings) { + const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => instance.until(arg), + `${description} is not a valid calendar ID` + ); +} 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 deleted file mode 100644 index 42eb452265..0000000000 --- a/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-number.js +++ /dev/null @@ -1,26 +0,0 @@ -// 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 not accepted -features: [Temporal] ----*/ - -const instance = new Temporal.PlainDateTime(1976, 11, 18); - -const numbers = [ - 1, - 19970327, - -19970327, - 1234567890, -]; - -for (const calendar of numbers) { - const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; - assert.throws( - TypeError, - () => instance.until(arg), - "Numbers cannot be used as a calendar" - ); -} diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-wrong-type.js index 05c7f85cb9..ccda8aa1b3 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/until/argument-propertybag-calendar-wrong-type.js @@ -9,33 +9,26 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const timeZone = "UTC"; const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321); -const primitiveTests = [ +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], - [1, "number that doesn't convert to a valid ISO string"], + [1, "number"], [1n, "bigint"], -]; - -for (const [calendar, description] of primitiveTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws( - typeof calendar === 'string' ? RangeError : TypeError, - () => instance.until(arg), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ + [19970327, "large number"], + [-19970327, "negative number"], + [1234567890, "very large integer"], [Symbol(), "symbol"], [{}, "object"], [new Temporal.Duration(), "duration instance"], ]; -for (const [calendar, description] of typeErrorTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(TypeError, () => instance.until(arg), `${description} is not a valid property bag and does not convert to a string`); +for (const [calendar, description] of wrongTypeTests) { + const arg = { year: 1976, monthCode: "M11", day: 18, calendar }; + assert.throws( + TypeError, + () => instance.until(arg), + `${description} is not a valid calendar` + ); } diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-number.js b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-invalid-iso-string.js similarity index 51% rename from test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-number.js rename to test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-invalid-iso-string.js index 2ea1291174..6531b58942 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-number.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-invalid-iso-string.js @@ -1,25 +1,22 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// Copyright (C) 2025 Brage Hogstad, University of Bergen. 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 not allowed to be a calendar +description: Invalid ISO 8601 string is not accepted as calendar features: [Temporal] ---*/ const instance = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, "iso8601"); -const numbers = [ - 1, - -19761118, - 19761118, - 1234567890, +const invalidStrings = [ + ["", "empty string"], ]; -for (const arg of numbers) { +for (const [arg, description] of invalidStrings) { assert.throws( - TypeError, + RangeError, () => instance.withCalendar(arg), - "A number is not a valid ISO string for Calendar" + `${description} is not a valid calendar ID` ); } diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-wrong-type.js b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-wrong-type.js index 14aad0c975..2eb77a2b2d 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/withCalendar/calendar-wrong-type.js @@ -11,28 +11,23 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, "iso8601"); -const primitiveTests = [ +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], [1, "number that doesn't convert to a valid ISO string"], [1n, "bigint"], -]; - -for (const [arg, description] of primitiveTests) { - assert.throws( - typeof arg === 'string' ? RangeError : TypeError, - () => instance.withCalendar(arg), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ + [19970327, "large number"], + [-19970327, "negative number"], + [1234567890, "very large integer"], [Symbol(), "symbol"], [{}, "object"], [new Temporal.Duration(), "duration instance"], ]; -for (const [arg, description] of typeErrorTests) { - assert.throws(TypeError, () => instance.withCalendar(arg), `${description} is not a valid object and does not convert to a string`); +for (const [arg, description] of wrongTypeTests) { + assert.throws( + TypeError, + () => instance.withCalendar(arg), + `${description} does not convert to a valid ISO string` + ); } diff --git a/test/built-ins/Temporal/PlainMonthDay/calendar-invalid-iso-string.js b/test/built-ins/Temporal/PlainMonthDay/calendar-invalid-iso-string.js new file mode 100644 index 0000000000..17ec6e7173 --- /dev/null +++ b/test/built-ins/Temporal/PlainMonthDay/calendar-invalid-iso-string.js @@ -0,0 +1,21 @@ +// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainmonthday.constructor +description: Various invalid ISO string values for calendar +features: [Temporal] +---*/ + +const invalidStrings = [ + ["", "empty string"], + ["1997-12-04[u-ca=iso8601]", "ISO string with calendar annotation"], +]; + +for (const [arg, description] of invalidStrings) { + assert.throws( + RangeError, + () => new Temporal.PlainMonthDay(12, 15, arg, 1972), + `${description} is not a valid calendar ID` + ); +} diff --git a/test/built-ins/Temporal/PlainMonthDay/calendar-iso-string.js b/test/built-ins/Temporal/PlainMonthDay/calendar-iso-string.js deleted file mode 100644 index 9affdf732f..0000000000 --- a/test/built-ins/Temporal/PlainMonthDay/calendar-iso-string.js +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (C) 2024 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.plainmonthday.constructor -description: An ISO string is not valid input for a constructor's calendar param -features: [Temporal] ----*/ - -assert.throws( - RangeError, - () => new Temporal.PlainMonthDay(12, 15, "1997-12-04[u-ca=iso8601]", 1972), - "An ISO string is not a valid calendar ID for constructor parameter" -); diff --git a/test/built-ins/Temporal/PlainMonthDay/calendar-number.js b/test/built-ins/Temporal/PlainMonthDay/calendar-number.js deleted file mode 100644 index 48d42b4ddc..0000000000 --- a/test/built-ins/Temporal/PlainMonthDay/calendar-number.js +++ /dev/null @@ -1,23 +0,0 @@ -// 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 not allowed to be a calendar -features: [Temporal] ----*/ - -const numbers = [ - 1, - -19761118, - 19761118, - 1234567890, -]; - -for (const arg of numbers) { - assert.throws( - TypeError, - () => new Temporal.PlainMonthDay(12, 15, arg, 1972), - "A number is not a valid ISO string for Calendar" - ); -} diff --git a/test/built-ins/Temporal/PlainMonthDay/calendar-wrong-type.js b/test/built-ins/Temporal/PlainMonthDay/calendar-wrong-type.js index 974ce17773..3b7ab5d89f 100644 --- a/test/built-ins/Temporal/PlainMonthDay/calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainMonthDay/calendar-wrong-type.js @@ -9,28 +9,23 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const primitiveTests = [ +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], - [1, "number that doesn't convert to a valid ISO string"], + [1, "number"], [1n, "bigint"], -]; - -for (const [arg, description] of primitiveTests) { - assert.throws( - typeof arg === 'string' ? RangeError : TypeError, - () => new Temporal.PlainMonthDay(12, 15, arg, 1972), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ + [-19761118, "negative number"], + [19761118, "large positive number"], + [1234567890, "large integer"], [Symbol(), "symbol"], [{}, "object"], [new Temporal.Duration(), "duration instance"], ]; -for (const [arg, description] of typeErrorTests) { - assert.throws(TypeError, () => new Temporal.PlainMonthDay(12, 15, arg, 1972), `${description} is not a valid object and does not convert to a string`); +for (const [arg, description] of wrongTypeTests) { + assert.throws( + TypeError, + () => new Temporal.PlainMonthDay(12, 15, arg, 1972), + `${description} is not a valid calendar` + ); } diff --git a/test/built-ins/Temporal/PlainMonthDay/from/argument-propertybag-calendar-invalid-iso-string.js b/test/built-ins/Temporal/PlainMonthDay/from/argument-propertybag-calendar-invalid-iso-string.js new file mode 100644 index 0000000000..fa76c111d8 --- /dev/null +++ b/test/built-ins/Temporal/PlainMonthDay/from/argument-propertybag-calendar-invalid-iso-string.js @@ -0,0 +1,21 @@ +// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainmonthday.from +description: Various invalid ISO string values for calendar in a property bag +features: [Temporal] +---*/ + +const invalidStrings = [ + ["", "empty string"], +]; + +for (const [calendar, description] of invalidStrings) { + const arg = { monthCode: "M11", day: 18, calendar }; + assert.throws( + RangeError, + () => Temporal.PlainMonthDay.from(arg), + `${description} is not a valid calendar ID` + ); +} diff --git a/test/built-ins/Temporal/PlainMonthDay/from/argument-propertybag-calendar-iso-string.js b/test/built-ins/Temporal/PlainMonthDay/from/argument-propertybag-calendar-iso-string.js index 249d41f1ff..734fdaabd1 100644 --- a/test/built-ins/Temporal/PlainMonthDay/from/argument-propertybag-calendar-iso-string.js +++ b/test/built-ins/Temporal/PlainMonthDay/from/argument-propertybag-calendar-iso-string.js @@ -1,4 +1,4 @@ -// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- 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 deleted file mode 100644 index 08a4c371b7..0000000000 --- a/test/built-ins/Temporal/PlainMonthDay/from/argument-propertybag-calendar-number.js +++ /dev/null @@ -1,24 +0,0 @@ -// 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 not accepted -features: [Temporal] ----*/ - -const numbers = [ - 1, - 19970327, - -19970327, - 1234567890, -]; - -for (const calendar of numbers) { - const arg = { monthCode: "M11", day: 18, calendar }; - assert.throws( - TypeError, - () => Temporal.PlainMonthDay.from(arg), - "Numbers cannot be used as a calendar" - ); -} diff --git a/test/built-ins/Temporal/PlainMonthDay/from/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainMonthDay/from/argument-propertybag-calendar-wrong-type.js index 9d182cf616..5561760b7d 100644 --- a/test/built-ins/Temporal/PlainMonthDay/from/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainMonthDay/from/argument-propertybag-calendar-wrong-type.js @@ -9,30 +9,24 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const primitiveTests = [ +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], - [1, "number that doesn't convert to a valid ISO string"], + [1, "number"], [1n, "bigint"], -]; - -for (const [calendar, description] of primitiveTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws( - typeof calendar === 'string' ? RangeError : TypeError, - () => Temporal.PlainMonthDay.from(arg), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ + [19970327, "large number"], + [-19970327, "negative number"], + [1234567890, "very large integer"], [Symbol(), "symbol"], [{}, "object"], [new Temporal.Duration(), "duration instance"], ]; -for (const [calendar, description] of typeErrorTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(TypeError, () => Temporal.PlainMonthDay.from(arg), `${description} is not a valid property bag and does not convert to a string`); +for (const [calendar, description] of wrongTypeTests) { + const arg = { monthCode: "M11", day: 18, calendar }; + assert.throws( + TypeError, + () => Temporal.PlainMonthDay.from(arg), + `${description} is not a valid calendar` + ); } diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-propertybag-calendar-invalid-iso-string.js b/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-propertybag-calendar-invalid-iso-string.js new file mode 100644 index 0000000000..54095c545d --- /dev/null +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-propertybag-calendar-invalid-iso-string.js @@ -0,0 +1,24 @@ +// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainmonthday.prototype.equals +description: > + A string value for calendar in a property bag that is not a valid calendar ID +features: [Temporal] +---*/ + +const instance = new Temporal.PlainMonthDay(5, 2); + +const invalidStrings = [ + ["", "empty string"], +]; + +for (const [calendar, description] of invalidStrings) { + const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; + assert.throws( + RangeError, + () => instance.equals(arg), + `${description} is not a valid calendar ID` + ); +} 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 deleted file mode 100644 index 7f49e1922d..0000000000 --- a/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-propertybag-calendar-number.js +++ /dev/null @@ -1,26 +0,0 @@ -// 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 not accepted -features: [Temporal] ----*/ - -const instance = new Temporal.PlainMonthDay(11, 18); - -const numbers = [ - 1, - 19970327, - -19970327, - 1234567890, -]; - -for (const calendar of numbers) { - const arg = { monthCode: "M11", day: 18, calendar }; - assert.throws( - TypeError, - () => instance.equals(arg), - "Numbers cannot be used as a calendar" - ); -} diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-propertybag-calendar-wrong-type.js index 6350e1b08a..19115e4192 100644 --- a/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/equals/argument-propertybag-calendar-wrong-type.js @@ -9,33 +9,26 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const timeZone = "UTC"; const instance = new Temporal.PlainMonthDay(5, 2); -const primitiveTests = [ +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], [1, "number that doesn't convert to a valid ISO string"], [1n, "bigint"], -]; - -for (const [calendar, description] of primitiveTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws( - typeof calendar === 'string' ? RangeError : TypeError, - () => instance.equals(arg), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ + [19970327, "large number"], + [-19970327, "negative number"], + [1234567890, "very large integer"], [Symbol(), "symbol"], [{}, "object"], [new Temporal.Duration(), "duration instance"], ]; -for (const [calendar, description] of typeErrorTests) { +for (const [calendar, description] of wrongTypeTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(TypeError, () => instance.equals(arg), `${description} is not a valid property bag and does not convert to a string`); + assert.throws( + TypeError, + () => instance.equals(arg), + `${description} does not convert to a valid ISO string` + ); } diff --git a/test/built-ins/Temporal/PlainYearMonth/calendar-invalid-iso-string.js b/test/built-ins/Temporal/PlainYearMonth/calendar-invalid-iso-string.js new file mode 100644 index 0000000000..59e257f7ec --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/calendar-invalid-iso-string.js @@ -0,0 +1,21 @@ +// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.constructor +description: Various invalid ISO string values for calendar +features: [Temporal] +---*/ + +const invalidStrings = [ + ["", "empty string"], + ["1997-12-04[u-ca=iso8601]", "ISO string with calendar annotation"], +]; + +for (const [arg, description] of invalidStrings) { + assert.throws( + RangeError, + () => new Temporal.PlainYearMonth(2000, 5, arg, 1), + `${description} is not a valid calendar ID` + ); +} diff --git a/test/built-ins/Temporal/PlainYearMonth/calendar-iso-string.js b/test/built-ins/Temporal/PlainYearMonth/calendar-iso-string.js deleted file mode 100644 index 5373947175..0000000000 --- a/test/built-ins/Temporal/PlainYearMonth/calendar-iso-string.js +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (C) 2024 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.plainyearmonth.constructor -description: An ISO string is not valid input for a constructor's calendar param -features: [Temporal] ----*/ - -assert.throws( - RangeError, - () => new Temporal.PlainYearMonth(2000, 5, "1997-12-04[u-ca=iso8601]", 1), - "An ISO string is not a valid calendar ID for constructor parameter" -); diff --git a/test/built-ins/Temporal/PlainYearMonth/calendar-number.js b/test/built-ins/Temporal/PlainYearMonth/calendar-number.js deleted file mode 100644 index 2c8875bef0..0000000000 --- a/test/built-ins/Temporal/PlainYearMonth/calendar-number.js +++ /dev/null @@ -1,23 +0,0 @@ -// 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 not allowed to be a calendar -features: [Temporal] ----*/ - -const numbers = [ - 1, - -19761118, - 19761118, - 1234567890, -]; - -for (const arg of numbers) { - assert.throws( - TypeError, - () => new Temporal.PlainYearMonth(2000, 5, arg, 1), - "A number is not a valid ISO string for Calendar" - ); -} diff --git a/test/built-ins/Temporal/PlainYearMonth/calendar-wrong-type.js b/test/built-ins/Temporal/PlainYearMonth/calendar-wrong-type.js index c5205e5508..4f954ee42a 100644 --- a/test/built-ins/Temporal/PlainYearMonth/calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainYearMonth/calendar-wrong-type.js @@ -9,28 +9,23 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const primitiveTests = [ +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], - [1, "number that doesn't convert to a valid ISO string"], + [1, "number"], [1n, "bigint"], -]; - -for (const [arg, description] of primitiveTests) { - assert.throws( - typeof arg === 'string' ? RangeError : TypeError, - () => new Temporal.PlainYearMonth(2000, 5, arg, 1), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ + [-19761118, "negative number"], + [19761118, "large positive number"], + [1234567890, "large integer"], [Symbol(), "symbol"], [{}, "object"], [new Temporal.Duration(), "duration instance"], ]; -for (const [arg, description] of typeErrorTests) { - assert.throws(TypeError, () => new Temporal.PlainYearMonth(2000, 5, arg, 1), `${description} is not a valid object and does not convert to a string`); +for (const [arg, description] of wrongTypeTests) { + assert.throws( + TypeError, + () => new Temporal.PlainYearMonth(2000, 5, arg, 1), + `${description} is not a valid calendar` + ); } diff --git a/test/built-ins/Temporal/PlainYearMonth/compare/argument-propertybag-calendar-number.js b/test/built-ins/Temporal/PlainYearMonth/compare/argument-propertybag-calendar-invalid-iso-string.js similarity index 50% rename from test/built-ins/Temporal/PlainYearMonth/compare/argument-propertybag-calendar-number.js rename to test/built-ins/Temporal/PlainYearMonth/compare/argument-propertybag-calendar-invalid-iso-string.js index 1a7884cf79..599237571e 100644 --- a/test/built-ins/Temporal/PlainYearMonth/compare/argument-propertybag-calendar-number.js +++ b/test/built-ins/Temporal/PlainYearMonth/compare/argument-propertybag-calendar-invalid-iso-string.js @@ -1,29 +1,26 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// Copyright (C) 2025 Brage Hogstad, University of Bergen. 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 not accepted +description: Invalid ISO string as calendar should throw RangeError features: [Temporal] ---*/ -const numbers = [ - 1, - 19970327, - -19970327, - 1234567890, +const invalidStrings = [ + ["", "empty string"], ]; - -for (const calendar of numbers) { + +for (const [calendar, description] of invalidStrings) { const arg = { year: 2019, monthCode: "M06", calendar }; assert.throws( - TypeError, + RangeError, () => Temporal.PlainYearMonth.compare(arg, new Temporal.PlainYearMonth(2019, 6)), - "A number is not a valid ISO string for calendar (first argument)" + `${description} is not a valid calendar ID (first argument)` ); assert.throws( - TypeError, + RangeError, () => Temporal.PlainYearMonth.compare(new Temporal.PlainYearMonth(2019, 6), arg), - "A number is not a valid ISO string for calendar (second argument)" + `${description} is not a valid calendar ID (second argument)` ); } diff --git a/test/built-ins/Temporal/PlainYearMonth/compare/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainYearMonth/compare/argument-propertybag-calendar-wrong-type.js index ad971ae72b..29b738509b 100644 --- a/test/built-ins/Temporal/PlainYearMonth/compare/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainYearMonth/compare/argument-propertybag-calendar-wrong-type.js @@ -9,36 +9,29 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const primitiveTests = [ +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], - [1, "number that doesn't convert to a valid ISO string"], + [1, "number"], [1n, "bigint"], -]; - -for (const [calendar, description] of primitiveTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws( - typeof calendar === "string" ? RangeError : TypeError, - () => Temporal.PlainYearMonth.compare(arg, new Temporal.PlainYearMonth(2019, 6)), - `${description} does not convert to a valid ISO string (first argument)` - ); - assert.throws( - typeof calendar === "string" ? RangeError : TypeError, - () => Temporal.PlainYearMonth.compare(new Temporal.PlainYearMonth(2019, 6), arg), - `${description} does not convert to a valid ISO string (second argument)` - ); -} - -const typeErrorTests = [ + [19970327, "large number"], + [-19970327, "negative number"], + [1234567890, "very large integer"], [Symbol(), "symbol"], [{}, "object"], [new Temporal.Duration(), "duration instance"], ]; -for (const [calendar, description] of typeErrorTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(TypeError, () => Temporal.PlainYearMonth.compare(arg, new Temporal.PlainYearMonth(2019, 6)), `${description} is not a valid property bag and does not convert to a string (first argument)`); - assert.throws(TypeError, () => Temporal.PlainYearMonth.compare(new Temporal.PlainYearMonth(2019, 6), arg), `${description} is not a valid property bag and does not convert to a string (second argument)`); +for (const [calendar, description] of wrongTypeTests) { + const arg = { year: 2019, monthCode: "M06", calendar }; + assert.throws( + TypeError, + () => Temporal.PlainYearMonth.compare(arg, new Temporal.PlainYearMonth(2019, 6)), + `${description} is not a valid calendar (first argument)` + ); + assert.throws( + TypeError, + () => Temporal.PlainYearMonth.compare(new Temporal.PlainYearMonth(2019, 6), arg), + `${description} is not a valid calendar (second argument)` + ); } diff --git a/test/built-ins/Temporal/PlainYearMonth/from/argument-propertybag-calendar-invalid-iso-string.js b/test/built-ins/Temporal/PlainYearMonth/from/argument-propertybag-calendar-invalid-iso-string.js new file mode 100644 index 0000000000..6cf3012544 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/from/argument-propertybag-calendar-invalid-iso-string.js @@ -0,0 +1,21 @@ +// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.from +description: Various invalid ISO string values for calendar in a property bag +features: [Temporal] +---*/ + +const invalidStrings = [ + ["", "empty string"], +]; + +for (const [calendar, description] of invalidStrings) { + const arg = { year: 2019, monthCode: "M11", calendar }; + assert.throws( + RangeError, + () => Temporal.PlainYearMonth.from(arg), + `${description} is not a valid calendar ID` + ); +} 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 deleted file mode 100644 index 8b5fec5911..0000000000 --- a/test/built-ins/Temporal/PlainYearMonth/from/argument-propertybag-calendar-number.js +++ /dev/null @@ -1,24 +0,0 @@ -// 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 not accepted -features: [Temporal] ----*/ - -const numbers = [ - 1, - 19970327, - -19970327, - 1234567890, -]; - -for (const calendar of numbers) { - const arg = { year: 2019, monthCode: "M06", calendar }; - assert.throws( - TypeError, - () => Temporal.PlainYearMonth.from(arg), - "Numbers cannot be used as a calendar" - ); -} diff --git a/test/built-ins/Temporal/PlainYearMonth/from/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainYearMonth/from/argument-propertybag-calendar-wrong-type.js index 13f11f91de..b92de9a427 100644 --- a/test/built-ins/Temporal/PlainYearMonth/from/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainYearMonth/from/argument-propertybag-calendar-wrong-type.js @@ -9,30 +9,24 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const primitiveTests = [ +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], - [1, "number that doesn't convert to a valid ISO string"], + [1, "number"], [1n, "bigint"], -]; - -for (const [calendar, description] of primitiveTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws( - typeof calendar === 'string' ? RangeError : TypeError, - () => Temporal.PlainYearMonth.from(arg), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ + [19970327, "large number"], + [-19970327, "negative number"], + [1234567890, "very large integer"], [Symbol(), "symbol"], [{}, "object"], [new Temporal.Duration(), "duration instance"], ]; -for (const [calendar, description] of typeErrorTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(TypeError, () => Temporal.PlainYearMonth.from(arg), `${description} is not a valid property bag and does not convert to a string`); +for (const [calendar, description] of wrongTypeTests) { + const arg = { year: 2019, monthCode: "M11", calendar }; + assert.throws( + TypeError, + () => Temporal.PlainYearMonth.from(arg), + `${description} is not a valid calendar` + ); } diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-propertybag-calendar-invalid-iso-string.js b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-propertybag-calendar-invalid-iso-string.js new file mode 100644 index 0000000000..050d6866d2 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-propertybag-calendar-invalid-iso-string.js @@ -0,0 +1,25 @@ +// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.prototype.equals +description: > + Appropriate error thrown when a calendar property from a property bag cannot + be converted to a calendar ID +features: [BigInt, Symbol, Temporal] +---*/ + +const instance = new Temporal.PlainYearMonth(2000, 5); + +const primitiveTests = [ + ["", "empty string"] +]; + +for (const [calendar, description] of primitiveTests) { + const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; + assert.throws( + RangeError, + () => instance.equals(arg), + `${description} does not convert to a valid ISO string` + ); +} 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 deleted file mode 100644 index 21be48be03..0000000000 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-propertybag-calendar-number.js +++ /dev/null @@ -1,26 +0,0 @@ -// 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 not accepted -features: [Temporal] ----*/ - -const instance = new Temporal.PlainYearMonth(2019, 6); - -const numbers = [ - 1, - 19970327, - -19970327, - 1234567890, -]; - -for (const calendar of numbers) { - const arg = { year: 2019, monthCode: "M06", calendar }; - assert.throws( - TypeError, - () => instance.equals(arg), - "Numbers cannot be used as a calendar" - ); -} diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-propertybag-calendar-wrong-type.js index e6851f931a..4ac01acbd7 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/equals/argument-propertybag-calendar-wrong-type.js @@ -9,33 +9,26 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const timeZone = "UTC"; const instance = new Temporal.PlainYearMonth(2000, 5); -const primitiveTests = [ +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], [1, "number that doesn't convert to a valid ISO string"], [1n, "bigint"], -]; - -for (const [calendar, description] of primitiveTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws( - typeof calendar === 'string' ? RangeError : TypeError, - () => instance.equals(arg), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ + [19970327, "large positive number"], + [-19970327, "negative number"], + [1234567890, "very large integer"], [Symbol(), "symbol"], [{}, "object"], [new Temporal.Duration(), "duration instance"], ]; -for (const [calendar, description] of typeErrorTests) { +for (const [calendar, description] of wrongTypeTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(TypeError, () => instance.equals(arg), `${description} is not a valid property bag and does not convert to a string`); + assert.throws( + TypeError, + () => instance.equals(arg), + `${description} does not convert to a valid ISO string` + ); } diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-propertybag-calendar-invalid-iso-string.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-propertybag-calendar-invalid-iso-string.js new file mode 100644 index 0000000000..46348f1869 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-propertybag-calendar-invalid-iso-string.js @@ -0,0 +1,24 @@ +// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.prototype.since +description: > + An ISO string that cannot be converted to a calendar ID should throw a RangeError +features: [Temporal] +---*/ + +const instance = new Temporal.PlainYearMonth(2000, 5); + +const invalidStrings = [ + ["", "empty string"], +]; + +for (const [calendar, description] of invalidStrings) { + const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; + assert.throws( + RangeError, + () => instance.since(arg), + `${description} is not a valid calendar ID` + ); +} 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 deleted file mode 100644 index 07cec8d784..0000000000 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-propertybag-calendar-number.js +++ /dev/null @@ -1,26 +0,0 @@ -// 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 not accepted -features: [Temporal] ----*/ - -const instance = new Temporal.PlainYearMonth(2019, 6); - -const numbers = [ - 1, - 19970327, - -19970327, - 1234567890, -]; - -for (const calendar of numbers) { - const arg = { year: 2019, monthCode: "M06", calendar }; - assert.throws( - TypeError, - () => instance.since(arg), - "Numbers cannot be used as a calendar" - ); -} diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-propertybag-calendar-wrong-type.js index b09dd90991..4329f48cfa 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/argument-propertybag-calendar-wrong-type.js @@ -11,30 +11,24 @@ features: [BigInt, Symbol, Temporal] const instance = new Temporal.PlainYearMonth(2000, 5); -const primitiveTests = [ +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], [1, "number that doesn't convert to a valid ISO string"], [1n, "bigint"], -]; - -for (const [calendar, description] of primitiveTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws( - typeof calendar === 'string' ? RangeError : TypeError, - () => instance.since(arg), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ + [19970327, "large positive number"], + [-19970327, "negative number"], + [1234567890, "very large integer"], [Symbol(), "symbol"], [{}, "object"], [new Temporal.Duration(), "duration instance"], ]; -for (const [calendar, description] of typeErrorTests) { +for (const [calendar, description] of wrongTypeTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(TypeError, () => instance.since(arg), `${description} is not a valid property bag and does not convert to a string`); + assert.throws( + TypeError, + () => instance.since(arg), + `${description} does not convert to a valid ISO string` + ); } diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-propertybag-calendar-invalid-iso-string.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-propertybag-calendar-invalid-iso-string.js new file mode 100644 index 0000000000..05861ccf72 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-propertybag-calendar-invalid-iso-string.js @@ -0,0 +1,24 @@ +// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.prototype.until +description: > + An ISO string that cannot be converted to a calendar ID should throw a RangeError +features: [Temporal] +---*/ + +const instance = new Temporal.PlainYearMonth(2000, 5); + +const invalidStrings = [ + ["", "empty string"] +]; + +for (const [calendar, description] of invalidStrings) { + const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; + assert.throws( + RangeError, + () => instance.until(arg), + `${description} is not a valid calendar ID` + ); +} 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 deleted file mode 100644 index af85b1d212..0000000000 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-propertybag-calendar-number.js +++ /dev/null @@ -1,26 +0,0 @@ -// 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 not accepted -features: [Temporal] ----*/ - -const instance = new Temporal.PlainYearMonth(2019, 6); - -const numbers = [ - 1, - 19970327, - -19970327, - 1234567890, -]; - -for (const calendar of numbers) { - const arg = { year: 2019, monthCode: "M06", calendar }; - assert.throws( - TypeError, - () => instance.until(arg), - "Numbers cannot be used as a calendar" - ); -} diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-propertybag-calendar-wrong-type.js index d60b9a93ca..a2bd9a3361 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/argument-propertybag-calendar-wrong-type.js @@ -9,33 +9,26 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const timeZone = "UTC"; const instance = new Temporal.PlainYearMonth(2000, 5); -const primitiveTests = [ +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], [1, "number that doesn't convert to a valid ISO string"], [1n, "bigint"], -]; - -for (const [calendar, description] of primitiveTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws( - typeof calendar === 'string' ? RangeError : TypeError, - () => instance.until(arg), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ + [19970327, "large positive number"], + [-19970327, "large negative number"], + [1234567890, "very large integer"], [Symbol(), "symbol"], [{}, "object"], [new Temporal.Duration(), "duration instance"], ]; -for (const [calendar, description] of typeErrorTests) { +for (const [calendar, description] of wrongTypeTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(TypeError, () => instance.until(arg), `${description} is not a valid property bag and does not convert to a string`); + assert.throws( + TypeError, + () => instance.until(arg), + `${description} does not convert to a valid ISO string` + ); } diff --git a/test/built-ins/Temporal/ZonedDateTime/calendar-invalid-iso-string.js b/test/built-ins/Temporal/ZonedDateTime/calendar-invalid-iso-string.js new file mode 100644 index 0000000000..c199b717fb --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/calendar-invalid-iso-string.js @@ -0,0 +1,21 @@ +// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.constructor +description: Various invalid ISO string values for calendar +features: [Temporal] +---*/ + +const invalidStrings = [ + ["", "empty string"], + ["1997-12-04[u-ca=iso8601]", "ISO string with calendar annotation"], +]; + +for (const [arg, description] of invalidStrings) { + assert.throws( + RangeError, + () => new Temporal.ZonedDateTime(0n, "UTC", arg), + `${description} is not a valid calendar ID` + ); +} diff --git a/test/built-ins/Temporal/ZonedDateTime/calendar-iso-string.js b/test/built-ins/Temporal/ZonedDateTime/calendar-iso-string.js deleted file mode 100644 index d47b0ec013..0000000000 --- a/test/built-ins/Temporal/ZonedDateTime/calendar-iso-string.js +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (C) 2024 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.zoneddatetime.constructor -description: An ISO string is not valid input for a constructor's calendar param -features: [Temporal] ----*/ - -assert.throws( - RangeError, - () => new Temporal.ZonedDateTime(0n, "UTC", "1997-12-04[u-ca=iso8601]"), - "An ISO string is not a valid calendar ID for constructor parameter" -); diff --git a/test/built-ins/Temporal/ZonedDateTime/calendar-number.js b/test/built-ins/Temporal/ZonedDateTime/calendar-number.js deleted file mode 100644 index 0edb6e4650..0000000000 --- a/test/built-ins/Temporal/ZonedDateTime/calendar-number.js +++ /dev/null @@ -1,23 +0,0 @@ -// 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 not allowed to be a calendar -features: [Temporal] ----*/ - -const numbers = [ - 1, - -19761118, - 19761118, - 1234567890, -]; - -for (const arg of numbers) { - assert.throws( - TypeError, - () => new Temporal.ZonedDateTime(0n, "UTC", arg), - "A number is not a valid ISO string for Calendar" - ); -} diff --git a/test/built-ins/Temporal/ZonedDateTime/calendar-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/calendar-wrong-type.js index 7483befa10..cf7157847f 100644 --- a/test/built-ins/Temporal/ZonedDateTime/calendar-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/calendar-wrong-type.js @@ -9,28 +9,23 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const primitiveTests = [ +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], - [1, "number that doesn't convert to a valid ISO string"], + [1, "number"], [1n, "bigint"], -]; - -for (const [arg, description] of primitiveTests) { - assert.throws( - typeof arg === 'string' ? RangeError : TypeError, - () => new Temporal.ZonedDateTime(0n, "UTC", arg), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ + [-19761118, "negative number"], + [19761118, "large positive number"], + [1234567890, "large integer"], [Symbol(), "symbol"], [{}, "object"], [new Temporal.Duration(), "duration instance"], ]; -for (const [arg, description] of typeErrorTests) { - assert.throws(TypeError, () => new Temporal.ZonedDateTime(0n, "UTC", arg), `${description} is not a valid object and does not convert to a string`); +for (const [arg, description] of wrongTypeTests) { + assert.throws( + TypeError, + () => new Temporal.ZonedDateTime(0n, "UTC", arg), + `${description} is not a valid calendar` + ); } diff --git a/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-calendar-invalid-iso-string.js b/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-calendar-invalid-iso-string.js new file mode 100644 index 0000000000..477a910903 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-calendar-invalid-iso-string.js @@ -0,0 +1,28 @@ +// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.compare +description: Invalid ISO string as calendar should throw RangeError +features: [Temporal] +---*/ + +const datetime = new Temporal.ZonedDateTime(0n, "UTC"); + +const invalidStrings = [ + ["", "empty string"], +]; + +for (const [calendar, description] of invalidStrings) { + const arg = { year: 1970, monthCode: "M01", day: 1, calendar, timeZone: "UTC" }; + assert.throws( + RangeError, + () => Temporal.ZonedDateTime.compare(arg, datetime), + `${description} is not a valid calendar ID (first argument)` + ); + assert.throws( + RangeError, + () => Temporal.ZonedDateTime.compare(datetime, arg), + `${description} is not a valid calendar ID (second argument)` + ); +} 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 deleted file mode 100644 index c681c39c30..0000000000 --- a/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-calendar-number.js +++ /dev/null @@ -1,32 +0,0 @@ -// 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 not accepted -features: [Temporal] ----*/ - -const timeZone = "UTC"; -const datetime = new Temporal.ZonedDateTime(0n, timeZone); - -const numbers = [ - 1, - 19970327, - -19970327, - 1234567890, -]; - -for (const calendar of numbers) { - const arg = { year: 1970, monthCode: "M01", day: 1, calendar, timeZone }; - assert.throws( - TypeError, - () => Temporal.ZonedDateTime.compare(arg, datetime), - "A number is not a valid ISO string for calendar (first argument)" - ); - assert.throws( - TypeError, - () => Temporal.ZonedDateTime.compare(datetime, arg), - "A number is not a valid ISO string for calendar (second argument)" - ); -} diff --git a/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-calendar-wrong-type.js index 4dc45c4239..6b5dc7f66e 100644 --- a/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-calendar-wrong-type.js @@ -11,36 +11,29 @@ features: [BigInt, Symbol, Temporal] const datetime = new Temporal.ZonedDateTime(0n, "UTC"); -const primitiveTests = [ +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], - [1, "number that doesn't convert to a valid ISO string"], + [1, "number"], [1n, "bigint"], -]; - -for (const [calendar, description] of primitiveTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws( - typeof calendar === "string" ? RangeError : TypeError, - () => Temporal.ZonedDateTime.compare(arg, datetime), - `${description} does not convert to a valid ISO string (first argument)` - ); - assert.throws( - typeof calendar === "string" ? RangeError : TypeError, - () => Temporal.ZonedDateTime.compare(datetime, arg), - `${description} does not convert to a valid ISO string (second argument)` - ); -} - -const typeErrorTests = [ + [19970327, "large number"], + [-19970327, "negative number"], + [1234567890, "very large integer"], [Symbol(), "symbol"], [{}, "object"], [new Temporal.Duration(), "duration instance"], ]; -for (const [calendar, description] of typeErrorTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(TypeError, () => Temporal.ZonedDateTime.compare(arg, datetime), `${description} is not a valid property bag and does not convert to a string (first argument)`); - assert.throws(TypeError, () => Temporal.ZonedDateTime.compare(datetime, arg), `${description} is not a valid property bag and does not convert to a string (second argument)`); +for (const [calendar, description] of wrongTypeTests) { + const arg = { year: 1970, monthCode: "M01", day: 1, calendar, timeZone: "UTC" }; + assert.throws( + TypeError, + () => Temporal.ZonedDateTime.compare(arg, datetime), + `${description} is not a valid calendar (first argument)` + ); + assert.throws( + TypeError, + () => Temporal.ZonedDateTime.compare(datetime, arg), + `${description} is not a valid calendar (second argument)` + ); } diff --git a/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-calendar-invalid-iso-string.js b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-calendar-invalid-iso-string.js new file mode 100644 index 0000000000..58359756cb --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-calendar-invalid-iso-string.js @@ -0,0 +1,23 @@ +// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.from +description: Various invalid ISO string values for calendar in a property bag +features: [Temporal] +---*/ + +const timeZone = "UTC"; + +const invalidStrings = [ + ["", "empty string"], +]; + +for (const [calendar, description] of invalidStrings) { + const arg = { year: 1970, monthCode: "M01", day: 1, timeZone, calendar }; + assert.throws( + RangeError, + () => Temporal.ZonedDateTime.from(arg), + `${description} is not a valid calendar ID` + ); +} 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 deleted file mode 100644 index 97dc4d646f..0000000000 --- a/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-calendar-number.js +++ /dev/null @@ -1,25 +0,0 @@ -// 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 not accepted -features: [Temporal] ----*/ -const timeZone = "UTC"; - -const numbers = [ - 1, - 19970327, - -19970327, - 1234567890, -]; - -for (const calendar of numbers) { - const arg = { year: 1970, monthCode: "M01", day: 1, timeZone, calendar }; - assert.throws( - TypeError, - () => Temporal.ZonedDateTime.from(arg), - "Numbers cannot be used as a calendar" - ); -} diff --git a/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-calendar-wrong-type.js index 7af5110605..4565a5845b 100644 --- a/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-calendar-wrong-type.js @@ -9,30 +9,25 @@ description: > features: [BigInt, Symbol, Temporal] ---*/ -const primitiveTests = [ +const timeZone = "UTC"; +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], - [1, "number that doesn't convert to a valid ISO string"], + [1, "number"], [1n, "bigint"], -]; - -for (const [calendar, description] of primitiveTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws( - typeof calendar === 'string' ? RangeError : TypeError, - () => Temporal.ZonedDateTime.from(arg), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ + [19970327, "large number"], + [-19970327, "negative number"], + [1234567890, "very large integer"], [Symbol(), "symbol"], [{}, "object"], [new Temporal.Duration(), "duration instance"], ]; -for (const [calendar, description] of typeErrorTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(TypeError, () => Temporal.ZonedDateTime.from(arg), `${description} is not a valid property bag and does not convert to a string`); +for (const [calendar, description] of wrongTypeTests) { + const arg = { year: 1970, monthCode: "M01", day: 1, timeZone, calendar }; + assert.throws( + TypeError, + () => Temporal.ZonedDateTime.from(arg), + `${description} is not a valid calendar` + ); } diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-calendar-invalid-iso-string.js b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-calendar-invalid-iso-string.js new file mode 100644 index 0000000000..49f8aee494 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-calendar-invalid-iso-string.js @@ -0,0 +1,25 @@ +// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.equals +description: > + An ISO string that cannot be converted to a calendar ID should throw a RangeError +features: [Temporal] +---*/ + +const timeZone = "UTC"; +const instance = new Temporal.ZonedDateTime(0n, timeZone); + +const invalidStrings = [ + ["", "empty string"] +]; + +for (const [calendar, description] of invalidStrings) { + const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; + assert.throws( + RangeError, + () => instance.equals(arg), + `${description} is not a valid calendar ID` + ); +} 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 deleted file mode 100644 index a975129dfb..0000000000 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-calendar-number.js +++ /dev/null @@ -1,27 +0,0 @@ -// 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 not accepted -features: [Temporal] ----*/ - -const timeZone = "UTC"; -const instance = new Temporal.ZonedDateTime(0n, timeZone); - -const numbers = [ - 1, - 19970327, - -19970327, - 1234567890, -]; - -for (const calendar of numbers) { - const arg = { year: 1970, monthCode: "M01", day: 1, timeZone, calendar }; - assert.throws( - TypeError, - () => instance.equals(arg), - "Numbers cannot be used as a calendar" - ); -} diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-calendar-wrong-type.js index 5c75ee186a..3dc8f562fa 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-calendar-wrong-type.js @@ -15,27 +15,21 @@ const instance = new Temporal.ZonedDateTime(0n, timeZone); const primitiveTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], [1, "number that doesn't convert to a valid ISO string"], [1n, "bigint"], -]; - -for (const [calendar, description] of primitiveTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws( - typeof calendar === 'string' ? RangeError : TypeError, - () => instance.equals(arg), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ + [19970327, "large number"], + [-19970327, "negative number"], + [1234567890, "very large integer"], [Symbol(), "symbol"], [{}, "object"], [new Temporal.Duration(), "duration instance"], ]; -for (const [calendar, description] of typeErrorTests) { +for (const [calendar, description] of primitiveTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(TypeError, () => instance.equals(arg), `${description} is not a valid property bag and does not convert to a string`); + assert.throws( + TypeError, + () => instance.equals(arg), + `${description} does not convert to a valid ISO string` + ); } diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-calendar-invalid-iso-string.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-calendar-invalid-iso-string.js new file mode 100644 index 0000000000..59462ea3f1 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-calendar-invalid-iso-string.js @@ -0,0 +1,25 @@ +// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.since +description: > + An ISO string that cannot be converted to a calendar ID should throw a RangeError +features: [Temporal] +---*/ + +const timeZone = "UTC"; +const instance = new Temporal.ZonedDateTime(0n, timeZone); + +const invalidStrings = [ + ["", "empty string"] +]; + +for (const [calendar, description] of invalidStrings) { + const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; + assert.throws( + RangeError, + () => instance.since(arg), + `${description} is not a valid calendar ID` + ); +} 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 deleted file mode 100644 index 49ce7c5ad9..0000000000 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-calendar-number.js +++ /dev/null @@ -1,27 +0,0 @@ -// 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 not accepted -features: [Temporal] ----*/ - -const timeZone = "UTC"; -const instance = new Temporal.ZonedDateTime(0n, timeZone); - -const numbers = [ - 1, - 19970327, - -19970327, - 1234567890, -]; - -for (const calendar of numbers) { - const arg = { year: 1970, monthCode: "M01", day: 1, timeZone, calendar }; - assert.throws( - TypeError, - () => instance.since(arg), - "Numbers cannot be used as a calendar" - ); -} diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-calendar-wrong-type.js index 6ba45bec1f..014f3568a3 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-calendar-wrong-type.js @@ -12,30 +12,24 @@ features: [BigInt, Symbol, Temporal] const timeZone = "UTC"; const instance = new Temporal.ZonedDateTime(0n, timeZone); -const primitiveTests = [ +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], [1, "number that doesn't convert to a valid ISO string"], [1n, "bigint"], -]; - -for (const [calendar, description] of primitiveTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws( - typeof calendar === 'string' ? RangeError : TypeError, - () => instance.since(arg), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ + [19970327, "large number"], + [-19970327, "negative number"], + [1234567890, "very large integer"], [Symbol(), "symbol"], [{}, "object"], [new Temporal.Duration(), "duration instance"], ]; -for (const [calendar, description] of typeErrorTests) { +for (const [calendar, description] of wrongTypeTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(TypeError, () => instance.since(arg), `${description} is not a valid property bag and does not convert to a string`); + assert.throws( + TypeError, + () => instance.since(arg), + `${description} does not convert to a valid ISO string` + ); } diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-calendar-invalid-iso-string.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-calendar-invalid-iso-string.js new file mode 100644 index 0000000000..2228097958 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-calendar-invalid-iso-string.js @@ -0,0 +1,25 @@ +// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.until +description: > + An ISO string that cannot be converted to a calendar ID should throw a RangeError +features: [Temporal] +---*/ + +const timeZone = "UTC"; +const instance = new Temporal.ZonedDateTime(0n, timeZone); + +const invalidStrings = [ + ["", "empty string"] +]; + +for (const [calendar, description] of invalidStrings) { + const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; + assert.throws( + RangeError, + () => instance.until(arg), + `${description} is not a valid calendar ID` + ); +} 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 deleted file mode 100644 index c3a0450817..0000000000 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-calendar-number.js +++ /dev/null @@ -1,27 +0,0 @@ -// 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 not accepted -features: [Temporal] ----*/ - -const timeZone = "UTC"; -const instance = new Temporal.ZonedDateTime(0n, timeZone); - -const numbers = [ - 1, - 19970327, - -19970327, - 1234567890, -]; - -for (const calendar of numbers) { - const arg = { year: 1970, monthCode: "M01", day: 1, timeZone, calendar }; - assert.throws( - TypeError, - () => instance.until(arg), - "Numbers cannot be used as a calendar" - ); -} diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-calendar-wrong-type.js index 79c80d3f2c..dde24b9baa 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-calendar-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-calendar-wrong-type.js @@ -12,30 +12,24 @@ features: [BigInt, Symbol, Temporal] const timeZone = "UTC"; const instance = new Temporal.ZonedDateTime(0n, timeZone); -const primitiveTests = [ +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], [1, "number that doesn't convert to a valid ISO string"], [1n, "bigint"], -]; - -for (const [calendar, description] of primitiveTests) { - const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws( - typeof calendar === 'string' ? RangeError : TypeError, - () => instance.until(arg), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ + [19970327, "large number"], + [-19970327, "negative number"], + [1234567890, "very large integer"], [Symbol(), "symbol"], [{}, "object"], [new Temporal.Duration(), "duration instance"], ]; -for (const [calendar, description] of typeErrorTests) { +for (const [calendar, description] of wrongTypeTests) { const arg = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(TypeError, () => instance.until(arg), `${description} is not a valid property bag and does not convert to a string`); + assert.throws( + TypeError, + () => instance.until(arg), + `${description} does not convert to a valid ISO string` + ); } diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-invalid-iso-string.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-invalid-iso-string.js new file mode 100644 index 0000000000..d9073b729b --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-invalid-iso-string.js @@ -0,0 +1,23 @@ +// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.withcalendar +description: > + An ISO string that cannot be converted to a calendar ID should throw a RangeError +features: [Temporal] +---*/ + +const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", "iso8601"); + +const invalidStrings = [ + ["", "empty string"] +]; + +for (const [arg, description] of invalidStrings) { + assert.throws( + RangeError, + () => instance.withCalendar(arg), + `${description} is not a valid calendar ID` + ); +} diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-number.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-number.js deleted file mode 100644 index 36a4a68857..0000000000 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-number.js +++ /dev/null @@ -1,25 +0,0 @@ -// 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 not allowed to be a calendar -features: [Temporal] ----*/ - -const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", "iso8601"); - -const numbers = [ - 1, - -19761118, - 19761118, - 1234567890, -]; - -for (const arg of numbers) { - assert.throws( - TypeError, - () => instance.withCalendar(arg), - "A number is not a valid ISO string for Calendar" - ); -} diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-wrong-type.js b/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-wrong-type.js index b4a4f49e36..6a79b92f05 100644 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-wrong-type.js +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-wrong-type.js @@ -4,35 +4,29 @@ /*--- esid: sec-temporal.zoneddatetime.prototype.withcalendar description: > - Appropriate error thrown when argument cannot be converted to a valid string - for Calendar + Appropriate error thrown when argument cannot be converted to a valid object or string features: [BigInt, Symbol, Temporal] ---*/ const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", "iso8601"); -const primitiveTests = [ +const wrongTypeTests = [ [null, "null"], [true, "boolean"], - ["", "empty string"], [1, "number that doesn't convert to a valid ISO string"], [1n, "bigint"], -]; - -for (const [arg, description] of primitiveTests) { - assert.throws( - typeof arg === 'string' ? RangeError : TypeError, - () => instance.withCalendar(arg), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ + [-19761118, "negative number"], + [19761118, "large positive number"], + [1234567890, "very large integer"], [Symbol(), "symbol"], [{}, "object"], [new Temporal.Duration(), "duration instance"], ]; -for (const [arg, description] of typeErrorTests) { - assert.throws(TypeError, () => instance.withCalendar(arg), `${description} is not a valid object and does not convert to a string`); +for (const [arg, description] of wrongTypeTests) { + assert.throws( + TypeError, + () => instance.withCalendar(arg), + `${description} does not convert to a valid ISO string` + ); }