-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Temporal: Add intl402 custom Calendar/TimeZone tests to cover rejecti…
…on of invalid output
- Loading branch information
Showing
8 changed files
with
408 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
test/intl402/Temporal/PlainDate/prototype/era/validate-calendar-value.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`); | ||
}); |
51 changes: 51 additions & 0 deletions
51
test/intl402/Temporal/PlainDate/prototype/eraYear/validate-calendar-value.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`); | ||
}); |
51 changes: 51 additions & 0 deletions
51
test/intl402/Temporal/PlainDateTime/prototype/era/validate-calendar-value.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`); | ||
}); |
51 changes: 51 additions & 0 deletions
51
test/intl402/Temporal/PlainDateTime/prototype/eraYear/validate-calendar-value.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`); | ||
}); |
51 changes: 51 additions & 0 deletions
51
test/intl402/Temporal/PlainYearMonth/prototype/era/validate-calendar-value.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`); | ||
}); |
51 changes: 51 additions & 0 deletions
51
test/intl402/Temporal/PlainYearMonth/prototype/eraYear/validate-calendar-value.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`); | ||
}); |
51 changes: 51 additions & 0 deletions
51
test/intl402/Temporal/ZonedDateTime/prototype/era/validate-calendar-value.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`); | ||
}); |
Oops, something went wrong.