Skip to content

Commit 6eaedd0

Browse files
author
David Erik Velten Baird
committed
Merge and extract for PlainDateTime/prototype equals and since
1 parent 6e4e4b9 commit 6eaedd0

6 files changed

+70
-65
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (C) 2025 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.plaindatetime.prototype.equals
6+
description: Invalid ISO string as calendar should throw RangeError
7+
features: [Temporal]
8+
---*/
9+
10+
const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
11+
12+
const invalidStrings = [
13+
["", "empty string"],
14+
];
15+
16+
for (const [calendar, description] of invalidStrings) {
17+
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
18+
assert.throws(
19+
RangeError,
20+
() => instance.equals(arg),
21+
`${description} is not a valid calendar ID`
22+
);
23+
}

test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-number.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

test/built-ins/Temporal/PlainDateTime/prototype/equals/argument-propertybag-calendar-wrong-type.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,24 @@ description: >
99
features: [BigInt, Symbol, Temporal]
1010
---*/
1111

12-
const timeZone = "UTC";
1312
const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
1413

1514
const primitiveTests = [
1615
[null, "null"],
1716
[true, "boolean"],
18-
["", "empty string"],
19-
[1, "number that doesn't convert to a valid ISO string"],
17+
[1, "number"],
2018
[1n, "bigint"],
19+
[19970327, "large number"],
20+
[-19970327, "negative number"],
21+
[1234567890, "very large integer"],
2122
];
2223

2324
for (const [calendar, description] of primitiveTests) {
24-
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
25+
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
2526
assert.throws(
26-
typeof calendar === 'string' ? RangeError : TypeError,
27+
TypeError,
2728
() => instance.equals(arg),
28-
`${description} does not convert to a valid ISO string`
29+
`${description} is not a valid calendar`
2930
);
3031
}
3132

@@ -37,5 +38,9 @@ const typeErrorTests = [
3738

3839
for (const [calendar, description] of typeErrorTests) {
3940
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
40-
assert.throws(TypeError, () => instance.equals(arg), `${description} is not a valid property bag and does not convert to a string`);
41+
assert.throws(
42+
TypeError,
43+
() => instance.equals(arg),
44+
`${description} is not a valid property bag and does not convert to a string`
45+
);
4146
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright (C) 2025 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.plaindatetime.prototype.since
6+
description: Invalid ISO string as calendar should throw RangeError
7+
features: [Temporal]
8+
---*/
9+
10+
const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
11+
12+
const invalidStrings = [
13+
["", "empty string"],
14+
];
15+
16+
for (const [calendar, description] of invalidStrings) {
17+
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
18+
assert.throws(
19+
RangeError,
20+
() => instance.since(arg),
21+
`${description} is not a valid calendar ID`
22+
);
23+
}

test/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-number.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

test/built-ins/Temporal/PlainDateTime/prototype/since/argument-propertybag-calendar-wrong-type.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@ const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 32
1414
const primitiveTests = [
1515
[null, "null"],
1616
[true, "boolean"],
17-
["", "empty string"],
18-
[1, "number that doesn't convert to a valid ISO string"],
17+
[1, "number"],
1918
[1n, "bigint"],
19+
[19970327, "large number"],
20+
[-19970327, "negative number"],
21+
[1234567890, "very large integer"],
2022
];
2123

2224
for (const [calendar, description] of primitiveTests) {
23-
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
25+
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
2426
assert.throws(
25-
typeof calendar === 'string' ? RangeError : TypeError,
27+
TypeError,
2628
() => instance.since(arg),
27-
`${description} does not convert to a valid ISO string`
29+
`${description} is not a valid calendar`
2830
);
2931
}
3032

@@ -36,5 +38,9 @@ const typeErrorTests = [
3638

3739
for (const [calendar, description] of typeErrorTests) {
3840
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
39-
assert.throws(TypeError, () => instance.since(arg), `${description} is not a valid property bag and does not convert to a string`);
41+
assert.throws(
42+
TypeError,
43+
() => instance.since(arg),
44+
`${description} is not a valid property bag and does not convert to a string`
45+
);
4046
}

0 commit comments

Comments
 (0)