From 274a2a020153898c7e0dec5018b4baf065adade0 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Tue, 4 Oct 2022 16:28:06 -0700 Subject: [PATCH] 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. --- .../day/calendar-returns-infinity.js | 27 ---------- .../prototype/day/validate-calendar-value.js | 51 +++++++++++++++++++ .../dayOfWeek/validate-calendar-value.js | 51 +++++++++++++++++++ .../dayOfYear/validate-calendar-value.js | 51 +++++++++++++++++++ .../daysInMonth/validate-calendar-value.js | 51 +++++++++++++++++++ .../daysInWeek/validate-calendar-value.js | 51 +++++++++++++++++++ .../daysInYear/validate-calendar-value.js | 51 +++++++++++++++++++ .../inLeapYear/validate-calendar-value.js | 40 +++++++++++++++ .../month/calendar-returns-infinity.js | 27 ---------- .../month/validate-calendar-value.js | 51 +++++++++++++++++++ .../monthCode/validate-calendar-value.js | 42 +++++++++++++++ .../monthsInYear/validate-calendar-value.js | 51 +++++++++++++++++++ .../weekOfYear/validate-calendar-value.js | 51 +++++++++++++++++++ .../year/calendar-returns-infinity.js | 27 ---------- .../prototype/year/validate-calendar-value.js | 51 +++++++++++++++++++ .../day/calendar-returns-infinity.js | 27 ---------- .../prototype/day/validate-calendar-value.js | 51 +++++++++++++++++++ .../dayOfWeek/validate-calendar-value.js | 51 +++++++++++++++++++ .../dayOfYear/validate-calendar-value.js | 51 +++++++++++++++++++ .../daysInMonth/validate-calendar-value.js | 51 +++++++++++++++++++ .../daysInWeek/validate-calendar-value.js | 51 +++++++++++++++++++ .../daysInYear/validate-calendar-value.js | 51 +++++++++++++++++++ .../inLeapYear/validate-calendar-value.js | 40 +++++++++++++++ .../month/calendar-returns-infinity.js | 27 ---------- .../month/validate-calendar-value.js | 51 +++++++++++++++++++ .../monthCode/validate-calendar-value.js | 42 +++++++++++++++ .../monthsInYear/validate-calendar-value.js | 51 +++++++++++++++++++ .../weekOfYear/validate-calendar-value.js | 51 +++++++++++++++++++ .../year/calendar-returns-infinity.js | 27 ---------- .../prototype/year/validate-calendar-value.js | 51 +++++++++++++++++++ .../day/calendar-returns-infinity.js | 27 ---------- .../prototype/day/validate-calendar-value.js | 51 +++++++++++++++++++ .../monthCode/validate-calendar-value.js | 42 +++++++++++++++ .../daysInMonth/validate-calendar-value.js | 51 +++++++++++++++++++ .../daysInYear/validate-calendar-value.js | 51 +++++++++++++++++++ .../inLeapYear/validate-calendar-value.js | 40 +++++++++++++++ .../month/calendar-returns-infinity.js | 27 ---------- .../month/validate-calendar-value.js | 51 +++++++++++++++++++ .../monthCode/validate-calendar-value.js | 42 +++++++++++++++ .../monthsInYear/validate-calendar-value.js | 51 +++++++++++++++++++ .../year/calendar-returns-infinity.js | 27 ---------- .../prototype/year/validate-calendar-value.js | 51 +++++++++++++++++++ .../day/calendar-returns-infinity.js | 27 ---------- .../prototype/day/validate-calendar-value.js | 51 +++++++++++++++++++ .../dayOfWeek/validate-calendar-value.js | 51 +++++++++++++++++++ .../dayOfYear/validate-calendar-value.js | 51 +++++++++++++++++++ .../daysInMonth/validate-calendar-value.js | 51 +++++++++++++++++++ .../daysInWeek/validate-calendar-value.js | 51 +++++++++++++++++++ .../daysInYear/validate-calendar-value.js | 51 +++++++++++++++++++ .../inLeapYear/validate-calendar-value.js | 40 +++++++++++++++ .../month/calendar-returns-infinity.js | 27 ---------- .../month/validate-calendar-value.js | 51 +++++++++++++++++++ .../monthCode/validate-calendar-value.js | 42 +++++++++++++++ .../monthsInYear/validate-calendar-value.js | 51 +++++++++++++++++++ .../weekOfYear/validate-calendar-value.js | 51 +++++++++++++++++++ .../year/calendar-returns-infinity.js | 27 ---------- .../prototype/year/validate-calendar-value.js | 51 +++++++++++++++++++ 57 files changed, 2206 insertions(+), 324 deletions(-) delete mode 100644 test/built-ins/Temporal/PlainDate/prototype/day/calendar-returns-infinity.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/day/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/dayOfWeek/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/dayOfYear/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/daysInMonth/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/daysInWeek/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/daysInYear/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/inLeapYear/validate-calendar-value.js delete mode 100644 test/built-ins/Temporal/PlainDate/prototype/month/calendar-returns-infinity.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/month/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/monthCode/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/monthsInYear/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/weekOfYear/validate-calendar-value.js delete mode 100644 test/built-ins/Temporal/PlainDate/prototype/year/calendar-returns-infinity.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/year/validate-calendar-value.js delete mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/day/calendar-returns-infinity.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/day/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/dayOfWeek/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/dayOfYear/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/daysInMonth/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/daysInWeek/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/daysInYear/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/inLeapYear/validate-calendar-value.js delete mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/month/calendar-returns-infinity.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/month/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/monthCode/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/monthsInYear/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/weekOfYear/validate-calendar-value.js delete mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/year/calendar-returns-infinity.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/year/validate-calendar-value.js delete mode 100644 test/built-ins/Temporal/PlainMonthDay/prototype/day/calendar-returns-infinity.js create mode 100644 test/built-ins/Temporal/PlainMonthDay/prototype/day/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/PlainMonthDay/prototype/monthCode/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/daysInMonth/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/daysInYear/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/inLeapYear/validate-calendar-value.js delete mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/month/calendar-returns-infinity.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/month/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/monthCode/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/monthsInYear/validate-calendar-value.js delete mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/year/calendar-returns-infinity.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/year/validate-calendar-value.js delete mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/day/calendar-returns-infinity.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/day/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/dayOfWeek/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/dayOfYear/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/daysInMonth/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/daysInWeek/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/daysInYear/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/inLeapYear/validate-calendar-value.js delete mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/month/calendar-returns-infinity.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/month/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/monthCode/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/monthsInYear/validate-calendar-value.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/weekOfYear/validate-calendar-value.js delete mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/year/calendar-returns-infinity.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/year/validate-calendar-value.js diff --git a/test/built-ins/Temporal/PlainDate/prototype/day/calendar-returns-infinity.js b/test/built-ins/Temporal/PlainDate/prototype/day/calendar-returns-infinity.js deleted file mode 100644 index f13b182d965..00000000000 --- a/test/built-ins/Temporal/PlainDate/prototype/day/calendar-returns-infinity.js +++ /dev/null @@ -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); diff --git a/test/built-ins/Temporal/PlainDate/prototype/day/validate-calendar-value.js b/test/built-ins/Temporal/PlainDate/prototype/day/validate-calendar-value.js new file mode 100644 index 00000000000..74a47a63b50 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/day/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainDate/prototype/dayOfWeek/validate-calendar-value.js b/test/built-ins/Temporal/PlainDate/prototype/dayOfWeek/validate-calendar-value.js new file mode 100644 index 00000000000..00b6dc497e1 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/dayOfWeek/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainDate/prototype/dayOfYear/validate-calendar-value.js b/test/built-ins/Temporal/PlainDate/prototype/dayOfYear/validate-calendar-value.js new file mode 100644 index 00000000000..b32f05b3fcf --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/dayOfYear/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainDate/prototype/daysInMonth/validate-calendar-value.js b/test/built-ins/Temporal/PlainDate/prototype/daysInMonth/validate-calendar-value.js new file mode 100644 index 00000000000..ae576fa301a --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/daysInMonth/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainDate/prototype/daysInWeek/validate-calendar-value.js b/test/built-ins/Temporal/PlainDate/prototype/daysInWeek/validate-calendar-value.js new file mode 100644 index 00000000000..ef3d8336757 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/daysInWeek/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainDate/prototype/daysInYear/validate-calendar-value.js b/test/built-ins/Temporal/PlainDate/prototype/daysInYear/validate-calendar-value.js new file mode 100644 index 00000000000..dd7094e5667 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/daysInYear/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainDate/prototype/inLeapYear/validate-calendar-value.js b/test/built-ins/Temporal/PlainDate/prototype/inLeapYear/validate-calendar-value.js new file mode 100644 index 00000000000..d90f2f5792a --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/inLeapYear/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainDate/prototype/month/calendar-returns-infinity.js b/test/built-ins/Temporal/PlainDate/prototype/month/calendar-returns-infinity.js deleted file mode 100644 index 572dbfcea80..00000000000 --- a/test/built-ins/Temporal/PlainDate/prototype/month/calendar-returns-infinity.js +++ /dev/null @@ -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); diff --git a/test/built-ins/Temporal/PlainDate/prototype/month/validate-calendar-value.js b/test/built-ins/Temporal/PlainDate/prototype/month/validate-calendar-value.js new file mode 100644 index 00000000000..261829a7262 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/month/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainDate/prototype/monthCode/validate-calendar-value.js b/test/built-ins/Temporal/PlainDate/prototype/monthCode/validate-calendar-value.js new file mode 100644 index 00000000000..9500d7cc5b9 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/monthCode/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainDate/prototype/monthsInYear/validate-calendar-value.js b/test/built-ins/Temporal/PlainDate/prototype/monthsInYear/validate-calendar-value.js new file mode 100644 index 00000000000..ac2b6dbb196 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/monthsInYear/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainDate/prototype/weekOfYear/validate-calendar-value.js b/test/built-ins/Temporal/PlainDate/prototype/weekOfYear/validate-calendar-value.js new file mode 100644 index 00000000000..705d987899e --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/weekOfYear/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainDate/prototype/year/calendar-returns-infinity.js b/test/built-ins/Temporal/PlainDate/prototype/year/calendar-returns-infinity.js deleted file mode 100644 index 3a0ad9cb83c..00000000000 --- a/test/built-ins/Temporal/PlainDate/prototype/year/calendar-returns-infinity.js +++ /dev/null @@ -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); diff --git a/test/built-ins/Temporal/PlainDate/prototype/year/validate-calendar-value.js b/test/built-ins/Temporal/PlainDate/prototype/year/validate-calendar-value.js new file mode 100644 index 00000000000..fe99fa065ae --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/year/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/day/calendar-returns-infinity.js b/test/built-ins/Temporal/PlainDateTime/prototype/day/calendar-returns-infinity.js deleted file mode 100644 index 5a97c2e9bbe..00000000000 --- a/test/built-ins/Temporal/PlainDateTime/prototype/day/calendar-returns-infinity.js +++ /dev/null @@ -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); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/day/validate-calendar-value.js b/test/built-ins/Temporal/PlainDateTime/prototype/day/validate-calendar-value.js new file mode 100644 index 00000000000..3adfcd975f0 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/day/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/dayOfWeek/validate-calendar-value.js b/test/built-ins/Temporal/PlainDateTime/prototype/dayOfWeek/validate-calendar-value.js new file mode 100644 index 00000000000..c8d8bc12b9f --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/dayOfWeek/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/dayOfYear/validate-calendar-value.js b/test/built-ins/Temporal/PlainDateTime/prototype/dayOfYear/validate-calendar-value.js new file mode 100644 index 00000000000..df738b21577 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/dayOfYear/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/daysInMonth/validate-calendar-value.js b/test/built-ins/Temporal/PlainDateTime/prototype/daysInMonth/validate-calendar-value.js new file mode 100644 index 00000000000..c3225c4b6dc --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/daysInMonth/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/daysInWeek/validate-calendar-value.js b/test/built-ins/Temporal/PlainDateTime/prototype/daysInWeek/validate-calendar-value.js new file mode 100644 index 00000000000..be4d132d06b --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/daysInWeek/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/daysInYear/validate-calendar-value.js b/test/built-ins/Temporal/PlainDateTime/prototype/daysInYear/validate-calendar-value.js new file mode 100644 index 00000000000..e776ffb782d --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/daysInYear/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/inLeapYear/validate-calendar-value.js b/test/built-ins/Temporal/PlainDateTime/prototype/inLeapYear/validate-calendar-value.js new file mode 100644 index 00000000000..086533e61c5 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/inLeapYear/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/month/calendar-returns-infinity.js b/test/built-ins/Temporal/PlainDateTime/prototype/month/calendar-returns-infinity.js deleted file mode 100644 index 27ec8f94651..00000000000 --- a/test/built-ins/Temporal/PlainDateTime/prototype/month/calendar-returns-infinity.js +++ /dev/null @@ -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); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/month/validate-calendar-value.js b/test/built-ins/Temporal/PlainDateTime/prototype/month/validate-calendar-value.js new file mode 100644 index 00000000000..ca6d3717bca --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/month/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/monthCode/validate-calendar-value.js b/test/built-ins/Temporal/PlainDateTime/prototype/monthCode/validate-calendar-value.js new file mode 100644 index 00000000000..f06f2c617ef --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/monthCode/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/monthsInYear/validate-calendar-value.js b/test/built-ins/Temporal/PlainDateTime/prototype/monthsInYear/validate-calendar-value.js new file mode 100644 index 00000000000..5ca0ff22357 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/monthsInYear/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/weekOfYear/validate-calendar-value.js b/test/built-ins/Temporal/PlainDateTime/prototype/weekOfYear/validate-calendar-value.js new file mode 100644 index 00000000000..8177f7ed1ad --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/weekOfYear/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/year/calendar-returns-infinity.js b/test/built-ins/Temporal/PlainDateTime/prototype/year/calendar-returns-infinity.js deleted file mode 100644 index e963454d24c..00000000000 --- a/test/built-ins/Temporal/PlainDateTime/prototype/year/calendar-returns-infinity.js +++ /dev/null @@ -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); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/year/validate-calendar-value.js b/test/built-ins/Temporal/PlainDateTime/prototype/year/validate-calendar-value.js new file mode 100644 index 00000000000..419206028c6 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/year/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/day/calendar-returns-infinity.js b/test/built-ins/Temporal/PlainMonthDay/prototype/day/calendar-returns-infinity.js deleted file mode 100644 index f07e1f3a087..00000000000 --- a/test/built-ins/Temporal/PlainMonthDay/prototype/day/calendar-returns-infinity.js +++ /dev/null @@ -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); diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/day/validate-calendar-value.js b/test/built-ins/Temporal/PlainMonthDay/prototype/day/validate-calendar-value.js new file mode 100644 index 00000000000..db81e23e74c --- /dev/null +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/day/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/monthCode/validate-calendar-value.js b/test/built-ins/Temporal/PlainMonthDay/prototype/monthCode/validate-calendar-value.js new file mode 100644 index 00000000000..a3ed3282e35 --- /dev/null +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/monthCode/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/daysInMonth/validate-calendar-value.js b/test/built-ins/Temporal/PlainYearMonth/prototype/daysInMonth/validate-calendar-value.js new file mode 100644 index 00000000000..fb97bae10c8 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/daysInMonth/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/daysInYear/validate-calendar-value.js b/test/built-ins/Temporal/PlainYearMonth/prototype/daysInYear/validate-calendar-value.js new file mode 100644 index 00000000000..d114a61a702 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/daysInYear/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/inLeapYear/validate-calendar-value.js b/test/built-ins/Temporal/PlainYearMonth/prototype/inLeapYear/validate-calendar-value.js new file mode 100644 index 00000000000..4d6d09b9df5 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/inLeapYear/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/month/calendar-returns-infinity.js b/test/built-ins/Temporal/PlainYearMonth/prototype/month/calendar-returns-infinity.js deleted file mode 100644 index 54919c7ba4d..00000000000 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/month/calendar-returns-infinity.js +++ /dev/null @@ -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); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/month/validate-calendar-value.js b/test/built-ins/Temporal/PlainYearMonth/prototype/month/validate-calendar-value.js new file mode 100644 index 00000000000..ab65acb4cd0 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/month/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/monthCode/validate-calendar-value.js b/test/built-ins/Temporal/PlainYearMonth/prototype/monthCode/validate-calendar-value.js new file mode 100644 index 00000000000..0dc2a91b567 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/monthCode/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/monthsInYear/validate-calendar-value.js b/test/built-ins/Temporal/PlainYearMonth/prototype/monthsInYear/validate-calendar-value.js new file mode 100644 index 00000000000..50ee9622b68 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/monthsInYear/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/year/calendar-returns-infinity.js b/test/built-ins/Temporal/PlainYearMonth/prototype/year/calendar-returns-infinity.js deleted file mode 100644 index 2a16a71ee49..00000000000 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/year/calendar-returns-infinity.js +++ /dev/null @@ -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); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/year/validate-calendar-value.js b/test/built-ins/Temporal/PlainYearMonth/prototype/year/validate-calendar-value.js new file mode 100644 index 00000000000..b8a514f5900 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/year/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/day/calendar-returns-infinity.js b/test/built-ins/Temporal/ZonedDateTime/prototype/day/calendar-returns-infinity.js deleted file mode 100644 index d26b459ccbe..00000000000 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/day/calendar-returns-infinity.js +++ /dev/null @@ -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); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/day/validate-calendar-value.js b/test/built-ins/Temporal/ZonedDateTime/prototype/day/validate-calendar-value.js new file mode 100644 index 00000000000..0304b68058c --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/day/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/dayOfWeek/validate-calendar-value.js b/test/built-ins/Temporal/ZonedDateTime/prototype/dayOfWeek/validate-calendar-value.js new file mode 100644 index 00000000000..01f19882ffe --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/dayOfWeek/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/dayOfYear/validate-calendar-value.js b/test/built-ins/Temporal/ZonedDateTime/prototype/dayOfYear/validate-calendar-value.js new file mode 100644 index 00000000000..12a615196e3 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/dayOfYear/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/daysInMonth/validate-calendar-value.js b/test/built-ins/Temporal/ZonedDateTime/prototype/daysInMonth/validate-calendar-value.js new file mode 100644 index 00000000000..e32d56206f7 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/daysInMonth/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/daysInWeek/validate-calendar-value.js b/test/built-ins/Temporal/ZonedDateTime/prototype/daysInWeek/validate-calendar-value.js new file mode 100644 index 00000000000..fa7b6ff1522 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/daysInWeek/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/daysInYear/validate-calendar-value.js b/test/built-ins/Temporal/ZonedDateTime/prototype/daysInYear/validate-calendar-value.js new file mode 100644 index 00000000000..b94926e7c35 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/daysInYear/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/inLeapYear/validate-calendar-value.js b/test/built-ins/Temporal/ZonedDateTime/prototype/inLeapYear/validate-calendar-value.js new file mode 100644 index 00000000000..cb03414600e --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/inLeapYear/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/month/calendar-returns-infinity.js b/test/built-ins/Temporal/ZonedDateTime/prototype/month/calendar-returns-infinity.js deleted file mode 100644 index aa4341dea33..00000000000 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/month/calendar-returns-infinity.js +++ /dev/null @@ -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); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/month/validate-calendar-value.js b/test/built-ins/Temporal/ZonedDateTime/prototype/month/validate-calendar-value.js new file mode 100644 index 00000000000..8cc847b079c --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/month/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/monthCode/validate-calendar-value.js b/test/built-ins/Temporal/ZonedDateTime/prototype/monthCode/validate-calendar-value.js new file mode 100644 index 00000000000..522110ae06e --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/monthCode/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/monthsInYear/validate-calendar-value.js b/test/built-ins/Temporal/ZonedDateTime/prototype/monthsInYear/validate-calendar-value.js new file mode 100644 index 00000000000..11f9a45c9f0 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/monthsInYear/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/weekOfYear/validate-calendar-value.js b/test/built-ins/Temporal/ZonedDateTime/prototype/weekOfYear/validate-calendar-value.js new file mode 100644 index 00000000000..25289741c91 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/weekOfYear/validate-calendar-value.js @@ -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}`); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/year/calendar-returns-infinity.js b/test/built-ins/Temporal/ZonedDateTime/prototype/year/calendar-returns-infinity.js deleted file mode 100644 index 2eb34813bc6..00000000000 --- a/test/built-ins/Temporal/ZonedDateTime/prototype/year/calendar-returns-infinity.js +++ /dev/null @@ -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); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/year/validate-calendar-value.js b/test/built-ins/Temporal/ZonedDateTime/prototype/year/validate-calendar-value.js new file mode 100644 index 00000000000..bf859f7b668 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/year/validate-calendar-value.js @@ -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}`); +});