Skip to content

Commit 44e87cb

Browse files
committed
Temporal: Add tests covering options bag argument of getTimeZoneTransition
1 parent b6aeb3c commit 44e87cb

File tree

5 files changed

+93
-0
lines changed

5 files changed

+93
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.zoneddatetime.prototype.gettimezonetransition
6+
description: If using options bag form, direction property is required
7+
info: |
8+
1. Let _direction_ be ? GetDirectionOption(_directionParam_).
9+
features: [Temporal]
10+
---*/
11+
12+
const zdt = new Temporal.ZonedDateTime(0n, "UTC");
13+
assert.throws(RangeError, () => zdt.getTimeZoneTransition({}));
14+
assert.throws(RangeError, () => zdt.getTimeZoneTransition({ direction: undefined }));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.zoneddatetime.prototype.gettimezonetransition
6+
description: Value of direction property cannot be a primitive other than string
7+
info: |
8+
1. Let _direction_ be ? GetDirectionOption(_directionParam_).
9+
features: [Temporal]
10+
---*/
11+
12+
const zdt = new Temporal.ZonedDateTime(0n, "UTC");
13+
14+
const rangeErrorValues = [false, 42, 55n, null];
15+
for (const badValue of rangeErrorValues) {
16+
assert.throws(RangeError, () => zdt.getTimeZoneTransition({ direction: badValue }), "Non-Symbol throws a RangeError");
17+
}
18+
assert.throws(TypeError, () => zdt.getTimeZoneTransition({ direction: Symbol("next") }), "Symbol throws a TypeError");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.zoneddatetime.prototype.gettimezonetransition
6+
description: Options argument is required
7+
info: |
8+
1. If _directionParam_ is *undefined*, throw a *TypeError* exception.
9+
features: [Temporal]
10+
---*/
11+
12+
const zdt = new Temporal.ZonedDateTime(0n, "UTC");
13+
14+
assert.throws(TypeError, () => zdt.getTimeZoneTransition());
15+
assert.throws(TypeError, () => zdt.getTimeZoneTransition(undefined));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.zoneddatetime.prototype.gettimezonetransition
6+
description: >
7+
Shorthand form is treated the same as options bag form with respect to
8+
incorrect strings
9+
info: |
10+
1. If _directionParam_ is a String, then
11+
1. Let _paramString_ be _directionParam_.
12+
1. Set _roundTo_ to OrdinaryObjectCreate(*null*).
13+
1. Perform ! CreateDataPropertyOrThrow(_directionParam_, *"direction"*, _paramString_).
14+
...
15+
1. Let _direction_ be ? GetDirectionOption(_directionParam_).
16+
features: [Temporal]
17+
---*/
18+
19+
const zdt = new Temporal.ZonedDateTime(0n, "UTC");
20+
21+
const badStrings = ['PREVIOUS', 'following', 'next\0', 'prevıous'];
22+
for (const badString of badStrings) {
23+
assert.throws(RangeError, () => zdt.getTimeZoneTransition(badString));
24+
assert.throws(RangeError, () => zdt.getTimeZoneTransition({ direction: badString }));
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.zoneddatetime.prototype.gettimezonetransition
6+
description: >
7+
Options bag cannot be anything other than a string, an object, or undefined
8+
info: |
9+
1. If _directionParam_ is a String, then
10+
...
11+
1. Else,
12+
1. Set _directionParam_ to ? GetOptionsObject(_directionParam_).
13+
features: [Temporal]
14+
---*/
15+
16+
const zdt = new Temporal.ZonedDateTime(0n, "UTC");
17+
18+
const badValues = [false, 42, 55n, Symbol("foo"), null];
19+
for (const badValue of badValues) {
20+
assert.throws(TypeError, () => zdt.getTimeZoneTransition(badValue));
21+
}

0 commit comments

Comments
 (0)