Skip to content

Commit

Permalink
Temporal: Add tests covering options bag argument of getTimeZoneTrans…
Browse files Browse the repository at this point in the history
…ition
  • Loading branch information
ptomato authored and Ms2ger committed Jul 5, 2024
1 parent 2f4b508 commit 627cc39
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.zoneddatetime.prototype.gettimezonetransition
description: If using options bag form, direction property is required
info: |
1. Let _direction_ be ? GetDirectionOption(_directionParam_).
features: [Temporal]
---*/

const zdt = new Temporal.ZonedDateTime(0n, "UTC");
assert.throws(RangeError, () => zdt.getTimeZoneTransition({}));
assert.throws(RangeError, () => zdt.getTimeZoneTransition({ direction: undefined }));
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.zoneddatetime.prototype.gettimezonetransition
description: Value of direction property cannot be a primitive other than string
info: |
1. Let _direction_ be ? GetDirectionOption(_directionParam_).
features: [Temporal]
---*/

const zdt = new Temporal.ZonedDateTime(0n, "UTC");

const rangeErrorValues = [false, 42, 55n, null];
for (const badValue of rangeErrorValues) {
assert.throws(RangeError, () => zdt.getTimeZoneTransition({ direction: badValue }), "Non-Symbol throws a RangeError");
}
assert.throws(TypeError, () => zdt.getTimeZoneTransition({ direction: Symbol("next") }), "Symbol throws a TypeError");
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.zoneddatetime.prototype.gettimezonetransition
description: Options argument is required
info: |
1. If _directionParam_ is *undefined*, throw a *TypeError* exception.
features: [Temporal]
---*/

const zdt = new Temporal.ZonedDateTime(0n, "UTC");

assert.throws(TypeError, () => zdt.getTimeZoneTransition());
assert.throws(TypeError, () => zdt.getTimeZoneTransition(undefined));
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.zoneddatetime.prototype.gettimezonetransition
description: >
Shorthand form is treated the same as options bag form with respect to
incorrect strings
info: |
1. If _directionParam_ is a String, then
1. Let _paramString_ be _directionParam_.
1. Set _roundTo_ to OrdinaryObjectCreate(*null*).
1. Perform ! CreateDataPropertyOrThrow(_directionParam_, *"direction"*, _paramString_).
...
1. Let _direction_ be ? GetDirectionOption(_directionParam_).
features: [Temporal]
---*/

const zdt = new Temporal.ZonedDateTime(0n, "UTC");

const badStrings = ['PREVIOUS', 'following', 'next\0', 'prevıous'];
for (const badString of badStrings) {
assert.throws(RangeError, () => zdt.getTimeZoneTransition(badString));
assert.throws(RangeError, () => zdt.getTimeZoneTransition({ direction: badString }));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.zoneddatetime.prototype.gettimezonetransition
description: >
Options bag cannot be anything other than a string, an object, or undefined
info: |
1. If _directionParam_ is a String, then
...
1. Else,
1. Set _directionParam_ to ? GetOptionsObject(_directionParam_).
features: [Temporal]
---*/

const zdt = new Temporal.ZonedDateTime(0n, "UTC");

const badValues = [false, 42, 55n, Symbol("foo"), null];
for (const badValue of badValues) {
assert.throws(TypeError, () => zdt.getTimeZoneTransition(badValue));
}

0 comments on commit 627cc39

Please sign in to comment.