Skip to content

Commit ea10ca0

Browse files
gibson042ptomato
authored andcommitted
Temporal: Add intl402 custom Calendar/TimeZone tests to cover rejection of invalid output
1 parent f9a62a4 commit ea10ca0

File tree

8 files changed

+408
-0
lines changed

8 files changed

+408
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (C) 2023 Richard Gibson. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-get-temporal.plaindate.prototype.era
6+
description: Validate result returned from calendar era() method
7+
features: [Temporal]
8+
---*/
9+
10+
const badResults = [
11+
[null, TypeError],
12+
[false, TypeError],
13+
[Infinity, TypeError],
14+
[-Infinity, TypeError],
15+
[NaN, TypeError],
16+
[-7, TypeError],
17+
[-0.1, TypeError],
18+
[Symbol("foo"), TypeError],
19+
[7n, TypeError],
20+
[{}, TypeError],
21+
[true, TypeError],
22+
[7.1, TypeError],
23+
[{valueOf() { return "7"; }}, TypeError],
24+
];
25+
26+
badResults.forEach(([result, error]) => {
27+
const calendar = new class extends Temporal.Calendar {
28+
era() {
29+
return result;
30+
}
31+
}("iso8601");
32+
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
33+
assert.throws(error, () => instance.era, `${typeof result} ${String(result)} not converted to string`);
34+
});
35+
36+
const preservedResults = [
37+
undefined,
38+
"string",
39+
"7",
40+
"7.5",
41+
];
42+
43+
preservedResults.forEach(result => {
44+
const calendar = new class extends Temporal.Calendar {
45+
era() {
46+
return result;
47+
}
48+
}("iso8601");
49+
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
50+
assert.sameValue(instance.era, result, `${typeof result} ${String(result)} preserved`);
51+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (C) 2023 Richard Gibson. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-get-temporal.plaindate.prototype.erayear
6+
description: Validate result returned from calendar eraYear() method
7+
features: [Temporal]
8+
---*/
9+
10+
const badResults = [
11+
[null, TypeError],
12+
[false, TypeError],
13+
[Infinity, RangeError],
14+
[-Infinity, RangeError],
15+
[NaN, RangeError],
16+
[-0.1, RangeError],
17+
["string", TypeError],
18+
[Symbol("foo"), TypeError],
19+
[7n, TypeError],
20+
[{}, TypeError],
21+
[true, TypeError],
22+
[7.1, RangeError],
23+
["7", TypeError],
24+
["7.5", TypeError],
25+
[{valueOf() { return 7; }}, TypeError],
26+
];
27+
28+
badResults.forEach(([result, error]) => {
29+
const calendar = new class extends Temporal.Calendar {
30+
eraYear() {
31+
return result;
32+
}
33+
}("iso8601");
34+
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
35+
assert.throws(error, () => instance.eraYear, `${typeof result} ${String(result)} not converted to integer`);
36+
});
37+
38+
const preservedResults = [
39+
undefined,
40+
-7,
41+
];
42+
43+
preservedResults.forEach(result => {
44+
const calendar = new class extends Temporal.Calendar {
45+
eraYear() {
46+
return result;
47+
}
48+
}("iso8601");
49+
const instance = new Temporal.PlainDate(1981, 12, 15, calendar);
50+
assert.sameValue(instance.eraYear, result, `${typeof result} ${String(result)} preserved`);
51+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (C) 2023 Richard Gibson. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-get-temporal.plaindatetime.prototype.era
6+
description: Validate result returned from calendar era() method
7+
features: [Temporal]
8+
---*/
9+
10+
const badResults = [
11+
[null, TypeError],
12+
[false, TypeError],
13+
[Infinity, TypeError],
14+
[-Infinity, TypeError],
15+
[NaN, TypeError],
16+
[-7, TypeError],
17+
[-0.1, TypeError],
18+
[Symbol("foo"), TypeError],
19+
[7n, TypeError],
20+
[{}, TypeError],
21+
[true, TypeError],
22+
[7.1, TypeError],
23+
[{valueOf() { return "7"; }}, TypeError],
24+
];
25+
26+
badResults.forEach(([result, error]) => {
27+
const calendar = new class extends Temporal.Calendar {
28+
era() {
29+
return result;
30+
}
31+
}("iso8601");
32+
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
33+
assert.throws(error, () => instance.era, `${typeof result} ${String(result)} not converted to string`);
34+
});
35+
36+
const preservedResults = [
37+
undefined,
38+
"string",
39+
"7",
40+
"7.5",
41+
];
42+
43+
preservedResults.forEach(result => {
44+
const calendar = new class extends Temporal.Calendar {
45+
era() {
46+
return result;
47+
}
48+
}("iso8601");
49+
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
50+
assert.sameValue(instance.era, result, `${typeof result} ${String(result)} preserved`);
51+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (C) 2023 Richard Gibson. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-get-temporal.plaindatetime.prototype.erayear
6+
description: Validate result returned from calendar eraYear() method
7+
features: [Temporal]
8+
---*/
9+
10+
const badResults = [
11+
[null, TypeError],
12+
[false, TypeError],
13+
[Infinity, RangeError],
14+
[-Infinity, RangeError],
15+
[NaN, RangeError],
16+
[-0.1, RangeError],
17+
["string", TypeError],
18+
[Symbol("foo"), TypeError],
19+
[7n, TypeError],
20+
[{}, TypeError],
21+
[true, TypeError],
22+
[7.1, RangeError],
23+
["7", TypeError],
24+
["7.5", TypeError],
25+
[{valueOf() { return 7; }}, TypeError],
26+
];
27+
28+
badResults.forEach(([result, error]) => {
29+
const calendar = new class extends Temporal.Calendar {
30+
eraYear() {
31+
return result;
32+
}
33+
}("iso8601");
34+
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
35+
assert.throws(error, () => instance.eraYear, `${typeof result} ${String(result)} not converted to integer`);
36+
});
37+
38+
const preservedResults = [
39+
undefined,
40+
-7,
41+
];
42+
43+
preservedResults.forEach(result => {
44+
const calendar = new class extends Temporal.Calendar {
45+
eraYear() {
46+
return result;
47+
}
48+
}("iso8601");
49+
const instance = new Temporal.PlainDateTime(1981, 12, 15, 14, 15, 45, 987, 654, 321, calendar);
50+
assert.sameValue(instance.eraYear, result, `${typeof result} ${String(result)} preserved`);
51+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (C) 2023 Richard Gibson. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-get-temporal.plainyearmonth.prototype.era
6+
description: Validate result returned from calendar era() method
7+
features: [Temporal]
8+
---*/
9+
10+
const badResults = [
11+
[null, TypeError],
12+
[false, TypeError],
13+
[Infinity, TypeError],
14+
[-Infinity, TypeError],
15+
[NaN, TypeError],
16+
[-7, TypeError],
17+
[-0.1, TypeError],
18+
[Symbol("foo"), TypeError],
19+
[7n, TypeError],
20+
[{}, TypeError],
21+
[true, TypeError],
22+
[7.1, TypeError],
23+
[{valueOf() { return "7"; }}, TypeError],
24+
];
25+
26+
badResults.forEach(([result, error]) => {
27+
const calendar = new class extends Temporal.Calendar {
28+
era() {
29+
return result;
30+
}
31+
}("iso8601");
32+
const instance = new Temporal.PlainYearMonth(1981, 12, calendar);
33+
assert.throws(error, () => instance.era, `${typeof result} ${String(result)} not converted to string`);
34+
});
35+
36+
const preservedResults = [
37+
undefined,
38+
"string",
39+
"7",
40+
"7.5",
41+
];
42+
43+
preservedResults.forEach(result => {
44+
const calendar = new class extends Temporal.Calendar {
45+
era() {
46+
return result;
47+
}
48+
}("iso8601");
49+
const instance = new Temporal.PlainYearMonth(1981, 12, calendar);
50+
assert.sameValue(instance.era, result, `${typeof result} ${String(result)} preserved`);
51+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (C) 2023 Richard Gibson. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-get-temporal.plainyearmonth.prototype.erayear
6+
description: Validate result returned from calendar eraYear() method
7+
features: [Temporal]
8+
---*/
9+
10+
const badResults = [
11+
[null, TypeError],
12+
[false, TypeError],
13+
[Infinity, RangeError],
14+
[-Infinity, RangeError],
15+
[NaN, RangeError],
16+
[-0.1, RangeError],
17+
["string", TypeError],
18+
[Symbol("foo"), TypeError],
19+
[7n, TypeError],
20+
[{}, TypeError],
21+
[true, TypeError],
22+
[7.1, RangeError],
23+
["7", TypeError],
24+
["7.5", TypeError],
25+
[{valueOf() { return 7; }}, TypeError],
26+
];
27+
28+
badResults.forEach(([result, error]) => {
29+
const calendar = new class extends Temporal.Calendar {
30+
eraYear() {
31+
return result;
32+
}
33+
}("iso8601");
34+
const instance = new Temporal.PlainYearMonth(1981, 12, calendar);
35+
assert.throws(error, () => instance.eraYear, `${typeof result} ${String(result)} not converted to integer`);
36+
});
37+
38+
const preservedResults = [
39+
undefined,
40+
-7,
41+
];
42+
43+
preservedResults.forEach(result => {
44+
const calendar = new class extends Temporal.Calendar {
45+
eraYear() {
46+
return result;
47+
}
48+
}("iso8601");
49+
const instance = new Temporal.PlainYearMonth(1981, 12, calendar);
50+
assert.sameValue(instance.eraYear, result, `${typeof result} ${String(result)} preserved`);
51+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright (C) 2023 Richard Gibson. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
/*---
5+
esid: sec-get-temporal.zoneddatetime.prototype.era
6+
description: Validate result returned from calendar era() method
7+
features: [Temporal]
8+
---*/
9+
10+
const badResults = [
11+
[null, TypeError],
12+
[false, TypeError],
13+
[Infinity, TypeError],
14+
[-Infinity, TypeError],
15+
[NaN, TypeError],
16+
[-7, TypeError],
17+
[-0.1, TypeError],
18+
[Symbol("foo"), TypeError],
19+
[7n, TypeError],
20+
[{}, TypeError],
21+
[true, TypeError],
22+
[7.1, TypeError],
23+
[{valueOf() { return "7"; }}, TypeError],
24+
];
25+
26+
badResults.forEach(([result, error]) => {
27+
const calendar = new class extends Temporal.Calendar {
28+
era() {
29+
return result;
30+
}
31+
}("iso8601");
32+
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
33+
assert.throws(error, () => instance.era, `${typeof result} ${String(result)} not converted to string`);
34+
});
35+
36+
const preservedResults = [
37+
undefined,
38+
"string",
39+
"7",
40+
"7.5",
41+
];
42+
43+
preservedResults.forEach(result => {
44+
const calendar = new class extends Temporal.Calendar {
45+
era() {
46+
return result;
47+
}
48+
}("iso8601");
49+
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC", calendar);
50+
assert.sameValue(instance.era, result, `${typeof result} ${String(result)} preserved`);
51+
});

0 commit comments

Comments
 (0)