Temporal: Add intl402 custom Calendar/TimeZone tests to cover rejection of invalid output

This commit is contained in:
Richard Gibson 2023-01-17 14:28:51 -05:00 committed by Philip Chimento
parent f9a62a4eb1
commit ea10ca0cc6
8 changed files with 408 additions and 0 deletions

View File

@ -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`);
});

View File

@ -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`);
});

View File

@ -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`);
});

View File

@ -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`);
});

View File

@ -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`);
});

View File

@ -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`);
});

View File

@ -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`);
});

View File

@ -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.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.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", 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.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
assert.sameValue(instance.eraYear, result, `${typeof result} ${String(result)} preserved`);
});