mirror of
https://github.com/tc39/test262.git
synced 2025-07-23 14:04:51 +02:00
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
This commit is contained in:
parent
64237beb0d
commit
443f0d2e7f
@ -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`
|
||||
);
|
||||
}
|
@ -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"],
|
||||
@ -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`
|
||||
);
|
||||
}
|
||||
|
@ -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`
|
||||
);
|
||||
}
|
@ -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"],
|
||||
@ -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`
|
||||
);
|
||||
}
|
||||
|
@ -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`
|
||||
);
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
// 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: An ISO string is not valid input for a constructor's calendar param
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => new Temporal.PlainDate(2000, 5, 2, "1997-12-04[u-ca=iso8601]"),
|
||||
"An ISO string is not a valid calendar ID for constructor parameter"
|
||||
);
|
@ -1,23 +0,0 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindate
|
||||
description: A number is not allowed to be a calendar
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const numbers = [
|
||||
1,
|
||||
-19761118,
|
||||
19761118,
|
||||
1234567890,
|
||||
];
|
||||
|
||||
for (const arg of numbers) {
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => new Temporal.PlainDate(2000, 5, 2, arg),
|
||||
"A number is not a valid ISO string for Calendar"
|
||||
);
|
||||
}
|
@ -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`
|
||||
);
|
||||
}
|
||||
|
@ -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)`
|
||||
);
|
||||
}
|
@ -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"],
|
||||
];
|
||||
|
||||
for (const [calendar, description] of primitiveTests) {
|
||||
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(
|
||||
typeof calendar === "string" ? RangeError : TypeError,
|
||||
() => Temporal.PlainDate.compare(arg, new Temporal.PlainDate(1976, 11, 18)),
|
||||
`${description} does not convert to a valid ISO string (first argument)`
|
||||
);
|
||||
assert.throws(
|
||||
typeof calendar === "string" ? RangeError : TypeError,
|
||||
() => Temporal.PlainDate.compare(new Temporal.PlainDate(1976, 11, 18), arg),
|
||||
`${description} does not convert to a valid ISO string (second argument)`
|
||||
);
|
||||
}
|
||||
|
||||
const typeErrorTests = [
|
||||
[19970327, "large number"],
|
||||
[-19970327, "negative number"],
|
||||
[1234567890, "very large integer"],
|
||||
[Symbol(), "symbol"],
|
||||
[{}, "object"],
|
||||
[new Temporal.Duration(), "duration instance"],
|
||||
];
|
||||
|
||||
for (const [calendar, description] of typeErrorTests) {
|
||||
for (const [calendar, description] of wrongTypeTests) {
|
||||
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)`);
|
||||
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)`
|
||||
);
|
||||
}
|
||||
|
@ -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`
|
||||
);
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
// Copyright (C) 2022 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: A number as calendar in a property bag is not accepted
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const numbers = [
|
||||
1,
|
||||
19970327,
|
||||
-19970327,
|
||||
1234567890,
|
||||
];
|
||||
|
||||
for (const calendar of numbers) {
|
||||
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => Temporal.PlainDate.from(arg),
|
||||
"Numbers cannot be used as a calendar"
|
||||
);
|
||||
}
|
@ -9,30 +9,24 @@ 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 [calendar, description] of primitiveTests) {
|
||||
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(
|
||||
typeof calendar === 'string' ? RangeError : TypeError,
|
||||
() => Temporal.PlainDate.from(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
||||
|
||||
const typeErrorTests = [
|
||||
[19970327, "large number"],
|
||||
[-19970327, "negative number"],
|
||||
[1234567890, "very large integer"],
|
||||
[Symbol(), "symbol"],
|
||||
[{}, "object"],
|
||||
[new Temporal.Duration(), "duration instance"],
|
||||
];
|
||||
|
||||
for (const [calendar, description] of typeErrorTests) {
|
||||
for (const [calendar, description] of wrongTypeTests) {
|
||||
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(TypeError, () => Temporal.PlainDate.from(arg), `${description} is not a valid property bag and does not convert to a string`);
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => Temporal.PlainDate.from(arg),
|
||||
`${description} is not a valid calendar`
|
||||
);
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
// 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.prototype.equals
|
||||
description: Invalid ISO string as calendar should throw RangeError
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDate(2000, 5, 2);
|
||||
|
||||
const invalidStrings = [
|
||||
["", "empty string"],
|
||||
];
|
||||
|
||||
for (const [calendar, description] of invalidStrings) {
|
||||
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.equals(arg),
|
||||
`${description} is not a valid calendar ID`
|
||||
);
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindate.prototype.equals
|
||||
description: A number as calendar in a property bag is not accepted
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDate(1976, 11, 18);
|
||||
|
||||
const numbers = [
|
||||
1,
|
||||
19970327,
|
||||
-19970327,
|
||||
1234567890,
|
||||
];
|
||||
|
||||
for (const calendar of numbers) {
|
||||
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.equals(arg),
|
||||
"Numbers cannot be used as a calendar"
|
||||
);
|
||||
}
|
@ -9,33 +9,26 @@ description: >
|
||||
features: [BigInt, Symbol, Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = "UTC";
|
||||
const instance = new Temporal.PlainDate(2000, 5, 2);
|
||||
|
||||
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 arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(
|
||||
typeof calendar === 'string' ? RangeError : TypeError,
|
||||
() => instance.equals(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
||||
|
||||
const typeErrorTests = [
|
||||
[19970327, "large number"],
|
||||
[-19970327, "negative number"],
|
||||
[1234567890, "very large integer"],
|
||||
[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, () => instance.equals(arg), `${description} is not a valid property bag and does not convert to a string`);
|
||||
for (const [calendar, description] of wrongTypeTests) {
|
||||
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.equals(arg),
|
||||
`${description} is not a valid calendar`
|
||||
);
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
// 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.prototype.since
|
||||
description: Invalid ISO string as calendar should throw RangeError
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDate(2000, 5, 2);
|
||||
|
||||
const invalidStrings = [
|
||||
["", "empty string"],
|
||||
];
|
||||
|
||||
for (const [calendar, description] of invalidStrings) {
|
||||
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.since(arg),
|
||||
`${description} is not a valid calendar ID`
|
||||
);
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindate.prototype.since
|
||||
description: A number as calendar in a property bag is not accepted
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDate(1976, 11, 18);
|
||||
|
||||
const numbers = [
|
||||
1,
|
||||
19970327,
|
||||
-19970327,
|
||||
1234567890,
|
||||
];
|
||||
for (const calendar of numbers) {
|
||||
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.since(arg),
|
||||
"Numbers cannot be used as a calendar"
|
||||
);
|
||||
}
|
@ -5,36 +5,30 @@
|
||||
esid: sec-temporal.plaindate.prototype.since
|
||||
description: >
|
||||
Appropriate error thrown when a calendar property from a property bag cannot
|
||||
be converted to a calendar object or string
|
||||
be converted to a calendar object
|
||||
features: [BigInt, Symbol, Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDate(2000, 5, 2);
|
||||
|
||||
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 arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(
|
||||
typeof calendar === 'string' ? RangeError : TypeError,
|
||||
() => instance.since(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
||||
|
||||
const typeErrorTests = [
|
||||
[19970327, "large number"],
|
||||
[-19970327, "negative number"],
|
||||
[1234567890, "very large integer"],
|
||||
[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, () => instance.since(arg), `${description} is not a valid property bag and does not convert to a string`);
|
||||
for (const [calendar, description] of wrongTypeTests) {
|
||||
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.since(arg),
|
||||
`${description} is not a valid calendar`
|
||||
);
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
// 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.prototype.until
|
||||
description: Invalid ISO string as calendar should throw RangeError
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDate(2000, 5, 2);
|
||||
|
||||
const invalidStrings = [
|
||||
["", "empty string"],
|
||||
];
|
||||
|
||||
for (const [calendar, description] of invalidStrings) {
|
||||
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.until(arg),
|
||||
`${description} is not a valid calendar ID`
|
||||
);
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindate.prototype.until
|
||||
description: A number as calendar in a property bag is not accepted
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDate(1976, 11, 18);
|
||||
|
||||
const numbers = [
|
||||
1,
|
||||
19970327,
|
||||
-19970327,
|
||||
1234567890,
|
||||
];
|
||||
for (const calendar of numbers) {
|
||||
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.until(arg),
|
||||
"Numbers cannot be used as a calendar"
|
||||
);
|
||||
}
|
@ -9,33 +9,26 @@ description: >
|
||||
features: [BigInt, Symbol, Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = "UTC";
|
||||
const instance = new Temporal.PlainDate(2000, 5, 2);
|
||||
|
||||
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 arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(
|
||||
typeof calendar === 'string' ? RangeError : TypeError,
|
||||
() => instance.until(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
||||
|
||||
const typeErrorTests = [
|
||||
[19970327, "large number"],
|
||||
[-19970327, "negative number"],
|
||||
[1234567890, "very large integer"],
|
||||
[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, () => instance.until(arg), `${description} is not a valid property bag and does not convert to a string`);
|
||||
for (const [calendar, description] of wrongTypeTests) {
|
||||
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.until(arg),
|
||||
`${description} is not a valid calendar`
|
||||
);
|
||||
}
|
||||
|
22
test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-invalid-iso-string.js
vendored
Normal file
22
test/built-ins/Temporal/PlainDate/prototype/withCalendar/calendar-invalid-iso-string.js
vendored
Normal file
@ -0,0 +1,22 @@
|
||||
// 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.prototype.withcalendar
|
||||
description: Invalid ISO string as calendar should throw RangeError
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDate(1976, 11, 18, "iso8601");
|
||||
|
||||
const invalidStrings = [
|
||||
["", "empty string"],
|
||||
];
|
||||
|
||||
for (const [arg, description] of invalidStrings) {
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.withCalendar(arg),
|
||||
`${description} is not a valid calendar ID`
|
||||
);
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindate.prototype.withcalendar
|
||||
description: A number is not allowed to be a calendar
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDate(1976, 11, 18, "iso8601");
|
||||
|
||||
const numbers = [
|
||||
1,
|
||||
-19761118,
|
||||
19761118,
|
||||
1234567890,
|
||||
];
|
||||
|
||||
for (const arg of numbers) {
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.withCalendar(arg),
|
||||
"A number is not a valid ISO string for Calendar"
|
||||
);
|
||||
}
|
@ -11,28 +11,23 @@ features: [BigInt, Symbol, Temporal]
|
||||
|
||||
const instance = new Temporal.PlainDate(1976, 11, 18, "iso8601");
|
||||
|
||||
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,
|
||||
() => instance.withCalendar(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
||||
|
||||
const typeErrorTests = [
|
||||
[-19761118, "negative number"],
|
||||
[19761118, "large positive number"],
|
||||
[1234567890, "very large integer"],
|
||||
[Symbol(), "symbol"],
|
||||
[{}, "object"],
|
||||
[new Temporal.Duration(), "duration instance"],
|
||||
];
|
||||
|
||||
for (const [arg, description] of typeErrorTests) {
|
||||
assert.throws(TypeError, () => instance.withCalendar(arg), `${description} is not a valid object and does not convert to a string`);
|
||||
for (const [arg, description] of wrongTypeTests) {
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.withCalendar(arg),
|
||||
`${description} is not a valid calendar`
|
||||
);
|
||||
}
|
||||
|
@ -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.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`
|
||||
);
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
// 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: An ISO string is not valid input for a constructor's calendar param
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => new Temporal.PlainDateTime(2000, 5, 2, 15, 23, 30, 987, 654, 321, "1997-12-04[u-ca=iso8601]"),
|
||||
"An ISO string is not a valid calendar ID for constructor parameter"
|
||||
);
|
@ -1,23 +0,0 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindatetime
|
||||
description: A number is not allowed to be a calendar
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const numbers = [
|
||||
1,
|
||||
-19761118,
|
||||
19761118,
|
||||
1234567890,
|
||||
];
|
||||
|
||||
for (const arg of numbers) {
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => new Temporal.PlainDateTime(2000, 5, 2, 15, 23, 30, 987, 654, 321, arg),
|
||||
"A number is not a valid ISO string for Calendar"
|
||||
);
|
||||
}
|
@ -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.PlainDateTime(2000, 5, 2, 15, 23, 30, 987, 654, 321, 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.PlainDateTime(2000, 5, 2, 15, 23, 30, 987, 654, 321, 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.PlainDateTime(2000, 5, 2, 15, 23, 30, 987, 654, 321, arg),
|
||||
`${description} is not a valid calendar`
|
||||
);
|
||||
}
|
||||
|
@ -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.plaindatetime.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.PlainDateTime.compare(arg, new Temporal.PlainDateTime(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.PlainDateTime.compare(new Temporal.PlainDateTime(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)`
|
||||
);
|
||||
}
|
@ -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"],
|
||||
];
|
||||
|
||||
for (const [calendar, description] of primitiveTests) {
|
||||
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(
|
||||
typeof calendar === "string" ? RangeError : TypeError,
|
||||
() => Temporal.PlainDateTime.compare(arg, new Temporal.PlainDateTime(1976, 11, 18)),
|
||||
`${description} does not convert to a valid ISO string (first argument)`
|
||||
);
|
||||
assert.throws(
|
||||
typeof calendar === "string" ? RangeError : TypeError,
|
||||
() => Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg),
|
||||
`${description} does not convert to a valid ISO string (second argument)`
|
||||
);
|
||||
}
|
||||
|
||||
const typeErrorTests = [
|
||||
[19970327, "large number"],
|
||||
[-19970327, "negative number"],
|
||||
[1234567890, "very large integer"],
|
||||
[Symbol(), "symbol"],
|
||||
[{}, "object"],
|
||||
[new Temporal.Duration(), "duration instance"],
|
||||
];
|
||||
|
||||
for (const [calendar, description] of typeErrorTests) {
|
||||
for (const [calendar, description] of wrongTypeTests) {
|
||||
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
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)`);
|
||||
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)`);
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => Temporal.PlainDateTime.compare(arg, new Temporal.PlainDateTime(1976, 11, 18)),
|
||||
`${description} is not a valid calendar (first argument)`
|
||||
);
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => Temporal.PlainDateTime.compare(new Temporal.PlainDateTime(1976, 11, 18), arg),
|
||||
`${description} is not a valid calendar (second argument)`
|
||||
);
|
||||
}
|
||||
|
@ -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.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`
|
||||
);
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
// Copyright (C) 2022 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: A number as calendar in a property bag is not accepted
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const numbers = [
|
||||
1,
|
||||
19970327,
|
||||
-19970327,
|
||||
1234567890,
|
||||
];
|
||||
|
||||
for (const calendar of numbers) {
|
||||
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => Temporal.PlainDateTime.from(arg),
|
||||
"Numbers cannot be used as a calendar"
|
||||
);
|
||||
}
|
@ -9,30 +9,24 @@ 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 [calendar, description] of primitiveTests) {
|
||||
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(
|
||||
typeof calendar === 'string' ? RangeError : TypeError,
|
||||
() => Temporal.PlainDateTime.from(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
||||
|
||||
const typeErrorTests = [
|
||||
[19970327, "large number"],
|
||||
[-19970327, "negative number"],
|
||||
[1234567890, "very large integer"],
|
||||
[Symbol(), "symbol"],
|
||||
[{}, "object"],
|
||||
[new Temporal.Duration(), "duration instance"],
|
||||
];
|
||||
|
||||
for (const [calendar, description] of typeErrorTests) {
|
||||
for (const [calendar, description] of wrongTypeTests) {
|
||||
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(TypeError, () => Temporal.PlainDateTime.from(arg), `${description} is not a valid property bag and does not convert to a string`);
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => Temporal.PlainDateTime.from(arg),
|
||||
`${description} is not a valid calendar`
|
||||
);
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
// 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.plaindatetime.prototype.equals
|
||||
description: Invalid ISO string as calendar should throw RangeError
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
|
||||
|
||||
const invalidStrings = [
|
||||
["", "empty string"],
|
||||
];
|
||||
|
||||
for (const [calendar, description] of invalidStrings) {
|
||||
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.equals(arg),
|
||||
`${description} is not a valid calendar ID`
|
||||
);
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindatetime.prototype.equals
|
||||
description: A number as calendar in a property bag is not accepted
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDateTime(1976, 11, 18);
|
||||
|
||||
const numbers = [
|
||||
1,
|
||||
19970327,
|
||||
-19970327,
|
||||
1234567890,
|
||||
];
|
||||
|
||||
for (const calendar of numbers) {
|
||||
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.equals(arg),
|
||||
"Numbers cannot be used as a calendar"
|
||||
);
|
||||
}
|
@ -9,33 +9,26 @@ description: >
|
||||
features: [BigInt, Symbol, Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = "UTC";
|
||||
const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
|
||||
|
||||
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 arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(
|
||||
typeof calendar === 'string' ? RangeError : TypeError,
|
||||
() => instance.equals(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
||||
|
||||
const typeErrorTests = [
|
||||
[19970327, "large number"],
|
||||
[-19970327, "negative number"],
|
||||
[1234567890, "very large integer"],
|
||||
[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, () => instance.equals(arg), `${description} is not a valid property bag and does not convert to a string`);
|
||||
for (const [calendar, description] of wrongTypeTests) {
|
||||
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.equals(arg),
|
||||
`${description} is not a valid calendar`
|
||||
);
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
// 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.plaindatetime.prototype.since
|
||||
description: Invalid ISO string as calendar should throw RangeError
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
|
||||
|
||||
const invalidStrings = [
|
||||
["", "empty string"],
|
||||
];
|
||||
|
||||
for (const [calendar, description] of invalidStrings) {
|
||||
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.since(arg),
|
||||
`${description} is not a valid calendar ID`
|
||||
);
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindatetime.prototype.since
|
||||
description: A number as calendar in a property bag is not accepted
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDateTime(1976, 11, 18);
|
||||
|
||||
const numbers = [
|
||||
1,
|
||||
19970327,
|
||||
-19970327,
|
||||
1234567890,
|
||||
];
|
||||
|
||||
for (const calendar of numbers) {
|
||||
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.since(arg),
|
||||
"Numbers cannot be used as a calendar"
|
||||
);
|
||||
}
|
@ -11,30 +11,24 @@ features: [BigInt, Symbol, Temporal]
|
||||
|
||||
const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
|
||||
|
||||
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 arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(
|
||||
typeof calendar === 'string' ? RangeError : TypeError,
|
||||
() => instance.since(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
||||
|
||||
const typeErrorTests = [
|
||||
[19970327, "large number"],
|
||||
[-19970327, "negative number"],
|
||||
[1234567890, "very large integer"],
|
||||
[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, () => instance.since(arg), `${description} is not a valid property bag and does not convert to a string`);
|
||||
for (const [calendar, description] of wrongTypeTests) {
|
||||
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.since(arg),
|
||||
`${description} is not a valid calendar`
|
||||
);
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
// 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.plaindatetime.prototype.until
|
||||
description: Invalid ISO string as calendar should throw RangeError
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
|
||||
|
||||
const invalidStrings = [
|
||||
["", "empty string"],
|
||||
];
|
||||
|
||||
for (const [calendar, description] of invalidStrings) {
|
||||
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.until(arg),
|
||||
`${description} is not a valid calendar ID`
|
||||
);
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindatetime.prototype.until
|
||||
description: A number as calendar in a property bag is not accepted
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDateTime(1976, 11, 18);
|
||||
|
||||
const numbers = [
|
||||
1,
|
||||
19970327,
|
||||
-19970327,
|
||||
1234567890,
|
||||
];
|
||||
|
||||
for (const calendar of numbers) {
|
||||
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.until(arg),
|
||||
"Numbers cannot be used as a calendar"
|
||||
);
|
||||
}
|
@ -9,33 +9,26 @@ description: >
|
||||
features: [BigInt, Symbol, Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = "UTC";
|
||||
const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321);
|
||||
|
||||
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 arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(
|
||||
typeof calendar === 'string' ? RangeError : TypeError,
|
||||
() => instance.until(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
||||
|
||||
const typeErrorTests = [
|
||||
[19970327, "large number"],
|
||||
[-19970327, "negative number"],
|
||||
[1234567890, "very large integer"],
|
||||
[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, () => instance.until(arg), `${description} is not a valid property bag and does not convert to a string`);
|
||||
for (const [calendar, description] of wrongTypeTests) {
|
||||
const arg = { year: 1976, monthCode: "M11", day: 18, calendar };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.until(arg),
|
||||
`${description} is not a valid calendar`
|
||||
);
|
||||
}
|
||||
|
@ -1,25 +1,22 @@
|
||||
// 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.plaindatetime.prototype.withcalendar
|
||||
description: A number is not allowed to be a calendar
|
||||
description: Invalid ISO 8601 string is not accepted as calendar
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, "iso8601");
|
||||
|
||||
const numbers = [
|
||||
1,
|
||||
-19761118,
|
||||
19761118,
|
||||
1234567890,
|
||||
const invalidStrings = [
|
||||
["", "empty string"],
|
||||
];
|
||||
|
||||
for (const arg of numbers) {
|
||||
for (const [arg, description] of invalidStrings) {
|
||||
assert.throws(
|
||||
TypeError,
|
||||
RangeError,
|
||||
() => instance.withCalendar(arg),
|
||||
"A number is not a valid ISO string for Calendar"
|
||||
`${description} is not a valid calendar ID`
|
||||
);
|
||||
}
|
@ -11,28 +11,23 @@ features: [BigInt, Symbol, Temporal]
|
||||
|
||||
const instance = new Temporal.PlainDateTime(1976, 11, 18, 15, 23, 30, 123, 456, 789, "iso8601");
|
||||
|
||||
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 [arg, description] of primitiveTests) {
|
||||
assert.throws(
|
||||
typeof arg === 'string' ? RangeError : TypeError,
|
||||
() => instance.withCalendar(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
||||
|
||||
const typeErrorTests = [
|
||||
[19970327, "large number"],
|
||||
[-19970327, "negative number"],
|
||||
[1234567890, "very large integer"],
|
||||
[Symbol(), "symbol"],
|
||||
[{}, "object"],
|
||||
[new Temporal.Duration(), "duration instance"],
|
||||
];
|
||||
|
||||
for (const [arg, description] of typeErrorTests) {
|
||||
assert.throws(TypeError, () => instance.withCalendar(arg), `${description} is not a valid object and does not convert to a string`);
|
||||
for (const [arg, description] of wrongTypeTests) {
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.withCalendar(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
||||
|
@ -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.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`
|
||||
);
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
// 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: An ISO string is not valid input for a constructor's calendar param
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => new Temporal.PlainMonthDay(12, 15, "1997-12-04[u-ca=iso8601]", 1972),
|
||||
"An ISO string is not a valid calendar ID for constructor parameter"
|
||||
);
|
@ -1,23 +0,0 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plainmonthday
|
||||
description: A number is not allowed to be a calendar
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const numbers = [
|
||||
1,
|
||||
-19761118,
|
||||
19761118,
|
||||
1234567890,
|
||||
];
|
||||
|
||||
for (const arg of numbers) {
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => new Temporal.PlainMonthDay(12, 15, arg, 1972),
|
||||
"A number is not a valid ISO string for Calendar"
|
||||
);
|
||||
}
|
@ -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.PlainMonthDay(12, 15, arg, 1972),
|
||||
`${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.PlainMonthDay(12, 15, arg, 1972), `${description} is not a valid object and does not convert to a string`);
|
||||
for (const [arg, description] of wrongTypeTests) {
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => new Temporal.PlainMonthDay(12, 15, arg, 1972),
|
||||
`${description} is not a valid calendar`
|
||||
);
|
||||
}
|
||||
|
@ -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.plainmonthday.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 = { monthCode: "M11", day: 18, calendar };
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => Temporal.PlainMonthDay.from(arg),
|
||||
`${description} is not a valid calendar ID`
|
||||
);
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2024 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.
|
||||
|
||||
/*---
|
||||
|
@ -1,24 +0,0 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plainmonthday.from
|
||||
description: A number as calendar in a property bag is not accepted
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const numbers = [
|
||||
1,
|
||||
19970327,
|
||||
-19970327,
|
||||
1234567890,
|
||||
];
|
||||
|
||||
for (const calendar of numbers) {
|
||||
const arg = { monthCode: "M11", day: 18, calendar };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => Temporal.PlainMonthDay.from(arg),
|
||||
"Numbers cannot be used as a calendar"
|
||||
);
|
||||
}
|
@ -9,30 +9,24 @@ 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 [calendar, description] of primitiveTests) {
|
||||
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(
|
||||
typeof calendar === 'string' ? RangeError : TypeError,
|
||||
() => Temporal.PlainMonthDay.from(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
||||
|
||||
const typeErrorTests = [
|
||||
[19970327, "large number"],
|
||||
[-19970327, "negative number"],
|
||||
[1234567890, "very large integer"],
|
||||
[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.PlainMonthDay.from(arg), `${description} is not a valid property bag and does not convert to a string`);
|
||||
for (const [calendar, description] of wrongTypeTests) {
|
||||
const arg = { monthCode: "M11", day: 18, calendar };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => Temporal.PlainMonthDay.from(arg),
|
||||
`${description} is not a valid calendar`
|
||||
);
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
// 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.plainmonthday.prototype.equals
|
||||
description: >
|
||||
A string value for calendar in a property bag that is not a valid calendar ID
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainMonthDay(5, 2);
|
||||
|
||||
const invalidStrings = [
|
||||
["", "empty string"],
|
||||
];
|
||||
|
||||
for (const [calendar, description] of invalidStrings) {
|
||||
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.equals(arg),
|
||||
`${description} is not a valid calendar ID`
|
||||
);
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plainmonthday.prototype.equals
|
||||
description: A number as calendar in a property bag is not accepted
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainMonthDay(11, 18);
|
||||
|
||||
const numbers = [
|
||||
1,
|
||||
19970327,
|
||||
-19970327,
|
||||
1234567890,
|
||||
];
|
||||
|
||||
for (const calendar of numbers) {
|
||||
const arg = { monthCode: "M11", day: 18, calendar };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.equals(arg),
|
||||
"Numbers cannot be used as a calendar"
|
||||
);
|
||||
}
|
@ -9,33 +9,26 @@ description: >
|
||||
features: [BigInt, Symbol, Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = "UTC";
|
||||
const instance = new Temporal.PlainMonthDay(5, 2);
|
||||
|
||||
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 arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(
|
||||
typeof calendar === 'string' ? RangeError : TypeError,
|
||||
() => instance.equals(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
||||
|
||||
const typeErrorTests = [
|
||||
[19970327, "large number"],
|
||||
[-19970327, "negative number"],
|
||||
[1234567890, "very large integer"],
|
||||
[Symbol(), "symbol"],
|
||||
[{}, "object"],
|
||||
[new Temporal.Duration(), "duration instance"],
|
||||
];
|
||||
|
||||
for (const [calendar, description] of typeErrorTests) {
|
||||
for (const [calendar, description] of wrongTypeTests) {
|
||||
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(TypeError, () => instance.equals(arg), `${description} is not a valid property bag and does not convert to a string`);
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.equals(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
||||
|
@ -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.plainyearmonth.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.PlainYearMonth(2000, 5, arg, 1),
|
||||
`${description} is not a valid calendar ID`
|
||||
);
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
// 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.plainyearmonth.constructor
|
||||
description: An ISO string is not valid input for a constructor's calendar param
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => new Temporal.PlainYearMonth(2000, 5, "1997-12-04[u-ca=iso8601]", 1),
|
||||
"An ISO string is not a valid calendar ID for constructor parameter"
|
||||
);
|
@ -1,23 +0,0 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plainyearmonth
|
||||
description: A number is not allowed to be a calendar
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const numbers = [
|
||||
1,
|
||||
-19761118,
|
||||
19761118,
|
||||
1234567890,
|
||||
];
|
||||
|
||||
for (const arg of numbers) {
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => new Temporal.PlainYearMonth(2000, 5, arg, 1),
|
||||
"A number is not a valid ISO string for Calendar"
|
||||
);
|
||||
}
|
@ -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.PlainYearMonth(2000, 5, arg, 1),
|
||||
`${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.PlainYearMonth(2000, 5, arg, 1), `${description} is not a valid object and does not convert to a string`);
|
||||
for (const [arg, description] of wrongTypeTests) {
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => new Temporal.PlainYearMonth(2000, 5, arg, 1),
|
||||
`${description} is not a valid calendar`
|
||||
);
|
||||
}
|
||||
|
@ -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.plainyearmonth.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: 2019, monthCode: "M06", calendar };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
RangeError,
|
||||
() => Temporal.PlainYearMonth.compare(arg, new Temporal.PlainYearMonth(2019, 6)),
|
||||
"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.PlainYearMonth.compare(new Temporal.PlainYearMonth(2019, 6), arg),
|
||||
"A number is not a valid ISO string for calendar (second argument)"
|
||||
`${description} is not a valid calendar ID (second argument)`
|
||||
);
|
||||
}
|
@ -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"],
|
||||
];
|
||||
|
||||
for (const [calendar, description] of primitiveTests) {
|
||||
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(
|
||||
typeof calendar === "string" ? RangeError : TypeError,
|
||||
() => Temporal.PlainYearMonth.compare(arg, new Temporal.PlainYearMonth(2019, 6)),
|
||||
`${description} does not convert to a valid ISO string (first argument)`
|
||||
);
|
||||
assert.throws(
|
||||
typeof calendar === "string" ? RangeError : TypeError,
|
||||
() => Temporal.PlainYearMonth.compare(new Temporal.PlainYearMonth(2019, 6), arg),
|
||||
`${description} does not convert to a valid ISO string (second argument)`
|
||||
);
|
||||
}
|
||||
|
||||
const typeErrorTests = [
|
||||
[19970327, "large number"],
|
||||
[-19970327, "negative number"],
|
||||
[1234567890, "very large integer"],
|
||||
[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.PlainYearMonth.compare(arg, new Temporal.PlainYearMonth(2019, 6)), `${description} is not a valid property bag and does not convert to a string (first argument)`);
|
||||
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)`);
|
||||
for (const [calendar, description] of wrongTypeTests) {
|
||||
const arg = { year: 2019, monthCode: "M06", calendar };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => Temporal.PlainYearMonth.compare(arg, new Temporal.PlainYearMonth(2019, 6)),
|
||||
`${description} is not a valid calendar (first argument)`
|
||||
);
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => Temporal.PlainYearMonth.compare(new Temporal.PlainYearMonth(2019, 6), arg),
|
||||
`${description} is not a valid calendar (second argument)`
|
||||
);
|
||||
}
|
||||
|
@ -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.plainyearmonth.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", calendar };
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => Temporal.PlainYearMonth.from(arg),
|
||||
`${description} is not a valid calendar ID`
|
||||
);
|
||||
}
|
@ -1,24 +0,0 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plainyearmonth.from
|
||||
description: A number as calendar in a property bag is not accepted
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const numbers = [
|
||||
1,
|
||||
19970327,
|
||||
-19970327,
|
||||
1234567890,
|
||||
];
|
||||
|
||||
for (const calendar of numbers) {
|
||||
const arg = { year: 2019, monthCode: "M06", calendar };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => Temporal.PlainYearMonth.from(arg),
|
||||
"Numbers cannot be used as a calendar"
|
||||
);
|
||||
}
|
@ -9,30 +9,24 @@ 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 [calendar, description] of primitiveTests) {
|
||||
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(
|
||||
typeof calendar === 'string' ? RangeError : TypeError,
|
||||
() => Temporal.PlainYearMonth.from(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
||||
|
||||
const typeErrorTests = [
|
||||
[19970327, "large number"],
|
||||
[-19970327, "negative number"],
|
||||
[1234567890, "very large integer"],
|
||||
[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.PlainYearMonth.from(arg), `${description} is not a valid property bag and does not convert to a string`);
|
||||
for (const [calendar, description] of wrongTypeTests) {
|
||||
const arg = { year: 2019, monthCode: "M11", calendar };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => Temporal.PlainYearMonth.from(arg),
|
||||
`${description} is not a valid calendar`
|
||||
);
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
// 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.plainyearmonth.prototype.equals
|
||||
description: >
|
||||
Appropriate error thrown when a calendar property from a property bag cannot
|
||||
be converted to a calendar ID
|
||||
features: [BigInt, Symbol, Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainYearMonth(2000, 5);
|
||||
|
||||
const primitiveTests = [
|
||||
["", "empty string"]
|
||||
];
|
||||
|
||||
for (const [calendar, description] of primitiveTests) {
|
||||
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.equals(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plainyearmonth.prototype.equals
|
||||
description: A number as calendar in a property bag is not accepted
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainYearMonth(2019, 6);
|
||||
|
||||
const numbers = [
|
||||
1,
|
||||
19970327,
|
||||
-19970327,
|
||||
1234567890,
|
||||
];
|
||||
|
||||
for (const calendar of numbers) {
|
||||
const arg = { year: 2019, monthCode: "M06", calendar };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.equals(arg),
|
||||
"Numbers cannot be used as a calendar"
|
||||
);
|
||||
}
|
@ -9,33 +9,26 @@ description: >
|
||||
features: [BigInt, Symbol, Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = "UTC";
|
||||
const instance = new Temporal.PlainYearMonth(2000, 5);
|
||||
|
||||
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 arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(
|
||||
typeof calendar === 'string' ? RangeError : TypeError,
|
||||
() => instance.equals(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
||||
|
||||
const typeErrorTests = [
|
||||
[19970327, "large positive number"],
|
||||
[-19970327, "negative number"],
|
||||
[1234567890, "very large integer"],
|
||||
[Symbol(), "symbol"],
|
||||
[{}, "object"],
|
||||
[new Temporal.Duration(), "duration instance"],
|
||||
];
|
||||
|
||||
for (const [calendar, description] of typeErrorTests) {
|
||||
for (const [calendar, description] of wrongTypeTests) {
|
||||
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(TypeError, () => instance.equals(arg), `${description} is not a valid property bag and does not convert to a string`);
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.equals(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
// 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.plainyearmonth.prototype.since
|
||||
description: >
|
||||
An ISO string that cannot be converted to a calendar ID should throw a RangeError
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainYearMonth(2000, 5);
|
||||
|
||||
const invalidStrings = [
|
||||
["", "empty string"],
|
||||
];
|
||||
|
||||
for (const [calendar, description] of invalidStrings) {
|
||||
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.since(arg),
|
||||
`${description} is not a valid calendar ID`
|
||||
);
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plainyearmonth.prototype.since
|
||||
description: A number as calendar in a property bag is not accepted
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainYearMonth(2019, 6);
|
||||
|
||||
const numbers = [
|
||||
1,
|
||||
19970327,
|
||||
-19970327,
|
||||
1234567890,
|
||||
];
|
||||
|
||||
for (const calendar of numbers) {
|
||||
const arg = { year: 2019, monthCode: "M06", calendar };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.since(arg),
|
||||
"Numbers cannot be used as a calendar"
|
||||
);
|
||||
}
|
@ -11,30 +11,24 @@ features: [BigInt, Symbol, Temporal]
|
||||
|
||||
const instance = new Temporal.PlainYearMonth(2000, 5);
|
||||
|
||||
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 arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(
|
||||
typeof calendar === 'string' ? RangeError : TypeError,
|
||||
() => instance.since(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
||||
|
||||
const typeErrorTests = [
|
||||
[19970327, "large positive number"],
|
||||
[-19970327, "negative number"],
|
||||
[1234567890, "very large integer"],
|
||||
[Symbol(), "symbol"],
|
||||
[{}, "object"],
|
||||
[new Temporal.Duration(), "duration instance"],
|
||||
];
|
||||
|
||||
for (const [calendar, description] of typeErrorTests) {
|
||||
for (const [calendar, description] of wrongTypeTests) {
|
||||
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(TypeError, () => instance.since(arg), `${description} is not a valid property bag and does not convert to a string`);
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.since(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
// 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.plainyearmonth.prototype.until
|
||||
description: >
|
||||
An ISO string that cannot be converted to a calendar ID should throw a RangeError
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainYearMonth(2000, 5);
|
||||
|
||||
const invalidStrings = [
|
||||
["", "empty string"]
|
||||
];
|
||||
|
||||
for (const [calendar, description] of invalidStrings) {
|
||||
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.until(arg),
|
||||
`${description} is not a valid calendar ID`
|
||||
);
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plainyearmonth.prototype.until
|
||||
description: A number as calendar in a property bag is not accepted
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainYearMonth(2019, 6);
|
||||
|
||||
const numbers = [
|
||||
1,
|
||||
19970327,
|
||||
-19970327,
|
||||
1234567890,
|
||||
];
|
||||
|
||||
for (const calendar of numbers) {
|
||||
const arg = { year: 2019, monthCode: "M06", calendar };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.until(arg),
|
||||
"Numbers cannot be used as a calendar"
|
||||
);
|
||||
}
|
@ -9,33 +9,26 @@ description: >
|
||||
features: [BigInt, Symbol, Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = "UTC";
|
||||
const instance = new Temporal.PlainYearMonth(2000, 5);
|
||||
|
||||
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 arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(
|
||||
typeof calendar === 'string' ? RangeError : TypeError,
|
||||
() => instance.until(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
||||
|
||||
const typeErrorTests = [
|
||||
[19970327, "large positive number"],
|
||||
[-19970327, "large negative number"],
|
||||
[1234567890, "very large integer"],
|
||||
[Symbol(), "symbol"],
|
||||
[{}, "object"],
|
||||
[new Temporal.Duration(), "duration instance"],
|
||||
];
|
||||
|
||||
for (const [calendar, description] of typeErrorTests) {
|
||||
for (const [calendar, description] of wrongTypeTests) {
|
||||
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(TypeError, () => instance.until(arg), `${description} is not a valid property bag and does not convert to a string`);
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.until(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
||||
|
@ -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.zoneddatetime.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.ZonedDateTime(0n, "UTC", arg),
|
||||
`${description} is not a valid calendar ID`
|
||||
);
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
// 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.zoneddatetime.constructor
|
||||
description: An ISO string is not valid input for a constructor's calendar param
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => new Temporal.ZonedDateTime(0n, "UTC", "1997-12-04[u-ca=iso8601]"),
|
||||
"An ISO string is not a valid calendar ID for constructor parameter"
|
||||
);
|
@ -1,23 +0,0 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime
|
||||
description: A number is not allowed to be a calendar
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const numbers = [
|
||||
1,
|
||||
-19761118,
|
||||
19761118,
|
||||
1234567890,
|
||||
];
|
||||
|
||||
for (const arg of numbers) {
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => new Temporal.ZonedDateTime(0n, "UTC", arg),
|
||||
"A number is not a valid ISO string for Calendar"
|
||||
);
|
||||
}
|
@ -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.ZonedDateTime(0n, "UTC", 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.ZonedDateTime(0n, "UTC", 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.ZonedDateTime(0n, "UTC", arg),
|
||||
`${description} is not a valid calendar`
|
||||
);
|
||||
}
|
||||
|
@ -0,0 +1,28 @@
|
||||
// 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.zoneddatetime.compare
|
||||
description: Invalid ISO string as calendar should throw RangeError
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const datetime = new Temporal.ZonedDateTime(0n, "UTC");
|
||||
|
||||
const invalidStrings = [
|
||||
["", "empty string"],
|
||||
];
|
||||
|
||||
for (const [calendar, description] of invalidStrings) {
|
||||
const arg = { year: 1970, monthCode: "M01", day: 1, calendar, timeZone: "UTC" };
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => Temporal.ZonedDateTime.compare(arg, datetime),
|
||||
`${description} is not a valid calendar ID (first argument)`
|
||||
);
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => Temporal.ZonedDateTime.compare(datetime, arg),
|
||||
`${description} is not a valid calendar ID (second argument)`
|
||||
);
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.compare
|
||||
description: A number as calendar in a property bag is not accepted
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = "UTC";
|
||||
const datetime = new Temporal.ZonedDateTime(0n, timeZone);
|
||||
|
||||
const numbers = [
|
||||
1,
|
||||
19970327,
|
||||
-19970327,
|
||||
1234567890,
|
||||
];
|
||||
|
||||
for (const calendar of numbers) {
|
||||
const arg = { year: 1970, monthCode: "M01", day: 1, calendar, timeZone };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => Temporal.ZonedDateTime.compare(arg, datetime),
|
||||
"A number is not a valid ISO string for calendar (first argument)"
|
||||
);
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => Temporal.ZonedDateTime.compare(datetime, arg),
|
||||
"A number is not a valid ISO string for calendar (second argument)"
|
||||
);
|
||||
}
|
@ -11,36 +11,29 @@ features: [BigInt, Symbol, Temporal]
|
||||
|
||||
const datetime = new Temporal.ZonedDateTime(0n, "UTC");
|
||||
|
||||
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 arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(
|
||||
typeof calendar === "string" ? RangeError : TypeError,
|
||||
() => Temporal.ZonedDateTime.compare(arg, datetime),
|
||||
`${description} does not convert to a valid ISO string (first argument)`
|
||||
);
|
||||
assert.throws(
|
||||
typeof calendar === "string" ? RangeError : TypeError,
|
||||
() => Temporal.ZonedDateTime.compare(datetime, arg),
|
||||
`${description} does not convert to a valid ISO string (second argument)`
|
||||
);
|
||||
}
|
||||
|
||||
const typeErrorTests = [
|
||||
[19970327, "large number"],
|
||||
[-19970327, "negative number"],
|
||||
[1234567890, "very large integer"],
|
||||
[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.ZonedDateTime.compare(arg, datetime), `${description} is not a valid property bag and does not convert to a string (first argument)`);
|
||||
assert.throws(TypeError, () => Temporal.ZonedDateTime.compare(datetime, arg), `${description} is not a valid property bag and does not convert to a string (second argument)`);
|
||||
for (const [calendar, description] of wrongTypeTests) {
|
||||
const arg = { year: 1970, monthCode: "M01", day: 1, calendar, timeZone: "UTC" };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => Temporal.ZonedDateTime.compare(arg, datetime),
|
||||
`${description} is not a valid calendar (first argument)`
|
||||
);
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => Temporal.ZonedDateTime.compare(datetime, arg),
|
||||
`${description} is not a valid calendar (second argument)`
|
||||
);
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
// 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.zoneddatetime.from
|
||||
description: Various invalid ISO string values for calendar in a property bag
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = "UTC";
|
||||
|
||||
const invalidStrings = [
|
||||
["", "empty string"],
|
||||
];
|
||||
|
||||
for (const [calendar, description] of invalidStrings) {
|
||||
const arg = { year: 1970, monthCode: "M01", day: 1, timeZone, calendar };
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => Temporal.ZonedDateTime.from(arg),
|
||||
`${description} is not a valid calendar ID`
|
||||
);
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.from
|
||||
description: A number as calendar in a property bag is not accepted
|
||||
features: [Temporal]
|
||||
---*/
|
||||
const timeZone = "UTC";
|
||||
|
||||
const numbers = [
|
||||
1,
|
||||
19970327,
|
||||
-19970327,
|
||||
1234567890,
|
||||
];
|
||||
|
||||
for (const calendar of numbers) {
|
||||
const arg = { year: 1970, monthCode: "M01", day: 1, timeZone, calendar };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => Temporal.ZonedDateTime.from(arg),
|
||||
"Numbers cannot be used as a calendar"
|
||||
);
|
||||
}
|
@ -9,30 +9,25 @@ description: >
|
||||
features: [BigInt, Symbol, Temporal]
|
||||
---*/
|
||||
|
||||
const primitiveTests = [
|
||||
const timeZone = "UTC";
|
||||
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 arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(
|
||||
typeof calendar === 'string' ? RangeError : TypeError,
|
||||
() => Temporal.ZonedDateTime.from(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
||||
|
||||
const typeErrorTests = [
|
||||
[19970327, "large number"],
|
||||
[-19970327, "negative number"],
|
||||
[1234567890, "very large integer"],
|
||||
[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.ZonedDateTime.from(arg), `${description} is not a valid property bag and does not convert to a string`);
|
||||
for (const [calendar, description] of wrongTypeTests) {
|
||||
const arg = { year: 1970, monthCode: "M01", day: 1, timeZone, calendar };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => Temporal.ZonedDateTime.from(arg),
|
||||
`${description} is not a valid calendar`
|
||||
);
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
// 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.zoneddatetime.prototype.equals
|
||||
description: >
|
||||
An ISO string that cannot be converted to a calendar ID should throw a RangeError
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = "UTC";
|
||||
const instance = new Temporal.ZonedDateTime(0n, timeZone);
|
||||
|
||||
const invalidStrings = [
|
||||
["", "empty string"]
|
||||
];
|
||||
|
||||
for (const [calendar, description] of invalidStrings) {
|
||||
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.equals(arg),
|
||||
`${description} is not a valid calendar ID`
|
||||
);
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.equals
|
||||
description: A number as calendar in a property bag is not accepted
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = "UTC";
|
||||
const instance = new Temporal.ZonedDateTime(0n, timeZone);
|
||||
|
||||
const numbers = [
|
||||
1,
|
||||
19970327,
|
||||
-19970327,
|
||||
1234567890,
|
||||
];
|
||||
|
||||
for (const calendar of numbers) {
|
||||
const arg = { year: 1970, monthCode: "M01", day: 1, timeZone, calendar };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.equals(arg),
|
||||
"Numbers cannot be used as a calendar"
|
||||
);
|
||||
}
|
@ -15,27 +15,21 @@ const instance = new Temporal.ZonedDateTime(0n, timeZone);
|
||||
const primitiveTests = [
|
||||
[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 arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(
|
||||
typeof calendar === 'string' ? RangeError : TypeError,
|
||||
() => instance.equals(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
||||
|
||||
const typeErrorTests = [
|
||||
[19970327, "large number"],
|
||||
[-19970327, "negative number"],
|
||||
[1234567890, "very large integer"],
|
||||
[Symbol(), "symbol"],
|
||||
[{}, "object"],
|
||||
[new Temporal.Duration(), "duration instance"],
|
||||
];
|
||||
|
||||
for (const [calendar, description] of typeErrorTests) {
|
||||
for (const [calendar, description] of primitiveTests) {
|
||||
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(TypeError, () => instance.equals(arg), `${description} is not a valid property bag and does not convert to a string`);
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.equals(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
// 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.zoneddatetime.prototype.since
|
||||
description: >
|
||||
An ISO string that cannot be converted to a calendar ID should throw a RangeError
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = "UTC";
|
||||
const instance = new Temporal.ZonedDateTime(0n, timeZone);
|
||||
|
||||
const invalidStrings = [
|
||||
["", "empty string"]
|
||||
];
|
||||
|
||||
for (const [calendar, description] of invalidStrings) {
|
||||
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.since(arg),
|
||||
`${description} is not a valid calendar ID`
|
||||
);
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.since
|
||||
description: A number as calendar in a property bag is not accepted
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = "UTC";
|
||||
const instance = new Temporal.ZonedDateTime(0n, timeZone);
|
||||
|
||||
const numbers = [
|
||||
1,
|
||||
19970327,
|
||||
-19970327,
|
||||
1234567890,
|
||||
];
|
||||
|
||||
for (const calendar of numbers) {
|
||||
const arg = { year: 1970, monthCode: "M01", day: 1, timeZone, calendar };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.since(arg),
|
||||
"Numbers cannot be used as a calendar"
|
||||
);
|
||||
}
|
@ -12,30 +12,24 @@ features: [BigInt, Symbol, Temporal]
|
||||
const timeZone = "UTC";
|
||||
const instance = new Temporal.ZonedDateTime(0n, timeZone);
|
||||
|
||||
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 arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(
|
||||
typeof calendar === 'string' ? RangeError : TypeError,
|
||||
() => instance.since(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
||||
|
||||
const typeErrorTests = [
|
||||
[19970327, "large number"],
|
||||
[-19970327, "negative number"],
|
||||
[1234567890, "very large integer"],
|
||||
[Symbol(), "symbol"],
|
||||
[{}, "object"],
|
||||
[new Temporal.Duration(), "duration instance"],
|
||||
];
|
||||
|
||||
for (const [calendar, description] of typeErrorTests) {
|
||||
for (const [calendar, description] of wrongTypeTests) {
|
||||
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(TypeError, () => instance.since(arg), `${description} is not a valid property bag and does not convert to a string`);
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.since(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
// 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.zoneddatetime.prototype.until
|
||||
description: >
|
||||
An ISO string that cannot be converted to a calendar ID should throw a RangeError
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = "UTC";
|
||||
const instance = new Temporal.ZonedDateTime(0n, timeZone);
|
||||
|
||||
const invalidStrings = [
|
||||
["", "empty string"]
|
||||
];
|
||||
|
||||
for (const [calendar, description] of invalidStrings) {
|
||||
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.until(arg),
|
||||
`${description} is not a valid calendar ID`
|
||||
);
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.until
|
||||
description: A number as calendar in a property bag is not accepted
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = "UTC";
|
||||
const instance = new Temporal.ZonedDateTime(0n, timeZone);
|
||||
|
||||
const numbers = [
|
||||
1,
|
||||
19970327,
|
||||
-19970327,
|
||||
1234567890,
|
||||
];
|
||||
|
||||
for (const calendar of numbers) {
|
||||
const arg = { year: 1970, monthCode: "M01", day: 1, timeZone, calendar };
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.until(arg),
|
||||
"Numbers cannot be used as a calendar"
|
||||
);
|
||||
}
|
@ -12,30 +12,24 @@ features: [BigInt, Symbol, Temporal]
|
||||
const timeZone = "UTC";
|
||||
const instance = new Temporal.ZonedDateTime(0n, timeZone);
|
||||
|
||||
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 arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(
|
||||
typeof calendar === 'string' ? RangeError : TypeError,
|
||||
() => instance.until(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
||||
|
||||
const typeErrorTests = [
|
||||
[19970327, "large number"],
|
||||
[-19970327, "negative number"],
|
||||
[1234567890, "very large integer"],
|
||||
[Symbol(), "symbol"],
|
||||
[{}, "object"],
|
||||
[new Temporal.Duration(), "duration instance"],
|
||||
];
|
||||
|
||||
for (const [calendar, description] of typeErrorTests) {
|
||||
for (const [calendar, description] of wrongTypeTests) {
|
||||
const arg = { year: 2019, monthCode: "M11", day: 1, calendar };
|
||||
assert.throws(TypeError, () => instance.until(arg), `${description} is not a valid property bag and does not convert to a string`);
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.until(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
||||
|
23
test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-invalid-iso-string.js
vendored
Normal file
23
test/built-ins/Temporal/ZonedDateTime/prototype/withCalendar/calendar-invalid-iso-string.js
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
// 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.zoneddatetime.prototype.withcalendar
|
||||
description: >
|
||||
An ISO string that cannot be converted to a calendar ID should throw a RangeError
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", "iso8601");
|
||||
|
||||
const invalidStrings = [
|
||||
["", "empty string"]
|
||||
];
|
||||
|
||||
for (const [arg, description] of invalidStrings) {
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.withCalendar(arg),
|
||||
`${description} is not a valid calendar ID`
|
||||
);
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.withcalendar
|
||||
description: A number is not allowed to be a calendar
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", "iso8601");
|
||||
|
||||
const numbers = [
|
||||
1,
|
||||
-19761118,
|
||||
19761118,
|
||||
1234567890,
|
||||
];
|
||||
|
||||
for (const arg of numbers) {
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.withCalendar(arg),
|
||||
"A number is not a valid ISO string for Calendar"
|
||||
);
|
||||
}
|
@ -4,35 +4,29 @@
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.withcalendar
|
||||
description: >
|
||||
Appropriate error thrown when argument cannot be converted to a valid string
|
||||
for Calendar
|
||||
Appropriate error thrown when argument cannot be converted to a valid object or string
|
||||
features: [BigInt, Symbol, Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", "iso8601");
|
||||
|
||||
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 [arg, description] of primitiveTests) {
|
||||
assert.throws(
|
||||
typeof arg === 'string' ? RangeError : TypeError,
|
||||
() => instance.withCalendar(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
||||
|
||||
const typeErrorTests = [
|
||||
[-19761118, "negative number"],
|
||||
[19761118, "large positive number"],
|
||||
[1234567890, "very large integer"],
|
||||
[Symbol(), "symbol"],
|
||||
[{}, "object"],
|
||||
[new Temporal.Duration(), "duration instance"],
|
||||
];
|
||||
|
||||
for (const [arg, description] of typeErrorTests) {
|
||||
assert.throws(TypeError, () => instance.withCalendar(arg), `${description} is not a valid object and does not convert to a string`);
|
||||
for (const [arg, description] of wrongTypeTests) {
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.withCalendar(arg),
|
||||
`${description} does not convert to a valid ISO string`
|
||||
);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user