Skip to content

Commit

Permalink
Add tests for invalid extended year "-000000"
Browse files Browse the repository at this point in the history
tc39/proposal-temporal#1753 records the
consensus reached at the October 2021 TC39 meeting to disallow "-000000"
as an extended year, both in Date.parse and Temporal. This adds tests for
the Temporal part of that.
  • Loading branch information
jessealama authored and ptomato committed Jan 31, 2022
1 parent fceb101 commit 4596c7e
Show file tree
Hide file tree
Showing 68 changed files with 1,272 additions and 0 deletions.
17 changes: 17 additions & 0 deletions test/built-ins/Temporal/Calendar/prototype/dateAdd/year-zero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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.calendar.prototype.dateadd
description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/

const arg = "-000000-10-31";
const instance = new Temporal.Calendar("iso8601");

assert.throws(
RangeError,
() => { instance.dateAdd(arg); },
"reject minus zero as extended year"
);
24 changes: 24 additions & 0 deletions test/built-ins/Temporal/Calendar/prototype/dateUntil/year-zero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// 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.calendar.prototype.dateuntil
description: Negative zero, as extended year, is invalid
features: [Temporal]
---*/

const calendar = new Temporal.Calendar("iso8601");
const date = new Temporal.PlainDate(2000, 5, 2);
const bad = "-000000-03-14";

assert.throws(
RangeError,
() => calendar.dateUntil(bad, date),
"cannot use minus zero as extended date (first argument)"
);

assert.throws(
RangeError,
() => calendar.dateUntil(date, bad),
"cannot use minus zero as extended date (second argument)"
);
17 changes: 17 additions & 0 deletions test/built-ins/Temporal/Calendar/prototype/day/year-zero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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.calendar.prototype.day
description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/

const arg = "-000000-10-31";
const instance = new Temporal.Calendar("iso8601");

assert.throws(
RangeError,
() => { instance.day(arg); },
"reject minus zero as extended year"
);
17 changes: 17 additions & 0 deletions test/built-ins/Temporal/Calendar/prototype/dayOfWeek/year-zero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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.calendar.prototype.dayofweek
description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/

const arg = "-000000-10-31";
const instance = new Temporal.Calendar("iso8601");

assert.throws(
RangeError,
() => { instance.dayOfWeek(arg); },
"reject minus zero as extended year"
);
17 changes: 17 additions & 0 deletions test/built-ins/Temporal/Calendar/prototype/dayOfYear/year-zero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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.calendar.prototype.dayofyear
description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/

const arg = "-000000-10-31";
const instance = new Temporal.Calendar("iso8601");

assert.throws(
RangeError,
() => { instance.dayOfYear(arg); },
"reject minus zero as extended year"
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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.calendar.prototype.daysinmonth
description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/

const arg = "-000000-10-31";
const instance = new Temporal.Calendar("iso8601");

assert.throws(
RangeError,
() => { instance.daysInMonth(arg); },
"reject minus zero as extended year"
);
17 changes: 17 additions & 0 deletions test/built-ins/Temporal/Calendar/prototype/daysInWeek/year-zero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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.calendar.prototype.daysinweek
description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/

const arg = "-000000-10-31";
const instance = new Temporal.Calendar("iso8601");

assert.throws(
RangeError,
() => { instance.daysInWeek(arg); },
"reject minus zero as extended year"
);
17 changes: 17 additions & 0 deletions test/built-ins/Temporal/Calendar/prototype/daysInYear/year-zero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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.calendar.prototype.daysinyear
description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/

const arg = "-000000-10-31";
const instance = new Temporal.Calendar("iso8601");

assert.throws(
RangeError,
() => { instance.daysInYear(arg); },
"reject minus zero as extended year"
);
17 changes: 17 additions & 0 deletions test/built-ins/Temporal/Calendar/prototype/inLeapYear/year-zero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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.calendar.prototype.inleapyear
description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/

const arg = "-000000-10-31";
const instance = new Temporal.Calendar("iso8601");

assert.throws(
RangeError,
() => { instance.inLeapYear(arg); },
"reject minus zero as extended year"
);
17 changes: 17 additions & 0 deletions test/built-ins/Temporal/Calendar/prototype/month/year-zero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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.calendar.prototype.month
description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/

const arg = "-000000-10-31";
const instance = new Temporal.Calendar("iso8601");

assert.throws(
RangeError,
() => { instance.month(arg); },
"reject minus zero as extended year"
);
17 changes: 17 additions & 0 deletions test/built-ins/Temporal/Calendar/prototype/monthCode/year-zero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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.calendar.prototype.monthcode
description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/

const arg = "-000000-10-31";
const instance = new Temporal.Calendar("iso8601");

assert.throws(
RangeError,
() => { instance.monthCode(arg); },
"reject minus zero as extended year"
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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.calendar.prototype.monthsinyear
description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/

const arg = "-000000-10-31";
const instance = new Temporal.Calendar("iso8601");

assert.throws(
RangeError,
() => { instance.monthsInYear(arg); },
"reject minus zero as extended year"
);
17 changes: 17 additions & 0 deletions test/built-ins/Temporal/Calendar/prototype/weekOfYear/year-zero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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.calendar.prototype.weekofyear
description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/

const arg = "-000000-10-31";
const instance = new Temporal.Calendar("iso8601");

assert.throws(
RangeError,
() => { instance.weekOfYear(arg); },
"reject minus zero as extended year"
);
17 changes: 17 additions & 0 deletions test/built-ins/Temporal/Calendar/prototype/year/year-zero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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.calendar.prototype.year
description: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/

const arg = "-000000-10-31";
const instance = new Temporal.Calendar("iso8601");

assert.throws(
RangeError,
() => { instance.year(arg); },
"reject minus zero as extended year"
);
18 changes: 18 additions & 0 deletions test/built-ins/Temporal/Duration/compare/year-zero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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: Negative zero, as an extended year, fails
features: [Temporal]
---*/

const duration1 = new Temporal.Duration(1);
const duration2 = new Temporal.Duration(2);
const bad = "-000000-11-01";

assert.throws(
RangeError,
() => Temporal.Duration.compare(duration1, duration2, { relativeTo: bad }),
"Cannot use negative zero as extended year"
);
17 changes: 17 additions & 0 deletions test/built-ins/Temporal/Duration/prototype/add/year-zero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/

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

let relativeTo = "-000000-11-04T00:00";
assert.throws(
RangeError,
() => { instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); },
"reject minus zero as extended year"
);
17 changes: 17 additions & 0 deletions test/built-ins/Temporal/Duration/prototype/round/year-zero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/

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

let relativeTo = "-000000-11-04T00:00";
assert.throws(
RangeError,
() => { instance.round({ largestUnit: "years", relativeTo }); },
"reject minus zero as extended year"
);
17 changes: 17 additions & 0 deletions test/built-ins/Temporal/Duration/prototype/subtract/year-zero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/

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

let relativeTo = "-000000-11-04T00:00";
assert.throws(
RangeError,
() => { instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); },
"reject minus zero as extended year"
);
17 changes: 17 additions & 0 deletions test/built-ins/Temporal/Duration/prototype/total/year-zero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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: Negative zero, as an extended year, is rejected
features: [Temporal, arrow-function]
---*/

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

let relativeTo = "-000000-11-04T00:00";
assert.throws(
RangeError,
() => { instance.total({ unit: "days", relativeTo }); },
"reject minus zero as extended year"
);
19 changes: 19 additions & 0 deletions test/built-ins/Temporal/Instant/compare/year-zero.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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.instant.compare
description: Negative zero, as an extended year, fails
features: [Temporal]
---*/

const instance = new Temporal.Instant(0n);
const bad = '-000000-03-30T00:45Z';

assert.throws(RangeError,
() => Temporal.Instant.compare(bad, instance),
"minus zero is invalid extended year (first argument)");
assert.throws(RangeError,
() => Temporal.Instant.compare(instance, bad),
"minus zero is invalid extended year (second argument)"
);
22 changes: 22 additions & 0 deletions test/built-ins/Temporal/Instant/from/year-zero.js
Original file line number Diff line number Diff line change
@@ -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.instant.from
description: Negative zero, as an extended year, is rejected
features: [Temporal]
---*/

const invalidStrings = [
"-000000-03-31T00:45Z",
"-000000-03-31T01:45+01:00",
"-000000-03-31T01:45:00+01:00[UTC]"
];

invalidStrings.forEach((str) => {
assert.throws(
RangeError,
() => Temporal.Instant.from(str),
"reject minus zero as extended year"
);
});
Loading

0 comments on commit 4596c7e

Please sign in to comment.