Skip to content

Temporal: Reorganize calendar and wrong-type tests #4415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
6cc037e
Reorganize calendar and wrong-type tests
Mar 4, 2025
1c79535
Merged number.js tests into wrong-type.js tests, and extracted the st…
Mar 11, 2025
e39813f
Merged and extracted argument-* tests in PlainDate/from
Mar 11, 2025
cd49862
Merge branch 'main' into merge-and-extract-calendar-number-and-wrong-…
brageh01 Mar 11, 2025
b3d0e46
added newline to argument-*-invalid-iso-string.js, due to an error-co…
Mar 11, 2025
ef15474
Merged and extracted argument-* tests for PlainYearMonth
Mar 11, 2025
9f83e49
Merge and extract argument-* tests in ZonedDateTime/from
Mar 11, 2025
9dfd5ad
Merge and extract argument-* tests in PlainDateTime/from
Mar 11, 2025
60112c0
Merge and extract argument-* tests in PlainMonthDay/from
Mar 11, 2025
b0e8885
Corrected a type-error which occured in creation of a file
Mar 11, 2025
2e56fc1
Corrected a type-error which occured when renaming a file
Mar 11, 2025
47df386
Merge branch 'main' into merge-and-extract-calendar-number-and-wrong-…
brageh01 Apr 7, 2025
8d23556
Merge and extract operation for files found in /compare for the tempo…
Apr 9, 2025
3ca6287
Fixed syntax issues regarding /compare files for some temporal types
Apr 9, 2025
6e4e4b9
Merge and extract for tests in PlainDate/prototype
Apr 9, 2025
588a588
Merge and extract for PlainDateTime/prototype equals and since
Apr 16, 2025
3b39021
Merge and extract for PlainDateTime/prototype until
Apr 16, 2025
2d6491a
Merge and extract for PlainDateTime/prototype withCalendar
Apr 16, 2025
b1ad5ef
Merge branch 'main' into merge-and-extract-calendar-number-and-wrong-…
Apr 16, 2025
4529ce2
Merge and extract for PlainMonthDay/prototype equals
Apr 16, 2025
0bc5d9b
Merge and extract for PlainYearMonth/prototype equals
Apr 16, 2025
d513a09
Fixed an error in the header for wrong-type.js in equals
Apr 16, 2025
25a6e8e
Merge and extract for PlainYearMonth/prototype since
Apr 16, 2025
614260d
Merge and extract for PlainYearMonth/prototype until
brageh01 Apr 17, 2025
e289ffa
Merge and extract for ZonedDateTime/prototype equals
brageh01 Apr 17, 2025
d668596
Merge and extract for ZonedDateTime/prototype since
brageh01 Apr 17, 2025
53caaec
Merge and extract for ZonedDateTime/prototype until
brageh01 Apr 17, 2025
a98d02f
Merge and extract for ZonedDateTime/prototype withCalendar
brageh01 Apr 17, 2025
b6863aa
Gone over altered files to correct some header mistakes and adjust in…
brageh01 Apr 17, 2025
6479588
Update copyright header in Temporal tests
Apr 23, 2025
53ffbc6
Merge branch 'main' into merge-and-extract-calendar-number-and-wrong-…
brageh01 Apr 23, 2025
7965082
Corrected mistake for invalid-iso-string for withCalendar in PlainDat…
Apr 23, 2025
b95e900
Added a missing 'calendar' for a invalid-iso-string.js file
Apr 23, 2025
29cc2d7
Merge and extract for Duration/prototype round
Apr 23, 2025
1f79b75
Merged lists of types tested as calander ID into one array for PlainDate
Apr 23, 2025
06de7c6
Merge branch 'main' into merge-and-extract-calendar-number-and-wrong-…
brageh01 Apr 23, 2025
960c5f1
Merged lists of types tested as calandar ID into one array for PlainD…
Apr 23, 2025
c9e1b85
Merged lists of types tested as calandar ID into one array for PlainM…
Apr 23, 2025
9fc22ca
Merged lists of types tested as calendar ID into one array for PlainY…
brageh01 Apr 23, 2025
e84c9cc
Merge branch 'main' into merge-and-extract-calendar-number-and-wrong-…
brageh01 Apr 23, 2025
f250834
Merged lists of types tested as calendar ID into one array for ZonedD…
Apr 23, 2025
7c39679
Merged lists of types tested as calendar ID into one array for Durati…
Apr 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// Copyright (C) 2025 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

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

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

