mirror of https://github.com/tc39/test262.git
Temporal: Add tests for invalid strings as values of 'offset' property
(...in property bags; the 'offset' option in an options object already has tests)
This commit is contained in:
parent
f932f079b3
commit
6b5297a142
|
@ -0,0 +1,23 @@
|
|||
// 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.duration.compare
|
||||
description: relativeTo property bag with offset property is rejected if offset is in the wrong format
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = new Temporal.TimeZone("UTC");
|
||||
const d1 = new Temporal.Duration(0, 1, 0, 280);
|
||||
const d2 = new Temporal.Duration(0, 1, 0, 281);
|
||||
|
||||
const badOffsets = [
|
||||
"00:00", // missing sign
|
||||
"+0", // too short
|
||||
"-000:00", // too long
|
||||
0, // converts to a string that is invalid
|
||||
];
|
||||
badOffsets.forEach((offset) => {
|
||||
const relativeTo = { year: 2021, month: 10, day: 28, offset, timeZone };
|
||||
assert.throws(RangeError, () => Temporal.Duration.compare(d1, d2, { relativeTo }), `"${offset} is not a valid offset string`);
|
||||
});
|
22
test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-invalid-offset-string.js
vendored
Normal file
22
test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-invalid-offset-string.js
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
// 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.duration.prototype.add
|
||||
description: relativeTo property bag with offset property is rejected if offset is in the wrong format
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = new Temporal.TimeZone("UTC");
|
||||
const instance = new Temporal.Duration(1, 0, 0, 1);
|
||||
|
||||
const badOffsets = [
|
||||
"00:00", // missing sign
|
||||
"+0", // too short
|
||||
"-000:00", // too long
|
||||
0, // converts to a string that is invalid
|
||||
];
|
||||
badOffsets.forEach((offset) => {
|
||||
const relativeTo = { year: 2021, month: 10, day: 28, offset, timeZone };
|
||||
assert.throws(RangeError, () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), `"${offset} is not a valid offset string`);
|
||||
});
|
22
test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-invalid-offset-string.js
vendored
Normal file
22
test/built-ins/Temporal/Duration/prototype/round/relativeto-propertybag-invalid-offset-string.js
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
// 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.duration.prototype.round
|
||||
description: relativeTo property bag with offset property is rejected if offset is in the wrong format
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = new Temporal.TimeZone("UTC");
|
||||
const instance = new Temporal.Duration(1, 0, 0, 0, 24);
|
||||
|
||||
const badOffsets = [
|
||||
"00:00", // missing sign
|
||||
"+0", // too short
|
||||
"-000:00", // too long
|
||||
0, // converts to a string that is invalid
|
||||
];
|
||||
badOffsets.forEach((offset) => {
|
||||
const relativeTo = { year: 2021, month: 10, day: 28, offset, timeZone };
|
||||
assert.throws(RangeError, () => instance.round({ largestUnit: "years", relativeTo }), `"${offset} is not a valid offset string`);
|
||||
});
|
|
@ -0,0 +1,22 @@
|
|||
// 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.duration.prototype.subtract
|
||||
description: relativeTo property bag with offset property is rejected if offset is in the wrong format
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = new Temporal.TimeZone("UTC");
|
||||
const instance = new Temporal.Duration(1, 0, 0, 1);
|
||||
|
||||
const badOffsets = [
|
||||
"00:00", // missing sign
|
||||
"+0", // too short
|
||||
"-000:00", // too long
|
||||
0, // converts to a string that is invalid
|
||||
];
|
||||
badOffsets.forEach((offset) => {
|
||||
const relativeTo = { year: 2021, month: 10, day: 28, offset, timeZone };
|
||||
assert.throws(RangeError, () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), `"${offset} is not a valid offset string`);
|
||||
});
|
22
test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-invalid-offset-string.js
vendored
Normal file
22
test/built-ins/Temporal/Duration/prototype/total/relativeto-propertybag-invalid-offset-string.js
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
// 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.duration.prototype.total
|
||||
description: relativeTo property bag with offset property is rejected if offset is in the wrong format
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = new Temporal.TimeZone("UTC");
|
||||
const instance = new Temporal.Duration(1, 0, 0, 0, 24);
|
||||
|
||||
const badOffsets = [
|
||||
"00:00", // missing sign
|
||||
"+0", // too short
|
||||
"-000:00", // too long
|
||||
0, // converts to a string that is invalid
|
||||
];
|
||||
badOffsets.forEach((offset) => {
|
||||
const relativeTo = { year: 2021, month: 10, day: 28, offset, timeZone };
|
||||
assert.throws(RangeError, () => instance.total({ unit: "days", relativeTo }), `"${offset} is not a valid offset string`);
|
||||
});
|
|
@ -0,0 +1,23 @@
|
|||
// 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: Property bag with offset property is rejected if offset is in the wrong format
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = new Temporal.TimeZone("UTC");
|
||||
const datetime = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone);
|
||||
|
||||
const badOffsets = [
|
||||
"00:00", // missing sign
|
||||
"+0", // too short
|
||||
"-000:00", // too long
|
||||
0, // converts to a string that is invalid
|
||||
];
|
||||
badOffsets.forEach((offset) => {
|
||||
const arg = { year: 2021, month: 10, day: 28, offset, timeZone };
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.compare(arg, datetime), `"${offset} is not a valid offset string (second argument)`);
|
||||
assert.throws(RangeError, () => Temporal.ZonedDateTime.compare(datetime, arg), `"${offset} is not a valid offset string (second argument)`);
|
||||
});
|
|
@ -0,0 +1,29 @@
|
|||
// 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: Property bag with offset property is rejected if offset is in the wrong format
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = new Temporal.TimeZone("UTC");
|
||||
|
||||
const offsetOptions = ['use', 'prefer', 'ignore', 'reject'];
|
||||
|
||||
const badOffsets = [
|
||||
"00:00", // missing sign
|
||||
"+0", // too short
|
||||
"-000:00", // too long
|
||||
0, // converts to a string that is invalid
|
||||
];
|
||||
offsetOptions.forEach((offsetOption) => {
|
||||
badOffsets.forEach((offset) => {
|
||||
const arg = { year: 2021, month: 10, day: 28, offset, timeZone };
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => Temporal.ZonedDateTime.from(arg, { offset: offsetOption }),
|
||||
`"${offset} is not a valid offset string (with offset option ${offsetOption})`
|
||||
);
|
||||
});
|
||||
});
|
|
@ -0,0 +1,22 @@
|
|||
// 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: Property bag with offset property is rejected if offset is in the wrong format
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = new Temporal.TimeZone("UTC");
|
||||
const instance = new Temporal.ZonedDateTime(0n, timeZone);
|
||||
|
||||
const badOffsets = [
|
||||
"00:00", // missing sign
|
||||
"+0", // too short
|
||||
"-000:00", // too long
|
||||
0, // converts to a string that is invalid
|
||||
];
|
||||
badOffsets.forEach((offset) => {
|
||||
const arg = { year: 2021, month: 10, day: 28, offset, timeZone };
|
||||
assert.throws(RangeError, () => instance.equals(arg), `"${offset} is not a valid offset string`);
|
||||
});
|
|
@ -0,0 +1,22 @@
|
|||
// 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: Property bag with offset property is rejected if offset is in the wrong format
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = new Temporal.TimeZone("UTC");
|
||||
const instance = new Temporal.ZonedDateTime(0n, timeZone);
|
||||
|
||||
const badOffsets = [
|
||||
"00:00", // missing sign
|
||||
"+0", // too short
|
||||
"-000:00", // too long
|
||||
0, // converts to a string that is invalid
|
||||
];
|
||||
badOffsets.forEach((offset) => {
|
||||
const arg = { year: 2021, month: 10, day: 28, offset, timeZone };
|
||||
assert.throws(RangeError, () => instance.since(arg), `"${offset} is not a valid offset string`);
|
||||
});
|
|
@ -0,0 +1,22 @@
|
|||
// 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: Property bag with offset property is rejected if offset is in the wrong format
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = new Temporal.TimeZone("UTC");
|
||||
const instance = new Temporal.ZonedDateTime(0n, timeZone);
|
||||
|
||||
const badOffsets = [
|
||||
"00:00", // missing sign
|
||||
"+0", // too short
|
||||
"-000:00", // too long
|
||||
0, // converts to a string that is invalid
|
||||
];
|
||||
badOffsets.forEach((offset) => {
|
||||
const arg = { year: 2021, month: 10, day: 28, offset, timeZone };
|
||||
assert.throws(RangeError, () => instance.until(arg), `"${offset} is not a valid offset string`);
|
||||
});
|
29
test/built-ins/Temporal/ZonedDateTime/prototype/with/offset-property-invalid-string.js
vendored
Normal file
29
test/built-ins/Temporal/ZonedDateTime/prototype/with/offset-property-invalid-string.js
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
// 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.with
|
||||
description: Property bag with offset property is rejected if offset is in the wrong format
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const timeZone = new Temporal.TimeZone("UTC");
|
||||
const instance = new Temporal.ZonedDateTime(0n, timeZone);
|
||||
|
||||
const offsetOptions = ['use', 'prefer', 'ignore', 'reject'];
|
||||
|
||||
const badOffsets = [
|
||||
"00:00", // missing sign
|
||||
"+0", // too short
|
||||
"-000:00", // too long
|
||||
0, // converts to a string that is invalid
|
||||
];
|
||||
offsetOptions.forEach((offsetOption) => {
|
||||
badOffsets.forEach((offset) => {
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.with({ offset }, { offset: offsetOption }),
|
||||
`"${offset} is not a valid offset string (with ${offsetOption} offset option)`,
|
||||
);
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue