Temporal: Add tests for calendar validation normative change

This adds tests for the normative change in tc39/proposal-temporal#2265,
which adds validation steps to certain abstract operations that call
Temporal.Calendar methods.

These had some duplication with some existing tests named
calendar-returns-infinity.js. Remove these, because the new tests are more
complete in testing what values are accepted.
This commit is contained in:
Philip Chimento 2022-10-04 16:28:06 -07:00 committed by Ms2ger
parent b83af50771
commit 534b94eb63
57 changed files with 2206 additions and 324 deletions

View File

@ -1,27 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plaindate.prototype.day
description: Getter throws if the calendar returns ± from its day method
features: [Temporal]
---*/
class InfinityCalendar extends Temporal.Calendar {
constructor(positive) {
super("iso8601");
this.positive = positive;
}
day() {
return this.positive ? Infinity : -Infinity;
}
}
const pos = new InfinityCalendar(true);
const instance1 = new Temporal.PlainDate(2000, 5, 2, pos);
assert.throws(RangeError, () => instance1.day);
const neg = new InfinityCalendar(false);
const instance2 = new Temporal.PlainDate(2000, 5, 2, neg);
assert.throws(RangeError, () => instance2.day);

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plaindate.prototype.day
description: Validate result returned from calendar day() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
day() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
assert.throws(error, () => instance.day, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
day() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
assert.sameValue(instance.day, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plaindate.prototype.dayofweek
description: Validate result returned from calendar dayOfWeek() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
dayOfWeek() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
assert.throws(error, () => instance.dayOfWeek, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
dayOfWeek() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
assert.sameValue(instance.dayOfWeek, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plaindate.prototype.dayofyear
description: Validate result returned from calendar dayOfYear() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
dayOfYear() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
assert.throws(error, () => instance.dayOfYear, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
dayOfYear() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
assert.sameValue(instance.dayOfYear, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plaindate.prototype.daysinmonth
description: Validate result returned from calendar daysInMonth() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
daysInMonth() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
assert.throws(error, () => instance.daysInMonth, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
daysInMonth() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
assert.sameValue(instance.daysInMonth, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plaindate.prototype.daysinweek
description: Validate result returned from calendar daysInWeek() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
daysInWeek() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
assert.throws(error, () => instance.daysInWeek, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
daysInWeek() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
assert.sameValue(instance.daysInWeek, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plaindate.prototype.daysinyear
description: Validate result returned from calendar daysInYear() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
daysInYear() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
assert.throws(error, () => instance.daysInYear, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
daysInYear() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
assert.sameValue(instance.daysInYear, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -0,0 +1,40 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plaindate.prototype.inleapyear
description: Validate result returned from calendar inLeapYear() method
features: [Temporal]
---*/
const convertedResults = [
[undefined, false],
[null, false],
[true, true],
[false, false],
[0, false],
[-0, false],
[42, true],
[7.1, true],
[NaN, false],
[Infinity, true],
[-Infinity, true],
["", false],
["a string", true],
["0", true],
[Symbol("foo"), true],
[0n, false],
[42n, true],
[{}, true],
[{valueOf() { return false; }}, true],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
inLeapYear() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
assert.sameValue(instance.inLeapYear, convertedResult, `${typeof result} converted to boolean ${convertedResult}`);
});

View File

@ -1,27 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plaindate.prototype.month
description: Getter throws if the calendar returns ± from its month method
features: [Temporal]
---*/
class InfinityCalendar extends Temporal.Calendar {
constructor(positive) {
super("iso8601");
this.positive = positive;
}
month() {
return this.positive ? Infinity : -Infinity;
}
}
const pos = new InfinityCalendar(true);
const instance1 = new Temporal.PlainDate(2000, 5, 2, pos);
assert.throws(RangeError, () => instance1.month);
const neg = new InfinityCalendar(false);
const instance2 = new Temporal.PlainDate(2000, 5, 2, neg);
assert.throws(RangeError, () => instance2.month);

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plaindate.prototype.month
description: Validate result returned from calendar month() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
month() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
assert.throws(error, () => instance.month, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
month() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
assert.sameValue(instance.month, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -0,0 +1,42 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plaindate.prototype.monthcode
description: Validate result returned from calendar monthCode() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[Symbol("foo"), TypeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
monthCode() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
assert.throws(error, () => instance.monthCode, `${typeof result} not converted to string`);
});
const convertedResults = [
[null, "null"],
[true, "true"],
[false, "false"],
[7.1, "7.1"],
["M01", "M01"],
[{toString() { return "M01"; }}, "M01"],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
monthCode() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
assert.sameValue(instance.monthCode, convertedResult, `${typeof result} converted to string ${convertedResult}`);
});

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plaindate.prototype.monthsinyear
description: Validate result returned from calendar monthsInYear() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
monthsInYear() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
assert.throws(error, () => instance.monthsInYear, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
monthsInYear() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
assert.sameValue(instance.monthsInYear, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plaindate.prototype.weekofyear
description: Validate result returned from calendar weekOfYear() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
weekOfYear() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
assert.throws(error, () => instance.weekOfYear, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
weekOfYear() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
assert.sameValue(instance.weekOfYear, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -1,27 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plaindate.prototype.year
description: Getter throws if the calendar returns ± from its year method
features: [Temporal]
---*/
class InfinityCalendar extends Temporal.Calendar {
constructor(positive) {
super("iso8601");
this.positive = positive;
}
year() {
return this.positive ? Infinity : -Infinity;
}
}
const pos = new InfinityCalendar(true);
const instance1 = new Temporal.PlainDate(2000, 5, 2, pos);
assert.throws(RangeError, () => instance1.year);
const neg = new InfinityCalendar(false);
const instance2 = new Temporal.PlainDate(2000, 5, 2, neg);
assert.throws(RangeError, () => instance2.year);

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plaindate.prototype.year
description: Validate result returned from calendar year() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
year() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
assert.throws(error, () => instance.year, `${typeof result} not converted to integer`);
});
const convertedResults = [
[null, 0],
[true, 1],
[false, 0],
[7.1, 7],
[-7, -7],
[-0.1, 0],
[NaN, 0],
["string", 0],
["7", 7],
["7.5", 7],
[{}, 0],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
year() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
assert.sameValue(instance.year, convertedResult, `${typeof result} converted to integer ${convertedResult}`);
});

View File

@ -1,27 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plaindatetime.prototype.day
description: Getter throws if the calendar returns ± from its day method
features: [Temporal]
---*/
class InfinityCalendar extends Temporal.Calendar {
constructor(positive) {
super("iso8601");
this.positive = positive;
}
day() {
return this.positive ? Infinity : -Infinity;
}
}
const pos = new InfinityCalendar(true);
const instance1 = new Temporal.PlainDateTime(2000, 5, 2, 15, 30, 45, 987, 654, 321, pos);
assert.throws(RangeError, () => instance1.day);
const neg = new InfinityCalendar(false);
const instance2 = new Temporal.PlainDateTime(2000, 5, 2, 15, 30, 45, 987, 654, 321, neg);
assert.throws(RangeError, () => instance2.day);

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plaindatetime.prototype.day
description: Validate result returned from calendar day() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
day() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
assert.throws(error, () => instance.day, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
day() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
assert.sameValue(instance.day, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plaindatetime.prototype.dayofweek
description: Validate result returned from calendar dayOfWeek() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
dayOfWeek() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
assert.throws(error, () => instance.dayOfWeek, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
dayOfWeek() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
assert.sameValue(instance.dayOfWeek, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plaindatetime.prototype.dayofyear
description: Validate result returned from calendar dayOfYear() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
dayOfYear() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
assert.throws(error, () => instance.dayOfYear, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
dayOfYear() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
assert.sameValue(instance.dayOfYear, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plaindatetime.prototype.daysinmonth
description: Validate result returned from calendar daysInMonth() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
daysInMonth() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
assert.throws(error, () => instance.daysInMonth, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
daysInMonth() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
assert.sameValue(instance.daysInMonth, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plaindatetime.prototype.daysinweek
description: Validate result returned from calendar daysInWeek() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
daysInWeek() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
assert.throws(error, () => instance.daysInWeek, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
daysInWeek() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
assert.sameValue(instance.daysInWeek, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plaindatetime.prototype.daysinyear
description: Validate result returned from calendar daysInYear() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
daysInYear() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
assert.throws(error, () => instance.daysInYear, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
daysInYear() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
assert.sameValue(instance.daysInYear, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -0,0 +1,40 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plaindatetime.prototype.inleapyear
description: Validate result returned from calendar inLeapYear() method
features: [Temporal]
---*/
const convertedResults = [
[undefined, false],
[null, false],
[true, true],
[false, false],
[0, false],
[-0, false],
[42, true],
[7.1, true],
[NaN, false],
[Infinity, true],
[-Infinity, true],
["", false],
["a string", true],
["0", true],
[Symbol("foo"), true],
[0n, false],
[42n, true],
[{}, true],
[{valueOf() { return false; }}, true],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
inLeapYear() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
assert.sameValue(instance.inLeapYear, convertedResult, `${typeof result} converted to boolean ${convertedResult}`);
});

View File

@ -1,27 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plaindatetime.prototype.month
description: Getter throws if the calendar returns ± from its month method
features: [Temporal]
---*/
class InfinityCalendar extends Temporal.Calendar {
constructor(positive) {
super("iso8601");
this.positive = positive;
}
month() {
return this.positive ? Infinity : -Infinity;
}
}
const pos = new InfinityCalendar(true);
const instance1 = new Temporal.PlainDateTime(2000, 5, 2, 15, 30, 45, 987, 654, 321, pos);
assert.throws(RangeError, () => instance1.month);
const neg = new InfinityCalendar(false);
const instance2 = new Temporal.PlainDateTime(2000, 5, 2, 15, 30, 45, 987, 654, 321, neg);
assert.throws(RangeError, () => instance2.month);

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plaindatetime.prototype.month
description: Validate result returned from calendar month() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
month() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
assert.throws(error, () => instance.month, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
month() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
assert.sameValue(instance.month, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -0,0 +1,42 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plaindatetime.prototype.monthcode
description: Validate result returned from calendar monthCode() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[Symbol("foo"), TypeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
monthCode() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
assert.throws(error, () => instance.monthCode, `${typeof result} not converted to string`);
});
const convertedResults = [
[null, "null"],
[true, "true"],
[false, "false"],
[7.1, "7.1"],
["M01", "M01"],
[{toString() { return "M01"; }}, "M01"],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
monthCode() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
assert.sameValue(instance.monthCode, convertedResult, `${typeof result} converted to string ${convertedResult}`);
});

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plaindatetime.prototype.monthsinyear
description: Validate result returned from calendar monthsInYear() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
monthsInYear() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
assert.throws(error, () => instance.monthsInYear, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
monthsInYear() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
assert.sameValue(instance.monthsInYear, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plaindatetime.prototype.weekofyear
description: Validate result returned from calendar weekOfYear() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
weekOfYear() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
assert.throws(error, () => instance.weekOfYear, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
weekOfYear() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
assert.sameValue(instance.weekOfYear, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -1,27 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plaindatetime.prototype.year
description: Getter throws if the calendar returns ± from its year method
features: [Temporal]
---*/
class InfinityCalendar extends Temporal.Calendar {
constructor(positive) {
super("iso8601");
this.positive = positive;
}
year() {
return this.positive ? Infinity : -Infinity;
}
}
const pos = new InfinityCalendar(true);
const instance1 = new Temporal.PlainDateTime(2000, 5, 2, 15, 30, 45, 987, 654, 321, pos);
assert.throws(RangeError, () => instance1.year);
const neg = new InfinityCalendar(false);
const instance2 = new Temporal.PlainDateTime(2000, 5, 2, 15, 30, 45, 987, 654, 321, neg);
assert.throws(RangeError, () => instance2.year);

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plaindatetime.prototype.year
description: Validate result returned from calendar year() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
year() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
assert.throws(error, () => instance.year, `${typeof result} not converted to integer`);
});
const convertedResults = [
[null, 0],
[true, 1],
[false, 0],
[7.1, 7],
[-7, -7],
[-0.1, 0],
[NaN, 0],
["string", 0],
["7", 7],
["7.5", 7],
[{}, 0],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
year() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
assert.sameValue(instance.year, convertedResult, `${typeof result} converted to integer ${convertedResult}`);
});

View File

@ -1,27 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plainmonthday.prototype.day
description: Getter throws if the calendar returns ± from its day method
features: [Temporal]
---*/
class InfinityCalendar extends Temporal.Calendar {
constructor(positive) {
super("iso8601");
this.positive = positive;
}
day() {
return this.positive ? Infinity : -Infinity;
}
}
const pos = new InfinityCalendar(true);
const instance1 = new Temporal.PlainMonthDay(5, 2, pos);
assert.throws(RangeError, () => instance1.day);
const neg = new InfinityCalendar(false);
const instance2 = new Temporal.PlainMonthDay(5, 2, neg);
assert.throws(RangeError, () => instance2.day);

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plainmonthday.prototype.day
description: Validate result returned from calendar day() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
day() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainMonthDay(12, 15, calendar);
assert.throws(error, () => instance.day, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
day() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainMonthDay(12, 15, calendar);
assert.sameValue(instance.day, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -0,0 +1,42 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plainmonthday.prototype.monthcode
description: Validate result returned from calendar monthCode() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[Symbol("foo"), TypeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
monthCode() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainMonthDay(12, 15, calendar);
assert.throws(error, () => instance.monthCode, `${typeof result} not converted to string`);
});
const convertedResults = [
[null, "null"],
[true, "true"],
[false, "false"],
[7.1, "7.1"],
["M01", "M01"],
[{toString() { return "M01"; }}, "M01"],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
monthCode() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainMonthDay(12, 15, calendar);
assert.sameValue(instance.monthCode, convertedResult, `${typeof result} converted to string ${convertedResult}`);
});

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plainyearmonth.prototype.daysinmonth
description: Validate result returned from calendar daysInMonth() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
daysInMonth() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainYearMonth(1981, 12, calendar);
assert.throws(error, () => instance.daysInMonth, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
daysInMonth() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainYearMonth(1981, 12, calendar);
assert.sameValue(instance.daysInMonth, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plainyearmonth.prototype.daysinyear
description: Validate result returned from calendar daysInYear() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
daysInYear() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainYearMonth(1981, 12, calendar);
assert.throws(error, () => instance.daysInYear, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
daysInYear() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainYearMonth(1981, 12, calendar);
assert.sameValue(instance.daysInYear, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -0,0 +1,40 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plainyearmonth.prototype.inleapyear
description: Validate result returned from calendar inLeapYear() method
features: [Temporal]
---*/
const convertedResults = [
[undefined, false],
[null, false],
[true, true],
[false, false],
[0, false],
[-0, false],
[42, true],
[7.1, true],
[NaN, false],
[Infinity, true],
[-Infinity, true],
["", false],
["a string", true],
["0", true],
[Symbol("foo"), true],
[0n, false],
[42n, true],
[{}, true],
[{valueOf() { return false; }}, true],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
inLeapYear() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainYearMonth(1981, 12, calendar);
assert.sameValue(instance.inLeapYear, convertedResult, `${typeof result} converted to boolean ${convertedResult}`);
});

View File

@ -1,27 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plainyearmonth.prototype.month
description: Getter throws if the calendar returns ± from its month method
features: [Temporal]
---*/
class InfinityCalendar extends Temporal.Calendar {
constructor(positive) {
super("iso8601");
this.positive = positive;
}
month() {
return this.positive ? Infinity : -Infinity;
}
}
const pos = new InfinityCalendar(true);
const instance1 = new Temporal.PlainYearMonth(2000, 5, pos);
assert.throws(RangeError, () => instance1.month);
const neg = new InfinityCalendar(false);
const instance2 = new Temporal.PlainYearMonth(2000, 5, neg);
assert.throws(RangeError, () => instance2.month);

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plainyearmonth.prototype.month
description: Validate result returned from calendar month() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
month() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainYearMonth(1981, 12, calendar);
assert.throws(error, () => instance.month, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
month() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainYearMonth(1981, 12, calendar);
assert.sameValue(instance.month, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -0,0 +1,42 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plainyearmonth.prototype.monthcode
description: Validate result returned from calendar monthCode() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[Symbol("foo"), TypeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
monthCode() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainYearMonth(1981, 12, calendar);
assert.throws(error, () => instance.monthCode, `${typeof result} not converted to string`);
});
const convertedResults = [
[null, "null"],
[true, "true"],
[false, "false"],
[7.1, "7.1"],
["M01", "M01"],
[{toString() { return "M01"; }}, "M01"],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
monthCode() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainYearMonth(1981, 12, calendar);
assert.sameValue(instance.monthCode, convertedResult, `${typeof result} converted to string ${convertedResult}`);
});

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plainyearmonth.prototype.monthsinyear
description: Validate result returned from calendar monthsInYear() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
monthsInYear() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainYearMonth(1981, 12, calendar);
assert.throws(error, () => instance.monthsInYear, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
monthsInYear() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainYearMonth(1981, 12, calendar);
assert.sameValue(instance.monthsInYear, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -1,27 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plainyearmonth.prototype.year
description: Getter throws if the calendar returns ± from its year method
features: [Temporal]
---*/
class InfinityCalendar extends Temporal.Calendar {
constructor(positive) {
super("iso8601");
this.positive = positive;
}
year() {
return this.positive ? Infinity : -Infinity;
}
}
const pos = new InfinityCalendar(true);
const instance1 = new Temporal.PlainYearMonth(2000, 5, pos);
assert.throws(RangeError, () => instance1.year);
const neg = new InfinityCalendar(false);
const instance2 = new Temporal.PlainYearMonth(2000, 5, neg);
assert.throws(RangeError, () => instance2.year);

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.plainyearmonth.prototype.year
description: Validate result returned from calendar year() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
year() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainYearMonth(1981, 12, calendar);
assert.throws(error, () => instance.year, `${typeof result} not converted to integer`);
});
const convertedResults = [
[null, 0],
[true, 1],
[false, 0],
[7.1, 7],
[-7, -7],
[-0.1, 0],
[NaN, 0],
["string", 0],
["7", 7],
["7.5", 7],
[{}, 0],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
year() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainYearMonth(1981, 12, calendar);
assert.sameValue(instance.year, convertedResult, `${typeof result} converted to integer ${convertedResult}`);
});

View File

@ -1,27 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.zoneddatetime.prototype.day
description: Getter throws if the calendar returns ± from its day method
features: [Temporal]
---*/
class InfinityCalendar extends Temporal.Calendar {
constructor(positive) {
super("iso8601");
this.positive = positive;
}
day() {
return this.positive ? Infinity : -Infinity;
}
}
const pos = new InfinityCalendar(true);
const instance1 = new Temporal.ZonedDateTime(0n, "UTC", pos);
assert.throws(RangeError, () => instance1.day);
const neg = new InfinityCalendar(false);
const instance2 = new Temporal.ZonedDateTime(0n, "UTC", neg);
assert.throws(RangeError, () => instance2.day);

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.zoneddatetime.prototype.day
description: Validate result returned from calendar day() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
day() {
return result;
}
}("iso8601");
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
assert.throws(error, () => instance.day, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
day() {
return result;
}
}("iso8601");
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
assert.sameValue(instance.day, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.zoneddatetime.prototype.dayofweek
description: Validate result returned from calendar dayOfWeek() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
dayOfWeek() {
return result;
}
}("iso8601");
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
assert.throws(error, () => instance.dayOfWeek, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
dayOfWeek() {
return result;
}
}("iso8601");
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
assert.sameValue(instance.dayOfWeek, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.zoneddatetime.prototype.dayofyear
description: Validate result returned from calendar dayOfYear() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
dayOfYear() {
return result;
}
}("iso8601");
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
assert.throws(error, () => instance.dayOfYear, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
dayOfYear() {
return result;
}
}("iso8601");
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
assert.sameValue(instance.dayOfYear, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.zoneddatetime.prototype.daysinmonth
description: Validate result returned from calendar daysInMonth() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
daysInMonth() {
return result;
}
}("iso8601");
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
assert.throws(error, () => instance.daysInMonth, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
daysInMonth() {
return result;
}
}("iso8601");
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
assert.sameValue(instance.daysInMonth, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.zoneddatetime.prototype.daysinweek
description: Validate result returned from calendar daysInWeek() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
daysInWeek() {
return result;
}
}("iso8601");
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
assert.throws(error, () => instance.daysInWeek, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
daysInWeek() {
return result;
}
}("iso8601");
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
assert.sameValue(instance.daysInWeek, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.zoneddatetime.prototype.daysinyear
description: Validate result returned from calendar daysInYear() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
daysInYear() {
return result;
}
}("iso8601");
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
assert.throws(error, () => instance.daysInYear, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
daysInYear() {
return result;
}
}("iso8601");
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
assert.sameValue(instance.daysInYear, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -0,0 +1,40 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.zoneddatetime.prototype.inleapyear
description: Validate result returned from calendar inLeapYear() method
features: [Temporal]
---*/
const convertedResults = [
[undefined, false],
[null, false],
[true, true],
[false, false],
[0, false],
[-0, false],
[42, true],
[7.1, true],
[NaN, false],
[Infinity, true],
[-Infinity, true],
["", false],
["a string", true],
["0", true],
[Symbol("foo"), true],
[0n, false],
[42n, true],
[{}, true],
[{valueOf() { return false; }}, true],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
inLeapYear() {
return result;
}
}("iso8601");
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
assert.sameValue(instance.inLeapYear, convertedResult, `${typeof result} converted to boolean ${convertedResult}`);
});

View File

@ -1,27 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.zoneddatetime.prototype.month
description: Getter throws if the calendar returns ± from its month method
features: [Temporal]
---*/
class InfinityCalendar extends Temporal.Calendar {
constructor(positive) {
super("iso8601");
this.positive = positive;
}
month() {
return this.positive ? Infinity : -Infinity;
}
}
const pos = new InfinityCalendar(true);
const instance1 = new Temporal.ZonedDateTime(0n, "UTC", pos);
assert.throws(RangeError, () => instance1.month);
const neg = new InfinityCalendar(false);
const instance2 = new Temporal.ZonedDateTime(0n, "UTC", neg);
assert.throws(RangeError, () => instance2.month);

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.zoneddatetime.prototype.month
description: Validate result returned from calendar month() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
month() {
return result;
}
}("iso8601");
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
assert.throws(error, () => instance.month, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
month() {
return result;
}
}("iso8601");
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
assert.sameValue(instance.month, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -0,0 +1,42 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.zoneddatetime.prototype.monthcode
description: Validate result returned from calendar monthCode() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[Symbol("foo"), TypeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
monthCode() {
return result;
}
}("iso8601");
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
assert.throws(error, () => instance.monthCode, `${typeof result} not converted to string`);
});
const convertedResults = [
[null, "null"],
[true, "true"],
[false, "false"],
[7.1, "7.1"],
["M01", "M01"],
[{toString() { return "M01"; }}, "M01"],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
monthCode() {
return result;
}
}("iso8601");
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
assert.sameValue(instance.monthCode, convertedResult, `${typeof result} converted to string ${convertedResult}`);
});

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.zoneddatetime.prototype.monthsinyear
description: Validate result returned from calendar monthsInYear() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
monthsInYear() {
return result;
}
}("iso8601");
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
assert.throws(error, () => instance.monthsInYear, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
monthsInYear() {
return result;
}
}("iso8601");
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
assert.sameValue(instance.monthsInYear, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.zoneddatetime.prototype.weekofyear
description: Validate result returned from calendar weekOfYear() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[null, RangeError],
[false, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-7, RangeError],
[-0.1, RangeError],
["string", RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, RangeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
weekOfYear() {
return result;
}
}("iso8601");
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
assert.throws(error, () => instance.weekOfYear, `${typeof result} not converted to positive integer`);
});
const convertedResults = [
[true, 1],
[7.1, 7],
["7", 7],
["7.5", 7],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
weekOfYear() {
return result;
}
}("iso8601");
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
assert.sameValue(instance.weekOfYear, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`);
});

View File

@ -1,27 +0,0 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.zoneddatetime.prototype.year
description: Getter throws if the calendar returns ± from its year method
features: [Temporal]
---*/
class InfinityCalendar extends Temporal.Calendar {
constructor(positive) {
super("iso8601");
this.positive = positive;
}
year() {
return this.positive ? Infinity : -Infinity;
}
}
const pos = new InfinityCalendar(true);
const instance1 = new Temporal.ZonedDateTime(0n, "UTC", pos);
assert.throws(RangeError, () => instance1.year);
const neg = new InfinityCalendar(false);
const instance2 = new Temporal.ZonedDateTime(0n, "UTC", neg);
assert.throws(RangeError, () => instance2.year);

View File

@ -0,0 +1,51 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-temporal.zoneddatetime.prototype.year
description: Validate result returned from calendar year() method
features: [Temporal]
---*/
const badResults = [
[undefined, RangeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
];
badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
year() {
return result;
}
}("iso8601");
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
assert.throws(error, () => instance.year, `${typeof result} not converted to integer`);
});
const convertedResults = [
[null, 0],
[true, 1],
[false, 0],
[7.1, 7],
[-7, -7],
[-0.1, 0],
[NaN, 0],
["string", 0],
["7", 7],
["7.5", 7],
[{}, 0],
[{valueOf() { return 7; }}, 7],
];
convertedResults.forEach(([result, convertedResult]) => {
const calendar = new class extends Temporal.Calendar {
year() {
return result;
}
}("iso8601");
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
assert.sameValue(instance.year, convertedResult, `${typeof result} converted to integer ${convertedResult}`);
});