From b37d74191a59d020fb5ec278162d7a54c0f5332f Mon Sep 17 00:00:00 2001 From: Aditi Date: Thu, 28 Jul 2022 18:04:58 +0530 Subject: [PATCH] Add tests for wrong argument type in Temporal.TimeZone --- .../getNextTransition/argument-wrong-type.js | 37 +++++++++++++++++++ .../argument-wrong-type.js | 37 +++++++++++++++++++ .../getOffsetStringFor/argument-wrong-type.js | 37 +++++++++++++++++++ .../argument-wrong-type.js | 37 +++++++++++++++++++ 4 files changed, 148 insertions(+) create mode 100644 test/built-ins/Temporal/TimeZone/prototype/getNextTransition/argument-wrong-type.js create mode 100644 test/built-ins/Temporal/TimeZone/prototype/getOffsetNanosecondsFor/argument-wrong-type.js create mode 100644 test/built-ins/Temporal/TimeZone/prototype/getOffsetStringFor/argument-wrong-type.js create mode 100644 test/built-ins/Temporal/TimeZone/prototype/getPreviousTransition/argument-wrong-type.js diff --git a/test/built-ins/Temporal/TimeZone/prototype/getNextTransition/argument-wrong-type.js b/test/built-ins/Temporal/TimeZone/prototype/getNextTransition/argument-wrong-type.js new file mode 100644 index 0000000000..2ee1c8a62e --- /dev/null +++ b/test/built-ins/Temporal/TimeZone/prototype/getNextTransition/argument-wrong-type.js @@ -0,0 +1,37 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.timezone.prototype.getnexttransition +description: > + Appropriate error thrown when argument cannot be converted to a valid string + for Instant +features: [BigInt, Symbol, Temporal] +---*/ + +const instance = new Temporal.TimeZone("UTC"); + +const rangeErrorTests = [ + [undefined, "undefined"], + [null, "null"], + [true, "boolean"], + ["", "empty string"], + [1, "number that doesn't convert to a valid ISO string"], + [19761118, "number that would convert to a valid ISO string in other contexts"], + [1n, "bigint"], + [{}, "plain object"], + [Temporal.Instant, "Temporal.Instant, object"], +]; + +for (const [arg, description] of rangeErrorTests) { + assert.throws(RangeError, () => instance.getNextTransition(arg), `${description} does not convert to a valid ISO string`); +} + +const typeErrorTests = [ + [Symbol(), "symbol"], + [Temporal.Instant.prototype, "Temporal.Instant.prototype, object"], // fails brand check in toString() +]; + +for (const [arg, description] of typeErrorTests) { + assert.throws(TypeError, () => instance.getNextTransition(arg), `${description} does not convert to a string`); +} diff --git a/test/built-ins/Temporal/TimeZone/prototype/getOffsetNanosecondsFor/argument-wrong-type.js b/test/built-ins/Temporal/TimeZone/prototype/getOffsetNanosecondsFor/argument-wrong-type.js new file mode 100644 index 0000000000..18524e21a6 --- /dev/null +++ b/test/built-ins/Temporal/TimeZone/prototype/getOffsetNanosecondsFor/argument-wrong-type.js @@ -0,0 +1,37 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.timezone.prototype.getoffsetnanosecondsfor +description: > + Appropriate error thrown when argument cannot be converted to a valid string + for Instant +features: [BigInt, Symbol, Temporal] +---*/ + +const instance = new Temporal.TimeZone("UTC"); + +const rangeErrorTests = [ + [undefined, "undefined"], + [null, "null"], + [true, "boolean"], + ["", "empty string"], + [1, "number that doesn't convert to a valid ISO string"], + [19761118, "number that would convert to a valid ISO string in other contexts"], + [1n, "bigint"], + [{}, "plain object"], + [Temporal.Instant, "Temporal.Instant, object"], +]; + +for (const [arg, description] of rangeErrorTests) { + assert.throws(RangeError, () => instance.getOffsetNanosecondsFor(arg), `${description} does not convert to a valid ISO string`); +} + +const typeErrorTests = [ + [Symbol(), "symbol"], + [Temporal.Instant.prototype, "Temporal.Instant.prototype, object"], // fails brand check in toString() +]; + +for (const [arg, description] of typeErrorTests) { + assert.throws(TypeError, () => instance.getOffsetNanosecondsFor(arg), `${description} does not convert to a string`); +} diff --git a/test/built-ins/Temporal/TimeZone/prototype/getOffsetStringFor/argument-wrong-type.js b/test/built-ins/Temporal/TimeZone/prototype/getOffsetStringFor/argument-wrong-type.js new file mode 100644 index 0000000000..9838043bfa --- /dev/null +++ b/test/built-ins/Temporal/TimeZone/prototype/getOffsetStringFor/argument-wrong-type.js @@ -0,0 +1,37 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.timezone.prototype.getoffsetstringfor +description: > + Appropriate error thrown when argument cannot be converted to a valid string + for Instant +features: [BigInt, Symbol, Temporal] +---*/ + +const instance = new Temporal.TimeZone("UTC"); + +const rangeErrorTests = [ + [undefined, "undefined"], + [null, "null"], + [true, "boolean"], + ["", "empty string"], + [1, "number that doesn't convert to a valid ISO string"], + [19761118, "number that would convert to a valid ISO string in other contexts"], + [1n, "bigint"], + [{}, "plain object"], + [Temporal.Instant, "Temporal.Instant, object"], +]; + +for (const [arg, description] of rangeErrorTests) { + assert.throws(RangeError, () => instance.getOffsetStringFor(arg), `${description} does not convert to a valid ISO string`); +} + +const typeErrorTests = [ + [Symbol(), "symbol"], + [Temporal.Instant.prototype, "Temporal.Instant.prototype, object"], // fails brand check in toString() +]; + +for (const [arg, description] of typeErrorTests) { + assert.throws(TypeError, () => instance.getOffsetStringFor(arg), `${description} does not convert to a string`); +} diff --git a/test/built-ins/Temporal/TimeZone/prototype/getPreviousTransition/argument-wrong-type.js b/test/built-ins/Temporal/TimeZone/prototype/getPreviousTransition/argument-wrong-type.js new file mode 100644 index 0000000000..5cda189165 --- /dev/null +++ b/test/built-ins/Temporal/TimeZone/prototype/getPreviousTransition/argument-wrong-type.js @@ -0,0 +1,37 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.timezone.prototype.getprevioustransition +description: > + Appropriate error thrown when argument cannot be converted to a valid string + for Instant +features: [BigInt, Symbol, Temporal] +---*/ + +const instance = new Temporal.TimeZone("UTC"); + +const rangeErrorTests = [ + [undefined, "undefined"], + [null, "null"], + [true, "boolean"], + ["", "empty string"], + [1, "number that doesn't convert to a valid ISO string"], + [19761118, "number that would convert to a valid ISO string in other contexts"], + [1n, "bigint"], + [{}, "plain object"], + [Temporal.Instant, "Temporal.Instant, object"], +]; + +for (const [arg, description] of rangeErrorTests) { + assert.throws(RangeError, () => instance.getPreviousTransition(arg), `${description} does not convert to a valid ISO string`); +} + +const typeErrorTests = [ + [Symbol(), "symbol"], + [Temporal.Instant.prototype, "Temporal.Instant.prototype, object"], // fails brand check in toString() +]; + +for (const [arg, description] of typeErrorTests) { + assert.throws(TypeError, () => instance.getPreviousTransition(arg), `${description} does not convert to a string`); +}