mirror of https://github.com/tc39/test262.git
Add tests for temporalDurationLike argument and improve existing tests
This commit is contained in:
parent
e41d581c6d
commit
dadf18f416
|
@ -0,0 +1,28 @@
|
|||
// 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: temporalDurationLike object must contain at least one correctly spelled property
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.add({}),
|
||||
"Throws TypeError if no property is present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.add({ nonsense: true }),
|
||||
"Throws TypeError if no recognized property is present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.add({ sign: 1 }),
|
||||
"Sign property is not recognized"
|
||||
);
|
|
@ -0,0 +1,17 @@
|
|||
// 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: Positive and negative values in the temporalDurationLike argument are not acceptable
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321);
|
||||
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.add({ hours: 1, minutes: -30 }),
|
||||
`mixed positive and negative values always throw`
|
||||
);
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
// 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: Passing a primitive other than string to add() throws
|
||||
features: [Symbol, Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321);
|
||||
assert.throws(RangeError, () => instance.add(undefined), "undefined");
|
||||
assert.throws(RangeError, () => instance.add(null), "null");
|
||||
assert.throws(RangeError, () => instance.add(true), "boolean");
|
||||
assert.throws(RangeError, () => instance.add(""), "empty string");
|
||||
assert.throws(TypeError, () => instance.add(Symbol()), "Symbol");
|
||||
assert.throws(RangeError, () => instance.add(7), "number");
|
||||
assert.throws(RangeError, () => instance.add(7n), "bigint");
|
||||
assert.throws(TypeError, () => instance.add([]), "array");
|
||||
assert.throws(TypeError, () => instance.add(() => {}), "function");
|
|
@ -1,13 +0,0 @@
|
|||
// 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: Mixed positive and negative values or missing properties always throw
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const duration = Temporal.Duration.from({ days: 1, minutes: 5 });
|
||||
assert.throws(RangeError, () => duration.add({ hours: 1, minutes: -30 }), "mixed signs");
|
||||
assert.throws(TypeError, () => duration.add({}), "no properties");
|
||||
assert.throws(TypeError, () => duration.add({ month: 12 }), "only singular 'month' property");
|
27
test/built-ins/Temporal/Duration/prototype/add/argument-singular-properties.js
vendored
Normal file
27
test/built-ins/Temporal/Duration/prototype/add/argument-singular-properties.js
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
// 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: Singular properties in the property bag are always ignored
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321);
|
||||
|
||||
[
|
||||
{ year: 1 },
|
||||
{ month: 2 },
|
||||
{ week: 3 },
|
||||
{ day: 4 },
|
||||
{ hour: 5 },
|
||||
{ minute: 6 },
|
||||
{ second: 7 },
|
||||
{ millisecond: 8 },
|
||||
{ microsecond: 9 },
|
||||
{ nanosecond: 10 },
|
||||
].forEach((badObject) => {
|
||||
assert.throws(TypeError, () => instance.add(badObject),
|
||||
"Throw TypeError if temporalDurationLike is not valid");
|
||||
});
|
||||
|
|
@ -7,7 +7,7 @@ description: A non-integer value for any recognized property in the property bag
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321);
|
||||
const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321);
|
||||
const fields = [
|
||||
"years",
|
||||
"months",
|
||||
|
|
28
test/built-ins/Temporal/Duration/prototype/subtract/argument-invalid-property.js
vendored
Normal file
28
test/built-ins/Temporal/Duration/prototype/subtract/argument-invalid-property.js
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
// 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: temporalDurationLike object must contain at least one correctly spelled property
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.subtract({}),
|
||||
"Throws TypeError if no property is present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.subtract({ nonsense: true }),
|
||||
"Throws TypeError if no recognized property is present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.subtract({ sign: 1 }),
|
||||
"Sign property is not recognized"
|
||||
);
|
|
@ -0,0 +1,16 @@
|
|||
// 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: Positive and negative values in the temporalDurationLike argument are not acceptable
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321);
|
||||
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.subtract({ hours: 1, minutes: -30 }),
|
||||
`mixed positive and negative values always throw`
|
||||
);
|
|
@ -0,0 +1,19 @@
|
|||
// 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: Passing a primitive other than string to subtract() throws
|
||||
features: [Symbol, Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321);
|
||||
assert.throws(RangeError, () => instance.subtract(undefined), "undefined");
|
||||
assert.throws(RangeError, () => instance.subtract(null), "null");
|
||||
assert.throws(RangeError, () => instance.subtract(true), "boolean");
|
||||
assert.throws(RangeError, () => instance.subtract(""), "empty string");
|
||||
assert.throws(TypeError, () => instance.subtract(Symbol()), "Symbol");
|
||||
assert.throws(RangeError, () => instance.subtract(7), "number");
|
||||
assert.throws(RangeError, () => instance.subtract(7n), "bigint");
|
||||
assert.throws(TypeError, () => instance.subtract([]), "array");
|
||||
assert.throws(TypeError, () => instance.subtract(() => {}), "function");
|
|
@ -1,13 +0,0 @@
|
|||
// 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: Mixed positive and negative values or missing properties always throw
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const duration = Temporal.Duration.from({ days: 1, minutes: 5 });
|
||||
assert.throws(RangeError, () => duration.subtract({ hours: 1, minutes: -30 }), "mixed signs");
|
||||
assert.throws(TypeError, () => duration.subtract({}), "no properties");
|
||||
assert.throws(TypeError, () => duration.subtract({ month: 12 }), "only singular 'month' property");
|
27
test/built-ins/Temporal/Duration/prototype/subtract/argument-singular-properties.js
vendored
Normal file
27
test/built-ins/Temporal/Duration/prototype/subtract/argument-singular-properties.js
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
// 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: Singular properties in the property bag are always ignored
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321);
|
||||
|
||||
[
|
||||
{ year: 1 },
|
||||
{ month: 2 },
|
||||
{ week: 3 },
|
||||
{ day: 4 },
|
||||
{ hour: 5 },
|
||||
{ minute: 6 },
|
||||
{ second: 7 },
|
||||
{ millisecond: 8 },
|
||||
{ microsecond: 9 },
|
||||
{ nanosecond: 10 },
|
||||
].forEach((badObject) => {
|
||||
assert.throws(TypeError, () => instance.subtract(badObject),
|
||||
"Throw TypeError if temporalDurationLike is not valid");
|
||||
});
|
||||
|
|
@ -7,7 +7,7 @@ description: A non-integer value for any recognized property in the property bag
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321);
|
||||
const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321);
|
||||
const fields = [
|
||||
"years",
|
||||
"months",
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
// 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.with
|
||||
description: Singular properties are ignored.
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const d = Temporal.Duration.from({ years: 5, days: 1 });
|
||||
const d2 = d.with({ year: 1, days: 0 });
|
||||
TemporalHelpers.assertDuration(d2, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
28
test/built-ins/Temporal/Duration/prototype/with/argument-invalid-property.js
vendored
Normal file
28
test/built-ins/Temporal/Duration/prototype/with/argument-invalid-property.js
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
// 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.with
|
||||
description: temporalDurationLike object must contain at least one correctly spelled property
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.with({}),
|
||||
"Throws TypeError if no property is present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.with({ nonsense: true }),
|
||||
"Throws TypeError if no recognized property is present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.with({ sign: 1 }),
|
||||
"Sign property is not recognized"
|
||||
);
|
|
@ -3,9 +3,14 @@
|
|||
|
||||
/*---
|
||||
esid: sec-temporal.duration.prototype.with
|
||||
description: The durationLike argument must not contain different signs.
|
||||
description: Positive and negative values in the temporalDurationLike argument are not acceptable
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const d = new Temporal.Duration(1, 2, 3, 4, 5);
|
||||
assert.throws(RangeError, () => d.with({ hours: 1, minutes: -1 }));
|
||||
const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321);
|
||||
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.with({ hours: 1, minutes: -30 }),
|
||||
`mixed positive and negative values always throw`
|
||||
);
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
// 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.with
|
||||
description: Passing a primitive other than string to with() throws
|
||||
features: [Symbol, Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321);
|
||||
assert.throws(TypeError, () => instance.with(undefined), "undefined");
|
||||
assert.throws(TypeError, () => instance.with(null), "null");
|
||||
assert.throws(TypeError, () => instance.with(true), "boolean");
|
||||
assert.throws(TypeError, () => instance.with(""), "empty string");
|
||||
assert.throws(TypeError, () => instance.with(Symbol()), "Symbol");
|
||||
assert.throws(TypeError, () => instance.with(7), "number");
|
||||
assert.throws(TypeError, () => instance.with(7n), "bigint");
|
||||
assert.throws(TypeError, () => instance.with([]), "array");
|
||||
assert.throws(TypeError, () => instance.with(() => {}), "function");
|
||||
assert.throws(TypeError, () => instance.with("string"), "string");
|
|
@ -1,14 +0,0 @@
|
|||
// 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.with
|
||||
description: Passing a sign property is not supported.
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const d = Temporal.Duration.from({ years: 5, days: 1 });
|
||||
assert.throws(TypeError, () => d.with({ sign: -1 }));
|
||||
const d2 = d.with({ sign: -1, days: 0 });
|
||||
TemporalHelpers.assertDuration(d2, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
@ -1,20 +1,16 @@
|
|||
// Copyright (C) 2021 the V8 project authors. 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.with
|
||||
description: >
|
||||
The durationLike argument must contain at least one correctly spelled property
|
||||
description: Singular properties in the property bag are always ignored
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
let d = new Temporal.Duration(1, 2, 3, 4, 5);
|
||||
const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321);
|
||||
|
||||
[
|
||||
{},
|
||||
[],
|
||||
() => {},
|
||||
// objects with only singular keys (plural is the correct spelling)
|
||||
{ year: 1 },
|
||||
{ month: 2 },
|
||||
{ week: 3 },
|
||||
|
@ -26,6 +22,7 @@ let d = new Temporal.Duration(1, 2, 3, 4, 5);
|
|||
{ microsecond: 9 },
|
||||
{ nanosecond: 10 },
|
||||
].forEach((badObject) => {
|
||||
assert.throws(TypeError, () => d.with(badObject),
|
||||
assert.throws(TypeError, () => instance.with(badObject),
|
||||
"Throw TypeError if temporalDurationLike is not valid");
|
||||
});
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
// Copyright (C) 2021 the V8 project authors. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.duration.prototype.with
|
||||
description: Throw TypeError if the temporalDurationLike argument is the wrong type
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
let d = new Temporal.Duration(1, 2, 3, 4, 5);
|
||||
|
||||
[
|
||||
"string",
|
||||
"P1YT1M",
|
||||
true,
|
||||
false,
|
||||
NaN,
|
||||
Infinity,
|
||||
undefined,
|
||||
null,
|
||||
123,
|
||||
Symbol(),
|
||||
456n,
|
||||
].forEach((badInput) => {
|
||||
assert.throws(TypeError, () => d.with(badInput),
|
||||
"Throw TypeError if temporalDurationLike is not valid");
|
||||
});
|
|
@ -7,7 +7,7 @@ description: A non-integer value for any recognized property in the property bag
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321);
|
||||
const instance = new Temporal.Duration(0, 0, 0, 1, 2, 3, 4, 987, 654, 321);
|
||||
const fields = [
|
||||
"years",
|
||||
"months",
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
// 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.add
|
||||
description: temporalDurationLike object must contain at least one correctly spelled property
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Instant(1_000_000_000_000_000_000n);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.add({}),
|
||||
"Throws TypeError if no property is present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.add({ nonsense: true }),
|
||||
"Throws TypeError if no recognized property is present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.add({ sign: 1 }),
|
||||
"Sign property is not recognized"
|
||||
);
|
|
@ -0,0 +1,16 @@
|
|||
// 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.add
|
||||
description: Positive and negative values in the temporalDurationLike argument are not acceptable
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Instant(1_000_000_000_000_000_000n);
|
||||
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.add({ hours: 1, minutes: -30 }),
|
||||
`mixed positive and negative values always throw`
|
||||
);
|
|
@ -0,0 +1,19 @@
|
|||
// 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.add
|
||||
description: Passing a primitive other than string to add() throws
|
||||
features: [Symbol, Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Instant(1_000_000_000_000_000_000n);
|
||||
assert.throws(RangeError, () => instance.add(undefined), "undefined");
|
||||
assert.throws(RangeError, () => instance.add(null), "null");
|
||||
assert.throws(RangeError, () => instance.add(true), "boolean");
|
||||
assert.throws(RangeError, () => instance.add(""), "empty string");
|
||||
assert.throws(TypeError, () => instance.add(Symbol()), "Symbol");
|
||||
assert.throws(RangeError, () => instance.add(7), "number");
|
||||
assert.throws(RangeError, () => instance.add(7n), "bigint");
|
||||
assert.throws(TypeError, () => instance.add([]), "array");
|
||||
assert.throws(TypeError, () => instance.add(() => {}), "function");
|
27
test/built-ins/Temporal/Instant/prototype/add/argument-singular-properties.js
vendored
Normal file
27
test/built-ins/Temporal/Instant/prototype/add/argument-singular-properties.js
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
// 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.add
|
||||
description: Singular properties in the property bag are always ignored
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Instant(1_000_000_000_000_000_000n);
|
||||
|
||||
[
|
||||
{ year: 1 },
|
||||
{ month: 2 },
|
||||
{ week: 3 },
|
||||
{ day: 4 },
|
||||
{ hour: 5 },
|
||||
{ minute: 6 },
|
||||
{ second: 7 },
|
||||
{ millisecond: 8 },
|
||||
{ microsecond: 9 },
|
||||
{ nanosecond: 10 },
|
||||
].forEach((badObject) => {
|
||||
assert.throws(TypeError, () => instance.add(badObject),
|
||||
"Throw TypeError if temporalDurationLike is not valid");
|
||||
});
|
||||
|
28
test/built-ins/Temporal/Instant/prototype/subtract/argument-invalid-property.js
vendored
Normal file
28
test/built-ins/Temporal/Instant/prototype/subtract/argument-invalid-property.js
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
// 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.subtract
|
||||
description: temporalDurationLike object must contain at least one correctly spelled property
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Instant(1_000_000_000_000_000_000n);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.subtract({}),
|
||||
"Throws TypeError if no property is present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.subtract({ nonsense: true }),
|
||||
"Throws TypeError if no recognized property is present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.subtract({ sign: 1 }),
|
||||
"Sign property is not recognized"
|
||||
);
|
|
@ -0,0 +1,16 @@
|
|||
// 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.subtract
|
||||
description: Positive and negative values in the temporalDurationLike argument are not acceptable
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Instant(1_000_000_000_000_000_000n);
|
||||
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.subtract({ hours: 1, minutes: -30 }),
|
||||
`mixed positive and negative values always throw`
|
||||
);
|
|
@ -0,0 +1,19 @@
|
|||
// 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.subtract
|
||||
description: Passing a primitive other than string to subtract() throws
|
||||
features: [Symbol, Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Instant(1_000_000_000_000_000_000n);
|
||||
assert.throws(RangeError, () => instance.subtract(undefined), "undefined");
|
||||
assert.throws(RangeError, () => instance.subtract(null), "null");
|
||||
assert.throws(RangeError, () => instance.subtract(true), "boolean");
|
||||
assert.throws(RangeError, () => instance.subtract(""), "empty string");
|
||||
assert.throws(TypeError, () => instance.subtract(Symbol()), "Symbol");
|
||||
assert.throws(RangeError, () => instance.subtract(7), "number");
|
||||
assert.throws(RangeError, () => instance.subtract(7n), "bigint");
|
||||
assert.throws(TypeError, () => instance.subtract([]), "array");
|
||||
assert.throws(TypeError, () => instance.subtract(() => {}), "function");
|
27
test/built-ins/Temporal/Instant/prototype/subtract/argument-singular-properties.js
vendored
Normal file
27
test/built-ins/Temporal/Instant/prototype/subtract/argument-singular-properties.js
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
// 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.subtract
|
||||
description: Singular properties in the property bag are always ignored
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Instant(1_000_000_000_000_000_000n);
|
||||
|
||||
[
|
||||
{ year: 1 },
|
||||
{ month: 2 },
|
||||
{ week: 3 },
|
||||
{ day: 4 },
|
||||
{ hour: 5 },
|
||||
{ minute: 6 },
|
||||
{ second: 7 },
|
||||
{ millisecond: 8 },
|
||||
{ microsecond: 9 },
|
||||
{ nanosecond: 10 },
|
||||
].forEach((badObject) => {
|
||||
assert.throws(TypeError, () => instance.subtract(badObject),
|
||||
"Throw TypeError if temporalDurationLike is not valid");
|
||||
});
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
// 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.prototype.add
|
||||
description: RangeError thrown when signs don't match in the duration
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const calendar = TemporalHelpers.calendarThrowEverything();
|
||||
const date = new Temporal.PlainDate(2000, 5, 2, calendar);
|
||||
const duration = { months: 1, days: -30 };
|
||||
for (const overflow of ["constrain", "reject"]) {
|
||||
assert.throws(RangeError, () => date.add(duration, { overflow }));
|
||||
}
|
28
test/built-ins/Temporal/PlainDate/prototype/add/argument-invalid-property.js
vendored
Normal file
28
test/built-ins/Temporal/PlainDate/prototype/add/argument-invalid-property.js
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
// 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.prototype.add
|
||||
description: temporalDurationLike object must contain at least one correctly spelled property
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDate(2000, 5, 2);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.add({}),
|
||||
"Throws TypeError if no property is present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.add({ nonsense: true }),
|
||||
"Throws TypeError if no recognized property is present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.add({ sign: 1 }),
|
||||
"Sign property is not recognized"
|
||||
);
|
|
@ -1,18 +0,0 @@
|
|||
// 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.prototype.add
|
||||
description: TypeError for missing properties
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const date = new Temporal.PlainDate(2000, 5, 2);
|
||||
const options = {
|
||||
get overflow() {
|
||||
TemporalHelpers.assertUnreachable("should not get overflow");
|
||||
}
|
||||
};
|
||||
assert.throws(TypeError, () => date.add({}, options), "empty object");
|
||||
assert.throws(TypeError, () => date.add({ month: 12 }, options), "misspelled 'months'");
|
|
@ -0,0 +1,18 @@
|
|||
// 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.prototype.add
|
||||
description: Positive and negative values in the temporalDurationLike argument are not acceptable
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDate(2000, 5, 2);
|
||||
|
||||
["constrain", "reject"].forEach((overflow) => {
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.add({ hours: 1, minutes: -30 }, { overflow }),
|
||||
`mixed positive and negative values always throw (overflow = "${overflow}")`
|
||||
);
|
||||
});
|
|
@ -7,7 +7,7 @@ description: Passing a primitive other than string to add() throws
|
|||
features: [Symbol, Temporal]
|
||||
---*/
|
||||
|
||||
const instance = Temporal.PlainDate.from({ year: 2000, month: 5, day: 2 });
|
||||
const instance = new Temporal.PlainDate(2000, 5, 2);
|
||||
assert.throws(RangeError, () => instance.add(undefined), "undefined");
|
||||
assert.throws(RangeError, () => instance.add(null), "null");
|
||||
assert.throws(RangeError, () => instance.add(true), "boolean");
|
||||
|
@ -15,3 +15,5 @@ assert.throws(RangeError, () => instance.add(""), "empty string");
|
|||
assert.throws(TypeError, () => instance.add(Symbol()), "Symbol");
|
||||
assert.throws(RangeError, () => instance.add(7), "number");
|
||||
assert.throws(RangeError, () => instance.add(7n), "bigint");
|
||||
assert.throws(TypeError, () => instance.add([]), "array");
|
||||
assert.throws(TypeError, () => instance.add(() => {}), "function");
|
||||
|
|
27
test/built-ins/Temporal/PlainDate/prototype/add/argument-singular-properties.js
vendored
Normal file
27
test/built-ins/Temporal/PlainDate/prototype/add/argument-singular-properties.js
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
// 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.prototype.add
|
||||
description: Singular properties in the property bag are always ignored
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDate(2000, 5, 2);
|
||||
|
||||
[
|
||||
{ year: 1 },
|
||||
{ month: 2 },
|
||||
{ week: 3 },
|
||||
{ day: 4 },
|
||||
{ hour: 5 },
|
||||
{ minute: 6 },
|
||||
{ second: 7 },
|
||||
{ millisecond: 8 },
|
||||
{ microsecond: 9 },
|
||||
{ nanosecond: 10 },
|
||||
].forEach((badObject) => {
|
||||
assert.throws(TypeError, () => instance.add(badObject),
|
||||
"Throw TypeError if temporalDurationLike is not valid");
|
||||
});
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
// 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.prototype.add
|
||||
description: Ignores singular properties
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const date = Temporal.PlainDate.from("2019-11-18");
|
||||
TemporalHelpers.assertPlainDate(date.add({ month: 1, days: 1 }),
|
||||
2019, 11, "M11", 19);
|
|
@ -1,16 +0,0 @@
|
|||
// 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.prototype.subtract
|
||||
description: RangeError thrown when signs don't match in the duration
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const calendar = TemporalHelpers.calendarThrowEverything();
|
||||
const date = new Temporal.PlainDate(2000, 5, 2, calendar);
|
||||
const duration = { months: 1, days: -30 };
|
||||
for (const overflow of ["constrain", "reject"]) {
|
||||
assert.throws(RangeError, () => date.subtract(duration, { overflow }));
|
||||
}
|
28
test/built-ins/Temporal/PlainDate/prototype/subtract/argument-invalid-property.js
vendored
Normal file
28
test/built-ins/Temporal/PlainDate/prototype/subtract/argument-invalid-property.js
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
// 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.prototype.subtract
|
||||
description: temporalDurationLike object must contain at least one correctly spelled property
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDate(2000, 5, 2);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.subtract({}),
|
||||
"Throws TypeError if no property is present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.subtract({ nonsense: true }),
|
||||
"Throws TypeError if no recognized property is present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.subtract({ sign: 1 }),
|
||||
"Sign property is not recognized"
|
||||
);
|
|
@ -1,18 +0,0 @@
|
|||
// 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.prototype.subtract
|
||||
description: TypeError for missing properties
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const date = new Temporal.PlainDate(2000, 5, 2);
|
||||
const options = {
|
||||
get overflow() {
|
||||
TemporalHelpers.assertUnreachable("should not get overflow");
|
||||
}
|
||||
};
|
||||
assert.throws(TypeError, () => date.subtract({}, options), "empty object");
|
||||
assert.throws(TypeError, () => date.subtract({ month: 12 }, options), "misspelled 'months'");
|
|
@ -0,0 +1,18 @@
|
|||
// 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.prototype.subtract
|
||||
description: Positive and negative values in the temporalDurationLike argument are not acceptable
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDate(2000, 5, 2);
|
||||
|
||||
["constrain", "reject"].forEach((overflow) => {
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.subtract({ hours: 1, minutes: -30 }, { overflow }),
|
||||
`mixed positive and negative values always throw (overflow = "${overflow}")`
|
||||
);
|
||||
});
|
|
@ -7,7 +7,7 @@ description: Passing a primitive other than string to subtract() throws
|
|||
features: [Symbol, Temporal]
|
||||
---*/
|
||||
|
||||
const instance = Temporal.PlainDate.from({ year: 2000, month: 5, day: 2 });
|
||||
const instance = new Temporal.PlainDate(2000, 5, 2);
|
||||
assert.throws(RangeError, () => instance.subtract(undefined), "undefined");
|
||||
assert.throws(RangeError, () => instance.subtract(null), "null");
|
||||
assert.throws(RangeError, () => instance.subtract(true), "boolean");
|
||||
|
@ -15,3 +15,5 @@ assert.throws(RangeError, () => instance.subtract(""), "empty string");
|
|||
assert.throws(TypeError, () => instance.subtract(Symbol()), "Symbol");
|
||||
assert.throws(RangeError, () => instance.subtract(7), "number");
|
||||
assert.throws(RangeError, () => instance.subtract(7n), "bigint");
|
||||
assert.throws(TypeError, () => instance.subtract([]), "array");
|
||||
assert.throws(TypeError, () => instance.subtract(() => {}), "function");
|
||||
|
|
27
test/built-ins/Temporal/PlainDate/prototype/subtract/argument-singular-properties.js
vendored
Normal file
27
test/built-ins/Temporal/PlainDate/prototype/subtract/argument-singular-properties.js
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
// 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.prototype.subtract
|
||||
description: Singular properties in the property bag are always ignored
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDate(2000, 5, 2);
|
||||
|
||||
[
|
||||
{ year: 1 },
|
||||
{ month: 2 },
|
||||
{ week: 3 },
|
||||
{ day: 4 },
|
||||
{ hour: 5 },
|
||||
{ minute: 6 },
|
||||
{ second: 7 },
|
||||
{ millisecond: 8 },
|
||||
{ microsecond: 9 },
|
||||
{ nanosecond: 10 },
|
||||
].forEach((badObject) => {
|
||||
assert.throws(TypeError, () => instance.subtract(badObject),
|
||||
"Throw TypeError if temporalDurationLike is not valid");
|
||||
});
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
// 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.prototype.subtract
|
||||
description: Ignores singular properties
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const date = Temporal.PlainDate.from("2019-11-18");
|
||||
TemporalHelpers.assertPlainDate(date.subtract({ month: 1, days: 1 }),
|
||||
2019, 11, "M11", 17);
|
28
test/built-ins/Temporal/PlainDateTime/prototype/add/argument-invalid-property.js
vendored
Normal file
28
test/built-ins/Temporal/PlainDateTime/prototype/add/argument-invalid-property.js
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
// 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.plaindatetime.prototype.add
|
||||
description: temporalDurationLike object must contain at least one correctly spelled property
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDateTime(2000, 5, 2, 15, 30, 45, 987, 654, 321);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.add({}),
|
||||
"Throws TypeError if no property is present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.add({ nonsense: true }),
|
||||
"Throws TypeError if no recognized property is present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.add({ sign: 1 }),
|
||||
"Sign property is not recognized"
|
||||
);
|
|
@ -7,12 +7,12 @@ description: Positive and negative values in the temporalDurationLike argument a
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const jan31 = new Temporal.PlainDateTime(2020, 1, 31, 15, 0);
|
||||
const instance = new Temporal.PlainDateTime(2000, 5, 2, 15, 30, 45, 987, 654, 321);
|
||||
|
||||
["constrain", "reject"].forEach((overflow) => {
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => jan31.add({ hours: 1, minutes: -30 }, { overflow }),
|
||||
() => instance.add({ hours: 1, minutes: -30 }, { overflow }),
|
||||
`mixed positive and negative values always throw (overflow = "${overflow}")`
|
||||
);
|
||||
});
|
|
@ -7,7 +7,7 @@ description: Passing a primitive other than string to add() throws
|
|||
features: [Symbol, Temporal]
|
||||
---*/
|
||||
|
||||
const instance = Temporal.PlainDateTime.from({ year: 2000, month: 5, day: 2, minute: 34, second: 56, millisecond: 987, microsecond: 654, nanosecond: 321 });
|
||||
const instance = new Temporal.PlainDateTime(2000, 5, 2, 15, 30, 45, 987, 654, 321);
|
||||
assert.throws(RangeError, () => instance.add(undefined), "undefined");
|
||||
assert.throws(RangeError, () => instance.add(null), "null");
|
||||
assert.throws(RangeError, () => instance.add(true), "boolean");
|
||||
|
@ -15,3 +15,5 @@ assert.throws(RangeError, () => instance.add(""), "empty string");
|
|||
assert.throws(TypeError, () => instance.add(Symbol()), "Symbol");
|
||||
assert.throws(RangeError, () => instance.add(7), "number");
|
||||
assert.throws(RangeError, () => instance.add(7n), "bigint");
|
||||
assert.throws(TypeError, () => instance.add([]), "array");
|
||||
assert.throws(TypeError, () => instance.add(() => {}), "function");
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
// 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.plaindatetime.prototype.add
|
||||
description: At least one recognized property has to be present in argument
|
||||
features: [Temporal]
|
||||
includes: [temporalHelpers.js]
|
||||
---*/
|
||||
|
||||
const jan31 = new Temporal.PlainDateTime(2020, 1, 31, 15, 0);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => jan31.add({}),
|
||||
"empty object not acceptable"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => jan31.add({ month: 12 }), // should be "months"
|
||||
"misspelled property in argument throws if no other properties are present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => jan31.add({ nonsense: true }),
|
||||
"unrecognized properties throw if no other recognized property is present"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
jan31.add({ nonsense: 1, days: 1 }),
|
||||
2020, 2, "M02", 1, 15, 0, 0, 0, 0, 0,
|
||||
"unrecognized properties ignored provided at least one recognized property is present"
|
||||
);
|
27
test/built-ins/Temporal/PlainDateTime/prototype/add/argument-singular-properties.js
vendored
Normal file
27
test/built-ins/Temporal/PlainDateTime/prototype/add/argument-singular-properties.js
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
// 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.plaindatetime.prototype.add
|
||||
description: Singular properties in the property bag are always ignored
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDateTime(2000, 5, 2, 15, 30, 45, 987, 654, 321);
|
||||
|
||||
[
|
||||
{ year: 1 },
|
||||
{ month: 2 },
|
||||
{ week: 3 },
|
||||
{ day: 4 },
|
||||
{ hour: 5 },
|
||||
{ minute: 6 },
|
||||
{ second: 7 },
|
||||
{ millisecond: 8 },
|
||||
{ microsecond: 9 },
|
||||
{ nanosecond: 10 },
|
||||
].forEach((badObject) => {
|
||||
assert.throws(TypeError, () => instance.add(badObject),
|
||||
"Throw TypeError if temporalDurationLike is not valid");
|
||||
});
|
||||
|
28
test/built-ins/Temporal/PlainDateTime/prototype/subtract/argument-invalid-property.js
vendored
Normal file
28
test/built-ins/Temporal/PlainDateTime/prototype/subtract/argument-invalid-property.js
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
// 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.plaindatetime.prototype.subtract
|
||||
description: temporalDurationLike object must contain at least one correctly spelled property
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDateTime(2000, 5, 2, 15, 30, 45, 987, 654, 321);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.subtract({}),
|
||||
"Throws TypeError if no property is present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.subtract({ nonsense: true }),
|
||||
"Throws TypeError if no recognized property is present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.subtract({ sign: 1 }),
|
||||
"Sign property is not recognized"
|
||||
);
|
|
@ -7,12 +7,12 @@ description: Positive and negative values in the temporalDurationLike argument a
|
|||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const jan31 = new Temporal.PlainDateTime(2020, 1, 31, 15, 0);
|
||||
const instance = new Temporal.PlainDateTime(2000, 5, 2, 15, 30, 45, 987, 654, 321);
|
||||
|
||||
["constrain", "reject"].forEach((overflow) => {
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => jan31.subtract({ hours: 1, minutes: -30 }, { overflow }),
|
||||
() => instance.subtract({ hours: 1, minutes: -30 }, { overflow }),
|
||||
`mixed positive and negative values always throw (overflow = "${overflow}")`
|
||||
);
|
||||
});
|
|
@ -7,7 +7,7 @@ description: Passing a primitive other than string to subtract() throws
|
|||
features: [Symbol, Temporal]
|
||||
---*/
|
||||
|
||||
const instance = Temporal.PlainDateTime.from({ year: 2000, month: 5, day: 2, minute: 34, second: 56, millisecond: 987, microsecond: 654, nanosecond: 321 });
|
||||
const instance = new Temporal.PlainDateTime(2000, 5, 2, 15, 30, 45, 987, 654, 321);
|
||||
assert.throws(RangeError, () => instance.subtract(undefined), "undefined");
|
||||
assert.throws(RangeError, () => instance.subtract(null), "null");
|
||||
assert.throws(RangeError, () => instance.subtract(true), "boolean");
|
||||
|
@ -15,3 +15,5 @@ assert.throws(RangeError, () => instance.subtract(""), "empty string");
|
|||
assert.throws(TypeError, () => instance.subtract(Symbol()), "Symbol");
|
||||
assert.throws(RangeError, () => instance.subtract(7), "number");
|
||||
assert.throws(RangeError, () => instance.subtract(7n), "bigint");
|
||||
assert.throws(TypeError, () => instance.subtract([]), "array");
|
||||
assert.throws(TypeError, () => instance.subtract(() => {}), "function");
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
// 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.plaindatetime.prototype.subtract
|
||||
description: At least one recognized property has to be present in argument
|
||||
features: [Temporal]
|
||||
includes: [temporalHelpers.js]
|
||||
---*/
|
||||
|
||||
const jan31 = new Temporal.PlainDateTime(2020, 1, 31, 15, 0);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => jan31.subtract({}),
|
||||
"empty object not acceptable"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => jan31.subtract({ month: 12 }), // should be "months"
|
||||
"misspelled property in argument throws if no other properties are present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => jan31.subtract({ nonsense: true }),
|
||||
"unrecognized properties throw if no other recognized property is present"
|
||||
);
|
||||
|
||||
TemporalHelpers.assertPlainDateTime(
|
||||
jan31.subtract({ nonsense: 1, days: 1 }),
|
||||
2020, 1, "M01", 30, 15, 0, 0, 0, 0, 0,
|
||||
"unrecognized properties ignored provided at least one recognized property is present"
|
||||
);
|
27
test/built-ins/Temporal/PlainDateTime/prototype/subtract/argument-singular-properties.js
vendored
Normal file
27
test/built-ins/Temporal/PlainDateTime/prototype/subtract/argument-singular-properties.js
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
// 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.plaindatetime.prototype.subtract
|
||||
description: Singular properties in the property bag are always ignored
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDateTime(2000, 5, 2, 15, 30, 45, 987, 654, 321);
|
||||
|
||||
[
|
||||
{ year: 1 },
|
||||
{ month: 2 },
|
||||
{ week: 3 },
|
||||
{ day: 4 },
|
||||
{ hour: 5 },
|
||||
{ minute: 6 },
|
||||
{ second: 7 },
|
||||
{ millisecond: 8 },
|
||||
{ microsecond: 9 },
|
||||
{ nanosecond: 10 },
|
||||
].forEach((badObject) => {
|
||||
assert.throws(TypeError, () => instance.subtract(badObject),
|
||||
"Throw TypeError if temporalDurationLike is not valid");
|
||||
});
|
||||
|
28
test/built-ins/Temporal/PlainTime/prototype/add/argument-invalid-property.js
vendored
Normal file
28
test/built-ins/Temporal/PlainTime/prototype/add/argument-invalid-property.js
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
// 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.plaintime.prototype.add
|
||||
description: temporalDurationLike object must contain at least one correctly spelled property
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainTime(15, 30, 45, 987, 654, 321);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.add({}),
|
||||
"Throws TypeError if no property is present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.add({ nonsense: true }),
|
||||
"Throws TypeError if no recognized property is present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.add({ sign: 1 }),
|
||||
"Sign property is not recognized"
|
||||
);
|
|
@ -0,0 +1,16 @@
|
|||
// 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.plaintime.prototype.add
|
||||
description: Positive and negative values in the temporalDurationLike argument are not acceptable
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainTime(15, 30, 45, 987, 654, 321);
|
||||
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.add({ hours: 1, minutes: -30 }),
|
||||
`mixed positive and negative values always throw`
|
||||
);
|
|
@ -7,7 +7,7 @@ description: Passing a primitive other than string to add() throws
|
|||
features: [Symbol, Temporal]
|
||||
---*/
|
||||
|
||||
const instance = Temporal.PlainTime.from({ hour: 12, minute: 34, second: 56, millisecond: 987, microsecond: 654, nanosecond: 321 });
|
||||
const instance = new Temporal.PlainTime(15, 30, 45, 987, 654, 321);
|
||||
assert.throws(RangeError, () => instance.add(undefined), "undefined");
|
||||
assert.throws(RangeError, () => instance.add(null), "null");
|
||||
assert.throws(RangeError, () => instance.add(true), "boolean");
|
||||
|
@ -15,3 +15,5 @@ assert.throws(RangeError, () => instance.add(""), "empty string");
|
|||
assert.throws(TypeError, () => instance.add(Symbol()), "Symbol");
|
||||
assert.throws(RangeError, () => instance.add(7), "number");
|
||||
assert.throws(RangeError, () => instance.add(7n), "bigint");
|
||||
assert.throws(TypeError, () => instance.add([]), "array");
|
||||
assert.throws(TypeError, () => instance.add(() => {}), "function");
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
// 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.plaintime.prototype.add
|
||||
description: Mixed positive and negative values or missing properties always throw
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const plainTime = new Temporal.PlainTime(12, 34, 56, 123, 987, 500);
|
||||
assert.throws(RangeError, () => plainTime.add({ hours: 1, minutes: -6 }), "mixed signs");
|
||||
assert.throws(TypeError, () => plainTime.add({}), "no properties");
|
||||
assert.throws(TypeError, () => plainTime.add({ hour: 12 }), "only singular 'hour' property");
|
27
test/built-ins/Temporal/PlainTime/prototype/add/argument-singular-properties.js
vendored
Normal file
27
test/built-ins/Temporal/PlainTime/prototype/add/argument-singular-properties.js
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
// 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.plaintime.prototype.add
|
||||
description: Singular properties in the property bag are always ignored
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainTime(15, 30, 45, 987, 654, 321);
|
||||
|
||||
[
|
||||
{ year: 1 },
|
||||
{ month: 2 },
|
||||
{ week: 3 },
|
||||
{ day: 4 },
|
||||
{ hour: 5 },
|
||||
{ minute: 6 },
|
||||
{ second: 7 },
|
||||
{ millisecond: 8 },
|
||||
{ microsecond: 9 },
|
||||
{ nanosecond: 10 },
|
||||
].forEach((badObject) => {
|
||||
assert.throws(TypeError, () => instance.add(badObject),
|
||||
"Throw TypeError if temporalDurationLike is not valid");
|
||||
});
|
||||
|
28
test/built-ins/Temporal/PlainTime/prototype/subtract/argument-invalid-property.js
vendored
Normal file
28
test/built-ins/Temporal/PlainTime/prototype/subtract/argument-invalid-property.js
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
// 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.plaintime.prototype.subtract
|
||||
description: temporalDurationLike object must contain at least one correctly spelled property
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainTime(15, 30, 45, 987, 654, 321);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.subtract({}),
|
||||
"Throws TypeError if no property is present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.subtract({ nonsense: true }),
|
||||
"Throws TypeError if no recognized property is present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.subtract({ sign: 1 }),
|
||||
"Sign property is not recognized"
|
||||
);
|
|
@ -0,0 +1,16 @@
|
|||
// 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.plaintime.prototype.subtract
|
||||
description: Positive and negative values in the temporalDurationLike argument are not acceptable
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainTime(15, 30, 45, 987, 654, 321);
|
||||
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.subtract({ hours: 1, minutes: -30 }),
|
||||
`mixed positive and negative values always throw`
|
||||
);
|
|
@ -7,7 +7,7 @@ description: Passing a primitive other than string to subtract() throws
|
|||
features: [Symbol, Temporal]
|
||||
---*/
|
||||
|
||||
const instance = Temporal.PlainTime.from({ hour: 12, minute: 34, second: 56, millisecond: 987, microsecond: 654, nanosecond: 321 });
|
||||
const instance = new Temporal.PlainTime(15, 30, 45, 987, 654, 321);
|
||||
assert.throws(RangeError, () => instance.subtract(undefined), "undefined");
|
||||
assert.throws(RangeError, () => instance.subtract(null), "null");
|
||||
assert.throws(RangeError, () => instance.subtract(true), "boolean");
|
||||
|
@ -15,3 +15,5 @@ assert.throws(RangeError, () => instance.subtract(""), "empty string");
|
|||
assert.throws(TypeError, () => instance.subtract(Symbol()), "Symbol");
|
||||
assert.throws(RangeError, () => instance.subtract(7), "number");
|
||||
assert.throws(RangeError, () => instance.subtract(7n), "bigint");
|
||||
assert.throws(TypeError, () => instance.subtract([]), "array");
|
||||
assert.throws(TypeError, () => instance.subtract(() => {}), "function");
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
// 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.plaintime.prototype.subtract
|
||||
description: Mixed positive and negative values or missing properties always throw
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const plainTime = new Temporal.PlainTime(12, 34, 56, 123, 987, 500);
|
||||
assert.throws(RangeError, () => plainTime.subtract({ hours: 1, minutes: -6 }), "mixed signs");
|
||||
assert.throws(TypeError, () => plainTime.subtract({}), "no properties");
|
||||
assert.throws(TypeError, () => plainTime.subtract({ hour: 12 }), "only singular 'hour' property");
|
27
test/built-ins/Temporal/PlainTime/prototype/subtract/argument-singular-properties.js
vendored
Normal file
27
test/built-ins/Temporal/PlainTime/prototype/subtract/argument-singular-properties.js
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
// 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.plaintime.prototype.subtract
|
||||
description: Singular properties in the property bag are always ignored
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainTime(15, 30, 45, 987, 654, 321);
|
||||
|
||||
[
|
||||
{ year: 1 },
|
||||
{ month: 2 },
|
||||
{ week: 3 },
|
||||
{ day: 4 },
|
||||
{ hour: 5 },
|
||||
{ minute: 6 },
|
||||
{ second: 7 },
|
||||
{ millisecond: 8 },
|
||||
{ microsecond: 9 },
|
||||
{ nanosecond: 10 },
|
||||
].forEach((badObject) => {
|
||||
assert.throws(TypeError, () => instance.subtract(badObject),
|
||||
"Throw TypeError if temporalDurationLike is not valid");
|
||||
});
|
||||
|
28
test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-invalid-property.js
vendored
Normal file
28
test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-invalid-property.js
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
// 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.plainyearmonth.prototype.add
|
||||
description: temporalDurationLike object must contain at least one correctly spelled property
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainYearMonth(2000, 5);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.add({}),
|
||||
"Throws TypeError if no property is present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.add({ nonsense: true }),
|
||||
"Throws TypeError if no recognized property is present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.add({ sign: 1 }),
|
||||
"Sign property is not recognized"
|
||||
);
|
|
@ -0,0 +1,18 @@
|
|||
// 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.plainyearmonth.prototype.add
|
||||
description: Positive and negative values in the temporalDurationLike argument are not acceptable
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainYearMonth(2000, 5);
|
||||
|
||||
["constrain", "reject"].forEach((overflow) => {
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.add({ hours: 1, minutes: -30 }, { overflow }),
|
||||
`mixed positive and negative values always throw (overflow = "${overflow}")`
|
||||
);
|
||||
});
|
|
@ -7,7 +7,7 @@ description: Passing a primitive other than string to add() throws
|
|||
features: [Symbol, Temporal]
|
||||
---*/
|
||||
|
||||
const instance = Temporal.PlainYearMonth.from({ year: 2000, month: 5 });
|
||||
const instance = new Temporal.PlainYearMonth(2000, 5);
|
||||
assert.throws(RangeError, () => instance.add(undefined), "undefined");
|
||||
assert.throws(RangeError, () => instance.add(null), "null");
|
||||
assert.throws(RangeError, () => instance.add(true), "boolean");
|
||||
|
@ -15,3 +15,5 @@ assert.throws(RangeError, () => instance.add(""), "empty string");
|
|||
assert.throws(TypeError, () => instance.add(Symbol()), "Symbol");
|
||||
assert.throws(RangeError, () => instance.add(7), "number");
|
||||
assert.throws(RangeError, () => instance.add(7n), "bigint");
|
||||
assert.throws(TypeError, () => instance.add([]), "array");
|
||||
assert.throws(TypeError, () => instance.add(() => {}), "function");
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
// 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.plainyearmonth.prototype.add
|
||||
description: Mixed positive and negative values or missing properties always throw
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const ym = Temporal.PlainYearMonth.from("2019-11");
|
||||
for (const overflow of ["constrain", "reject"]) {
|
||||
assert.throws(RangeError, () => ym.add({ years: 1, months: -6 }, { overflow }), overflow)
|
||||
}
|
||||
|
||||
assert.throws(TypeError, () => ym.add({}), "no properties");
|
||||
assert.throws(TypeError, () => ym.add({ month: 12 }), "only singular 'month' property");
|
|
@ -1,12 +0,0 @@
|
|||
// 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.plainyearmonth.prototype.add
|
||||
description: Singular properties are ignored
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const ym = Temporal.PlainYearMonth.from("2019-11");
|
||||
TemporalHelpers.assertPlainYearMonth(ym.add({ month: 1, years: 1 }), 2020, 11, "M11");
|
27
test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-singular-properties.js
vendored
Normal file
27
test/built-ins/Temporal/PlainYearMonth/prototype/add/argument-singular-properties.js
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
// 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.plainyearmonth.prototype.add
|
||||
description: Singular properties in the property bag are always ignored
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainYearMonth(2000, 5);
|
||||
|
||||
[
|
||||
{ year: 1 },
|
||||
{ month: 2 },
|
||||
{ week: 3 },
|
||||
{ day: 4 },
|
||||
{ hour: 5 },
|
||||
{ minute: 6 },
|
||||
{ second: 7 },
|
||||
{ millisecond: 8 },
|
||||
{ microsecond: 9 },
|
||||
{ nanosecond: 10 },
|
||||
].forEach((badObject) => {
|
||||
assert.throws(TypeError, () => instance.add(badObject),
|
||||
"Throw TypeError if temporalDurationLike is not valid");
|
||||
});
|
||||
|
28
test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-invalid-property.js
vendored
Normal file
28
test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-invalid-property.js
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
// 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.plainyearmonth.prototype.subtract
|
||||
description: temporalDurationLike object must contain at least one correctly spelled property
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainYearMonth(2000, 5);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.subtract({}),
|
||||
"Throws TypeError if no property is present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.subtract({ nonsense: true }),
|
||||
"Throws TypeError if no recognized property is present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.subtract({ sign: 1 }),
|
||||
"Sign property is not recognized"
|
||||
);
|
18
test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-mixed-sign.js
vendored
Normal file
18
test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-mixed-sign.js
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
// 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.plainyearmonth.prototype.subtract
|
||||
description: Positive and negative values in the temporalDurationLike argument are not acceptable
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainYearMonth(2000, 5);
|
||||
|
||||
["constrain", "reject"].forEach((overflow) => {
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.subtract({ hours: 1, minutes: -30 }, { overflow }),
|
||||
`mixed positive and negative values always throw (overflow = "${overflow}")`
|
||||
);
|
||||
});
|
|
@ -7,7 +7,7 @@ description: Passing a primitive other than string to subtract() throws
|
|||
features: [Symbol, Temporal]
|
||||
---*/
|
||||
|
||||
const instance = Temporal.PlainYearMonth.from({ year: 2000, month: 5 });
|
||||
const instance = new Temporal.PlainYearMonth(2000, 5);
|
||||
assert.throws(RangeError, () => instance.subtract(undefined), "undefined");
|
||||
assert.throws(RangeError, () => instance.subtract(null), "null");
|
||||
assert.throws(RangeError, () => instance.subtract(true), "boolean");
|
||||
|
@ -15,3 +15,5 @@ assert.throws(RangeError, () => instance.subtract(""), "empty string");
|
|||
assert.throws(TypeError, () => instance.subtract(Symbol()), "Symbol");
|
||||
assert.throws(RangeError, () => instance.subtract(7), "number");
|
||||
assert.throws(RangeError, () => instance.subtract(7n), "bigint");
|
||||
assert.throws(TypeError, () => instance.subtract([]), "array");
|
||||
assert.throws(TypeError, () => instance.subtract(() => {}), "function");
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
// 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.plainyearmonth.prototype.subtract
|
||||
description: Mixed positive and negative values or missing properties always throw
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const ym = Temporal.PlainYearMonth.from("2019-11");
|
||||
for (const overflow of ["constrain", "reject"]) {
|
||||
assert.throws(RangeError, () => ym.subtract({ years: 1, months: -6 }, { overflow }), overflow)
|
||||
}
|
||||
|
||||
assert.throws(TypeError, () => ym.subtract({}), "no properties");
|
||||
assert.throws(TypeError, () => ym.subtract({ month: 12 }), "only singular 'month' property");
|
|
@ -1,12 +0,0 @@
|
|||
// 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.plainyearmonth.prototype.subtract
|
||||
description: Singular properties are ignored
|
||||
includes: [temporalHelpers.js]
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const ym = Temporal.PlainYearMonth.from("2019-11");
|
||||
TemporalHelpers.assertPlainYearMonth(ym.subtract({ month: 1, years: 1 }), 2018, 11, "M11");
|
27
test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-singular-properties.js
vendored
Normal file
27
test/built-ins/Temporal/PlainYearMonth/prototype/subtract/argument-singular-properties.js
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
// 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.plainyearmonth.prototype.subtract
|
||||
description: Singular properties in the property bag are always ignored
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainYearMonth(2000, 5);
|
||||
|
||||
[
|
||||
{ year: 1 },
|
||||
{ month: 2 },
|
||||
{ week: 3 },
|
||||
{ day: 4 },
|
||||
{ hour: 5 },
|
||||
{ minute: 6 },
|
||||
{ second: 7 },
|
||||
{ millisecond: 8 },
|
||||
{ microsecond: 9 },
|
||||
{ nanosecond: 10 },
|
||||
].forEach((badObject) => {
|
||||
assert.throws(TypeError, () => instance.subtract(badObject),
|
||||
"Throw TypeError if temporalDurationLike is not valid");
|
||||
});
|
||||
|
28
test/built-ins/Temporal/ZonedDateTime/prototype/add/argument-invalid-property.js
vendored
Normal file
28
test/built-ins/Temporal/ZonedDateTime/prototype/add/argument-invalid-property.js
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
// 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.zoneddatetime.prototype.add
|
||||
description: temporalDurationLike object must contain at least one correctly spelled property
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC");
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.add({}),
|
||||
"Throws TypeError if no property is present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.add({ nonsense: true }),
|
||||
"Throws TypeError if no recognized property is present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.add({ sign: 1 }),
|
||||
"Sign property is not recognized"
|
||||
);
|
|
@ -0,0 +1,18 @@
|
|||
// 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.zoneddatetime.prototype.add
|
||||
description: Positive and negative values in the temporalDurationLike argument are not acceptable
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC");
|
||||
|
||||
["constrain", "reject"].forEach((overflow) => {
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.add({ hours: 1, minutes: -30 }, { overflow }),
|
||||
`mixed positive and negative values always throw (overflow = "${overflow}")`
|
||||
);
|
||||
});
|
|
@ -0,0 +1,19 @@
|
|||
// 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.zoneddatetime.prototype.add
|
||||
description: Passing a primitive other than string to add() throws
|
||||
features: [Symbol, Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC");
|
||||
assert.throws(RangeError, () => instance.add(undefined), "undefined");
|
||||
assert.throws(RangeError, () => instance.add(null), "null");
|
||||
assert.throws(RangeError, () => instance.add(true), "boolean");
|
||||
assert.throws(RangeError, () => instance.add(""), "empty string");
|
||||
assert.throws(TypeError, () => instance.add(Symbol()), "Symbol");
|
||||
assert.throws(RangeError, () => instance.add(7), "number");
|
||||
assert.throws(RangeError, () => instance.add(7n), "bigint");
|
||||
assert.throws(TypeError, () => instance.add([]), "array");
|
||||
assert.throws(TypeError, () => instance.add(() => {}), "function");
|
27
test/built-ins/Temporal/ZonedDateTime/prototype/add/argument-singular-properties.js
vendored
Normal file
27
test/built-ins/Temporal/ZonedDateTime/prototype/add/argument-singular-properties.js
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
// 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.zoneddatetime.prototype.add
|
||||
description: Singular properties in the property bag are always ignored
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC");
|
||||
|
||||
[
|
||||
{ year: 1 },
|
||||
{ month: 2 },
|
||||
{ week: 3 },
|
||||
{ day: 4 },
|
||||
{ hour: 5 },
|
||||
{ minute: 6 },
|
||||
{ second: 7 },
|
||||
{ millisecond: 8 },
|
||||
{ microsecond: 9 },
|
||||
{ nanosecond: 10 },
|
||||
].forEach((badObject) => {
|
||||
assert.throws(TypeError, () => instance.add(badObject),
|
||||
"Throw TypeError if temporalDurationLike is not valid");
|
||||
});
|
||||
|
28
test/built-ins/Temporal/ZonedDateTime/prototype/subtract/argument-invalid-property.js
vendored
Normal file
28
test/built-ins/Temporal/ZonedDateTime/prototype/subtract/argument-invalid-property.js
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
// 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.zoneddatetime.prototype.subtract
|
||||
description: temporalDurationLike object must contain at least one correctly spelled property
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC");
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.subtract({}),
|
||||
"Throws TypeError if no property is present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.subtract({ nonsense: true }),
|
||||
"Throws TypeError if no recognized property is present"
|
||||
);
|
||||
|
||||
assert.throws(
|
||||
TypeError,
|
||||
() => instance.subtract({ sign: 1 }),
|
||||
"Sign property is not recognized"
|
||||
);
|
18
test/built-ins/Temporal/ZonedDateTime/prototype/subtract/argument-mixed-sign.js
vendored
Normal file
18
test/built-ins/Temporal/ZonedDateTime/prototype/subtract/argument-mixed-sign.js
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
// 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.zoneddatetime.prototype.subtract
|
||||
description: Positive and negative values in the temporalDurationLike argument are not acceptable
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC");
|
||||
|
||||
["constrain", "reject"].forEach((overflow) => {
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.subtract({ hours: 1, minutes: -30 }, { overflow }),
|
||||
`mixed positive and negative values always throw (overflow = "${overflow}")`
|
||||
);
|
||||
});
|
19
test/built-ins/Temporal/ZonedDateTime/prototype/subtract/argument-not-object.js
vendored
Normal file
19
test/built-ins/Temporal/ZonedDateTime/prototype/subtract/argument-not-object.js
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
// 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.zoneddatetime.prototype.subtract
|
||||
description: Passing a primitive other than string to subtract() throws
|
||||
features: [Symbol, Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC");
|
||||
assert.throws(RangeError, () => instance.subtract(undefined), "undefined");
|
||||
assert.throws(RangeError, () => instance.subtract(null), "null");
|
||||
assert.throws(RangeError, () => instance.subtract(true), "boolean");
|
||||
assert.throws(RangeError, () => instance.subtract(""), "empty string");
|
||||
assert.throws(TypeError, () => instance.subtract(Symbol()), "Symbol");
|
||||
assert.throws(RangeError, () => instance.subtract(7), "number");
|
||||
assert.throws(RangeError, () => instance.subtract(7n), "bigint");
|
||||
assert.throws(TypeError, () => instance.subtract([]), "array");
|
||||
assert.throws(TypeError, () => instance.subtract(() => {}), "function");
|
27
test/built-ins/Temporal/ZonedDateTime/prototype/subtract/argument-singular-properties.js
vendored
Normal file
27
test/built-ins/Temporal/ZonedDateTime/prototype/subtract/argument-singular-properties.js
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
// 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.zoneddatetime.prototype.subtract
|
||||
description: Singular properties in the property bag are always ignored
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC");
|
||||
|
||||
[
|
||||
{ year: 1 },
|
||||
{ month: 2 },
|
||||
{ week: 3 },
|
||||
{ day: 4 },
|
||||
{ hour: 5 },
|
||||
{ minute: 6 },
|
||||
{ second: 7 },
|
||||
{ millisecond: 8 },
|
||||
{ microsecond: 9 },
|
||||
{ nanosecond: 10 },
|
||||
].forEach((badObject) => {
|
||||
assert.throws(TypeError, () => instance.subtract(badObject),
|
||||
"Throw TypeError if temporalDurationLike is not valid");
|
||||
});
|
||||
|
Loading…
Reference in New Issue