Skip to content

Commit 8d23556

Browse files
author
Brage Hogstad
committed
Merge and extract operation for files found in /compare for the temporal types
1 parent 47df386 commit 8d23556

9 files changed

+137
-109
lines changed

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 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.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: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,24 @@ features: [BigInt, Symbol, Temporal]
1212
const primitiveTests = [
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"],
1820
];
1921

2022
for (const [calendar, description] of primitiveTests) {
2123
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
2224
assert.throws(
23-
typeof calendar === "string" ? RangeError : TypeError,
25+
TypeError,
2426
() => Temporal.PlainDate.compare(arg, new Temporal.PlainDate(1976, 11, 18)),
25-
`${description} does not convert to a valid ISO string (first argument)`
27+
`${description} is not a valid calendar (first argument)`
2628
);
2729
assert.throws(
28-
typeof calendar === "string" ? RangeError : TypeError,
30+
TypeError,
2931
() => Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg),
30-
`${description} does not convert to a valid ISO string (second argument)`
32+
`${description} is not a valid calendar (second argument)`
3133
);
3234
}
3335

@@ -39,6 +41,14 @@ const typeErrorTests = [
3941

4042
for (const [calendar, description] of typeErrorTests) {
4143
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+
assert.throws(
45+
TypeError,
46+
() => Temporal.PlainDate.compare(arg, new Temporal.PlainDate(1976, 11, 18)),
47+
`${description} is not a valid property bag and does not convert to a string (first argument)`
48+
);
49+
assert.throws(
50+
TypeError,
51+
() => Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg),
52+
`${description} is not a valid property bag and does not convert to a string (second argument)`
53+
);
4454
}

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

Lines changed: 11 additions & 14 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 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.plaindatetime.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.PlainDateTime.compare(arg, new Temporal.PlainDateTime(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.PlainDateTime.compare(new Temporal.PlainDateTime(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
);
29-
}
26+
}

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,24 @@ features: [BigInt, Symbol, Temporal]
1212
const primitiveTests = [
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"],
1820
];
1921

2022
for (const [calendar, description] of primitiveTests) {
2123
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
22-
assert.throws(
23-
typeof calendar === "string" ? RangeError : TypeError,
24-
() => Temporal.PlainDateTime.compare(arg, new Temporal.PlainDateTime(1976, 11, 18)),
25-
`${description} does not convert to a valid ISO string (first argument)`
26-
);
2724
assert.throws(
28-
typeof calendar === "string" ? RangeError : TypeError,
25+
TypeError,
26+
() => Temporal.PlainDateTime.compare(arg, new Temporal.PlainDateTime(1976, 11, 18)),
27+
`${description} is not a valid calendar (first argument)`
28+
);
29+
assert.throws(
30+
TypeError,
2931
() => Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg),
30-
`${description} does not convert to a valid ISO string (second argument)`
32+
`${description} is not a valid calendar (second argument)`
3133
);
3234
}
3335

