forked from tc39/test262
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Temporal: Add tests for calendar validation normative change
This adds tests for the normative change in tc39/proposal-temporal#2265, which adds validation steps to certain abstract operations that call Temporal.Calendar methods. These had some duplication with some existing tests named calendar-returns-infinity.js. Remove these, because the new tests are more complete in testing what values are accepted.
- Loading branch information
Showing
57 changed files
with
2,206 additions
and
324 deletions.
There are no files selected for viewing
27 changes: 0 additions & 27 deletions
27
test/built-ins/Temporal/PlainDate/prototype/day/calendar-returns-infinity.js
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
test/built-ins/Temporal/PlainDate/prototype/day/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) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-get-temporal.plaindate.prototype.day | ||
description: Validate result returned from calendar day() method | ||
features: [Temporal] | ||
---*/ | ||
|
||
const badResults = [ | ||
[undefined, RangeError], | ||
[null, RangeError], | ||
[false, RangeError], | ||
[Infinity, RangeError], | ||
[-Infinity, RangeError], | ||
[NaN, RangeError], | ||
[-7, RangeError], | ||
[-0.1, RangeError], | ||
["string", RangeError], | ||
[Symbol("foo"), TypeError], | ||
[7n, TypeError], | ||
[{}, RangeError], | ||
]; | ||
|
||
badResults.forEach(([result, error]) => { | ||
const calendar = new class extends Temporal.Calendar { | ||
day() { | ||
return result; | ||
} | ||
}("iso8601"); | ||
const instance = new Temporal.PlainDate(1981, 12, 15, calendar); | ||
assert.throws(error, () => instance.day, `${typeof result} not converted to positive integer`); | ||
}); | ||
|
||
const convertedResults = [ | ||
[true, 1], | ||
[7.1, 7], | ||
["7", 7], | ||
["7.5", 7], | ||
[{valueOf() { return 7; }}, 7], | ||
]; | ||
|
||
convertedResults.forEach(([result, convertedResult]) => { | ||
const calendar = new class extends Temporal.Calendar { | ||
day() { | ||
return result; | ||
} | ||
}("iso8601"); | ||
const instance = new Temporal.PlainDate(1981, 12, 15, calendar); | ||
assert.sameValue(instance.day, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`); | ||
}); |
51 changes: 51 additions & 0 deletions
51
test/built-ins/Temporal/PlainDate/prototype/dayOfWeek/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) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-get-temporal.plaindate.prototype.dayofweek | ||
description: Validate result returned from calendar dayOfWeek() method | ||
features: [Temporal] | ||
---*/ | ||
|
||
const badResults = [ | ||
[undefined, RangeError], | ||
[null, RangeError], | ||
[false, RangeError], | ||
[Infinity, RangeError], | ||
[-Infinity, RangeError], | ||
[NaN, RangeError], | ||
[-7, RangeError], | ||
[-0.1, RangeError], | ||
["string", RangeError], | ||
[Symbol("foo"), TypeError], | ||
[7n, TypeError], | ||
[{}, RangeError], | ||
]; | ||
|
||
badResults.forEach(([result, error]) => { | ||
const calendar = new class extends Temporal.Calendar { | ||
dayOfWeek() { | ||
return result; | ||
} | ||
}("iso8601"); | ||
const instance = new Temporal.PlainDate(1981, 12, 15, calendar); | ||
assert.throws(error, () => instance.dayOfWeek, `${typeof result} not converted to positive integer`); | ||
}); | ||
|
||
const convertedResults = [ | ||
[true, 1], | ||
[7.1, 7], | ||
["7", 7], | ||
["7.5", 7], | ||
[{valueOf() { return 7; }}, 7], | ||
]; | ||
|
||
convertedResults.forEach(([result, convertedResult]) => { | ||
const calendar = new class extends Temporal.Calendar { | ||
dayOfWeek() { | ||
return result; | ||
} | ||
}("iso8601"); | ||
const instance = new Temporal.PlainDate(1981, 12, 15, calendar); | ||
assert.sameValue(instance.dayOfWeek, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`); | ||
}); |
51 changes: 51 additions & 0 deletions
51
test/built-ins/Temporal/PlainDate/prototype/dayOfYear/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) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-get-temporal.plaindate.prototype.dayofyear | ||
description: Validate result returned from calendar dayOfYear() method | ||
features: [Temporal] | ||
---*/ | ||
|
||
const badResults = [ | ||
[undefined, RangeError], | ||
[null, RangeError], | ||
[false, RangeError], | ||
[Infinity, RangeError], | ||
[-Infinity, RangeError], | ||
[NaN, RangeError], | ||
[-7, RangeError], | ||
[-0.1, RangeError], | ||
["string", RangeError], | ||
[Symbol("foo"), TypeError], | ||
[7n, TypeError], | ||
[{}, RangeError], | ||
]; | ||
|
||
badResults.forEach(([result, error]) => { | ||
const calendar = new class extends Temporal.Calendar { | ||
dayOfYear() { | ||
return result; | ||
} | ||
}("iso8601"); | ||
const instance = new Temporal.PlainDate(1981, 12, 15, calendar); | ||
assert.throws(error, () => instance.dayOfYear, `${typeof result} not converted to positive integer`); | ||
}); | ||
|
||
const convertedResults = [ | ||
[true, 1], | ||
[7.1, 7], | ||
["7", 7], | ||
["7.5", 7], | ||
[{valueOf() { return 7; }}, 7], | ||
]; | ||
|
||
convertedResults.forEach(([result, convertedResult]) => { | ||
const calendar = new class extends Temporal.Calendar { | ||
dayOfYear() { | ||
return result; | ||
} | ||
}("iso8601"); | ||
const instance = new Temporal.PlainDate(1981, 12, 15, calendar); | ||
assert.sameValue(instance.dayOfYear, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`); | ||
}); |
51 changes: 51 additions & 0 deletions
51
test/built-ins/Temporal/PlainDate/prototype/daysInMonth/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) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-get-temporal.plaindate.prototype.daysinmonth | ||
description: Validate result returned from calendar daysInMonth() method | ||
features: [Temporal] | ||
---*/ | ||
|
||
const badResults = [ | ||
[undefined, RangeError], | ||
[null, RangeError], | ||
[false, RangeError], | ||
[Infinity, RangeError], | ||
[-Infinity, RangeError], | ||
[NaN, RangeError], | ||
[-7, RangeError], | ||
[-0.1, RangeError], | ||
["string", RangeError], | ||
[Symbol("foo"), TypeError], | ||
[7n, TypeError], | ||
[{}, RangeError], | ||
]; | ||
|
||
badResults.forEach(([result, error]) => { | ||
const calendar = new class extends Temporal.Calendar { | ||
daysInMonth() { | ||
return result; | ||
} | ||
}("iso8601"); | ||
const instance = new Temporal.PlainDate(1981, 12, 15, calendar); | ||
assert.throws(error, () => instance.daysInMonth, `${typeof result} not converted to positive integer`); | ||
}); | ||
|
||
const convertedResults = [ | ||
[true, 1], | ||
[7.1, 7], | ||
["7", 7], | ||
["7.5", 7], | ||
[{valueOf() { return 7; }}, 7], | ||
]; | ||
|
||
convertedResults.forEach(([result, convertedResult]) => { | ||
const calendar = new class extends Temporal.Calendar { | ||
daysInMonth() { | ||
return result; | ||
} | ||
}("iso8601"); | ||
const instance = new Temporal.PlainDate(1981, 12, 15, calendar); | ||
assert.sameValue(instance.daysInMonth, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`); | ||
}); |
51 changes: 51 additions & 0 deletions
51
test/built-ins/Temporal/PlainDate/prototype/daysInWeek/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) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-get-temporal.plaindate.prototype.daysinweek | ||
description: Validate result returned from calendar daysInWeek() method | ||
features: [Temporal] | ||
---*/ | ||
|
||
const badResults = [ | ||
[undefined, RangeError], | ||
[null, RangeError], | ||
[false, RangeError], | ||
[Infinity, RangeError], | ||
[-Infinity, RangeError], | ||
[NaN, RangeError], | ||
[-7, RangeError], | ||
[-0.1, RangeError], | ||
["string", RangeError], | ||
[Symbol("foo"), TypeError], | ||
[7n, TypeError], | ||
[{}, RangeError], | ||
]; | ||
|
||
badResults.forEach(([result, error]) => { | ||
const calendar = new class extends Temporal.Calendar { | ||
daysInWeek() { | ||
return result; | ||
} | ||
}("iso8601"); | ||
const instance = new Temporal.PlainDate(1981, 12, 15, calendar); | ||
assert.throws(error, () => instance.daysInWeek, `${typeof result} not converted to positive integer`); | ||
}); | ||
|
||
const convertedResults = [ | ||
[true, 1], | ||
[7.1, 7], | ||
["7", 7], | ||
["7.5", 7], | ||
[{valueOf() { return 7; }}, 7], | ||
]; | ||
|
||
convertedResults.forEach(([result, convertedResult]) => { | ||
const calendar = new class extends Temporal.Calendar { | ||
daysInWeek() { | ||
return result; | ||
} | ||
}("iso8601"); | ||
const instance = new Temporal.PlainDate(1981, 12, 15, calendar); | ||
assert.sameValue(instance.daysInWeek, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`); | ||
}); |
51 changes: 51 additions & 0 deletions
51
test/built-ins/Temporal/PlainDate/prototype/daysInYear/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) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-get-temporal.plaindate.prototype.daysinyear | ||
description: Validate result returned from calendar daysInYear() method | ||
features: [Temporal] | ||
---*/ | ||
|
||
const badResults = [ | ||
[undefined, RangeError], | ||
[null, RangeError], | ||
[false, RangeError], | ||
[Infinity, RangeError], | ||
[-Infinity, RangeError], | ||
[NaN, RangeError], | ||
[-7, RangeError], | ||
[-0.1, RangeError], | ||
["string", RangeError], | ||
[Symbol("foo"), TypeError], | ||
[7n, TypeError], | ||
[{}, RangeError], | ||
]; | ||
|
||
badResults.forEach(([result, error]) => { | ||
const calendar = new class extends Temporal.Calendar { | ||
daysInYear() { | ||
return result; | ||
} | ||
}("iso8601"); | ||
const instance = new Temporal.PlainDate(1981, 12, 15, calendar); | ||
assert.throws(error, () => instance.daysInYear, `${typeof result} not converted to positive integer`); | ||
}); | ||
|
||
const convertedResults = [ | ||
[true, 1], | ||
[7.1, 7], | ||
["7", 7], | ||
["7.5", 7], | ||
[{valueOf() { return 7; }}, 7], | ||
]; | ||
|
||
convertedResults.forEach(([result, convertedResult]) => { | ||
const calendar = new class extends Temporal.Calendar { | ||
daysInYear() { | ||
return result; | ||
} | ||
}("iso8601"); | ||
const instance = new Temporal.PlainDate(1981, 12, 15, calendar); | ||
assert.sameValue(instance.daysInYear, convertedResult, `${typeof result} converted to positive integer ${convertedResult}`); | ||
}); |
40 changes: 40 additions & 0 deletions
40
test/built-ins/Temporal/PlainDate/prototype/inLeapYear/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,40 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-get-temporal.plaindate.prototype.inleapyear | ||
description: Validate result returned from calendar inLeapYear() method | ||
features: [Temporal] | ||
---*/ | ||
|
||
const convertedResults = [ | ||
[undefined, false], | ||
[null, false], | ||
[true, true], | ||
[false, false], | ||
[0, false], | ||
[-0, false], | ||
[42, true], | ||
[7.1, true], | ||
[NaN, false], | ||
[Infinity, true], | ||
[-Infinity, true], | ||
["", false], | ||
["a string", true], | ||
["0", true], | ||
[Symbol("foo"), true], | ||
[0n, false], | ||
[42n, true], | ||
[{}, true], | ||
[{valueOf() { return false; }}, true], | ||
]; | ||
|
||
convertedResults.forEach(([result, convertedResult]) => { | ||
const calendar = new class extends Temporal.Calendar { | ||
inLeapYear() { | ||
return result; | ||
} | ||
}("iso8601"); | ||
const instance = new Temporal.PlainDate(1981, 12, 15, calendar); | ||
assert.sameValue(instance.inLeapYear, convertedResult, `${typeof result} converted to boolean ${convertedResult}`); | ||
}); |
Oops, something went wrong.