mirror of
https://github.com/tc39/test262.git
synced 2025-07-22 05:24:38 +02:00
Temporal: Add intl402 custom Calendar/TimeZone tests to cover rejection of invalid output
This commit is contained in:
parent
f9a62a4eb1
commit
ea10ca0cc6
51
test/intl402/Temporal/PlainDate/prototype/era/validate-calendar-value.js
vendored
Normal file
51
test/intl402/Temporal/PlainDate/prototype/era/validate-calendar-value.js
vendored
Normal 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`);
|
||||||
|
});
|
51
test/intl402/Temporal/PlainDate/prototype/eraYear/validate-calendar-value.js
vendored
Normal file
51
test/intl402/Temporal/PlainDate/prototype/eraYear/validate-calendar-value.js
vendored
Normal 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`);
|
||||||
|
});
|
51
test/intl402/Temporal/PlainDateTime/prototype/era/validate-calendar-value.js
vendored
Normal file
51
test/intl402/Temporal/PlainDateTime/prototype/era/validate-calendar-value.js
vendored
Normal 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`);
|
||||||
|
});
|
51
test/intl402/Temporal/PlainDateTime/prototype/eraYear/validate-calendar-value.js
vendored
Normal file
51
test/intl402/Temporal/PlainDateTime/prototype/eraYear/validate-calendar-value.js
vendored
Normal 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`);
|
||||||
|
});
|
51
test/intl402/Temporal/PlainYearMonth/prototype/era/validate-calendar-value.js
vendored
Normal file
51
test/intl402/Temporal/PlainYearMonth/prototype/era/validate-calendar-value.js
vendored
Normal 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`);
|
||||||
|
});
|
51
test/intl402/Temporal/PlainYearMonth/prototype/eraYear/validate-calendar-value.js
vendored
Normal file
51
test/intl402/Temporal/PlainYearMonth/prototype/eraYear/validate-calendar-value.js
vendored
Normal 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`);
|
||||||
|
});
|
51
test/intl402/Temporal/ZonedDateTime/prototype/era/validate-calendar-value.js
vendored
Normal file
51
test/intl402/Temporal/ZonedDateTime/prototype/era/validate-calendar-value.js
vendored
Normal 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`);
|
||||||
|
});
|
51
test/intl402/Temporal/ZonedDateTime/prototype/eraYear/validate-calendar-value.js
vendored
Normal file
51
test/intl402/Temporal/ZonedDateTime/prototype/eraYear/validate-calendar-value.js
vendored
Normal 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`);
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user