Skip to content

Commit 443f0d2

Browse files
authored
Temporal: Reorganize calendar and wrong-type tests (#4415)
Changes made to: - PlainDate - PlainYearMonth - ZonedDateTime - PlainDateTime - PlainMonthDay Merged calendar-number.js and calendar-wrong-type.js, due to no special behaviour of number to be tested. Extracted string tests to calendar-iso-string.js and renamed the file to calendar-invalid-iso-string.js, due to the contents of the file initially testing invalid ISO strings. Closes #3873
1 parent 64237be commit 443f0d2

File tree

96 files changed

+1004
-1350
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+1004
-1350
lines changed

test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-calendar-number.js renamed to test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-calendar-invalid-iso-string.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
1-
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
1+
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
22
// This code is governed by the BSD license found in the LICENSE file.
33

44
/*---
55
esid: sec-temporal.duration.prototype.round
6-
description: A number as calendar in relativeTo property bag is invalid
6+
description: >
7+
An ISO string that cannot be converted to a calendar ID should throw a RangeError
78
features: [Temporal]
89
---*/
910

1011
const instance = new Temporal.Duration(1, 0, 0, 0, 24);
1112

12-
const numbers = [
13-
1,
14-
19970327,
15-
-19970327,
16-
1234567890,
13+
const invalidStrings = [
14+
["", "empty string"]
1715
];
1816

19-
for (const calendar of numbers) {
17+
for (const [calendar, description] of invalidStrings) {
2018
const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar };
2119
assert.throws(
22-
TypeError,
20+
RangeError,
2321
() => instance.round({ largestUnit: "years", relativeTo }),
24-
`A number (${calendar}) is not a valid ISO string for relativeTo.calendar`
22+
`${description} is not a valid calendar ID`
2523
);
2624
}

test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-calendar-wrong-type.js

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,16 @@ description: >
99
features: [BigInt, Symbol, Temporal]
1010
---*/
1111

12-
const timeZone = "UTC";
1312
const instance = new Temporal.Duration(1, 0, 0, 0, 24);
1413

15-
const primitiveTests = [
14+
const wrongTypeTests = [
1615
[null, "null"],
1716
[true, "boolean"],
18-
["", "empty string"],
1917
[1, "number that doesn't convert to a valid ISO string"],
2018
[1n, "bigint"],
21-
];
22-
23-
for (const [calendar, description] of primitiveTests) {
24-
const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar };
25-
assert.throws(
26-
typeof calendar === 'string' ? RangeError : TypeError,
27-
() => instance.round({ largestUnit: "years", relativeTo }),
28-
`${description} does not convert to a valid ISO string`
29-
);
30-
}
31-
32-
const typeErrorTests = [
19+
[19970327, "large number"],
20+
[-19970327, "negative number"],
21+
[1234567890, "very large integer"],
3322
[Symbol(), "symbol"],
3423
[{}, "object"],
3524
[Temporal.PlainDate, "Temporal.PlainDate, object"],
@@ -38,7 +27,11 @@ const typeErrorTests = [
3827
[Temporal.ZonedDateTime.prototype, "Temporal.ZonedDateTime.prototype, object"],
3928
];
4029

41-
for (const [calendar, description] of typeErrorTests) {
30+
for (const [calendar, description] of wrongTypeTests) {
4231
const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar };
43-
assert.throws(TypeError, () => instance.round({ largestUnit: "years", relativeTo }), `${description} is not a valid property bag and does not convert to a string`);
32+
assert.throws(
33+
TypeError,
34+
() => instance.round({ largestUnit: "years", relativeTo }),
35+
`${description} does not convert to a valid ISO string`
36+
);
4437
}

test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-calendar-number.js renamed to test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-calendar-invalid-iso-string.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
1-
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
1+
// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved.
22
// This code is governed by the BSD license found in the LICENSE file.
33

44
/*---
55
esid: sec-temporal.duration.prototype.total
6-
description: A number as calendar in relativeTo property bag is invalid
6+
description: Various invalid ISO string values for relativeTo.calendar
77
features: [Temporal]
88
---*/
99

1010
const instance = new Temporal.Duration(1, 0, 0, 0, 24);
1111

12-
const numbers = [
13-
1,
14-
19970327,
15-
-19970327,
16-
1234567890,
12+
const invalidStrings = [
13+
["", "empty string"],
1714
];
1815

19-
for (const calendar of numbers) {
16+
for (const [calendar, description] of invalidStrings) {
2017
const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar };
2118
assert.throws(
22-
TypeError,
19+
RangeError,
2320
() => instance.total({ unit: "days", relativeTo }),
24-
`A number (${calendar}) is not a valid ISO string for relativeTo.calendar`
21+
`${description} is not a valid calendar ID`
2522
);
2623
}

test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-calendar-wrong-type.js

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,16 @@ description: >
99
features: [BigInt, Symbol, Temporal]
1010
---*/
1111

12-
const timeZone = "UTC";
1312
const instance = new Temporal.Duration(1, 0, 0, 0, 24);
1413

15-
const primitiveTests = [
14+
const wrongTypeTests = [
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"],
21-
];
22-
23-
for (const [calendar, description] of primitiveTests) {
24-
const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar };
25-
assert.throws(
26-
typeof calendar === 'string' ? RangeError : TypeError,
27-
() => instance.total({ unit: "days", relativeTo }),
28-
`${description} does not convert to a valid ISO string`
29-
);
30-
}
31-
32-
const typeErrorTests = [
19+
[19970327, "large number"],
20+
[-19970327, "negative number"],
21+
[1234567890, "very large integer"],
3322
[Symbol(), "symbol"],
3423
[{}, "object"],
3524
[Temporal.PlainDate, "Temporal.PlainDate, object"],
@@ -38,7 +27,11 @@ const typeErrorTests = [
3827
[Temporal.ZonedDateTime.prototype, "Temporal.ZonedDateTime.prototype, object"],
3928
];
4029

41-
for (const [calendar, description] of typeErrorTests) {
30+
for (const [calendar, description] of wrongTypeTests) {
4231
const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar };
43-
assert.throws(TypeError, () => instance.total({ unit: "days", relativeTo }), `${description} is not a valid property bag and does not convert to a string`);
32+
assert.throws(
33+
TypeError,
34+
() => instance.total({ unit: "days", relativeTo }),
35+
`${description} is not a valid calendar`
36+
);
4437
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-temporal.plaindate.constructor
6+
description: Various invalid ISO string values for calendar
7+
features: [Temporal]
8+
---*/
9+
10+
const invalidStrings = [
11+
["", "empty string"],
12+
["1997-12-04[u-ca=iso8601]", "ISO string with calendar annotation"],
13+
];
14+
15+
for (const [arg, description] of invalidStrings) {
16+
assert.throws(
17+
RangeError,
18+
() => new Temporal.PlainDate(2000, 5, 2, arg),
19+
`${description} is not a valid calendar ID`
20+
);
21+
}

test/built-ins/Temporal/PlainDate/calendar-iso-string.js

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

test/built-ins/Temporal/PlainDate/calendar-number.js

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

test/built-ins/Temporal/PlainDate/calendar-wrong-type.js

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

12-
const primitiveTests = [
12+
const wrongTypeTests = [
1313
[null, "null"],
1414
[true, "boolean"],
15-
["", "empty string"],
16-
[1, "number that doesn't convert to a valid ISO string"],
15+
[1, "number"],
1716
[1n, "bigint"],
18-
];
19-
20-
for (const [arg, description] of primitiveTests) {
21-
assert.throws(
22-
typeof arg === 'string' ? RangeError : TypeError,
23-
() => new Temporal.PlainDate(2000, 5, 2, arg),
24-
`${description} does not convert to a valid ISO string`
25-
);
26-
}
27-
28-
const typeErrorTests = [
17+
[-19761118, "negative number"],
18+
[19761118, "large positive number"],
19+
[1234567890, "large integer"],
2920
[Symbol(), "symbol"],
3021
[{}, "object"],
3122
[new Temporal.Duration(), "duration instance"],
3223
];
3324

34-
for (const [arg, description] of typeErrorTests) {
35-
assert.throws(TypeError, () => new Temporal.PlainDate(2000, 5, 2, arg), `${description} is not a valid object and does not convert to a string`);
25+
for (const [arg, description] of wrongTypeTests) {
26+
assert.throws(
27+
TypeError,
28+
() => new Temporal.PlainDate(2000, 5, 2, arg),
29+
`${description} is not a valid calendar`
30+
);
3631
}

test/built-ins/Temporal/PlainDate/compare/argument-propertybag-calendar-number.js renamed to test/built-ins/Temporal/PlainDate/compare/argument-propertybag-calendar-invalid-iso-string.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
1-
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
1+
// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved.
22
// This code is governed by the BSD license found in the LICENSE file.
33

44
/*---
55
esid: sec-temporal.plaindate.compare
6-
description: A number as calendar in a property bag is not accepted
6+
description: Invalid ISO string as calendar should throw RangeError
77
features: [Temporal]
88
---*/
99

10-
const numbers = [
11-
1,
12-
19970327,
13-
-19970327,
14-
1234567890,
10+
const invalidStrings = [
11+
["", "empty string"],
1512
];
16-
17-
for (const calendar of numbers) {
13+
14+
for (const [calendar, description] of invalidStrings) {
1815
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
1916
assert.throws(
20-
TypeError,
17+
RangeError,
2118
() => Temporal.PlainDate.compare(arg, new Temporal.PlainDate(1976, 11, 18)),
22-
"A number is not a valid ISO string for calendar (first argument)"
19+
`${description} is not a valid calendar ID (first argument)`
2320
);
2421
assert.throws(
25-
TypeError,
22+
RangeError,
2623
() => Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg),
27-
"A number is not a valid ISO string for calendar (second argument)"
24+
`${description} is not a valid calendar ID (second argument)`
2825
);
2926
}

test/built-ins/Temporal/PlainDate/compare/argument-propertybag-calendar-wrong-type.js

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,29 @@ description: >
99
features: [BigInt, Symbol, Temporal]
1010
---*/
1111

12-
const primitiveTests = [
12+
const wrongTypeTests = [
1313
[null, "null"],
1414
[true, "boolean"],
15-
["", "empty string"],
16-
[1, "number that doesn't convert to a valid ISO string"],
15+
[1, "number"],
1716
[1n, "bigint"],
17+
[19970327, "large number"],
18+
[-19970327, "negative number"],
19+
[1234567890, "very large integer"],
20+
[Symbol(), "symbol"],
21+
[{}, "object"],
22+
[new Temporal.Duration(), "duration instance"],
1823
];
1924

20-
for (const [calendar, description] of primitiveTests) {
25+
for (const [calendar, description] of wrongTypeTests) {
2126
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
2227
assert.throws(
23-
typeof calendar === "string" ? RangeError : TypeError,
28+
TypeError,
2429
() => Temporal.PlainDate.compare(arg, new Temporal.PlainDate(1976, 11, 18)),
25-
`${description} does not convert to a valid ISO string (first argument)`
30+
`${description} is not a valid property bag and does not convert to a string (first argument)`
2631
);
2732
assert.throws(
28-
typeof calendar === "string" ? RangeError : TypeError,
33+
TypeError,
2934
() => Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg),
30-
`${description} does not convert to a valid ISO string (second argument)`
35+
`${description} is not a valid property bag and does not convert to a string (second argument)`
3136
);
3237
}
33-
34-
const typeErrorTests = [
35-
[Symbol(), "symbol"],
36-
[{}, "object"],
37-
[new Temporal.Duration(), "duration instance"],
38-
];
39-
40-
for (const [calendar, description] of typeErrorTests) {
41-
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
42-
assert.throws(TypeError, () => Temporal.PlainDate.compare(arg, new Temporal.PlainDate(1976, 11, 18)), `${description} is not a valid property bag and does not convert to a string (first argument)`);
43-
assert.throws(TypeError, () => Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg), `${description} is not a valid property bag and does not convert to a string (second argument)`);
44-
}

0 commit comments

Comments
 (0)