Skip to content

Commit

Permalink
Temporal: Add intl402 custom Calendar/TimeZone tests to cover rejecti…
Browse files Browse the repository at this point in the history
…on of invalid output
  • Loading branch information
gibson042 authored and ptomato committed Feb 1, 2023
1 parent f9a62a4 commit ea10ca0
Show file tree
Hide file tree
Showing 8 changed files with 408 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (C) 2023 Richard Gibson. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-get-temporal.plaindate.prototype.era
description: Validate result returned from calendar era() method
features: [Temporal]
---*/

const badResults = [
[null, TypeError],
[false, TypeError],
[Infinity, TypeError],
[-Infinity, TypeError],
[NaN, TypeError],
[-7, TypeError],
[-0.1, TypeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, TypeError],
[true, TypeError],
[7.1, TypeError],
[{valueOf() { return "7"; }}, TypeError],
];

badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
era() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
assert.throws(error, () => instance.era, `${typeof result} ${String(result)} not converted to string`);
});

const preservedResults = [
undefined,
"string",
"7",
"7.5",
];

preservedResults.forEach(result => {
const calendar = new class extends Temporal.Calendar {
era() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
assert.sameValue(instance.era, result, `${typeof result} ${String(result)} preserved`);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (C) 2023 Richard Gibson. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-get-temporal.plaindate.prototype.erayear
description: Validate result returned from calendar eraYear() method
features: [Temporal]
---*/

const badResults = [
[null, TypeError],
[false, TypeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-0.1, RangeError],
["string", TypeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, TypeError],
[true, TypeError],
[7.1, RangeError],
["7", TypeError],
["7.5", TypeError],
[{valueOf() { return 7; }}, TypeError],
];

badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
eraYear() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
assert.throws(error, () => instance.eraYear, `${typeof result} ${String(result)} not converted to integer`);
});

const preservedResults = [
undefined,
-7,
];

preservedResults.forEach(result => {
const calendar = new class extends Temporal.Calendar {
eraYear() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
assert.sameValue(instance.eraYear, result, `${typeof result} ${String(result)} preserved`);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (C) 2023 Richard Gibson. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-get-temporal.plaindatetime.prototype.era
description: Validate result returned from calendar era() method
features: [Temporal]
---*/

const badResults = [
[null, TypeError],
[false, TypeError],
[Infinity, TypeError],
[-Infinity, TypeError],
[NaN, TypeError],
[-7, TypeError],
[-0.1, TypeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, TypeError],
[true, TypeError],
[7.1, TypeError],
[{valueOf() { return "7"; }}, TypeError],
];

badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
era() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
assert.throws(error, () => instance.era, `${typeof result} ${String(result)} not converted to string`);
});

const preservedResults = [
undefined,
"string",
"7",
"7.5",
];

preservedResults.forEach(result => {
const calendar = new class extends Temporal.Calendar {
era() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
assert.sameValue(instance.era, result, `${typeof result} ${String(result)} preserved`);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (C) 2023 Richard Gibson. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-get-temporal.plaindatetime.prototype.erayear
description: Validate result returned from calendar eraYear() method
features: [Temporal]
---*/

const badResults = [
[null, TypeError],
[false, TypeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-0.1, RangeError],
["string", TypeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, TypeError],
[true, TypeError],
[7.1, RangeError],
["7", TypeError],
["7.5", TypeError],
[{valueOf() { return 7; }}, TypeError],
];

badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
eraYear() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
assert.throws(error, () => instance.eraYear, `${typeof result} ${String(result)} not converted to integer`);
});

const preservedResults = [
undefined,
-7,
];

preservedResults.forEach(result => {
const calendar = new class extends Temporal.Calendar {
eraYear() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
assert.sameValue(instance.eraYear, result, `${typeof result} ${String(result)} preserved`);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (C) 2023 Richard Gibson. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-get-temporal.plainyearmonth.prototype.era
description: Validate result returned from calendar era() method
features: [Temporal]
---*/

const badResults = [
[null, TypeError],
[false, TypeError],
[Infinity, TypeError],
[-Infinity, TypeError],
[NaN, TypeError],
[-7, TypeError],
[-0.1, TypeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, TypeError],
[true, TypeError],
[7.1, TypeError],
[{valueOf() { return "7"; }}, TypeError],
];

badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
era() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainYearMonth(1981, 12, calendar);
assert.throws(error, () => instance.era, `${typeof result} ${String(result)} not converted to string`);
});

const preservedResults = [
undefined,
"string",
"7",
"7.5",
];

preservedResults.forEach(result => {
const calendar = new class extends Temporal.Calendar {
era() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainYearMonth(1981, 12, calendar);
assert.sameValue(instance.era, result, `${typeof result} ${String(result)} preserved`);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (C) 2023 Richard Gibson. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-get-temporal.plainyearmonth.prototype.erayear
description: Validate result returned from calendar eraYear() method
features: [Temporal]
---*/

const badResults = [
[null, TypeError],
[false, TypeError],
[Infinity, RangeError],
[-Infinity, RangeError],
[NaN, RangeError],
[-0.1, RangeError],
["string", TypeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, TypeError],
[true, TypeError],
[7.1, RangeError],
["7", TypeError],
["7.5", TypeError],
[{valueOf() { return 7; }}, TypeError],
];

badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
eraYear() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainYearMonth(1981, 12, calendar);
assert.throws(error, () => instance.eraYear, `${typeof result} ${String(result)} not converted to integer`);
});

const preservedResults = [
undefined,
-7,
];

preservedResults.forEach(result => {
const calendar = new class extends Temporal.Calendar {
eraYear() {
return result;
}
}("iso8601");
const instance = new Temporal.PlainYearMonth(1981, 12, calendar);
assert.sameValue(instance.eraYear, result, `${typeof result} ${String(result)} preserved`);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (C) 2023 Richard Gibson. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-get-temporal.zoneddatetime.prototype.era
description: Validate result returned from calendar era() method
features: [Temporal]
---*/

const badResults = [
[null, TypeError],
[false, TypeError],
[Infinity, TypeError],
[-Infinity, TypeError],
[NaN, TypeError],
[-7, TypeError],
[-0.1, TypeError],
[Symbol("foo"), TypeError],
[7n, TypeError],
[{}, TypeError],
[true, TypeError],
[7.1, TypeError],
[{valueOf() { return "7"; }}, TypeError],
];

badResults.forEach(([result, error]) => {
const calendar = new class extends Temporal.Calendar {
era() {
return result;
}
}("iso8601");
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
assert.throws(error, () => instance.era, `${typeof result} ${String(result)} not converted to string`);
});

const preservedResults = [
undefined,
"string",
"7",
"7.5",
];

preservedResults.forEach(result => {
const calendar = new class extends Temporal.Calendar {
era() {
return result;
}
}("iso8601");
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
assert.sameValue(instance.era, result, `${typeof result} ${String(result)} preserved`);
});
Loading

0 comments on commit ea10ca0

Please sign in to comment.