From 22539853cda386c2e3249c400dbb73e950a096aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Bargull?= Date: Tue, 19 Nov 2024 16:30:20 +0100 Subject: [PATCH] Temporal: Coverage for Temporal.PlainDate --- .../get-prototype-from-constructor-throws.js | 40 ++++++++++++++++ ...if-rounded-date-outside-valid-iso-range.js | 47 +++++++++++++++++++ .../argument-object-get-plainTime-throws.js | 32 +++++++++++++ .../argument-object-get-timezone-throws.js | 26 ++++++++++ .../argument-object-timezone-wrong-type.js | 43 +++++++++++++++++ .../get-epoch-nanoseconds-for-throws.js | 46 ++++++++++++++++++ .../get-start-of-day-throws.js | 25 ++++++++++ ...bined-date-time-outside-valid-iso-range.js | 30 ++++++++++++ ...if-rounded-date-outside-valid-iso-range.js | 47 +++++++++++++++++++ 9 files changed, 336 insertions(+) create mode 100644 test/built-ins/Temporal/PlainDate/get-prototype-from-constructor-throws.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/since/throws-if-rounded-date-outside-valid-iso-range.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-object-get-plainTime-throws.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-object-get-timezone-throws.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-object-timezone-wrong-type.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/get-epoch-nanoseconds-for-throws.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/get-start-of-day-throws.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/throws-if-combined-date-time-outside-valid-iso-range.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/until/throws-if-rounded-date-outside-valid-iso-range.js diff --git a/test/built-ins/Temporal/PlainDate/get-prototype-from-constructor-throws.js b/test/built-ins/Temporal/PlainDate/get-prototype-from-constructor-throws.js new file mode 100644 index 0000000000..daaa184151 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/get-prototype-from-constructor-throws.js @@ -0,0 +1,40 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate +description: > + OrdinaryCreateFromConstructor returns with an abrupt completion. +info: | + CreateTemporalDate ( isoDate, calendar [ , newTarget ] ) + + ... + 3. Let object be ? OrdinaryCreateFromConstructor(newTarget, + "%Temporal.PlainDate.prototype%", « [[InitializedTemporalDate]], [[ISODate]], + [[Calendar]] »). + ... + + OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, intrinsicDefaultProto). + ... + + GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 2. Let proto be ? Get(constructor, "prototype"). + ... + +features: [Temporal] +---*/ + +var newTarget = Object.defineProperty(function(){}.bind(), "prototype", { + get() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Reflect.construct(Temporal.PlainDate, [1970, 1, 1], newTarget) +}); diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/throws-if-rounded-date-outside-valid-iso-range.js b/test/built-ins/Temporal/PlainDate/prototype/since/throws-if-rounded-date-outside-valid-iso-range.js new file mode 100644 index 0000000000..9ff4c1e1ba --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/since/throws-if-rounded-date-outside-valid-iso-range.js @@ -0,0 +1,47 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.since +description: > + Throws if rounded date outside valid ISO date range. +info: | + Temporal.PlainDate.prototype.since ( other [ , options ] ) + + ... + 3. Return ? DifferenceTemporalPlainDate(since, temporalDate, other, options). + + DifferenceTemporalPlainDate ( operation, temporalDate, other, options ) + + ... + 8. If settings.[[SmallestUnit]] is not day or settings.[[RoundingIncrement]] ≠ 1, then + ... + d. Set duration to ? RoundRelativeDuration(duration, destEpochNs, isoDateTime, + unset, temporalDate.[[Calendar]], settings.[[LargestUnit]], + settings.[[RoundingIncrement]], settings.[[SmallestUnit]], settings.[[RoundingMode]]). + ... + + RoundRelativeDuration ( duration, destEpochNs, isoDateTime, timeZone, calendar, + largestUnit, increment, smallestUnit, roundingMode ) + + ... + 5. If irregularLengthUnit is true, then + a. Let record be ? NudgeToCalendarUnit(sign, duration, destEpochNs, isoDateTime, + timeZone, calendar, increment, smallestUnit, roundingMode). + ... + + NudgeToCalendarUnit ( sign, duration, destEpochNs, isoDateTime, timeZone, calendar, + increment, unit, roundingMode ) + + ... + 8. Let end be ? CalendarDateAdd(calendar, isoDateTime.[[ISODate]], endDuration, constrain). + ... + +features: [Temporal] +---*/ + +var from = new Temporal.PlainDate(1970, 1, 1); +var to = new Temporal.PlainDate(1971, 1, 1); +var options = {roundingIncrement: 100_000_000, smallestUnit: "months"}; + +assert.throws(RangeError, () => from.since(to, options)); diff --git a/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-object-get-plainTime-throws.js b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-object-get-plainTime-throws.js new file mode 100644 index 0000000000..7ddf1a421c --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-object-get-plainTime-throws.js @@ -0,0 +1,32 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.tozoneddatetime +description: > + Accessor property for "plainTime" throws an error. +info: | + Temporal.PlainDate.prototype.toZonedDateTime ( item ) + + ... + 3. If item is an Object, then + a. Let timeZoneLike be ? Get(item, "timeZone"). + b. If timeZoneLike is undefined, then + ... + c. Else, + i. Let timeZone be ? ToTemporalTimeZoneIdentifier(timeZoneLike). + ii. Let temporalTime be ? Get(item, "plainTime"). + ... +features: [Temporal] +---*/ + +var instance = new Temporal.PlainDate(1970, 1, 1); + +var item = { + timeZone: "UTC", + get plainTime() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, () => instance.toZonedDateTime(item)); diff --git a/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-object-get-timezone-throws.js b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-object-get-timezone-throws.js new file mode 100644 index 0000000000..3e3e417124 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-object-get-timezone-throws.js @@ -0,0 +1,26 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.tozoneddatetime +description: > + Accessor property for "timeZone" throws an error. +info: | + Temporal.PlainDate.prototype.toZonedDateTime ( item ) + + ... + 3. If item is an Object, then + a. Let timeZoneLike be ? Get(item, "timeZone"). + ... +features: [Temporal] +---*/ + +var instance = new Temporal.PlainDate(1970, 1, 1); + +var item = { + get timeZone() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, () => instance.toZonedDateTime(item)); diff --git a/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-object-timezone-wrong-type.js b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-object-timezone-wrong-type.js new file mode 100644 index 0000000000..d053f05cce --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/argument-object-timezone-wrong-type.js @@ -0,0 +1,43 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.tozoneddatetime +description: > + Property "timeZone" can't be parsed as a time zone. +info: | + Temporal.PlainDate.prototype.toZonedDateTime ( item ) + + ... + 3. If item is an Object, then + a. Let timeZoneLike be ? Get(item, "timeZone"). + b. If timeZoneLike is undefined, then + .. + c. Else, + i. Let timeZone be ? ToTemporalTimeZoneIdentifier(timeZoneLike). + ... + + ToTemporalTimeZoneIdentifier ( temporalTimeZoneLike ) + + 1. If temporalTimeZoneLike is an Object, then + ... + 2. If temporalTimeZoneLike is not a String, throw a TypeError exception. + ... +features: [Temporal] +---*/ + +var instance = new Temporal.PlainDate(1970, 1, 1); + +for (var timeZone of [ + null, + false, + 0, + 0n, + Symbol(), + {}, + [], + function() {}, +]) { + var item = {timeZone}; + assert.throws(TypeError, () => instance.toZonedDateTime(item)); +} diff --git a/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/get-epoch-nanoseconds-for-throws.js b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/get-epoch-nanoseconds-for-throws.js new file mode 100644 index 0000000000..d9973b56c2 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/get-epoch-nanoseconds-for-throws.js @@ -0,0 +1,46 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.tozoneddatetime +description: > + GetEpochNanosecondsFor throws a RangeError for values outside the valid limits. +info: | + Temporal.PlainDate.prototype.toZonedDateTime ( item ) + + ... + 5. If temporalTime is undefined, then + ... + 6. Else, + ... + d. Let epochNs be ? GetEpochNanosecondsFor(timeZone, isoDateTime, compatible). + ... +features: [Temporal] +---*/ + +var minDate = new Temporal.PlainDate(-271821, 4, 19); +var minDateTime = new Temporal.PlainDate(-271821, 4, 20); +var maxDate = new Temporal.PlainDate(275760, 9, 13); + +var midnight = new Temporal.PlainTime(); +var oneHourPastMidnight = new Temporal.PlainTime(1); + +assert.throws(RangeError, () => minDate.toZonedDateTime({ + timeZone: "UTC", + plainTime: oneHourPastMidnight, +})); + +assert.throws(RangeError, () => minDate.toZonedDateTime({ + timeZone: "+00", + plainTime: oneHourPastMidnight, +})); + +assert.throws(RangeError, () => minDateTime.toZonedDateTime({ + timeZone: "+01", + temporalTime: midnight, +})); + +assert.throws(RangeError, () => maxDate.toZonedDateTime({ + timeZone: "-01", + temporalTime: midnight, +})); diff --git a/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/get-start-of-day-throws.js b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/get-start-of-day-throws.js new file mode 100644 index 0000000000..304b1266ae --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/get-start-of-day-throws.js @@ -0,0 +1,25 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.tozoneddatetime +description: > + GetStartOfDay throws a RangeError for values outside the valid limits. +info: | + Temporal.PlainDate.prototype.toZonedDateTime ( item ) + + ... + 5. If temporalTime is undefined, then + a. Let epochNs be ? GetStartOfDay(timeZone, temporalDate.[[ISODate]]). + ... +features: [Temporal] +---*/ + +var minDate = new Temporal.PlainDate(-271821, 4, 19); +var minDateTime = new Temporal.PlainDate(-271821, 4, 20); +var maxDate = new Temporal.PlainDate(275760, 9, 13); + +assert.throws(RangeError, () => minDate.toZonedDateTime("UTC")); +assert.throws(RangeError, () => minDate.toZonedDateTime("+00")); +assert.throws(RangeError, () => minDateTime.toZonedDateTime("+01")); +assert.throws(RangeError, () => maxDate.toZonedDateTime("-01")); diff --git a/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/throws-if-combined-date-time-outside-valid-iso-range.js b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/throws-if-combined-date-time-outside-valid-iso-range.js new file mode 100644 index 0000000000..d0bbc02c60 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/toZonedDateTime/throws-if-combined-date-time-outside-valid-iso-range.js @@ -0,0 +1,30 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.tozoneddatetime +description: > + Throws if combined date-time outside valid ISO date range. +info: | + Temporal.PlainDate.prototype.toZonedDateTime ( item ) + + 1. Let temporalDate be the this value. + ... + 5. If temporalTime is undefined, then + ... + 6. Else, + a. Set temporalTime to ? ToTemporalTime(temporalTime). + b. Let isoDateTime be CombineISODateAndTimeRecord(temporalDate.[[ISODate]], temporalTime.[[Time]]). + c. If ISODateTimeWithinLimits(isoDateTime) is false, throw a RangeError exception. + ... +features: [Temporal] +---*/ + +var minDate = new Temporal.PlainDate(-271821, 4, 19); +var midnight = new Temporal.PlainTime(); +var item = { + timeZone: "+00", + plainTime: midnight, +}; + +assert.throws(RangeError, () => minDate.toZonedDateTime(item)); diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/throws-if-rounded-date-outside-valid-iso-range.js b/test/built-ins/Temporal/PlainDate/prototype/until/throws-if-rounded-date-outside-valid-iso-range.js new file mode 100644 index 0000000000..c3651b980f --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/until/throws-if-rounded-date-outside-valid-iso-range.js @@ -0,0 +1,47 @@ +// Copyright (C) 2024 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.until +description: > + Throws if rounded date outside valid ISO date range. +info: | + Temporal.PlainDate.prototype.until ( other [ , options ] ) + + ... + 3. Return ? DifferenceTemporalPlainDate(until, temporalDate, other, options). + + DifferenceTemporalPlainDate ( operation, temporalDate, other, options ) + + ... + 8. If settings.[[SmallestUnit]] is not day or settings.[[RoundingIncrement]] ≠ 1, then + ... + d. Set duration to ? RoundRelativeDuration(duration, destEpochNs, isoDateTime, + unset, temporalDate.[[Calendar]], settings.[[LargestUnit]], + settings.[[RoundingIncrement]], settings.[[SmallestUnit]], settings.[[RoundingMode]]). + ... + + RoundRelativeDuration ( duration, destEpochNs, isoDateTime, timeZone, calendar, + largestUnit, increment, smallestUnit, roundingMode ) + + ... + 5. If irregularLengthUnit is true, then + a. Let record be ? NudgeToCalendarUnit(sign, duration, destEpochNs, isoDateTime, + timeZone, calendar, increment, smallestUnit, roundingMode). + ... + + NudgeToCalendarUnit ( sign, duration, destEpochNs, isoDateTime, timeZone, calendar, + increment, unit, roundingMode ) + + ... + 8. Let end be ? CalendarDateAdd(calendar, isoDateTime.[[ISODate]], endDuration, constrain). + ... + +features: [Temporal] +---*/ + +var from = new Temporal.PlainDate(1970, 1, 1); +var to = new Temporal.PlainDate(1971, 1, 1); +var options = {roundingIncrement: 100_000_000, smallestUnit: "months"}; + +assert.throws(RangeError, () => from.until(to, options));