From 6b5297a14238cc5a6498a02b76ff37f2b316fd17 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Tue, 26 Jul 2022 17:56:55 -0700 Subject: [PATCH] Temporal: Add tests for invalid strings as values of 'offset' property (...in property bags; the 'offset' option in an options object already has tests) --- ...iveto-propertybag-invalid-offset-string.js | 23 +++++++++++++++ ...iveto-propertybag-invalid-offset-string.js | 22 ++++++++++++++ ...iveto-propertybag-invalid-offset-string.js | 22 ++++++++++++++ ...iveto-propertybag-invalid-offset-string.js | 22 ++++++++++++++ ...iveto-propertybag-invalid-offset-string.js | 22 ++++++++++++++ ...ument-propertybag-invalid-offset-string.js | 23 +++++++++++++++ ...ument-propertybag-invalid-offset-string.js | 29 +++++++++++++++++++ ...ument-propertybag-invalid-offset-string.js | 22 ++++++++++++++ ...ument-propertybag-invalid-offset-string.js | 22 ++++++++++++++ ...ument-propertybag-invalid-offset-string.js | 22 ++++++++++++++ .../with/offset-property-invalid-string.js | 29 +++++++++++++++++++ 11 files changed, 258 insertions(+) create mode 100644 test/built-ins/Temporal/Duration/compare/relativeto-propertybag-invalid-offset-string.js create mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-invalid-offset-string.js create mode 100644 test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-invalid-offset-string.js create mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-invalid-offset-string.js create mode 100644 test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-invalid-offset-string.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-invalid-offset-string.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-invalid-offset-string.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-invalid-offset-string.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-invalid-offset-string.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-invalid-offset-string.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/with/offset-property-invalid-string.js diff --git a/test/built-ins/Temporal/Duration/compare/relativeto-propertybag-invalid-offset-string.js b/test/built-ins/Temporal/Duration/compare/relativeto-propertybag-invalid-offset-string.js new file mode 100644 index 0000000000..108c773a7b --- /dev/null +++ b/test/built-ins/Temporal/Duration/compare/relativeto-propertybag-invalid-offset-string.js @@ -0,0 +1,23 @@ +// 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.compare +description: relativeTo property bag with offset property is rejected if offset is in the wrong format +features: [Temporal] +---*/ + +const timeZone = new Temporal.TimeZone("UTC"); +const d1 = new Temporal.Duration(0, 1, 0, 280); +const d2 = new Temporal.Duration(0, 1, 0, 281); + +const badOffsets = [ + "00:00", // missing sign + "+0", // too short + "-000:00", // too long + 0, // converts to a string that is invalid +]; +badOffsets.forEach((offset) => { + const relativeTo = { year: 2021, month: 10, day: 28, offset, timeZone }; + assert.throws(RangeError, () => Temporal.Duration.compare(d1, d2, { relativeTo }), `"${offset} is not a valid offset string`); +}); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-invalid-offset-string.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-invalid-offset-string.js new file mode 100644 index 0000000000..3eda03336f --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-invalid-offset-string.js @@ -0,0 +1,22 @@ +// 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: relativeTo property bag with offset property is rejected if offset is in the wrong format +features: [Temporal] +---*/ + +const timeZone = new Temporal.TimeZone("UTC"); +const instance = new Temporal.Duration(1, 0, 0, 1); + +const badOffsets = [ + "00:00", // missing sign + "+0", // too short + "-000:00", // too long + 0, // converts to a string that is invalid +]; +badOffsets.forEach((offset) => { + const relativeTo = { year: 2021, month: 10, day: 28, offset, timeZone }; + assert.throws(RangeError, () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), `"${offset} is not a valid offset string`); +}); diff --git a/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-invalid-offset-string.js b/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-invalid-offset-string.js new file mode 100644 index 0000000000..109e22b3e7 --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-invalid-offset-string.js @@ -0,0 +1,22 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.round +description: relativeTo property bag with offset property is rejected if offset is in the wrong format +features: [Temporal] +---*/ + +const timeZone = new Temporal.TimeZone("UTC"); +const instance = new Temporal.Duration(1, 0, 0, 0, 24); + +const badOffsets = [ + "00:00", // missing sign + "+0", // too short + "-000:00", // too long + 0, // converts to a string that is invalid +]; +badOffsets.forEach((offset) => { + const relativeTo = { year: 2021, month: 10, day: 28, offset, timeZone }; + assert.throws(RangeError, () => instance.round({ largestUnit: "years", relativeTo }), `"${offset} is not a valid offset string`); +}); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-invalid-offset-string.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-invalid-offset-string.js new file mode 100644 index 0000000000..8043830d66 --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-invalid-offset-string.js @@ -0,0 +1,22 @@ +// 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: relativeTo property bag with offset property is rejected if offset is in the wrong format +features: [Temporal] +---*/ + +const timeZone = new Temporal.TimeZone("UTC"); +const instance = new Temporal.Duration(1, 0, 0, 1); + +const badOffsets = [ + "00:00", // missing sign + "+0", // too short + "-000:00", // too long + 0, // converts to a string that is invalid +]; +badOffsets.forEach((offset) => { + const relativeTo = { year: 2021, month: 10, day: 28, offset, timeZone }; + assert.throws(RangeError, () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), `"${offset} is not a valid offset string`); +}); diff --git a/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-invalid-offset-string.js b/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-invalid-offset-string.js new file mode 100644 index 0000000000..a36594be83 --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-invalid-offset-string.js @@ -0,0 +1,22 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.duration.prototype.total +description: relativeTo property bag with offset property is rejected if offset is in the wrong format +features: [Temporal] +---*/ + +const timeZone = new Temporal.TimeZone("UTC"); +const instance = new Temporal.Duration(1, 0, 0, 0, 24); + +const badOffsets = [ + "00:00", // missing sign + "+0", // too short + "-000:00", // too long + 0, // converts to a string that is invalid +]; +badOffsets.forEach((offset) => { + const relativeTo = { year: 2021, month: 10, day: 28, offset, timeZone }; + assert.throws(RangeError, () => instance.total({ unit: "days", relativeTo }), `"${offset} is not a valid offset string`); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-invalid-offset-string.js b/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-invalid-offset-string.js new file mode 100644 index 0000000000..6a10a37901 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-invalid-offset-string.js @@ -0,0 +1,23 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.compare +description: Property bag with offset property is rejected if offset is in the wrong format +features: [Temporal] +---*/ + +const timeZone = new Temporal.TimeZone("UTC"); +const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone); + +const badOffsets = [ + "00:00", // missing sign + "+0", // too short + "-000:00", // too long + 0, // converts to a string that is invalid +]; +badOffsets.forEach((offset) => { + const arg = { year: 2021, month: 10, day: 28, offset, timeZone }; + assert.throws(RangeError, () => Temporal.ZonedDateTime.compare(arg, datetime), `"${offset} is not a valid offset string (second argument)`); + assert.throws(RangeError, () => Temporal.ZonedDateTime.compare(datetime, arg), `"${offset} is not a valid offset string (second argument)`); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-invalid-offset-string.js b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-invalid-offset-string.js new file mode 100644 index 0000000000..edbb81772b --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/from/argument-propertybag-invalid-offset-string.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.from +description: Property bag with offset property is rejected if offset is in the wrong format +features: [Temporal] +---*/ + +const timeZone = new Temporal.TimeZone("UTC"); + +const offsetOptions = ['use', 'prefer', 'ignore', 'reject']; + +const badOffsets = [ + "00:00", // missing sign + "+0", // too short + "-000:00", // too long + 0, // converts to a string that is invalid +]; +offsetOptions.forEach((offsetOption) => { + badOffsets.forEach((offset) => { + const arg = { year: 2021, month: 10, day: 28, offset, timeZone }; + assert.throws( + RangeError, + () => Temporal.ZonedDateTime.from(arg, { offset: offsetOption }), + `"${offset} is not a valid offset string (with offset option ${offsetOption})` + ); + }); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-invalid-offset-string.js b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-invalid-offset-string.js new file mode 100644 index 0000000000..35f4b6d469 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/equals/argument-propertybag-invalid-offset-string.js @@ -0,0 +1,22 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.equals +description: Property bag with offset property is rejected if offset is in the wrong format +features: [Temporal] +---*/ + +const timeZone = new Temporal.TimeZone("UTC"); +const instance = new Temporal.ZonedDateTime(0n, timeZone); + +const badOffsets = [ + "00:00", // missing sign + "+0", // too short + "-000:00", // too long + 0, // converts to a string that is invalid +]; +badOffsets.forEach((offset) => { + const arg = { year: 2021, month: 10, day: 28, offset, timeZone }; + assert.throws(RangeError, () => instance.equals(arg), `"${offset} is not a valid offset string`); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-invalid-offset-string.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-invalid-offset-string.js new file mode 100644 index 0000000000..80a15d787c --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/argument-propertybag-invalid-offset-string.js @@ -0,0 +1,22 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.since +description: Property bag with offset property is rejected if offset is in the wrong format +features: [Temporal] +---*/ + +const timeZone = new Temporal.TimeZone("UTC"); +const instance = new Temporal.ZonedDateTime(0n, timeZone); + +const badOffsets = [ + "00:00", // missing sign + "+0", // too short + "-000:00", // too long + 0, // converts to a string that is invalid +]; +badOffsets.forEach((offset) => { + const arg = { year: 2021, month: 10, day: 28, offset, timeZone }; + assert.throws(RangeError, () => instance.since(arg), `"${offset} is not a valid offset string`); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-invalid-offset-string.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-invalid-offset-string.js new file mode 100644 index 0000000000..adcbc5b9d9 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/argument-propertybag-invalid-offset-string.js @@ -0,0 +1,22 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.until +description: Property bag with offset property is rejected if offset is in the wrong format +features: [Temporal] +---*/ + +const timeZone = new Temporal.TimeZone("UTC"); +const instance = new Temporal.ZonedDateTime(0n, timeZone); + +const badOffsets = [ + "00:00", // missing sign + "+0", // too short + "-000:00", // too long + 0, // converts to a string that is invalid +]; +badOffsets.forEach((offset) => { + const arg = { year: 2021, month: 10, day: 28, offset, timeZone }; + assert.throws(RangeError, () => instance.until(arg), `"${offset} is not a valid offset string`); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/with/offset-property-invalid-string.js b/test/built-ins/Temporal/ZonedDateTime/prototype/with/offset-property-invalid-string.js new file mode 100644 index 0000000000..18e5cb4074 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/with/offset-property-invalid-string.js @@ -0,0 +1,29 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.with +description: Property bag with offset property is rejected if offset is in the wrong format +features: [Temporal] +---*/ + +const timeZone = new Temporal.TimeZone("UTC"); +const instance = new Temporal.ZonedDateTime(0n, timeZone); + +const offsetOptions = ['use', 'prefer', 'ignore', 'reject']; + +const badOffsets = [ + "00:00", // missing sign + "+0", // too short + "-000:00", // too long + 0, // converts to a string that is invalid +]; +offsetOptions.forEach((offsetOption) => { + badOffsets.forEach((offset) => { + assert.throws( + RangeError, + () => instance.with({ offset }, { offset: offsetOption }), + `"${offset} is not a valid offset string (with ${offsetOption} offset option)`, + ); + }); +});