Skip to content

Commit 6e4e4b9

Browse files
author
Brage Hogstad
committed
Merge and extract for tests in PlainDate/prototype
1 parent 3ca6287 commit 6e4e4b9

11 files changed

+123
-111
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.plaindate.prototype.equals
6+
description: Invalid ISO string as calendar should throw RangeError
7+
features: [Temporal]
8+
---*/
9+
10+
const instance = new Temporal.PlainDate(2000, 5, 2);
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/PlainDate/prototype/equals/argument-propertybag-calendar-number.js

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

test/built-ins/Temporal/PlainDate/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.PlainDate(2000, 5, 2);
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.plaindate.prototype.since
6+
description: Invalid ISO string as calendar should throw RangeError
7+
features: [Temporal]
8+
---*/
9+
10+
const instance = new Temporal.PlainDate(2000, 5, 2);
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/PlainDate/prototype/since/argument-propertybag-calendar-number.js

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

test/built-ins/Temporal/PlainDate/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.PlainDate(2000, 5, 2);
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
}
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.plaindate.prototype.until
6+
description: Invalid ISO string as calendar should throw RangeError
7+
features: [Temporal]
8+
---*/
9+
10+
const instance = new Temporal.PlainDate(2000, 5, 2);
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.until(arg),
21+
`${description} is not a valid calendar ID`
22+
);
23+
}

test/built-ins/Temporal/PlainDate/prototype/until/argument-propertybag-calendar-number.js

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

test/built-ins/Temporal/PlainDate/prototype/until/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.PlainDate(2000, 5, 2);
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.until(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.until(arg), `${description} is not a valid property bag and does not convert to a string`);
41+
assert.throws(
42+
TypeError,
43+
() => instance.until(arg),
44+
`${description} is not a valid property bag and does not convert to a string`
45+
);
4146
}

test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-number.js renamed to test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-invalid-iso-string.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
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.plaindate.prototype.withcalendar
6-
description: A number is not allowed to be a calendar
6+
description: Invalid ISO string as calendar should throw RangeError
77
features: [Temporal]
88
---*/
99

1010
const instance = new Temporal.PlainDate(1976, 11, 18, "iso8601");
1111

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

19-
for (const arg of numbers) {
16+
for (const [arg, description] of invalidStrings) {
2017
assert.throws(
21-
TypeError,
18+
RangeError,
2219
() => instance.withCalendar(arg),
23-
"A number is not a valid ISO string for Calendar"
20+
`${description} is not a valid calendar ID`
2421
);
2522
}

0 commit comments

Comments
 (0)