From 9c6ecf53267532c81ea390b83c39db2edf209ae9 Mon Sep 17 00:00:00 2001 From: Sarah GHP <sarah.groff.palermo@gmail.com> Date: Tue, 16 Nov 2021 19:48:53 +0100 Subject: [PATCH] Tests disallowed smallest and largest unit arguments to PYM.since --- .../since/largestunit-disallowed-units.js | 24 ++++++++++++++++ .../since/smallestunit-disallowed-units.js | 28 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/since/largestunit-disallowed-units.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/since/smallestunit-disallowed-units.js diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/since/largestunit-disallowed-units.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/largestunit-disallowed-units.js new file mode 100644 index 0000000000..da5ff92999 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/largestunit-disallowed-units.js @@ -0,0 +1,24 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.prototype.since +description: Since throws on to0-small largestUnit +features: [Temporal, arrow-function] +---*/ + +const earlier = new Temporal.PlainYearMonth(2019, 1); +const later = new Temporal.PlainYearMonth(2021, 9); + +[ + 'weeks', + 'days', + 'hours', + 'minutes', + 'seconds', + 'milliseconds', + 'microseconds', + 'nanoseconds' +].forEach((largestUnit) => { + assert.throws(RangeError, () => later.since(earlier, { largestUnit }),`throws on disallowed or invalid largestUnit: ${largestUnit}`); +}); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/since/smallestunit-disallowed-units.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/smallestunit-disallowed-units.js new file mode 100644 index 0000000000..919ec154cd --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/smallestunit-disallowed-units.js @@ -0,0 +1,28 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.prototype.since +description: Since throws on disallowed or invalid smallestUnit +features: [Temporal, arrow-function] +---*/ + +const earlier = new Temporal.PlainYearMonth(2019, 1); +const later = new Temporal.PlainYearMonth(2021, 9); + +[ + 'era', + 'weeks', + 'days', + 'hours', + 'minutes', + 'seconds', + 'milliseconds', + 'microseconds', + 'nanoseconds', + 'nonsense' +].forEach((smallestUnit) => { + assert.throws(RangeError, () => later.since(earlier, { smallestUnit }),`throws on disallowed or invalid smallestUnit: ${smallestUnit}`); +}); + +assert.throws(RangeError, () => later.since(earlier, { largestUnit: 'months', smallestUnit: 'years' }), 'throws if smallestUnit is larger than largestUnit');