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.
Add tests for Temporal options bags being of the wrong type
This consolidates the few existing tests for options bags in Temporal being of the wrong type, and adds them for every entry point in Temporal that accepts an options bag. These are mostly identical tests, but there is a variation for methods like round() where either an options bag or string is accepted.
- Loading branch information
Showing
56 changed files
with
1,239 additions
and
20 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
test/built-ins/Temporal/Calendar/prototype/dateAdd/options-wrong-type.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,23 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.calendar.prototype.dateadd | ||
description: TypeError thrown when options argument is a primitive | ||
features: [BigInt, Symbol, Temporal] | ||
---*/ | ||
|
||
const badOptions = [ | ||
null, | ||
true, | ||
"some string", | ||
Symbol(), | ||
1, | ||
2n, | ||
]; | ||
|
||
const instance = new Temporal.Calendar("iso8601"); | ||
for (const value of badOptions) { | ||
assert.throws(TypeError, () => instance.dateAdd(new Temporal.PlainDate(1976, 11, 18), new Temporal.Duration(1), value), | ||
`TypeError on wrong options type ${typeof value}`); | ||
}; |
23 changes: 23 additions & 0 deletions
23
test/built-ins/Temporal/Calendar/prototype/dateFromFields/options-wrong-type.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,23 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.calendar.prototype.datefromfields | ||
description: TypeError thrown when options argument is a primitive | ||
features: [BigInt, Symbol, Temporal] | ||
---*/ | ||
|
||
const badOptions = [ | ||
null, | ||
true, | ||
"some string", | ||
Symbol(), | ||
1, | ||
2n, | ||
]; | ||
|
||
const instance = new Temporal.Calendar("iso8601"); | ||
for (const value of badOptions) { | ||
assert.throws(TypeError, () => instance.dateFromFields({ year: 1976, month: 11, day: 18 }, value), | ||
`TypeError on wrong options type ${typeof value}`); | ||
}; |
23 changes: 23 additions & 0 deletions
23
test/built-ins/Temporal/Calendar/prototype/dateUntil/options-wrong-type.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,23 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.calendar.prototype.dateuntil | ||
description: TypeError thrown when options argument is a primitive | ||
features: [BigInt, Symbol, Temporal] | ||
---*/ | ||
|
||
const badOptions = [ | ||
null, | ||
true, | ||
"some string", | ||
Symbol(), | ||
1, | ||
2n, | ||
]; | ||
|
||
const instance = new Temporal.Calendar("iso8601"); | ||
for (const value of badOptions) { | ||
assert.throws(TypeError, () => instance.dateUntil(new Temporal.PlainDate(1976, 11, 18), new Temporal.PlainDate(1984, 5, 31), value), | ||
`TypeError on wrong options type ${typeof value}`); | ||
}; |
23 changes: 23 additions & 0 deletions
23
test/built-ins/Temporal/Calendar/prototype/monthDayFromFields/options-wrong-type.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,23 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.calendar.prototype.monthdayfromfields | ||
description: TypeError thrown when options argument is a primitive | ||
features: [BigInt, Symbol, Temporal] | ||
---*/ | ||
|
||
const badOptions = [ | ||
null, | ||
true, | ||
"some string", | ||
Symbol(), | ||
1, | ||
2n, | ||
]; | ||
|
||
const instance = new Temporal.Calendar("iso8601"); | ||
for (const value of badOptions) { | ||
assert.throws(TypeError, () => instance.monthDayFromFields({ monthCode: "M12", day: 15 }, value), | ||
`TypeError on wrong options type ${typeof value}`); | ||
}; |
23 changes: 23 additions & 0 deletions
23
test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/options-wrong-type.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,23 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.calendar.prototype.yearmonthfromfields | ||
description: TypeError thrown when options argument is a primitive | ||
features: [BigInt, Symbol, Temporal] | ||
---*/ | ||
|
||
const badOptions = [ | ||
null, | ||
true, | ||
"some string", | ||
Symbol(), | ||
1, | ||
2n, | ||
]; | ||
|
||
const instance = new Temporal.Calendar("iso8601"); | ||
for (const value of badOptions) { | ||
assert.throws(TypeError, () => instance.yearMonthFromFields({ year: 2000, monthCode: "M05" }, value), | ||
`TypeError on wrong options type ${typeof value}`); | ||
}; |
22 changes: 22 additions & 0 deletions
22
test/built-ins/Temporal/Duration/compare/options-wrong-type.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,22 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.duration.compare | ||
description: TypeError thrown when options argument is a primitive | ||
features: [BigInt, Symbol, Temporal] | ||
---*/ | ||
|
||
const badOptions = [ | ||
null, | ||
true, | ||
"some string", | ||
Symbol(), | ||
1, | ||
2n, | ||
]; | ||
|
||
for (const value of badOptions) { | ||
assert.throws(TypeError, () => Temporal.Duration.compare({ hours: 1 }, { minutes: 60 }, value), | ||
`TypeError on wrong options type ${typeof value}`); | ||
}; |
23 changes: 23 additions & 0 deletions
23
test/built-ins/Temporal/Duration/prototype/add/options-wrong-type.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,23 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.duration.prototype.add | ||
description: TypeError thrown when options argument is a primitive | ||
features: [BigInt, Symbol, Temporal] | ||
---*/ | ||
|
||
const badOptions = [ | ||
null, | ||
true, | ||
"some string", | ||
Symbol(), | ||
1, | ||
2n, | ||
]; | ||
|
||
const instance = new Temporal.Duration(0, 0, 0, 0, 1); | ||
for (const value of badOptions) { | ||
assert.throws(TypeError, () => instance.add({ hours: 1 }, value), | ||
`TypeError on wrong options type ${typeof value}`); | ||
}; |
24 changes: 24 additions & 0 deletions
24
test/built-ins/Temporal/Duration/prototype/round/options-wrong-type.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,24 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.duration.prototype.round | ||
description: TypeError thrown when options argument is missing or a non-string primitive | ||
features: [BigInt, Symbol, Temporal] | ||
---*/ | ||
|
||
const badOptions = [ | ||
undefined, | ||
null, | ||
true, | ||
Symbol(), | ||
1, | ||
2n, | ||
]; | ||
|
||
const instance = new Temporal.Duration(0, 0, 0, 0, 1); | ||
assert.throws(TypeError, () => instance.round(), "TypeError on missing options argument"); | ||
for (const value of badOptions) { | ||
assert.throws(TypeError, () => instance.round(value), | ||
`TypeError on wrong options type ${typeof value}`); | ||
}; |
23 changes: 23 additions & 0 deletions
23
test/built-ins/Temporal/Duration/prototype/subtract/options-wrong-type.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,23 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.duration.prototype.subtract | ||
description: TypeError thrown when options argument is a primitive | ||
features: [BigInt, Symbol, Temporal] | ||
---*/ | ||
|
||
const badOptions = [ | ||
null, | ||
true, | ||
"some string", | ||
Symbol(), | ||
1, | ||
2n, | ||
]; | ||
|
||
const instance = new Temporal.Duration(0, 0, 0, 0, 1); | ||
for (const value of badOptions) { | ||
assert.throws(TypeError, () => instance.subtract({ hours: 1 }, value), | ||
`TypeError on wrong options type ${typeof value}`); | ||
}; |
23 changes: 23 additions & 0 deletions
23
test/built-ins/Temporal/Duration/prototype/toString/options-wrong-type.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,23 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.duration.prototype.tostring | ||
description: TypeError thrown when options argument is a primitive | ||
features: [BigInt, Symbol, Temporal] | ||
---*/ | ||
|
||
const badOptions = [ | ||
null, | ||
true, | ||
"some string", | ||
Symbol(), | ||
1, | ||
2n, | ||
]; | ||
|
||
const instance = new Temporal.Duration(0, 0, 0, 0, 1); | ||
for (const value of badOptions) { | ||
assert.throws(TypeError, () => instance.toString(value), | ||
`TypeError on wrong options type ${typeof value}`); | ||
}; |
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
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
23 changes: 23 additions & 0 deletions
23
test/built-ins/Temporal/Instant/prototype/since/options-wrong-type.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,23 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.instant.prototype.since | ||
description: TypeError thrown when options argument is a primitive | ||
features: [BigInt, Symbol, Temporal] | ||
---*/ | ||
|
||
const badOptions = [ | ||
null, | ||
true, | ||
"some string", | ||
Symbol(), | ||
1, | ||
2n, | ||
]; | ||
|
||
const instance = new Temporal.Instant(0n); | ||
for (const value of badOptions) { | ||
assert.throws(TypeError, () => instance.since(new Temporal.Instant(3600_000_000_000n), value), | ||
`TypeError on wrong options type ${typeof value}`); | ||
}; |
23 changes: 23 additions & 0 deletions
23
test/built-ins/Temporal/Instant/prototype/toString/options-wrong-type.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,23 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.instant.prototype.tostring | ||
description: TypeError thrown when options argument is a primitive | ||
features: [BigInt, Symbol, Temporal] | ||
---*/ | ||
|
||
const badOptions = [ | ||
null, | ||
true, | ||
"some string", | ||
Symbol(), | ||
1, | ||
2n, | ||
]; | ||
|
||
const instance = new Temporal.Instant(0n); | ||
for (const value of badOptions) { | ||
assert.throws(TypeError, () => instance.toString(value), | ||
`TypeError on wrong options type ${typeof value}`); | ||
}; |
23 changes: 23 additions & 0 deletions
23
test/built-ins/Temporal/Instant/prototype/until/options-wrong-type.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,23 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.instant.prototype.until | ||
description: TypeError thrown when options argument is a primitive | ||
features: [BigInt, Symbol, Temporal] | ||
---*/ | ||
|
||
const badOptions = [ | ||
null, | ||
true, | ||
"some string", | ||
Symbol(), | ||
1, | ||
2n, | ||
]; | ||
|
||
const instance = new Temporal.Instant(0n); | ||
for (const value of badOptions) { | ||
assert.throws(TypeError, () => instance.until(new Temporal.Instant(3600_000_000_000n), value), | ||
`TypeError on wrong options type ${typeof value}`); | ||
}; |
22 changes: 22 additions & 0 deletions
22
test/built-ins/Temporal/PlainDate/from/options-wrong-type.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,22 @@ | ||
// Copyright (C) 2022 Igalia, S.L. All rights reserved. | ||
// This code is governed by the BSD license found in the LICENSE file. | ||
|
||
/*--- | ||
esid: sec-temporal.plaindate.from | ||
description: TypeError thrown when options argument is a primitive | ||
features: [BigInt, Symbol, Temporal] | ||
---*/ | ||
|
||
const badOptions = [ | ||
null, | ||
true, | ||
"some string", | ||
Symbol(), | ||
1, | ||
2n, | ||
]; | ||
|
||
for (const value of badOptions) { | ||
assert.throws(TypeError, () => Temporal.PlainDate.from({ year: 1976, month: 11, day: 18 }, value), | ||
`TypeError on wrong options type ${typeof value}`); | ||
}; |
Oops, something went wrong.