From dadf18f4165794b6206ce8359695203864eb66ac Mon Sep 17 00:00:00 2001 From: Aditi Date: Mon, 11 Jul 2022 18:24:28 +0530 Subject: [PATCH] Add tests for temporalDurationLike argument and improve existing tests --- .../add/argument-invalid-property.js | 28 +++++++++++++++ .../prototype/add/argument-mixed-sign.js | 17 +++++++++ .../prototype/add/argument-not-object.js | 19 ++++++++++ .../prototype/add/argument-object-invalid.js | 13 ------- .../add/argument-singular-properties.js | 27 ++++++++++++++ .../add/non-integer-throws-rangeerror.js | 2 +- .../subtract/argument-invalid-property.js | 28 +++++++++++++++ .../prototype/subtract/argument-mixed-sign.js | 16 +++++++++ .../prototype/subtract/argument-not-object.js | 19 ++++++++++ .../subtract/argument-object-invalid.js | 13 ------- .../subtract/argument-singular-properties.js | 27 ++++++++++++++ .../subtract/non-integer-throws-rangeerror.js | 2 +- .../prototype/with/argument-invalid-prop.js | 13 ------- .../with/argument-invalid-property.js | 28 +++++++++++++++ .../prototype/with/argument-mixed-sign.js | 11 ++++-- .../prototype/with/argument-not-object.js | 20 +++++++++++ .../prototype/with/argument-sign-prop.js | 14 -------- ...ape.js => argument-singular-properties.js} | 13 +++---- .../prototype/with/argument-wrong-type.js | 27 -------------- .../with/non-integer-throws-rangeerror.js | 2 +- .../add/argument-invalid-property.js | 28 +++++++++++++++ .../prototype/add/argument-mixed-sign.js | 16 +++++++++ .../prototype/add/argument-not-object.js | 19 ++++++++++ .../add/argument-singular-properties.js | 27 ++++++++++++++ .../subtract/argument-invalid-property.js | 28 +++++++++++++++ .../prototype/subtract/argument-mixed-sign.js | 16 +++++++++ .../prototype/subtract/argument-not-object.js | 19 ++++++++++ .../subtract/argument-singular-properties.js | 27 ++++++++++++++ .../add/argument-invalid-duration.js | 16 --------- .../add/argument-invalid-property.js | 28 +++++++++++++++ .../add/argument-missing-properties.js | 18 ---------- .../prototype/add/argument-mixed-sign.js | 18 ++++++++++ .../prototype/add/argument-not-object.js | 4 ++- .../add/argument-singular-properties.js | 27 ++++++++++++++ .../prototype/add/argument-singular-units.js | 13 ------- .../subtract/argument-invalid-duration.js | 16 --------- .../subtract/argument-invalid-property.js | 28 +++++++++++++++ .../subtract/argument-missing-properties.js | 18 ---------- .../prototype/subtract/argument-mixed-sign.js | 18 ++++++++++ .../prototype/subtract/argument-not-object.js | 4 ++- .../subtract/argument-singular-properties.js | 27 ++++++++++++++ .../subtract/argument-singular-units.js | 13 ------- .../add/argument-invalid-property.js | 28 +++++++++++++++ ...-mixed-signs.js => argument-mixed-sign.js} | 4 +-- .../prototype/add/argument-not-object.js | 4 ++- .../add/argument-object-insufficient-data.js | 35 ------------------- .../add/argument-singular-properties.js | 27 ++++++++++++++ .../subtract/argument-invalid-property.js | 28 +++++++++++++++ ...-mixed-signs.js => argument-mixed-sign.js} | 4 +-- .../prototype/subtract/argument-not-object.js | 4 ++- .../argument-object-insufficient-data.js | 35 ------------------- .../subtract/argument-singular-properties.js | 27 ++++++++++++++ .../add/argument-invalid-property.js | 28 +++++++++++++++ .../prototype/add/argument-mixed-sign.js | 16 +++++++++ .../prototype/add/argument-not-object.js | 4 ++- .../prototype/add/argument-object-invalid.js | 13 ------- .../add/argument-singular-properties.js | 27 ++++++++++++++ .../subtract/argument-invalid-property.js | 28 +++++++++++++++ .../prototype/subtract/argument-mixed-sign.js | 16 +++++++++ .../prototype/subtract/argument-not-object.js | 4 ++- .../subtract/argument-object-invalid.js | 13 ------- .../subtract/argument-singular-properties.js | 27 ++++++++++++++ .../add/argument-invalid-property.js | 28 +++++++++++++++ .../prototype/add/argument-mixed-sign.js | 18 ++++++++++ .../prototype/add/argument-not-object.js | 4 ++- .../prototype/add/argument-object-invalid.js | 16 --------- .../prototype/add/argument-object-plural.js | 12 ------- .../add/argument-singular-properties.js | 27 ++++++++++++++ .../subtract/argument-invalid-property.js | 28 +++++++++++++++ .../prototype/subtract/argument-mixed-sign.js | 18 ++++++++++ .../prototype/subtract/argument-not-object.js | 4 ++- .../subtract/argument-object-invalid.js | 16 --------- .../subtract/argument-object-plural.js | 12 ------- .../subtract/argument-singular-properties.js | 27 ++++++++++++++ .../add/argument-invalid-property.js | 28 +++++++++++++++ .../prototype/add/argument-mixed-sign.js | 18 ++++++++++ .../prototype/add/argument-not-object.js | 19 ++++++++++ .../add/argument-singular-properties.js | 27 ++++++++++++++ .../subtract/argument-invalid-property.js | 28 +++++++++++++++ .../prototype/subtract/argument-mixed-sign.js | 18 ++++++++++ .../prototype/subtract/argument-not-object.js | 19 ++++++++++ .../subtract/argument-singular-properties.js | 27 ++++++++++++++ 82 files changed, 1181 insertions(+), 352 deletions(-) create mode 100644 test/built-ins/Temporal/Duration/prototype/add/argument-invalid-property.js create mode 100644 test/built-ins/Temporal/Duration/prototype/add/argument-mixed-sign.js create mode 100644 test/built-ins/Temporal/Duration/prototype/add/argument-not-object.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/argument-object-invalid.js create mode 100644 test/built-ins/Temporal/Duration/prototype/add/argument-singular-properties.js create mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/argument-invalid-property.js create mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/argument-mixed-sign.js create mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/argument-not-object.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/argument-object-invalid.js create mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/argument-singular-properties.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/with/argument-invalid-prop.js create mode 100644 test/built-ins/Temporal/Duration/prototype/with/argument-invalid-property.js create mode 100644 test/built-ins/Temporal/Duration/prototype/with/argument-not-object.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/with/argument-sign-prop.js rename test/built-ins/Temporal/Duration/prototype/with/{argument-object-wrong-shape.js => argument-singular-properties.js} (62%) delete mode 100644 test/built-ins/Temporal/Duration/prototype/with/argument-wrong-type.js create mode 100644 test/built-ins/Temporal/Instant/prototype/add/argument-invalid-property.js create mode 100644 test/built-ins/Temporal/Instant/prototype/add/argument-mixed-sign.js create mode 100644 test/built-ins/Temporal/Instant/prototype/add/argument-not-object.js create mode 100644 test/built-ins/Temporal/Instant/prototype/add/argument-singular-properties.js create mode 100644 test/built-ins/Temporal/Instant/prototype/subtract/argument-invalid-property.js create mode 100644 test/built-ins/Temporal/Instant/prototype/subtract/argument-mixed-sign.js create mode 100644 test/built-ins/Temporal/Instant/prototype/subtract/argument-not-object.js create mode 100644 test/built-ins/Temporal/Instant/prototype/subtract/argument-singular-properties.js delete mode 100644 test/built-ins/Temporal/PlainDate/prototype/add/argument-invalid-duration.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/add/argument-invalid-property.js delete mode 100644 test/built-ins/Temporal/PlainDate/prototype/add/argument-missing-properties.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/add/argument-mixed-sign.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/add/argument-singular-properties.js delete mode 100644 test/built-ins/Temporal/PlainDate/prototype/add/argument-singular-units.js delete mode 100644 test/built-ins/Temporal/PlainDate/prototype/subtract/argument-invalid-duration.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/subtract/argument-invalid-property.js delete mode 100644 test/built-ins/Temporal/PlainDate/prototype/subtract/argument-missing-properties.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/subtract/argument-mixed-sign.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/subtract/argument-singular-properties.js delete mode 100644 test/built-ins/Temporal/PlainDate/prototype/subtract/argument-singular-units.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/add/argument-invalid-property.js rename test/built-ins/Temporal/PlainDateTime/prototype/add/{argument-plain-object-mixed-signs.js => argument-mixed-sign.js} (76%) delete mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/add/argument-object-insufficient-data.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/add/argument-singular-properties.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/subtract/argument-invalid-property.js rename test/built-ins/Temporal/PlainDateTime/prototype/subtract/{argument-plain-object-mixed-signs.js => argument-mixed-sign.js} (75%) delete mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/subtract/argument-object-insufficient-data.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/subtract/argument-singular-properties.js create mode 100644 test/built-ins/Temporal/PlainTime/prototype/add/argument-invalid-property.js create mode 100644 test/built-ins/Temporal/PlainTime/prototype/add/argument-mixed-sign.js delete mode 100644 test/built-ins/Temporal/PlainTime/prototype/add/argument-object-invalid.js create mode 100644 test/built-ins/Temporal/PlainTime/prototype/add/argument-singular-properties.js create mode 100644 test/built-ins/Temporal/PlainTime/prototype/subtract/argument-invalid-property.js create mode 100644 test/built-ins/Temporal/PlainTime/prototype/subtract/argument-mixed-sign.js delete mode 100644 test/built-ins/Temporal/PlainTime/prototype/subtract/argument-object-invalid.js create mode 100644 test/built-ins/Temporal/PlainTime/prototype/subtract/argument-singular-properties.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-invalid-property.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-mixed-sign.js delete mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-object-invalid.js delete mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-object-plural.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-singular-properties.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-invalid-property.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-mixed-sign.js delete mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-object-invalid.js delete mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-object-plural.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-singular-properties.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/add/argument-invalid-property.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/add/argument-mixed-sign.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/add/argument-not-object.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/add/argument-singular-properties.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/subtract/argument-invalid-property.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/subtract/argument-mixed-sign.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/subtract/argument-not-object.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/subtract/argument-singular-properties.js diff --git a/test/built-ins/Temporal/Duration/prototype/add/argument-invalid-property.js b/test/built-ins/Temporal/Duration/prototype/add/argument-invalid-property.js new file mode 100644 index 0000000000..3e73c747cf --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/add/argument-invalid-property.js @@ -0,0 +1,28 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.add +description: temporalDurationLike object must contain at least one correctly spelled property +features: [Temporal] +---*/ + +const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321); + +assert.throws( + TypeError, + () => instance.add({}), + "Throws TypeError if no property is present" +); + +assert.throws( + TypeError, + () => instance.add({ nonsense: true }), + "Throws TypeError if no recognized property is present" +); + +assert.throws( + TypeError, + () => instance.add({ sign: 1 }), + "Sign property is not recognized" +); diff --git a/test/built-ins/Temporal/Duration/prototype/add/argument-mixed-sign.js b/test/built-ins/Temporal/Duration/prototype/add/argument-mixed-sign.js new file mode 100644 index 0000000000..b179b97ab8 --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/add/argument-mixed-sign.js @@ -0,0 +1,17 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.add +description: Positive and negative values in the temporalDurationLike argument are not acceptable +features: [Temporal] +---*/ + +const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321); + +assert.throws( + RangeError, + () => instance.add({ hours: 1, minutes: -30 }), + `mixed positive and negative values always throw` +); + diff --git a/test/built-ins/Temporal/Duration/prototype/add/argument-not-object.js b/test/built-ins/Temporal/Duration/prototype/add/argument-not-object.js new file mode 100644 index 0000000000..9e96ed318a --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/add/argument-not-object.js @@ -0,0 +1,19 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.add +description: Passing a primitive other than string to add() throws +features: [Symbol, Temporal] +---*/ + +const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321); +assert.throws(RangeError, () => instance.add(undefined), "undefined"); +assert.throws(RangeError, () => instance.add(null), "null"); +assert.throws(RangeError, () => instance.add(true), "boolean"); +assert.throws(RangeError, () => instance.add(""), "empty string"); +assert.throws(TypeError, () => instance.add(Symbol()), "Symbol"); +assert.throws(RangeError, () => instance.add(7), "number"); +assert.throws(RangeError, () => instance.add(7n), "bigint"); +assert.throws(TypeError, () => instance.add([]), "array"); +assert.throws(TypeError, () => instance.add(() => {}), "function"); diff --git a/test/built-ins/Temporal/Duration/prototype/add/argument-object-invalid.js b/test/built-ins/Temporal/Duration/prototype/add/argument-object-invalid.js deleted file mode 100644 index ed5b5873a3..0000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/argument-object-invalid.js +++ /dev/null @@ -1,13 +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.duration.prototype.add -description: Mixed positive and negative values or missing properties always throw -features: [Temporal] ----*/ - -const duration = Temporal.Duration.from({ days: 1, minutes: 5 }); -assert.throws(RangeError, () => duration.add({ hours: 1, minutes: -30 }), "mixed signs"); -assert.throws(TypeError, () => duration.add({}), "no properties"); -assert.throws(TypeError, () => duration.add({ month: 12 }), "only singular 'month' property"); diff --git a/test/built-ins/Temporal/Duration/prototype/add/argument-singular-properties.js b/test/built-ins/Temporal/Duration/prototype/add/argument-singular-properties.js new file mode 100644 index 0000000000..59731a1679 --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/add/argument-singular-properties.js @@ -0,0 +1,27 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.add +description: Singular properties in the property bag are always ignored +features: [Temporal] +---*/ + +const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321); + +[ + { year: 1 }, + { month: 2 }, + { week: 3 }, + { day: 4 }, + { hour: 5 }, + { minute: 6 }, + { second: 7 }, + { millisecond: 8 }, + { microsecond: 9 }, + { nanosecond: 10 }, +].forEach((badObject) => { + assert.throws(TypeError, () => instance.add(badObject), + "Throw TypeError if temporalDurationLike is not valid"); +}); + diff --git a/test/built-ins/Temporal/Duration/prototype/add/non-integer-throws-rangeerror.js b/test/built-ins/Temporal/Duration/prototype/add/non-integer-throws-rangeerror.js index 7b82df1931..085e668912 100644 --- a/test/built-ins/Temporal/Duration/prototype/add/non-integer-throws-rangeerror.js +++ b/test/built-ins/Temporal/Duration/prototype/add/non-integer-throws-rangeerror.js @@ -7,7 +7,7 @@ description: A non-integer value for any recognized property in the property bag features: [Temporal] ---*/ -const instance = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321); +const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321); const fields = [ "years", "months", diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/argument-invalid-property.js b/test/built-ins/Temporal/Duration/prototype/subtract/argument-invalid-property.js new file mode 100644 index 0000000000..9dfa927160 --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/subtract/argument-invalid-property.js @@ -0,0 +1,28 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.subtract +description: temporalDurationLike object must contain at least one correctly spelled property +features: [Temporal] +---*/ + +const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321); + +assert.throws( + TypeError, + () => instance.subtract({}), + "Throws TypeError if no property is present" +); + +assert.throws( + TypeError, + () => instance.subtract({ nonsense: true }), + "Throws TypeError if no recognized property is present" +); + +assert.throws( + TypeError, + () => instance.subtract({ sign: 1 }), + "Sign property is not recognized" +); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/argument-mixed-sign.js b/test/built-ins/Temporal/Duration/prototype/subtract/argument-mixed-sign.js new file mode 100644 index 0000000000..c83c773ba4 --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/subtract/argument-mixed-sign.js @@ -0,0 +1,16 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.subtract +description: Positive and negative values in the temporalDurationLike argument are not acceptable +features: [Temporal] +---*/ + +const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321); + +assert.throws( + RangeError, + () => instance.subtract({ hours: 1, minutes: -30 }), + `mixed positive and negative values always throw` +); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/argument-not-object.js b/test/built-ins/Temporal/Duration/prototype/subtract/argument-not-object.js new file mode 100644 index 0000000000..813213c210 --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/subtract/argument-not-object.js @@ -0,0 +1,19 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.subtract +description: Passing a primitive other than string to subtract() throws +features: [Symbol, Temporal] +---*/ + +const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321); +assert.throws(RangeError, () => instance.subtract(undefined), "undefined"); +assert.throws(RangeError, () => instance.subtract(null), "null"); +assert.throws(RangeError, () => instance.subtract(true), "boolean"); +assert.throws(RangeError, () => instance.subtract(""), "empty string"); +assert.throws(TypeError, () => instance.subtract(Symbol()), "Symbol"); +assert.throws(RangeError, () => instance.subtract(7), "number"); +assert.throws(RangeError, () => instance.subtract(7n), "bigint"); +assert.throws(TypeError, () => instance.subtract([]), "array"); +assert.throws(TypeError, () => instance.subtract(() => {}), "function"); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/argument-object-invalid.js b/test/built-ins/Temporal/Duration/prototype/subtract/argument-object-invalid.js deleted file mode 100644 index 8d823237fa..0000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/argument-object-invalid.js +++ /dev/null @@ -1,13 +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.duration.prototype.subtract -description: Mixed positive and negative values or missing properties always throw -features: [Temporal] ----*/ - -const duration = Temporal.Duration.from({ days: 1, minutes: 5 }); -assert.throws(RangeError, () => duration.subtract({ hours: 1, minutes: -30 }), "mixed signs"); -assert.throws(TypeError, () => duration.subtract({}), "no properties"); -assert.throws(TypeError, () => duration.subtract({ month: 12 }), "only singular 'month' property"); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/argument-singular-properties.js b/test/built-ins/Temporal/Duration/prototype/subtract/argument-singular-properties.js new file mode 100644 index 0000000000..d3180a16af --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/subtract/argument-singular-properties.js @@ -0,0 +1,27 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.subtract +description: Singular properties in the property bag are always ignored +features: [Temporal] +---*/ + +const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321); + +[ + { year: 1 }, + { month: 2 }, + { week: 3 }, + { day: 4 }, + { hour: 5 }, + { minute: 6 }, + { second: 7 }, + { millisecond: 8 }, + { microsecond: 9 }, + { nanosecond: 10 }, +].forEach((badObject) => { + assert.throws(TypeError, () => instance.subtract(badObject), + "Throw TypeError if temporalDurationLike is not valid"); +}); + diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/non-integer-throws-rangeerror.js b/test/built-ins/Temporal/Duration/prototype/subtract/non-integer-throws-rangeerror.js index 17092e1ee8..d7daeb6f31 100644 --- a/test/built-ins/Temporal/Duration/prototype/subtract/non-integer-throws-rangeerror.js +++ b/test/built-ins/Temporal/Duration/prototype/subtract/non-integer-throws-rangeerror.js @@ -7,7 +7,7 @@ description: A non-integer value for any recognized property in the property bag features: [Temporal] ---*/ -const instance = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321); +const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321); const fields = [ "years", "months", diff --git a/test/built-ins/Temporal/Duration/prototype/with/argument-invalid-prop.js b/test/built-ins/Temporal/Duration/prototype/with/argument-invalid-prop.js deleted file mode 100644 index f12c9f49dc..0000000000 --- a/test/built-ins/Temporal/Duration/prototype/with/argument-invalid-prop.js +++ /dev/null @@ -1,13 +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.duration.prototype.with -description: Singular properties are ignored. -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const d = Temporal.Duration.from({ years: 5, days: 1 }); -const d2 = d.with({ year: 1, days: 0 }); -TemporalHelpers.assertDuration(d2, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0); diff --git a/test/built-ins/Temporal/Duration/prototype/with/argument-invalid-property.js b/test/built-ins/Temporal/Duration/prototype/with/argument-invalid-property.js new file mode 100644 index 0000000000..9b39e2bcca --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/with/argument-invalid-property.js @@ -0,0 +1,28 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.with +description: temporalDurationLike object must contain at least one correctly spelled property +features: [Temporal] +---*/ + +const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321); + +assert.throws( + TypeError, + () => instance.with({}), + "Throws TypeError if no property is present" +); + +assert.throws( + TypeError, + () => instance.with({ nonsense: true }), + "Throws TypeError if no recognized property is present" +); + +assert.throws( + TypeError, + () => instance.with({ sign: 1 }), + "Sign property is not recognized" +); diff --git a/test/built-ins/Temporal/Duration/prototype/with/argument-mixed-sign.js b/test/built-ins/Temporal/Duration/prototype/with/argument-mixed-sign.js index ca215ef33e..3088645107 100644 --- a/test/built-ins/Temporal/Duration/prototype/with/argument-mixed-sign.js +++ b/test/built-ins/Temporal/Duration/prototype/with/argument-mixed-sign.js @@ -3,9 +3,14 @@ /*--- esid: sec-temporal.duration.prototype.with -description: The durationLike argument must not contain different signs. +description: Positive and negative values in the temporalDurationLike argument are not acceptable features: [Temporal] ---*/ -const d = new Temporal.Duration(1, 2, 3, 4, 5); -assert.throws(RangeError, () => d.with({ hours: 1, minutes: -1 })); +const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321); + +assert.throws( + RangeError, + () => instance.with({ hours: 1, minutes: -30 }), + `mixed positive and negative values always throw` +); diff --git a/test/built-ins/Temporal/Duration/prototype/with/argument-not-object.js b/test/built-ins/Temporal/Duration/prototype/with/argument-not-object.js new file mode 100644 index 0000000000..3af6bbeb5c --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/with/argument-not-object.js @@ -0,0 +1,20 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.with +description: Passing a primitive other than string to with() throws +features: [Symbol, Temporal] +---*/ + +const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321); +assert.throws(TypeError, () => instance.with(undefined), "undefined"); +assert.throws(TypeError, () => instance.with(null), "null"); +assert.throws(TypeError, () => instance.with(true), "boolean"); +assert.throws(TypeError, () => instance.with(""), "empty string"); +assert.throws(TypeError, () => instance.with(Symbol()), "Symbol"); +assert.throws(TypeError, () => instance.with(7), "number"); +assert.throws(TypeError, () => instance.with(7n), "bigint"); +assert.throws(TypeError, () => instance.with([]), "array"); +assert.throws(TypeError, () => instance.with(() => {}), "function"); +assert.throws(TypeError, () => instance.with("string"), "string"); diff --git a/test/built-ins/Temporal/Duration/prototype/with/argument-sign-prop.js b/test/built-ins/Temporal/Duration/prototype/with/argument-sign-prop.js deleted file mode 100644 index 728d2f92ee..0000000000 --- a/test/built-ins/Temporal/Duration/prototype/with/argument-sign-prop.js +++ /dev/null @@ -1,14 +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.duration.prototype.with -description: Passing a sign property is not supported. -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const d = Temporal.Duration.from({ years: 5, days: 1 }); -assert.throws(TypeError, () => d.with({ sign: -1 })); -const d2 = d.with({ sign: -1, days: 0 }); -TemporalHelpers.assertDuration(d2, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0); diff --git a/test/built-ins/Temporal/Duration/prototype/with/argument-object-wrong-shape.js b/test/built-ins/Temporal/Duration/prototype/with/argument-singular-properties.js similarity index 62% rename from test/built-ins/Temporal/Duration/prototype/with/argument-object-wrong-shape.js rename to test/built-ins/Temporal/Duration/prototype/with/argument-singular-properties.js index 5c17076bec..e2b4c8b084 100644 --- a/test/built-ins/Temporal/Duration/prototype/with/argument-object-wrong-shape.js +++ b/test/built-ins/Temporal/Duration/prototype/with/argument-singular-properties.js @@ -1,20 +1,16 @@ // Copyright (C) 2021 the V8 project authors. All rights reserved. +// Copyright (C) 2022 Igalia, S.L. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /*--- esid: sec-temporal.duration.prototype.with -description: > - The durationLike argument must contain at least one correctly spelled property +description: Singular properties in the property bag are always ignored features: [Temporal] ---*/ -let d = new Temporal.Duration(1, 2, 3, 4, 5); +const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321); [ - {}, - [], - () => {}, - // objects with only singular keys (plural is the correct spelling) { year: 1 }, { month: 2 }, { week: 3 }, @@ -26,6 +22,7 @@ let d = new Temporal.Duration(1, 2, 3, 4, 5); { microsecond: 9 }, { nanosecond: 10 }, ].forEach((badObject) => { - assert.throws(TypeError, () => d.with(badObject), + assert.throws(TypeError, () => instance.with(badObject), "Throw TypeError if temporalDurationLike is not valid"); }); + diff --git a/test/built-ins/Temporal/Duration/prototype/with/argument-wrong-type.js b/test/built-ins/Temporal/Duration/prototype/with/argument-wrong-type.js deleted file mode 100644 index 41163a35da..0000000000 --- a/test/built-ins/Temporal/Duration/prototype/with/argument-wrong-type.js +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (C) 2021 the V8 project authors. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.with -description: Throw TypeError if the temporalDurationLike argument is the wrong type -features: [Temporal] ----*/ - -let d = new Temporal.Duration(1, 2, 3, 4, 5); - -[ - "string", - "P1YT1M", - true, - false, - NaN, - Infinity, - undefined, - null, - 123, - Symbol(), - 456n, -].forEach((badInput) => { - assert.throws(TypeError, () => d.with(badInput), - "Throw TypeError if temporalDurationLike is not valid"); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/with/non-integer-throws-rangeerror.js b/test/built-ins/Temporal/Duration/prototype/with/non-integer-throws-rangeerror.js index db746ccaa0..0a1a753199 100644 --- a/test/built-ins/Temporal/Duration/prototype/with/non-integer-throws-rangeerror.js +++ b/test/built-ins/Temporal/Duration/prototype/with/non-integer-throws-rangeerror.js @@ -7,7 +7,7 @@ description: A non-integer value for any recognized property in the property bag features: [Temporal] ---*/ -const instance = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321); +const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321); const fields = [ "years", "months", diff --git a/test/built-ins/Temporal/Instant/prototype/add/argument-invalid-property.js b/test/built-ins/Temporal/Instant/prototype/add/argument-invalid-property.js new file mode 100644 index 0000000000..ffb19ce30c --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/add/argument-invalid-property.js @@ -0,0 +1,28 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.prototype.add +description: temporalDurationLike object must contain at least one correctly spelled property +features: [Temporal] +---*/ + +const instance = new Temporal.Instant(1_000_000_000_000_000_000n); + +assert.throws( + TypeError, + () => instance.add({}), + "Throws TypeError if no property is present" +); + +assert.throws( + TypeError, + () => instance.add({ nonsense: true }), + "Throws TypeError if no recognized property is present" +); + +assert.throws( + TypeError, + () => instance.add({ sign: 1 }), + "Sign property is not recognized" +); diff --git a/test/built-ins/Temporal/Instant/prototype/add/argument-mixed-sign.js b/test/built-ins/Temporal/Instant/prototype/add/argument-mixed-sign.js new file mode 100644 index 0000000000..7618b60625 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/add/argument-mixed-sign.js @@ -0,0 +1,16 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.prototype.add +description: Positive and negative values in the temporalDurationLike argument are not acceptable +features: [Temporal] +---*/ + +const instance = new Temporal.Instant(1_000_000_000_000_000_000n); + +assert.throws( + RangeError, + () => instance.add({ hours: 1, minutes: -30 }), + `mixed positive and negative values always throw` +); diff --git a/test/built-ins/Temporal/Instant/prototype/add/argument-not-object.js b/test/built-ins/Temporal/Instant/prototype/add/argument-not-object.js new file mode 100644 index 0000000000..6e7f79c57e --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/add/argument-not-object.js @@ -0,0 +1,19 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.prototype.add +description: Passing a primitive other than string to add() throws +features: [Symbol, Temporal] +---*/ + +const instance = new Temporal.Instant(1_000_000_000_000_000_000n); +assert.throws(RangeError, () => instance.add(undefined), "undefined"); +assert.throws(RangeError, () => instance.add(null), "null"); +assert.throws(RangeError, () => instance.add(true), "boolean"); +assert.throws(RangeError, () => instance.add(""), "empty string"); +assert.throws(TypeError, () => instance.add(Symbol()), "Symbol"); +assert.throws(RangeError, () => instance.add(7), "number"); +assert.throws(RangeError, () => instance.add(7n), "bigint"); +assert.throws(TypeError, () => instance.add([]), "array"); +assert.throws(TypeError, () => instance.add(() => {}), "function"); diff --git a/test/built-ins/Temporal/Instant/prototype/add/argument-singular-properties.js b/test/built-ins/Temporal/Instant/prototype/add/argument-singular-properties.js new file mode 100644 index 0000000000..a26fd96eba --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/add/argument-singular-properties.js @@ -0,0 +1,27 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.prototype.add +description: Singular properties in the property bag are always ignored +features: [Temporal] +---*/ + +const instance = new Temporal.Instant(1_000_000_000_000_000_000n); + +[ + { year: 1 }, + { month: 2 }, + { week: 3 }, + { day: 4 }, + { hour: 5 }, + { minute: 6 }, + { second: 7 }, + { millisecond: 8 }, + { microsecond: 9 }, + { nanosecond: 10 }, +].forEach((badObject) => { + assert.throws(TypeError, () => instance.add(badObject), + "Throw TypeError if temporalDurationLike is not valid"); +}); + diff --git a/test/built-ins/Temporal/Instant/prototype/subtract/argument-invalid-property.js b/test/built-ins/Temporal/Instant/prototype/subtract/argument-invalid-property.js new file mode 100644 index 0000000000..99aa8f9cef --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/subtract/argument-invalid-property.js @@ -0,0 +1,28 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.prototype.subtract +description: temporalDurationLike object must contain at least one correctly spelled property +features: [Temporal] +---*/ + +const instance = new Temporal.Instant(1_000_000_000_000_000_000n); + +assert.throws( + TypeError, + () => instance.subtract({}), + "Throws TypeError if no property is present" +); + +assert.throws( + TypeError, + () => instance.subtract({ nonsense: true }), + "Throws TypeError if no recognized property is present" +); + +assert.throws( + TypeError, + () => instance.subtract({ sign: 1 }), + "Sign property is not recognized" +); diff --git a/test/built-ins/Temporal/Instant/prototype/subtract/argument-mixed-sign.js b/test/built-ins/Temporal/Instant/prototype/subtract/argument-mixed-sign.js new file mode 100644 index 0000000000..a08c799091 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/subtract/argument-mixed-sign.js @@ -0,0 +1,16 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.prototype.subtract +description: Positive and negative values in the temporalDurationLike argument are not acceptable +features: [Temporal] +---*/ + +const instance = new Temporal.Instant(1_000_000_000_000_000_000n); + +assert.throws( + RangeError, + () => instance.subtract({ hours: 1, minutes: -30 }), + `mixed positive and negative values always throw` +); diff --git a/test/built-ins/Temporal/Instant/prototype/subtract/argument-not-object.js b/test/built-ins/Temporal/Instant/prototype/subtract/argument-not-object.js new file mode 100644 index 0000000000..af8fd963c8 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/subtract/argument-not-object.js @@ -0,0 +1,19 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.prototype.subtract +description: Passing a primitive other than string to subtract() throws +features: [Symbol, Temporal] +---*/ + +const instance = new Temporal.Instant(1_000_000_000_000_000_000n); +assert.throws(RangeError, () => instance.subtract(undefined), "undefined"); +assert.throws(RangeError, () => instance.subtract(null), "null"); +assert.throws(RangeError, () => instance.subtract(true), "boolean"); +assert.throws(RangeError, () => instance.subtract(""), "empty string"); +assert.throws(TypeError, () => instance.subtract(Symbol()), "Symbol"); +assert.throws(RangeError, () => instance.subtract(7), "number"); +assert.throws(RangeError, () => instance.subtract(7n), "bigint"); +assert.throws(TypeError, () => instance.subtract([]), "array"); +assert.throws(TypeError, () => instance.subtract(() => {}), "function"); diff --git a/test/built-ins/Temporal/Instant/prototype/subtract/argument-singular-properties.js b/test/built-ins/Temporal/Instant/prototype/subtract/argument-singular-properties.js new file mode 100644 index 0000000000..d3e2707502 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/subtract/argument-singular-properties.js @@ -0,0 +1,27 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.prototype.subtract +description: Singular properties in the property bag are always ignored +features: [Temporal] +---*/ + +const instance = new Temporal.Instant(1_000_000_000_000_000_000n); + +[ + { year: 1 }, + { month: 2 }, + { week: 3 }, + { day: 4 }, + { hour: 5 }, + { minute: 6 }, + { second: 7 }, + { millisecond: 8 }, + { microsecond: 9 }, + { nanosecond: 10 }, +].forEach((badObject) => { + assert.throws(TypeError, () => instance.subtract(badObject), + "Throw TypeError if temporalDurationLike is not valid"); +}); + diff --git a/test/built-ins/Temporal/PlainDate/prototype/add/argument-invalid-duration.js b/test/built-ins/Temporal/PlainDate/prototype/add/argument-invalid-duration.js deleted file mode 100644 index 62485edac1..0000000000 --- a/test/built-ins/Temporal/PlainDate/prototype/add/argument-invalid-duration.js +++ /dev/null @@ -1,16 +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.add -description: RangeError thrown when signs don't match in the duration -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const calendar = TemporalHelpers.calendarThrowEverything(); -const date = new Temporal.PlainDate(2000, 5, 2, calendar); -const duration = { months: 1, days: -30 }; -for (const overflow of ["constrain", "reject"]) { - assert.throws(RangeError, () => date.add(duration, { overflow })); -} diff --git a/test/built-ins/Temporal/PlainDate/prototype/add/argument-invalid-property.js b/test/built-ins/Temporal/PlainDate/prototype/add/argument-invalid-property.js new file mode 100644 index 0000000000..d2c02423c4 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/add/argument-invalid-property.js @@ -0,0 +1,28 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.add +description: temporalDurationLike object must contain at least one correctly spelled property +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDate(2000, 5, 2); + +assert.throws( + TypeError, + () => instance.add({}), + "Throws TypeError if no property is present" +); + +assert.throws( + TypeError, + () => instance.add({ nonsense: true }), + "Throws TypeError if no recognized property is present" +); + +assert.throws( + TypeError, + () => instance.add({ sign: 1 }), + "Sign property is not recognized" +); diff --git a/test/built-ins/Temporal/PlainDate/prototype/add/argument-missing-properties.js b/test/built-ins/Temporal/PlainDate/prototype/add/argument-missing-properties.js deleted file mode 100644 index 99d31b4fee..0000000000 --- a/test/built-ins/Temporal/PlainDate/prototype/add/argument-missing-properties.js +++ /dev/null @@ -1,18 +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.add -description: TypeError for missing properties -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const date = new Temporal.PlainDate(2000, 5, 2); -const options = { - get overflow() { - TemporalHelpers.assertUnreachable("should not get overflow"); - } -}; -assert.throws(TypeError, () => date.add({}, options), "empty object"); -assert.throws(TypeError, () => date.add({ month: 12 }, options), "misspelled 'months'"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/add/argument-mixed-sign.js b/test/built-ins/Temporal/PlainDate/prototype/add/argument-mixed-sign.js new file mode 100644 index 0000000000..cad8310449 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/add/argument-mixed-sign.js @@ -0,0 +1,18 @@ +// 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.add +description: Positive and negative values in the temporalDurationLike argument are not acceptable +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDate(2000, 5, 2); + +["constrain", "reject"].forEach((overflow) => { + assert.throws( + RangeError, + () => instance.add({ hours: 1, minutes: -30 }, { overflow }), + `mixed positive and negative values always throw (overflow = "${overflow}")` + ); +}); diff --git a/test/built-ins/Temporal/PlainDate/prototype/add/argument-not-object.js b/test/built-ins/Temporal/PlainDate/prototype/add/argument-not-object.js index 6a88e4b19e..cad57d9735 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/add/argument-not-object.js +++ b/test/built-ins/Temporal/PlainDate/prototype/add/argument-not-object.js @@ -7,7 +7,7 @@ description: Passing a primitive other than string to add() throws features: [Symbol, Temporal] ---*/ -const instance = Temporal.PlainDate.from({ year: 2000, month: 5, day: 2 }); +const instance = new Temporal.PlainDate(2000, 5, 2); assert.throws(RangeError, () => instance.add(undefined), "undefined"); assert.throws(RangeError, () => instance.add(null), "null"); assert.throws(RangeError, () => instance.add(true), "boolean"); @@ -15,3 +15,5 @@ assert.throws(RangeError, () => instance.add(""), "empty string"); assert.throws(TypeError, () => instance.add(Symbol()), "Symbol"); assert.throws(RangeError, () => instance.add(7), "number"); assert.throws(RangeError, () => instance.add(7n), "bigint"); +assert.throws(TypeError, () => instance.add([]), "array"); +assert.throws(TypeError, () => instance.add(() => {}), "function"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/add/argument-singular-properties.js b/test/built-ins/Temporal/PlainDate/prototype/add/argument-singular-properties.js new file mode 100644 index 0000000000..527575e312 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/add/argument-singular-properties.js @@ -0,0 +1,27 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.add +description: Singular properties in the property bag are always ignored +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDate(2000, 5, 2); + +[ + { year: 1 }, + { month: 2 }, + { week: 3 }, + { day: 4 }, + { hour: 5 }, + { minute: 6 }, + { second: 7 }, + { millisecond: 8 }, + { microsecond: 9 }, + { nanosecond: 10 }, +].forEach((badObject) => { + assert.throws(TypeError, () => instance.add(badObject), + "Throw TypeError if temporalDurationLike is not valid"); +}); + diff --git a/test/built-ins/Temporal/PlainDate/prototype/add/argument-singular-units.js b/test/built-ins/Temporal/PlainDate/prototype/add/argument-singular-units.js deleted file mode 100644 index dff07c5857..0000000000 --- a/test/built-ins/Temporal/PlainDate/prototype/add/argument-singular-units.js +++ /dev/null @@ -1,13 +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.add -description: Ignores singular properties -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const date = Temporal.PlainDate.from("2019-11-18"); -TemporalHelpers.assertPlainDate(date.add({ month: 1, days: 1 }), - 2019, 11, "M11", 19); diff --git a/test/built-ins/Temporal/PlainDate/prototype/subtract/argument-invalid-duration.js b/test/built-ins/Temporal/PlainDate/prototype/subtract/argument-invalid-duration.js deleted file mode 100644 index 9aab227b5d..0000000000 --- a/test/built-ins/Temporal/PlainDate/prototype/subtract/argument-invalid-duration.js +++ /dev/null @@ -1,16 +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.subtract -description: RangeError thrown when signs don't match in the duration -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const calendar = TemporalHelpers.calendarThrowEverything(); -const date = new Temporal.PlainDate(2000, 5, 2, calendar); -const duration = { months: 1, days: -30 }; -for (const overflow of ["constrain", "reject"]) { - assert.throws(RangeError, () => date.subtract(duration, { overflow })); -} diff --git a/test/built-ins/Temporal/PlainDate/prototype/subtract/argument-invalid-property.js b/test/built-ins/Temporal/PlainDate/prototype/subtract/argument-invalid-property.js new file mode 100644 index 0000000000..74a3f01ceb --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/subtract/argument-invalid-property.js @@ -0,0 +1,28 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.subtract +description: temporalDurationLike object must contain at least one correctly spelled property +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDate(2000, 5, 2); + +assert.throws( + TypeError, + () => instance.subtract({}), + "Throws TypeError if no property is present" +); + +assert.throws( + TypeError, + () => instance.subtract({ nonsense: true }), + "Throws TypeError if no recognized property is present" +); + +assert.throws( + TypeError, + () => instance.subtract({ sign: 1 }), + "Sign property is not recognized" +); diff --git a/test/built-ins/Temporal/PlainDate/prototype/subtract/argument-missing-properties.js b/test/built-ins/Temporal/PlainDate/prototype/subtract/argument-missing-properties.js deleted file mode 100644 index 3a865fa6c0..0000000000 --- a/test/built-ins/Temporal/PlainDate/prototype/subtract/argument-missing-properties.js +++ /dev/null @@ -1,18 +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.subtract -description: TypeError for missing properties -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const date = new Temporal.PlainDate(2000, 5, 2); -const options = { - get overflow() { - TemporalHelpers.assertUnreachable("should not get overflow"); - } -}; -assert.throws(TypeError, () => date.subtract({}, options), "empty object"); -assert.throws(TypeError, () => date.subtract({ month: 12 }, options), "misspelled 'months'"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/subtract/argument-mixed-sign.js b/test/built-ins/Temporal/PlainDate/prototype/subtract/argument-mixed-sign.js new file mode 100644 index 0000000000..85d04326f2 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/subtract/argument-mixed-sign.js @@ -0,0 +1,18 @@ +// 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.subtract +description: Positive and negative values in the temporalDurationLike argument are not acceptable +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDate(2000, 5, 2); + +["constrain", "reject"].forEach((overflow) => { + assert.throws( + RangeError, + () => instance.subtract({ hours: 1, minutes: -30 }, { overflow }), + `mixed positive and negative values always throw (overflow = "${overflow}")` + ); +}); diff --git a/test/built-ins/Temporal/PlainDate/prototype/subtract/argument-not-object.js b/test/built-ins/Temporal/PlainDate/prototype/subtract/argument-not-object.js index 540356eda7..bf2435ca21 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/subtract/argument-not-object.js +++ b/test/built-ins/Temporal/PlainDate/prototype/subtract/argument-not-object.js @@ -7,7 +7,7 @@ description: Passing a primitive other than string to subtract() throws features: [Symbol, Temporal] ---*/ -const instance = Temporal.PlainDate.from({ year: 2000, month: 5, day: 2 }); +const instance = new Temporal.PlainDate(2000, 5, 2); assert.throws(RangeError, () => instance.subtract(undefined), "undefined"); assert.throws(RangeError, () => instance.subtract(null), "null"); assert.throws(RangeError, () => instance.subtract(true), "boolean"); @@ -15,3 +15,5 @@ assert.throws(RangeError, () => instance.subtract(""), "empty string"); assert.throws(TypeError, () => instance.subtract(Symbol()), "Symbol"); assert.throws(RangeError, () => instance.subtract(7), "number"); assert.throws(RangeError, () => instance.subtract(7n), "bigint"); +assert.throws(TypeError, () => instance.subtract([]), "array"); +assert.throws(TypeError, () => instance.subtract(() => {}), "function"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/subtract/argument-singular-properties.js b/test/built-ins/Temporal/PlainDate/prototype/subtract/argument-singular-properties.js new file mode 100644 index 0000000000..b83b101653 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/subtract/argument-singular-properties.js @@ -0,0 +1,27 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.subtract +description: Singular properties in the property bag are always ignored +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDate(2000, 5, 2); + +[ + { year: 1 }, + { month: 2 }, + { week: 3 }, + { day: 4 }, + { hour: 5 }, + { minute: 6 }, + { second: 7 }, + { millisecond: 8 }, + { microsecond: 9 }, + { nanosecond: 10 }, +].forEach((badObject) => { + assert.throws(TypeError, () => instance.subtract(badObject), + "Throw TypeError if temporalDurationLike is not valid"); +}); + diff --git a/test/built-ins/Temporal/PlainDate/prototype/subtract/argument-singular-units.js b/test/built-ins/Temporal/PlainDate/prototype/subtract/argument-singular-units.js deleted file mode 100644 index c8d7a3818b..0000000000 --- a/test/built-ins/Temporal/PlainDate/prototype/subtract/argument-singular-units.js +++ /dev/null @@ -1,13 +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.subtract -description: Ignores singular properties -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const date = Temporal.PlainDate.from("2019-11-18"); -TemporalHelpers.assertPlainDate(date.subtract({ month: 1, days: 1 }), - 2019, 11, "M11", 17); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/add/argument-invalid-property.js b/test/built-ins/Temporal/PlainDateTime/prototype/add/argument-invalid-property.js new file mode 100644 index 0000000000..892e91e1b7 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/add/argument-invalid-property.js @@ -0,0 +1,28 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.add +description: temporalDurationLike object must contain at least one correctly spelled property +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(2000, 5, 2, 15, 30, 45, 987, 654, 321); + +assert.throws( + TypeError, + () => instance.add({}), + "Throws TypeError if no property is present" +); + +assert.throws( + TypeError, + () => instance.add({ nonsense: true }), + "Throws TypeError if no recognized property is present" +); + +assert.throws( + TypeError, + () => instance.add({ sign: 1 }), + "Sign property is not recognized" +); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/add/argument-plain-object-mixed-signs.js b/test/built-ins/Temporal/PlainDateTime/prototype/add/argument-mixed-sign.js similarity index 76% rename from test/built-ins/Temporal/PlainDateTime/prototype/add/argument-plain-object-mixed-signs.js rename to test/built-ins/Temporal/PlainDateTime/prototype/add/argument-mixed-sign.js index 0a308a79a0..f49bd1284c 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/add/argument-plain-object-mixed-signs.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/add/argument-mixed-sign.js @@ -7,12 +7,12 @@ description: Positive and negative values in the temporalDurationLike argument a features: [Temporal] ---*/ -const jan31 = new Temporal.PlainDateTime(2020, 1, 31, 15, 0); +const instance = new Temporal.PlainDateTime(2000, 5, 2, 15, 30, 45, 987, 654, 321); ["constrain", "reject"].forEach((overflow) => { assert.throws( RangeError, - () => jan31.add({ hours: 1, minutes: -30 }, { overflow }), + () => instance.add({ hours: 1, minutes: -30 }, { overflow }), `mixed positive and negative values always throw (overflow = "${overflow}")` ); }); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/add/argument-not-object.js b/test/built-ins/Temporal/PlainDateTime/prototype/add/argument-not-object.js index 27f9fec46f..d47cbe93ae 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/add/argument-not-object.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/add/argument-not-object.js @@ -7,7 +7,7 @@ description: Passing a primitive other than string to add() throws features: [Symbol, Temporal] ---*/ -const instance = Temporal.PlainDateTime.from({ year: 2000, month: 5, day: 2, minute: 34, second: 56, millisecond: 987, microsecond: 654, nanosecond: 321 }); +const instance = new Temporal.PlainDateTime(2000, 5, 2, 15, 30, 45, 987, 654, 321); assert.throws(RangeError, () => instance.add(undefined), "undefined"); assert.throws(RangeError, () => instance.add(null), "null"); assert.throws(RangeError, () => instance.add(true), "boolean"); @@ -15,3 +15,5 @@ assert.throws(RangeError, () => instance.add(""), "empty string"); assert.throws(TypeError, () => instance.add(Symbol()), "Symbol"); assert.throws(RangeError, () => instance.add(7), "number"); assert.throws(RangeError, () => instance.add(7n), "bigint"); +assert.throws(TypeError, () => instance.add([]), "array"); +assert.throws(TypeError, () => instance.add(() => {}), "function"); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/add/argument-object-insufficient-data.js b/test/built-ins/Temporal/PlainDateTime/prototype/add/argument-object-insufficient-data.js deleted file mode 100644 index 4780d5ac08..0000000000 --- a/test/built-ins/Temporal/PlainDateTime/prototype/add/argument-object-insufficient-data.js +++ /dev/null @@ -1,35 +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.add -description: At least one recognized property has to be present in argument -features: [Temporal] -includes: [temporalHelpers.js] ----*/ - -const jan31 = new Temporal.PlainDateTime(2020, 1, 31, 15, 0); - -assert.throws( - TypeError, - () => jan31.add({}), - "empty object not acceptable" -); - -assert.throws( - TypeError, - () => jan31.add({ month: 12 }), // should be "months" - "misspelled property in argument throws if no other properties are present" -); - -assert.throws( - TypeError, - () => jan31.add({ nonsense: true }), - "unrecognized properties throw if no other recognized property is present" -); - -TemporalHelpers.assertPlainDateTime( - jan31.add({ nonsense: 1, days: 1 }), - 2020, 2, "M02", 1, 15, 0, 0, 0, 0, 0, - "unrecognized properties ignored provided at least one recognized property is present" -); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/add/argument-singular-properties.js b/test/built-ins/Temporal/PlainDateTime/prototype/add/argument-singular-properties.js new file mode 100644 index 0000000000..4c0e572d99 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/add/argument-singular-properties.js @@ -0,0 +1,27 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.add +description: Singular properties in the property bag are always ignored +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(2000, 5, 2, 15, 30, 45, 987, 654, 321); + +[ + { year: 1 }, + { month: 2 }, + { week: 3 }, + { day: 4 }, + { hour: 5 }, + { minute: 6 }, + { second: 7 }, + { millisecond: 8 }, + { microsecond: 9 }, + { nanosecond: 10 }, +].forEach((badObject) => { + assert.throws(TypeError, () => instance.add(badObject), + "Throw TypeError if temporalDurationLike is not valid"); +}); + diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/subtract/argument-invalid-property.js b/test/built-ins/Temporal/PlainDateTime/prototype/subtract/argument-invalid-property.js new file mode 100644 index 0000000000..d2ffb7275c --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/subtract/argument-invalid-property.js @@ -0,0 +1,28 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.subtract +description: temporalDurationLike object must contain at least one correctly spelled property +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(2000, 5, 2, 15, 30, 45, 987, 654, 321); + +assert.throws( + TypeError, + () => instance.subtract({}), + "Throws TypeError if no property is present" +); + +assert.throws( + TypeError, + () => instance.subtract({ nonsense: true }), + "Throws TypeError if no recognized property is present" +); + +assert.throws( + TypeError, + () => instance.subtract({ sign: 1 }), + "Sign property is not recognized" +); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/subtract/argument-plain-object-mixed-signs.js b/test/built-ins/Temporal/PlainDateTime/prototype/subtract/argument-mixed-sign.js similarity index 75% rename from test/built-ins/Temporal/PlainDateTime/prototype/subtract/argument-plain-object-mixed-signs.js rename to test/built-ins/Temporal/PlainDateTime/prototype/subtract/argument-mixed-sign.js index cabfd20939..70674852fd 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/subtract/argument-plain-object-mixed-signs.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/subtract/argument-mixed-sign.js @@ -7,12 +7,12 @@ description: Positive and negative values in the temporalDurationLike argument a features: [Temporal] ---*/ -const jan31 = new Temporal.PlainDateTime(2020, 1, 31, 15, 0); +const instance = new Temporal.PlainDateTime(2000, 5, 2, 15, 30, 45, 987, 654, 321); ["constrain", "reject"].forEach((overflow) => { assert.throws( RangeError, - () => jan31.subtract({ hours: 1, minutes: -30 }, { overflow }), + () => instance.subtract({ hours: 1, minutes: -30 }, { overflow }), `mixed positive and negative values always throw (overflow = "${overflow}")` ); }); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/subtract/argument-not-object.js b/test/built-ins/Temporal/PlainDateTime/prototype/subtract/argument-not-object.js index b60b50dcfd..d0e0797d87 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/subtract/argument-not-object.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/subtract/argument-not-object.js @@ -7,7 +7,7 @@ description: Passing a primitive other than string to subtract() throws features: [Symbol, Temporal] ---*/ -const instance = Temporal.PlainDateTime.from({ year: 2000, month: 5, day: 2, minute: 34, second: 56, millisecond: 987, microsecond: 654, nanosecond: 321 }); +const instance = new Temporal.PlainDateTime(2000, 5, 2, 15, 30, 45, 987, 654, 321); assert.throws(RangeError, () => instance.subtract(undefined), "undefined"); assert.throws(RangeError, () => instance.subtract(null), "null"); assert.throws(RangeError, () => instance.subtract(true), "boolean"); @@ -15,3 +15,5 @@ assert.throws(RangeError, () => instance.subtract(""), "empty string"); assert.throws(TypeError, () => instance.subtract(Symbol()), "Symbol"); assert.throws(RangeError, () => instance.subtract(7), "number"); assert.throws(RangeError, () => instance.subtract(7n), "bigint"); +assert.throws(TypeError, () => instance.subtract([]), "array"); +assert.throws(TypeError, () => instance.subtract(() => {}), "function"); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/subtract/argument-object-insufficient-data.js b/test/built-ins/Temporal/PlainDateTime/prototype/subtract/argument-object-insufficient-data.js deleted file mode 100644 index 450d14cefe..0000000000 --- a/test/built-ins/Temporal/PlainDateTime/prototype/subtract/argument-object-insufficient-data.js +++ /dev/null @@ -1,35 +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.subtract -description: At least one recognized property has to be present in argument -features: [Temporal] -includes: [temporalHelpers.js] ----*/ - -const jan31 = new Temporal.PlainDateTime(2020, 1, 31, 15, 0); - -assert.throws( - TypeError, - () => jan31.subtract({}), - "empty object not acceptable" -); - -assert.throws( - TypeError, - () => jan31.subtract({ month: 12 }), // should be "months" - "misspelled property in argument throws if no other properties are present" -); - -assert.throws( - TypeError, - () => jan31.subtract({ nonsense: true }), - "unrecognized properties throw if no other recognized property is present" -); - -TemporalHelpers.assertPlainDateTime( - jan31.subtract({ nonsense: 1, days: 1 }), - 2020, 1, "M01", 30, 15, 0, 0, 0, 0, 0, - "unrecognized properties ignored provided at least one recognized property is present" -); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/subtract/argument-singular-properties.js b/test/built-ins/Temporal/PlainDateTime/prototype/subtract/argument-singular-properties.js new file mode 100644 index 0000000000..f38215f9f2 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/subtract/argument-singular-properties.js @@ -0,0 +1,27 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.subtract +description: Singular properties in the property bag are always ignored +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(2000, 5, 2, 15, 30, 45, 987, 654, 321); + +[ + { year: 1 }, + { month: 2 }, + { week: 3 }, + { day: 4 }, + { hour: 5 }, + { minute: 6 }, + { second: 7 }, + { millisecond: 8 }, + { microsecond: 9 }, + { nanosecond: 10 }, +].forEach((badObject) => { + assert.throws(TypeError, () => instance.subtract(badObject), + "Throw TypeError if temporalDurationLike is not valid"); +}); + diff --git a/test/built-ins/Temporal/PlainTime/prototype/add/argument-invalid-property.js b/test/built-ins/Temporal/PlainTime/prototype/add/argument-invalid-property.js new file mode 100644 index 0000000000..91ff9aaa8c --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/add/argument-invalid-property.js @@ -0,0 +1,28 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaintime.prototype.add +description: temporalDurationLike object must contain at least one correctly spelled property +features: [Temporal] +---*/ + +const instance = new Temporal.PlainTime(15, 30, 45, 987, 654, 321); + +assert.throws( + TypeError, + () => instance.add({}), + "Throws TypeError if no property is present" +); + +assert.throws( + TypeError, + () => instance.add({ nonsense: true }), + "Throws TypeError if no recognized property is present" +); + +assert.throws( + TypeError, + () => instance.add({ sign: 1 }), + "Sign property is not recognized" +); diff --git a/test/built-ins/Temporal/PlainTime/prototype/add/argument-mixed-sign.js b/test/built-ins/Temporal/PlainTime/prototype/add/argument-mixed-sign.js new file mode 100644 index 0000000000..7d83c8761c --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/add/argument-mixed-sign.js @@ -0,0 +1,16 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaintime.prototype.add +description: Positive and negative values in the temporalDurationLike argument are not acceptable +features: [Temporal] +---*/ + +const instance = new Temporal.PlainTime(15, 30, 45, 987, 654, 321); + +assert.throws( + RangeError, + () => instance.add({ hours: 1, minutes: -30 }), + `mixed positive and negative values always throw` +); diff --git a/test/built-ins/Temporal/PlainTime/prototype/add/argument-not-object.js b/test/built-ins/Temporal/PlainTime/prototype/add/argument-not-object.js index d9680e852c..7141264772 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/add/argument-not-object.js +++ b/test/built-ins/Temporal/PlainTime/prototype/add/argument-not-object.js @@ -7,7 +7,7 @@ description: Passing a primitive other than string to add() throws features: [Symbol, Temporal] ---*/ -const instance = Temporal.PlainTime.from({ hour: 12, minute: 34, second: 56, millisecond: 987, microsecond: 654, nanosecond: 321 }); +const instance = new Temporal.PlainTime(15, 30, 45, 987, 654, 321); assert.throws(RangeError, () => instance.add(undefined), "undefined"); assert.throws(RangeError, () => instance.add(null), "null"); assert.throws(RangeError, () => instance.add(true), "boolean"); @@ -15,3 +15,5 @@ assert.throws(RangeError, () => instance.add(""), "empty string"); assert.throws(TypeError, () => instance.add(Symbol()), "Symbol"); assert.throws(RangeError, () => instance.add(7), "number"); assert.throws(RangeError, () => instance.add(7n), "bigint"); +assert.throws(TypeError, () => instance.add([]), "array"); +assert.throws(TypeError, () => instance.add(() => {}), "function"); diff --git a/test/built-ins/Temporal/PlainTime/prototype/add/argument-object-invalid.js b/test/built-ins/Temporal/PlainTime/prototype/add/argument-object-invalid.js deleted file mode 100644 index 553e04fbcd..0000000000 --- a/test/built-ins/Temporal/PlainTime/prototype/add/argument-object-invalid.js +++ /dev/null @@ -1,13 +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.plaintime.prototype.add -description: Mixed positive and negative values or missing properties always throw -features: [Temporal] ----*/ - -const plainTime = new Temporal.PlainTime(12, 34, 56, 123, 987, 500); -assert.throws(RangeError, () => plainTime.add({ hours: 1, minutes: -6 }), "mixed signs"); -assert.throws(TypeError, () => plainTime.add({}), "no properties"); -assert.throws(TypeError, () => plainTime.add({ hour: 12 }), "only singular 'hour' property"); diff --git a/test/built-ins/Temporal/PlainTime/prototype/add/argument-singular-properties.js b/test/built-ins/Temporal/PlainTime/prototype/add/argument-singular-properties.js new file mode 100644 index 0000000000..0d0f3a55e9 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/add/argument-singular-properties.js @@ -0,0 +1,27 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaintime.prototype.add +description: Singular properties in the property bag are always ignored +features: [Temporal] +---*/ + +const instance = new Temporal.PlainTime(15, 30, 45, 987, 654, 321); + +[ + { year: 1 }, + { month: 2 }, + { week: 3 }, + { day: 4 }, + { hour: 5 }, + { minute: 6 }, + { second: 7 }, + { millisecond: 8 }, + { microsecond: 9 }, + { nanosecond: 10 }, +].forEach((badObject) => { + assert.throws(TypeError, () => instance.add(badObject), + "Throw TypeError if temporalDurationLike is not valid"); +}); + diff --git a/test/built-ins/Temporal/PlainTime/prototype/subtract/argument-invalid-property.js b/test/built-ins/Temporal/PlainTime/prototype/subtract/argument-invalid-property.js new file mode 100644 index 0000000000..0bcdeb7df6 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/subtract/argument-invalid-property.js @@ -0,0 +1,28 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaintime.prototype.subtract +description: temporalDurationLike object must contain at least one correctly spelled property +features: [Temporal] +---*/ + +const instance = new Temporal.PlainTime(15, 30, 45, 987, 654, 321); + +assert.throws( + TypeError, + () => instance.subtract({}), + "Throws TypeError if no property is present" +); + +assert.throws( + TypeError, + () => instance.subtract({ nonsense: true }), + "Throws TypeError if no recognized property is present" +); + +assert.throws( + TypeError, + () => instance.subtract({ sign: 1 }), + "Sign property is not recognized" +); diff --git a/test/built-ins/Temporal/PlainTime/prototype/subtract/argument-mixed-sign.js b/test/built-ins/Temporal/PlainTime/prototype/subtract/argument-mixed-sign.js new file mode 100644 index 0000000000..ab79bd1e40 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/subtract/argument-mixed-sign.js @@ -0,0 +1,16 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaintime.prototype.subtract +description: Positive and negative values in the temporalDurationLike argument are not acceptable +features: [Temporal] +---*/ + +const instance = new Temporal.PlainTime(15, 30, 45, 987, 654, 321); + +assert.throws( + RangeError, + () => instance.subtract({ hours: 1, minutes: -30 }), + `mixed positive and negative values always throw` +); diff --git a/test/built-ins/Temporal/PlainTime/prototype/subtract/argument-not-object.js b/test/built-ins/Temporal/PlainTime/prototype/subtract/argument-not-object.js index f8ea166d1d..fd202ca805 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/subtract/argument-not-object.js +++ b/test/built-ins/Temporal/PlainTime/prototype/subtract/argument-not-object.js @@ -7,7 +7,7 @@ description: Passing a primitive other than string to subtract() throws features: [Symbol, Temporal] ---*/ -const instance = Temporal.PlainTime.from({ hour: 12, minute: 34, second: 56, millisecond: 987, microsecond: 654, nanosecond: 321 }); +const instance = new Temporal.PlainTime(15, 30, 45, 987, 654, 321); assert.throws(RangeError, () => instance.subtract(undefined), "undefined"); assert.throws(RangeError, () => instance.subtract(null), "null"); assert.throws(RangeError, () => instance.subtract(true), "boolean"); @@ -15,3 +15,5 @@ assert.throws(RangeError, () => instance.subtract(""), "empty string"); assert.throws(TypeError, () => instance.subtract(Symbol()), "Symbol"); assert.throws(RangeError, () => instance.subtract(7), "number"); assert.throws(RangeError, () => instance.subtract(7n), "bigint"); +assert.throws(TypeError, () => instance.subtract([]), "array"); +assert.throws(TypeError, () => instance.subtract(() => {}), "function"); diff --git a/test/built-ins/Temporal/PlainTime/prototype/subtract/argument-object-invalid.js b/test/built-ins/Temporal/PlainTime/prototype/subtract/argument-object-invalid.js deleted file mode 100644 index df7fcaa34a..0000000000 --- a/test/built-ins/Temporal/PlainTime/prototype/subtract/argument-object-invalid.js +++ /dev/null @@ -1,13 +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.plaintime.prototype.subtract -description: Mixed positive and negative values or missing properties always throw -features: [Temporal] ----*/ - -const plainTime = new Temporal.PlainTime(12, 34, 56, 123, 987, 500); -assert.throws(RangeError, () => plainTime.subtract({ hours: 1, minutes: -6 }), "mixed signs"); -assert.throws(TypeError, () => plainTime.subtract({}), "no properties"); -assert.throws(TypeError, () => plainTime.subtract({ hour: 12 }), "only singular 'hour' property"); diff --git a/test/built-ins/Temporal/PlainTime/prototype/subtract/argument-singular-properties.js b/test/built-ins/Temporal/PlainTime/prototype/subtract/argument-singular-properties.js new file mode 100644 index 0000000000..1f532b9e29 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/subtract/argument-singular-properties.js @@ -0,0 +1,27 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaintime.prototype.subtract +description: Singular properties in the property bag are always ignored +features: [Temporal] +---*/ + +const instance = new Temporal.PlainTime(15, 30, 45, 987, 654, 321); + +[ + { year: 1 }, + { month: 2 }, + { week: 3 }, + { day: 4 }, + { hour: 5 }, + { minute: 6 }, + { second: 7 }, + { millisecond: 8 }, + { microsecond: 9 }, + { nanosecond: 10 }, +].forEach((badObject) => { + assert.throws(TypeError, () => instance.subtract(badObject), + "Throw TypeError if temporalDurationLike is not valid"); +}); + diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-invalid-property.js b/test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-invalid-property.js new file mode 100644 index 0000000000..f67bcc7a38 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-invalid-property.js @@ -0,0 +1,28 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.prototype.add +description: temporalDurationLike object must contain at least one correctly spelled property +features: [Temporal] +---*/ + +const instance = new Temporal.PlainYearMonth(2000, 5); + +assert.throws( + TypeError, + () => instance.add({}), + "Throws TypeError if no property is present" +); + +assert.throws( + TypeError, + () => instance.add({ nonsense: true }), + "Throws TypeError if no recognized property is present" +); + +assert.throws( + TypeError, + () => instance.add({ sign: 1 }), + "Sign property is not recognized" +); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-mixed-sign.js b/test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-mixed-sign.js new file mode 100644 index 0000000000..0096756af5 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-mixed-sign.js @@ -0,0 +1,18 @@ +// 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.add +description: Positive and negative values in the temporalDurationLike argument are not acceptable +features: [Temporal] +---*/ + +const instance = new Temporal.PlainYearMonth(2000, 5); + +["constrain", "reject"].forEach((overflow) => { + assert.throws( + RangeError, + () => instance.add({ hours: 1, minutes: -30 }, { overflow }), + `mixed positive and negative values always throw (overflow = "${overflow}")` + ); +}); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-not-object.js b/test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-not-object.js index 38d7029fd6..fdc21ea1a5 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-not-object.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-not-object.js @@ -7,7 +7,7 @@ description: Passing a primitive other than string to add() throws features: [Symbol, Temporal] ---*/ -const instance = Temporal.PlainYearMonth.from({ year: 2000, month: 5 }); +const instance = new Temporal.PlainYearMonth(2000, 5); assert.throws(RangeError, () => instance.add(undefined), "undefined"); assert.throws(RangeError, () => instance.add(null), "null"); assert.throws(RangeError, () => instance.add(true), "boolean"); @@ -15,3 +15,5 @@ assert.throws(RangeError, () => instance.add(""), "empty string"); assert.throws(TypeError, () => instance.add(Symbol()), "Symbol"); assert.throws(RangeError, () => instance.add(7), "number"); assert.throws(RangeError, () => instance.add(7n), "bigint"); +assert.throws(TypeError, () => instance.add([]), "array"); +assert.throws(TypeError, () => instance.add(() => {}), "function"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-object-invalid.js b/test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-object-invalid.js deleted file mode 100644 index 559be9c9a0..0000000000 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-object-invalid.js +++ /dev/null @@ -1,16 +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.add -description: Mixed positive and negative values or missing properties always throw -features: [Temporal] ----*/ - -const ym = Temporal.PlainYearMonth.from("2019-11"); -for (const overflow of ["constrain", "reject"]) { - assert.throws(RangeError, () => ym.add({ years: 1, months: -6 }, { overflow }), overflow) -} - -assert.throws(TypeError, () => ym.add({}), "no properties"); -assert.throws(TypeError, () => ym.add({ month: 12 }), "only singular 'month' property"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-object-plural.js b/test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-object-plural.js deleted file mode 100644 index 0e2614a9bb..0000000000 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-object-plural.js +++ /dev/null @@ -1,12 +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.add -description: Singular properties are ignored -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const ym = Temporal.PlainYearMonth.from("2019-11"); -TemporalHelpers.assertPlainYearMonth(ym.add({ month: 1, years: 1 }), 2020, 11, "M11"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-singular-properties.js b/test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-singular-properties.js new file mode 100644 index 0000000000..e84adf731c --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-singular-properties.js @@ -0,0 +1,27 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.prototype.add +description: Singular properties in the property bag are always ignored +features: [Temporal] +---*/ + +const instance = new Temporal.PlainYearMonth(2000, 5); + +[ + { year: 1 }, + { month: 2 }, + { week: 3 }, + { day: 4 }, + { hour: 5 }, + { minute: 6 }, + { second: 7 }, + { millisecond: 8 }, + { microsecond: 9 }, + { nanosecond: 10 }, +].forEach((badObject) => { + assert.throws(TypeError, () => instance.add(badObject), + "Throw TypeError if temporalDurationLike is not valid"); +}); + diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-invalid-property.js b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-invalid-property.js new file mode 100644 index 0000000000..d97253f79d --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-invalid-property.js @@ -0,0 +1,28 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.prototype.subtract +description: temporalDurationLike object must contain at least one correctly spelled property +features: [Temporal] +---*/ + +const instance = new Temporal.PlainYearMonth(2000, 5); + +assert.throws( + TypeError, + () => instance.subtract({}), + "Throws TypeError if no property is present" +); + +assert.throws( + TypeError, + () => instance.subtract({ nonsense: true }), + "Throws TypeError if no recognized property is present" +); + +assert.throws( + TypeError, + () => instance.subtract({ sign: 1 }), + "Sign property is not recognized" +); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-mixed-sign.js b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-mixed-sign.js new file mode 100644 index 0000000000..955eb89262 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-mixed-sign.js @@ -0,0 +1,18 @@ +// 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.subtract +description: Positive and negative values in the temporalDurationLike argument are not acceptable +features: [Temporal] +---*/ + +const instance = new Temporal.PlainYearMonth(2000, 5); + +["constrain", "reject"].forEach((overflow) => { + assert.throws( + RangeError, + () => instance.subtract({ hours: 1, minutes: -30 }, { overflow }), + `mixed positive and negative values always throw (overflow = "${overflow}")` + ); +}); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-not-object.js b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-not-object.js index d637cf0e53..1bc421fb86 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-not-object.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-not-object.js @@ -7,7 +7,7 @@ description: Passing a primitive other than string to subtract() throws features: [Symbol, Temporal] ---*/ -const instance = Temporal.PlainYearMonth.from({ year: 2000, month: 5 }); +const instance = new Temporal.PlainYearMonth(2000, 5); assert.throws(RangeError, () => instance.subtract(undefined), "undefined"); assert.throws(RangeError, () => instance.subtract(null), "null"); assert.throws(RangeError, () => instance.subtract(true), "boolean"); @@ -15,3 +15,5 @@ assert.throws(RangeError, () => instance.subtract(""), "empty string"); assert.throws(TypeError, () => instance.subtract(Symbol()), "Symbol"); assert.throws(RangeError, () => instance.subtract(7), "number"); assert.throws(RangeError, () => instance.subtract(7n), "bigint"); +assert.throws(TypeError, () => instance.subtract([]), "array"); +assert.throws(TypeError, () => instance.subtract(() => {}), "function"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-object-invalid.js b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-object-invalid.js deleted file mode 100644 index fb3d4991aa..0000000000 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-object-invalid.js +++ /dev/null @@ -1,16 +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.subtract -description: Mixed positive and negative values or missing properties always throw -features: [Temporal] ----*/ - -const ym = Temporal.PlainYearMonth.from("2019-11"); -for (const overflow of ["constrain", "reject"]) { - assert.throws(RangeError, () => ym.subtract({ years: 1, months: -6 }, { overflow }), overflow) -} - -assert.throws(TypeError, () => ym.subtract({}), "no properties"); -assert.throws(TypeError, () => ym.subtract({ month: 12 }), "only singular 'month' property"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-object-plural.js b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-object-plural.js deleted file mode 100644 index 80fedfc3a4..0000000000 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-object-plural.js +++ /dev/null @@ -1,12 +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.subtract -description: Singular properties are ignored -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const ym = Temporal.PlainYearMonth.from("2019-11"); -TemporalHelpers.assertPlainYearMonth(ym.subtract({ month: 1, years: 1 }), 2018, 11, "M11"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-singular-properties.js b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-singular-properties.js new file mode 100644 index 0000000000..79fbc0a99e --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-singular-properties.js @@ -0,0 +1,27 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.prototype.subtract +description: Singular properties in the property bag are always ignored +features: [Temporal] +---*/ + +const instance = new Temporal.PlainYearMonth(2000, 5); + +[ + { year: 1 }, + { month: 2 }, + { week: 3 }, + { day: 4 }, + { hour: 5 }, + { minute: 6 }, + { second: 7 }, + { millisecond: 8 }, + { microsecond: 9 }, + { nanosecond: 10 }, +].forEach((badObject) => { + assert.throws(TypeError, () => instance.subtract(badObject), + "Throw TypeError if temporalDurationLike is not valid"); +}); + diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/add/argument-invalid-property.js b/test/built-ins/Temporal/ZonedDateTime/prototype/add/argument-invalid-property.js new file mode 100644 index 0000000000..54e0643380 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/add/argument-invalid-property.js @@ -0,0 +1,28 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.add +description: temporalDurationLike object must contain at least one correctly spelled property +features: [Temporal] +---*/ + +const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC"); + +assert.throws( + TypeError, + () => instance.add({}), + "Throws TypeError if no property is present" +); + +assert.throws( + TypeError, + () => instance.add({ nonsense: true }), + "Throws TypeError if no recognized property is present" +); + +assert.throws( + TypeError, + () => instance.add({ sign: 1 }), + "Sign property is not recognized" +); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/add/argument-mixed-sign.js b/test/built-ins/Temporal/ZonedDateTime/prototype/add/argument-mixed-sign.js new file mode 100644 index 0000000000..e52940b8ff --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/add/argument-mixed-sign.js @@ -0,0 +1,18 @@ +// 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.add +description: Positive and negative values in the temporalDurationLike argument are not acceptable +features: [Temporal] +---*/ + +const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC"); + +["constrain", "reject"].forEach((overflow) => { + assert.throws( + RangeError, + () => instance.add({ hours: 1, minutes: -30 }, { overflow }), + `mixed positive and negative values always throw (overflow = "${overflow}")` + ); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/add/argument-not-object.js b/test/built-ins/Temporal/ZonedDateTime/prototype/add/argument-not-object.js new file mode 100644 index 0000000000..51d6ade9a7 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/add/argument-not-object.js @@ -0,0 +1,19 @@ +// 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.add +description: Passing a primitive other than string to add() throws +features: [Symbol, Temporal] +---*/ + +const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC"); +assert.throws(RangeError, () => instance.add(undefined), "undefined"); +assert.throws(RangeError, () => instance.add(null), "null"); +assert.throws(RangeError, () => instance.add(true), "boolean"); +assert.throws(RangeError, () => instance.add(""), "empty string"); +assert.throws(TypeError, () => instance.add(Symbol()), "Symbol"); +assert.throws(RangeError, () => instance.add(7), "number"); +assert.throws(RangeError, () => instance.add(7n), "bigint"); +assert.throws(TypeError, () => instance.add([]), "array"); +assert.throws(TypeError, () => instance.add(() => {}), "function"); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/add/argument-singular-properties.js b/test/built-ins/Temporal/ZonedDateTime/prototype/add/argument-singular-properties.js new file mode 100644 index 0000000000..f210f62093 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/add/argument-singular-properties.js @@ -0,0 +1,27 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.add +description: Singular properties in the property bag are always ignored +features: [Temporal] +---*/ + +const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC"); + +[ + { year: 1 }, + { month: 2 }, + { week: 3 }, + { day: 4 }, + { hour: 5 }, + { minute: 6 }, + { second: 7 }, + { millisecond: 8 }, + { microsecond: 9 }, + { nanosecond: 10 }, +].forEach((badObject) => { + assert.throws(TypeError, () => instance.add(badObject), + "Throw TypeError if temporalDurationLike is not valid"); +}); + diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/subtract/argument-invalid-property.js b/test/built-ins/Temporal/ZonedDateTime/prototype/subtract/argument-invalid-property.js new file mode 100644 index 0000000000..347927b78a --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/subtract/argument-invalid-property.js @@ -0,0 +1,28 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.subtract +description: temporalDurationLike object must contain at least one correctly spelled property +features: [Temporal] +---*/ + +const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC"); + +assert.throws( + TypeError, + () => instance.subtract({}), + "Throws TypeError if no property is present" +); + +assert.throws( + TypeError, + () => instance.subtract({ nonsense: true }), + "Throws TypeError if no recognized property is present" +); + +assert.throws( + TypeError, + () => instance.subtract({ sign: 1 }), + "Sign property is not recognized" +); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/subtract/argument-mixed-sign.js b/test/built-ins/Temporal/ZonedDateTime/prototype/subtract/argument-mixed-sign.js new file mode 100644 index 0000000000..c755f5a0fd --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/subtract/argument-mixed-sign.js @@ -0,0 +1,18 @@ +// 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.subtract +description: Positive and negative values in the temporalDurationLike argument are not acceptable +features: [Temporal] +---*/ + +const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC"); + +["constrain", "reject"].forEach((overflow) => { + assert.throws( + RangeError, + () => instance.subtract({ hours: 1, minutes: -30 }, { overflow }), + `mixed positive and negative values always throw (overflow = "${overflow}")` + ); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/subtract/argument-not-object.js b/test/built-ins/Temporal/ZonedDateTime/prototype/subtract/argument-not-object.js new file mode 100644 index 0000000000..5da56f4630 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/subtract/argument-not-object.js @@ -0,0 +1,19 @@ +// 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.subtract +description: Passing a primitive other than string to subtract() throws +features: [Symbol, Temporal] +---*/ + +const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC"); +assert.throws(RangeError, () => instance.subtract(undefined), "undefined"); +assert.throws(RangeError, () => instance.subtract(null), "null"); +assert.throws(RangeError, () => instance.subtract(true), "boolean"); +assert.throws(RangeError, () => instance.subtract(""), "empty string"); +assert.throws(TypeError, () => instance.subtract(Symbol()), "Symbol"); +assert.throws(RangeError, () => instance.subtract(7), "number"); +assert.throws(RangeError, () => instance.subtract(7n), "bigint"); +assert.throws(TypeError, () => instance.subtract([]), "array"); +assert.throws(TypeError, () => instance.subtract(() => {}), "function"); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/subtract/argument-singular-properties.js b/test/built-ins/Temporal/ZonedDateTime/prototype/subtract/argument-singular-properties.js new file mode 100644 index 0000000000..a4ced51b08 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/subtract/argument-singular-properties.js @@ -0,0 +1,27 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.subtract +description: Singular properties in the property bag are always ignored +features: [Temporal] +---*/ + +const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC"); + +[ + { year: 1 }, + { month: 2 }, + { week: 3 }, + { day: 4 }, + { hour: 5 }, + { minute: 6 }, + { second: 7 }, + { millisecond: 8 }, + { microsecond: 9 }, + { nanosecond: 10 }, +].forEach((badObject) => { + assert.throws(TypeError, () => instance.subtract(badObject), + "Throw TypeError if temporalDurationLike is not valid"); +}); +