Skip to content

Commit

Permalink
Add tests for Temporal options bags being of the wrong type
Browse files Browse the repository at this point in the history
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
ptomato authored and Ms2ger committed Apr 13, 2022
1 parent 9f30311 commit 4ac16c2
Show file tree
Hide file tree
Showing 56 changed files with 1,239 additions and 20 deletions.
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}`);
};
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}`);
};
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}`);
};
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}`);
};
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 test/built-ins/Temporal/Duration/compare/options-wrong-type.js
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}`);
};
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}`);
};
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}`);
};
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}`);
};
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}`);
};
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// 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.total
description: TypeError thrown when options argument is missing or a primitive
description: TypeError thrown when options argument is missing or a non-string primitive
features: [BigInt, Symbol, Temporal]
---*/

const values = [
const badOptions = [
undefined,
null,
true,
Expand All @@ -17,7 +17,8 @@ const values = [
];

const instance = new Temporal.Duration(0, 0, 0, 0, 1);
assert.throws(TypeError, () => instance.total(), "TypeError on missing argument");
values.forEach((value) => {
assert.throws(TypeError, () => instance.total(value), `TypeError on wrong argument type ${typeof(value)}`);
});
assert.throws(TypeError, () => instance.total(), "TypeError on missing options argument");
for (const value of badOptions) {
assert.throws(TypeError, () => instance.total(value),
`TypeError on wrong options type ${typeof value}`);
};
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
// 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.round
description: TypeError thrown when options argument is missing or a primitive
features: [Symbol, Temporal]
description: TypeError thrown when options argument is missing or a non-string primitive
features: [BigInt, Symbol, Temporal]
---*/

const values = [
const badOptions = [
undefined,
null,
true,
Expand All @@ -17,7 +17,8 @@ const values = [
];

const instance = new Temporal.Instant(0n);
assert.throws(TypeError, () => instance.round(), "missing argument");
for (const value of values) {
assert.throws(TypeError, () => instance.round(value), `argument ${String(value)}`);
}
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}`);
};
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}`);
};
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}`);
};
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 test/built-ins/Temporal/PlainDate/from/options-wrong-type.js
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}`);
};
Loading

0 comments on commit 4ac16c2

Please sign in to comment.