const numbers = [
1,
19970327,
-19970327,
1234567890,
const invalidStrings = [
["", "empty string"]
];

for (const calendar of numbers) {
for (const [calendar, description] of invalidStrings) {
const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(
TypeError,
RangeError,
() => instance.round({ largestUnit: "years", relativeTo }),
`A number (${calendar}) is not a valid ISO string for relativeTo.calendar`
`${description} is not a valid calendar ID`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,16 @@ description: >
features: [BigInt, Symbol, Temporal]
---*/

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

const primitiveTests = [
const wrongTypeTests = [
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[1n, "bigint"],
];

for (const [calendar, description] of primitiveTests) {
const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(
typeof calendar === 'string' ? RangeError : TypeError,
() => instance.round({ largestUnit: "years", relativeTo }),
`${description} does not convert to a valid ISO string`
);
}

const typeErrorTests = [
[19970327, "large number"],
[-19970327, "negative number"],
[1234567890, "very large integer"],
[Symbol(), "symbol"],
[{}, "object"],
[Temporal.PlainDate, "Temporal.PlainDate, object"],
Expand All @@ -38,7 +27,11 @@ const typeErrorTests = [
[Temporal.ZonedDateTime.prototype, "Temporal.ZonedDateTime.prototype, object"],
];

for (const [calendar, description] of typeErrorTests) {
for (const [calendar, description] of wrongTypeTests) {
const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(TypeError, () => instance.round({ largestUnit: "years", relativeTo }), `${description} is not a valid property bag and does not convert to a string`);
assert.throws(
TypeError,
() => instance.round({ largestUnit: "years", relativeTo }),
`${description} does not convert to a valid ISO string`
);
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

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

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

const numbers = [
1,
19970327,
-19970327,
1234567890,
const invalidStrings = [
["", "empty string"],
];

for (const calendar of numbers) {
for (const [calendar, description] of invalidStrings) {
const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(
TypeError,
RangeError,
() => instance.total({ unit: "days", relativeTo }),
`A number (${calendar}) is not a valid ISO string for relativeTo.calendar`
`${description} is not a valid calendar ID`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,16 @@ description: >
features: [BigInt, Symbol, Temporal]
---*/

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

const primitiveTests = [
const wrongTypeTests = [
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[1, "number"],
[1n, "bigint"],
];

for (const [calendar, description] of primitiveTests) {
const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(
typeof calendar === 'string' ? RangeError : TypeError,
() => instance.total({ unit: "days", relativeTo }),
`${description} does not convert to a valid ISO string`
);
}

const typeErrorTests = [
[19970327, "large number"],
[-19970327, "negative number"],
[1234567890, "very large integer"],
[Symbol(), "symbol"],
[{}, "object"],
[Temporal.PlainDate, "Temporal.PlainDate, object"],
Expand All @@ -38,7 +27,11 @@ const typeErrorTests = [
[Temporal.ZonedDateTime.prototype, "Temporal.ZonedDateTime.prototype, object"],
];

for (const [calendar, description] of typeErrorTests) {
for (const [calendar, description] of wrongTypeTests) {
const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(TypeError, () => instance.total({ unit: "days", relativeTo }), `${description} is not a valid property bag and does not convert to a string`);
assert.throws(
TypeError,
() => instance.total({ unit: "days", relativeTo }),
`${description} is not a valid calendar`
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.plaindate.constructor
description: Various invalid ISO string values for calendar
features: [Temporal]
---*/

const invalidStrings = [
["", "empty string"],
["1997-12-04[u-ca=iso8601]", "ISO string with calendar annotation"],
];

for (const [arg, description] of invalidStrings) {
assert.throws(
RangeError,
() => new Temporal.PlainDate(2000, 5, 2, arg),
`${description} is not a valid calendar ID`
);
}
14 changes: 0 additions & 14 deletions test/built-ins/Temporal/PlainDate/calendar-iso-string.js

This file was deleted.

23 changes: 0 additions & 23 deletions test/built-ins/Temporal/PlainDate/calendar-number.js

This file was deleted.

27 changes: 11 additions & 16 deletions test/built-ins/Temporal/PlainDate/calendar-wrong-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,23 @@ description: >
features: [BigInt, Symbol, Temporal]
---*/

const primitiveTests = [
const wrongTypeTests = [
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[1, "number"],
[1n, "bigint"],
];

for (const [arg, description] of primitiveTests) {
assert.throws(
typeof arg === 'string' ? RangeError : TypeError,
() => new Temporal.PlainDate(2000, 5, 2, arg),
`${description} does not convert to a valid ISO string`
);
}

const typeErrorTests = [
[-19761118, "negative number"],
[19761118, "large positive number"],
[1234567890, "large integer"],
[Symbol(), "symbol"],
[{}, "object"],
[new Temporal.Duration(), "duration instance"],
];

for (const [arg, description] of typeErrorTests) {
assert.throws(TypeError, () => new Temporal.PlainDate(2000, 5, 2, arg), `${description} is not a valid object and does not convert to a string`);
for (const [arg, description] of wrongTypeTests) {
assert.throws(
TypeError,
() => new Temporal.PlainDate(2000, 5, 2, arg),
`${description} is not a valid calendar`
);
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

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

const numbers = [
1,
19970327,
-19970327,
1234567890,
const invalidStrings = [
["", "empty string"],
];

for (const calendar of numbers) {
for (const [calendar, description] of invalidStrings) {
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
assert.throws(
TypeError,
RangeError,
() => Temporal.PlainDate.compare(arg, new Temporal.PlainDate(1976, 11, 18)),
"A number is not a valid ISO string for calendar (first argument)"
`${description} is not a valid calendar ID (first argument)`
);
assert.throws(
TypeError,
RangeError,
() => Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg),
"A number is not a valid ISO string for calendar (second argument)"
`${description} is not a valid calendar ID (second argument)`
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,29 @@ description: >
features: [BigInt, Symbol, Temporal]
---*/

const primitiveTests = [
const wrongTypeTests = [
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[1, "number"],
[1n, "bigint"],
[19970327, "large number"],
[-19970327, "negative number"],
[1234567890, "very large integer"],
[Symbol(), "symbol"],
[{}, "object"],
[new Temporal.Duration(), "duration instance"],
];

for (const [calendar, description] of primitiveTests) {
for (const [calendar, description] of wrongTypeTests) {
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(
typeof calendar === "string" ? RangeError : TypeError,
TypeError,
() => Temporal.PlainDate.compare(arg, new Temporal.PlainDate(1976, 11, 18)),
`${description} does not convert to a valid ISO string (first argument)`
`${description} is not a valid property bag and does not convert to a string (first argument)`
);
assert.throws(
typeof calendar === "string" ? RangeError : TypeError,
TypeError,
() => Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg),
`${description} does not convert to a valid ISO string (second argument)`
`${description} is not a valid property bag and does not convert to a string (second argument)`
);
}

const typeErrorTests = [
[Symbol(), "symbol"],
[{}, "object"],
[new Temporal.Duration(), "duration instance"],
];

for (const [calendar, description] of typeErrorTests) {
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
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)`);
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)`);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (C) 2025 Brage Hogstad, University of Bergen. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.plaindate.from
description: Various invalid ISO string values for calendar in a property bag
features: [Temporal]
---*/

const invalidStrings = [
["", "empty string"],
];

for (const [calendar, description] of invalidStrings) {
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
assert.throws(
RangeError,
() => Temporal.PlainDate.from(arg),
`${description} is not a valid calendar ID`
);
}

This file was deleted.

Loading