mirror of
https://github.com/tc39/test262.git
synced 2025-11-01 20:23:53 +01:00
Temporal: Add an overflow test for date addition with maximum year (#4618)
* Temporal: Add an overflow test for date addition with maximum year * Add tests for other cases * Fix minimum dates * Add cases for adding/subtracting the negated duration to the opposite end of the allowed years
This commit is contained in:
parent
759fe87f1c
commit
61d0eb9167
15
test/built-ins/Temporal/PlainDate/prototype/add/overflow-adding-months-to-max-year.js
vendored
Normal file
15
test/built-ins/Temporal/PlainDate/prototype/add/overflow-adding-months-to-max-year.js
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
// 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.plaindate.prototype.add
|
||||
description: Adding months to maximum year should throw
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const maxYear = new Temporal.PlainDate(275760, 1, 1);
|
||||
const duration = new Temporal.Duration(0, 5432, 5432, 0, 0, 0, 0, 0, 0, 0);
|
||||
assert.throws(RangeError, () => maxYear.add(duration));
|
||||
|
||||
const minYear = new Temporal.PlainDate(-271821, 4, 19);
|
||||
assert.throws(RangeError, () => minYear.add(duration.negated()));
|
||||
@ -0,0 +1,15 @@
|
||||
// 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.plaindate.prototype.subtract
|
||||
description: Subtracting months from minimum year should throw
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const minYear = new Temporal.PlainDate(-271821, 4, 19);
|
||||
const duration = new Temporal.Duration(0, 5432, 5432, 0, 0, 0, 0, 0, 0, 0);
|
||||
assert.throws(RangeError, () => minYear.subtract(duration));
|
||||
|
||||
const maxYear = new Temporal.PlainDate(275760, 1, 1);
|
||||
assert.throws(RangeError, () => maxYear.subtract(duration.negated()));
|
||||
15
test/built-ins/Temporal/PlainDateTime/prototype/add/overflow-adding-months-to-max-year.js
vendored
Normal file
15
test/built-ins/Temporal/PlainDateTime/prototype/add/overflow-adding-months-to-max-year.js
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
// 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.plaindatetime.prototype.add
|
||||
description: Adding months to maximum year should throw
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const maxYear = new Temporal.PlainDateTime(275760, 1, 1);
|
||||
const duration = new Temporal.Duration(0, 5432, 5432, 0, 0, 0, 0, 0, 0, 0);
|
||||
assert.throws(RangeError, () => maxYear.add(duration));
|
||||
|
||||
const minYear = new Temporal.PlainDateTime(-271821, 4, 19, 0, 0, 0, 0, 0, 1);
|
||||
assert.throws(RangeError, () => minYear.add(duration.negated()));
|
||||
@ -0,0 +1,15 @@
|
||||
// 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.plaindatetime.prototype.subtract
|
||||
description: Subtracting months from minimum year should throw
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const minYear = new Temporal.PlainDateTime(-271821, 4, 19, 0, 0, 0, 0, 0, 1);
|
||||
const duration = new Temporal.Duration(0, 5432, 5432, 0, 0, 0, 0, 0, 0, 0);
|
||||
assert.throws(RangeError, () => minYear.subtract(duration));
|
||||
|
||||
const maxYear = new Temporal.PlainDateTime(275760, 1, 1);
|
||||
assert.throws(RangeError, () => maxYear.subtract(duration.negated()));
|
||||
15
test/built-ins/Temporal/PlainYearMonth/prototype/add/overflow-adding-months-to-max-year.js
vendored
Normal file
15
test/built-ins/Temporal/PlainYearMonth/prototype/add/overflow-adding-months-to-max-year.js
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
// 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.plainyearmonth.prototype.add
|
||||
description: Adding months to maximum year should throw
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const maxYear = new Temporal.PlainYearMonth(275760, 1);
|
||||
const duration = new Temporal.Duration(0, 5432, 5432, 0, 0, 0, 0, 0, 0, 0);
|
||||
assert.throws(RangeError, () => maxYear.add(duration));
|
||||
|
||||
const minYear = new Temporal.PlainYearMonth(-271821, 4);
|
||||
assert.throws(RangeError, () => minYear.add(duration.negated()));
|
||||
@ -0,0 +1,15 @@
|
||||
// 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.plainyearmonth.prototype.subtract
|
||||
description: Subtracting months from minimum year should throw
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const minYear = new Temporal.PlainYearMonth(-271821, 4);
|
||||
const duration = new Temporal.Duration(0, 5432, 5432, 0, 0, 0, 0, 0, 0, 0);
|
||||
assert.throws(RangeError, () => minYear.subtract(duration));
|
||||
|
||||
const maxYear = new Temporal.PlainYearMonth(275760, 1);
|
||||
assert.throws(RangeError, () => maxYear.subtract(duration.negated()));
|
||||
15
test/built-ins/Temporal/ZonedDateTime/prototype/add/overflow-adding-months-to-max-year.js
vendored
Normal file
15
test/built-ins/Temporal/ZonedDateTime/prototype/add/overflow-adding-months-to-max-year.js
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
// 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.zoneddatetime.prototype.add
|
||||
description: Adding months to maximum year should throw
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const maxYear = new Temporal.PlainDate(275760, 1, 1).toZonedDateTime("UTC");
|
||||
const duration = new Temporal.Duration(0, 5432, 5432, 0, 0, 0, 0, 0, 0, 0);
|
||||
assert.throws(RangeError, () => maxYear.add(duration));
|
||||
|
||||
const minYear = new Temporal.ZonedDateTime(-(864n * 10n ** 19n), "UTC");
|
||||
assert.throws(RangeError, () => minYear.add(duration.negated()));
|
||||
@ -0,0 +1,15 @@
|
||||
// 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.zoneddatetime.prototype.subtract
|
||||
description: Subtracting months from minimum year should throw
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const minYear = new Temporal.ZonedDateTime(-(864n * 10n ** 19n), "UTC");
|
||||
const duration = new Temporal.Duration(0, 5432, 5432, 0, 0, 0, 0, 0, 0, 0);
|
||||
assert.throws(RangeError, () => minYear.subtract(duration));
|
||||
|
||||
const maxYear = new Temporal.PlainDateTime(275760, 1, 1).toZonedDateTime("UTC");
|
||||
assert.throws(RangeError, () => maxYear.subtract(duration.negated()));
|
||||
Loading…
x
Reference in New Issue
Block a user