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 11 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
Expand Up @@ -9,23 +9,24 @@ description: >
features: [BigInt, Symbol, Temporal]
---*/

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

const primitiveTests = [
[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"],
];

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

Expand Down
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) 2024 Igalia, S.L. 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"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: you could consider adding more cases in tests such as this one. For example: strings that are neither ISO strings nor valid calendar identifiers. (If you decide this is out of scope for this PR, that would be fine, but I'd appreciate if you could open a follow up issue on GitHub in that case.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now see that I have not done the merge and extract for round in the same file location which I will do. In regards of your suggestion of adding more cases in tests "such as this one", do you imply only for the relativeto-propertybag files, or all of the calendar-invalid-iso-string files in general?

I believe it will be more transparent to create a new issue for this, but I can both create a new issue and start a PR after knowing more specificly which files that are relevant.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant for the calendar-invalid-iso-string files in general. Every file where the only test case is ["", "empty string"]. I agree, it's fine to create a new issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found an already open issue that covers this topic, I think: #3896

];

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
@@ -0,0 +1,21 @@
// Copyright (C) 2024 Igalia, S.L. 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.

10 changes: 6 additions & 4 deletions test/built-ins/Temporal/PlainDate/calendar-wrong-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ features: [BigInt, Symbol, Temporal]
const primitiveTests = [
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[1, "number"],
[1n, "bigint"],
[-19761118, "negative number"],
[19761118, "large positive number"],
[1234567890, "large integer"],
];

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (C) 2024 Igalia, S.L. 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.

Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@ features: [BigInt, Symbol, Temporal]
const primitiveTests = [
[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"],
];

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.plaindatetime.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.PlainDateTime(2000, 5, 2, 15, 23, 30, 987, 654, 321, arg),
`${description} is not a valid calendar ID`
);
}
14 changes: 0 additions & 14 deletions test/built-ins/Temporal/PlainDateTime/calendar-iso-string.js

This file was deleted.

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

This file was deleted.

10 changes: 6 additions & 4 deletions test/built-ins/Temporal/PlainDateTime/calendar-wrong-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@ features: [BigInt, Symbol, Temporal]
const primitiveTests = [
[null, "null"],
[true, "boolean"],
["", "empty string"],
[1, "number that doesn't convert to a valid ISO string"],
[1, "number"],
[1n, "bigint"],
[-19761118, "negative number"],
[19761118, "large positive number"],
[1234567890, "large integer"],
];

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.plaindatetime.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.PlainDateTime.from(arg),
`${description} is not a valid calendar ID`
);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@ features: [BigInt, Symbol, Temporal]
const primitiveTests = [
[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"],
];

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-temporal.plainmonthday.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.PlainMonthDay(12, 15, arg, 1972),
`${description} is not a valid calendar ID`
);
}
Loading