@@ -39,6 +41,14 @@ const typeErrorTests = [
3941

4042
for (const [calendar, description] of typeErrorTests) {
4143
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
42-
assert.throws(TypeError, () => Temporal.PlainDateTime.compare(arg, new Temporal.PlainDateTime(1976, 11, 18)), `${description} is not a valid property bag and does not convert to a string (first argument)`);
43-
assert.throws(TypeError, () => Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg), `${description} is not a valid property bag and does not convert to a string (second argument)`);
44+
assert.throws(
45+
TypeError,
46+
() => Temporal.PlainDateTime.compare(arg, new Temporal.PlainDateTime(1976, 11, 18)),
47+
`${description} is not a valid property bag and does not convert to a string (first argument)`
48+
);
49+
assert.throws(
50+
TypeError,
51+
() => Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg),
52+
`${description} is not a valid property bag and does not convert to a string (second argument)`
53+
);
4454
}

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
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.plainyearmonth.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: 2019, monthCode: "M06", calendar };
1916
assert.throws(
20-
TypeError,
17+
RangeError,
2118
() => Temporal.PlainYearMonth.compare(arg, new Temporal.PlainYearMonth(2019, 6)),
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.PlainYearMonth.compare(new Temporal.PlainYearMonth(2019, 6), 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
}
27+

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,24 @@ features: [BigInt, Symbol, Temporal]
1212
const primitiveTests = [
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"],
1820
];
1921

2022
for (const [calendar, description] of primitiveTests) {
21-
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
23+
const arg = { year: 2019, monthCode: "M06", calendar };
2224
assert.throws(
23-
typeof calendar === "string" ? RangeError : TypeError,
25+
TypeError,
2426
() => Temporal.PlainYearMonth.compare(arg, new Temporal.PlainYearMonth(2019, 6)),
25-
`${description} does not convert to a valid ISO string (first argument)`
27+
`${description} is not a valid calendar (first argument)`
2628
);
2729
assert.throws(
28-
typeof calendar === "string" ? RangeError : TypeError,
30+
TypeError,
2931
() => Temporal.PlainYearMonth.compare(new Temporal.PlainYearMonth(2019, 6), arg),
30-
`${description} does not convert to a valid ISO string (second argument)`
32+
`${description} is not a valid calendar (second argument)`
3133
);
3234
}
3335

@@ -39,6 +41,14 @@ const typeErrorTests = [
3941

4042
for (const [calendar, description] of typeErrorTests) {
4143
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
42-
assert.throws(TypeError, () => Temporal.PlainYearMonth.compare(arg, new Temporal.PlainYearMonth(2019, 6)), `${description} is not a valid property bag and does not convert to a string (first argument)`);
43-
assert.throws(TypeError, () => Temporal.PlainYearMonth.compare(new Temporal.PlainYearMonth(2019, 6), arg), `${description} is not a valid property bag and does not convert to a string (second argument)`);
44+
assert.throws(
45+
TypeError,
46+
() => Temporal.PlainYearMonth.compare(arg, new Temporal.PlainYearMonth(2019, 6)),
47+
`${description} is not a valid property bag and does not convert to a string (first argument)`
48+
);
49+
assert.throws(
50+
TypeError,
51+
() => Temporal.PlainYearMonth.compare(new Temporal.PlainYearMonth(2019, 6), arg),
52+
`${description} is not a valid property bag and does not convert to a string (second argument)`
53+
);
4454
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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.zoneddatetime.compare
6+
description: Invalid ISO string as calendar should throw RangeError
7+
features: [Temporal]
8+
---*/
9+
10+
const datetime = new Temporal.ZonedDateTime(0n, "UTC");
11+
12+
const invalidStrings = [
13+
["", "empty string"],
14+
];
15+
16+
for (const [calendar, description] of invalidStrings) {
17+
const arg = { year: 1970, monthCode: "M01", day: 1, calendar, timeZone: "UTC" };
18+
assert.throws(
19+
RangeError,
20+
() => Temporal.ZonedDateTime.compare(arg, datetime),
21+
`${description} is not a valid calendar ID (first argument)`
22+
);
23+
assert.throws(
24+
RangeError,
25+
() => Temporal.ZonedDateTime.compare(datetime, arg),
26+
`${description} is not a valid calendar ID (second argument)`
27+
);
28+
}

test/built-ins/Temporal/ZonedDateTime/compare/argument-propertybag-calendar-number.js

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

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,24 @@ const datetime = new Temporal.ZonedDateTime(0n, "UTC");
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: 1970, monthCode: "M01", day: 1, calendar, timeZone: "UTC" };
2426
assert.throws(
25-
typeof calendar === "string" ? RangeError : TypeError,
27+
TypeError,
2628
() => Temporal.ZonedDateTime.compare(arg, datetime),
27-
`${description} does not convert to a valid ISO string (first argument)`
29+
`${description} is not a valid calendar (first argument)`
2830
);
2931
assert.throws(
30-
typeof calendar === "string" ? RangeError : TypeError,
32+
TypeError,
3133
() => Temporal.ZonedDateTime.compare(datetime, arg),
32-
`${description} does not convert to a valid ISO string (second argument)`
34+
`${description} is not a valid calendar (second argument)`
3335
);
3436
}
3537

@@ -41,6 +43,14 @@ const typeErrorTests = [
4143

4244
for (const [calendar, description] of typeErrorTests) {
4345
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
44-
assert.throws(TypeError, () => Temporal.ZonedDateTime.compare(arg, datetime), `${description} is not a valid property bag and does not convert to a string (first argument)`);
45-
assert.throws(TypeError, () => Temporal.ZonedDateTime.compare(datetime, arg), `${description} is not a valid property bag and does not convert to a string (second argument)`);
46+
assert.throws(
47+
TypeError,
48+
() => Temporal.ZonedDateTime.compare(arg, datetime),
49+
`${description} is not a valid property bag and does not convert to a string (first argument)`
50+
);
51+
assert.throws(
52+
TypeError,
53+
() => Temporal.ZonedDateTime.compare(datetime, arg),
54+
`${description} is not a valid property bag and does not convert to a string (second argument)`
55+
);
4656
}

0 commit comments

Comments
 (0)