mirror of https://github.com/tc39/test262.git
Temporal: Consolidate tests for invalid string argument to round().
This commit is contained in:
parent
1c19242ae4
commit
ff5af6fccf
|
@ -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.round
|
||||
description: RangeError thrown when smallestUnit option not one of the allowed string values
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const duration = new Temporal.Duration(0, 0, 0, 0, 12, 34, 56, 123, 987, 500);
|
||||
const badValues = [
|
||||
"era",
|
||||
"eraYear",
|
||||
"millisecond\0",
|
||||
"mill\u0131second",
|
||||
"SECOND",
|
||||
"eras",
|
||||
"eraYears",
|
||||
"milliseconds\0",
|
||||
"mill\u0131seconds",
|
||||
"SECONDS",
|
||||
"other string",
|
||||
];
|
||||
for (const smallestUnit of badValues) {
|
||||
assert.throws(RangeError, () => duration.round(smallestUnit),
|
||||
`"${smallestUnit}" is not a valid value for smallest unit`);
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
// Copyright (C) 2021 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: Specifically disallowed units for the smallestUnit option
|
||||
features: [Temporal, arrow-function]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Duration(0, 0, 0, 4, 5, 6, 7, 987, 654, 321);
|
||||
const invalidUnits = [
|
||||
"era",
|
||||
"eras",
|
||||
];
|
||||
invalidUnits.forEach((smallestUnit) => {
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.round({ smallestUnit }),
|
||||
`{ smallestUnit: "${smallestUnit}" } should not be allowed as an argument to round`
|
||||
);
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.round(smallestUnit),
|
||||
`"${smallestUnit}" should not be allowed as an argument to round`
|
||||
);
|
||||
});
|
|
@ -0,0 +1,35 @@
|
|||
// 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: RangeError thrown when smallestUnit option not one of the allowed string values
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const instant = new Temporal.Instant(1_000_000_000_123_987_500n);
|
||||
const badValues = [
|
||||
"era",
|
||||
"eraYear",
|
||||
"year",
|
||||
"month",
|
||||
"week",
|
||||
"day",
|
||||
"millisecond\0",
|
||||
"mill\u0131second",
|
||||
"SECOND",
|
||||
"eras",
|
||||
"eraYears",
|
||||
"years",
|
||||
"months",
|
||||
"weeks",
|
||||
"days",
|
||||
"milliseconds\0",
|
||||
"mill\u0131seconds",
|
||||
"SECONDS",
|
||||
"other string",
|
||||
];
|
||||
for (const smallestUnit of badValues) {
|
||||
assert.throws(RangeError, () => instant.round(smallestUnit),
|
||||
`"${smallestUnit}" is not a valid value for smallest unit`);
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
// Copyright (C) 2021 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: Specifically disallowed units for the smallestUnit option
|
||||
features: [Temporal, arrow-function]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.Instant(1_000_000_000_987_654_321n);
|
||||
const invalidUnits = [
|
||||
"era",
|
||||
"eras",
|
||||
"year",
|
||||
"month",
|
||||
"week",
|
||||
"years",
|
||||
"months",
|
||||
"weeks",
|
||||
"day",
|
||||
"days",
|
||||
];
|
||||
invalidUnits.forEach((smallestUnit) => {
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.round({ smallestUnit }),
|
||||
`{ smallestUnit: "${smallestUnit}" } should not be allowed as an argument to round`
|
||||
);
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.round(smallestUnit),
|
||||
`"${smallestUnit}" should not be allowed as an argument to round`
|
||||
);
|
||||
});
|
33
test/built-ins/Temporal/PlainDateTime/prototype/round/roundto-invalid-string.js
vendored
Normal file
33
test/built-ins/Temporal/PlainDateTime/prototype/round/roundto-invalid-string.js
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
// 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.round
|
||||
description: RangeError thrown when smallestUnit option not one of the allowed string values
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 123, 987, 500);
|
||||
const badValues = [
|
||||
"era",
|
||||
"eraYear",
|
||||
"year",
|
||||
"month",
|
||||
"week",
|
||||
"millisecond\0",
|
||||
"mill\u0131second",
|
||||
"SECOND",
|
||||
"eras",
|
||||
"eraYears",
|
||||
"years",
|
||||
"months",
|
||||
"weeks",
|
||||
"milliseconds\0",
|
||||
"mill\u0131seconds",
|
||||
"SECONDS",
|
||||
"other string",
|
||||
];
|
||||
for (const smallestUnit of badValues) {
|
||||
assert.throws(RangeError, () => datetime.round(smallestUnit),
|
||||
`"${smallestUnit}" is not a valid value for smallest unit`);
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaindatetime.prototype.round
|
||||
description: Specifically disallowed units for the smallestUnit option
|
||||
features: [Temporal, arrow-function]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 789, 999, 999);
|
||||
const invalidUnits = [
|
||||
"era",
|
||||
"eras",
|
||||
"year",
|
||||
"month",
|
||||
"week",
|
||||
"years",
|
||||
"months",
|
||||
"weeks",
|
||||
];
|
||||
invalidUnits.forEach((smallestUnit) => {
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.round({ smallestUnit }),
|
||||
`{ smallestUnit: "${smallestUnit}" } should not be allowed as an argument to round`
|
||||
);
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.round(smallestUnit),
|
||||
`"${smallestUnit}" should not be allowed as an argument to round`
|
||||
);
|
||||
});
|
|
@ -0,0 +1,35 @@
|
|||
// 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.round
|
||||
description: RangeError thrown when smallestUnit option not one of the allowed string values
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const time = new Temporal.PlainTime(12, 34, 56, 123, 987, 500);
|
||||
const badValues = [
|
||||
"era",
|
||||
"eraYear",
|
||||
"year",
|
||||
"month",
|
||||
"week",
|
||||
"day",
|
||||
"millisecond\0",
|
||||
"mill\u0131second",
|
||||
"SECOND",
|
||||
"eras",
|
||||
"eraYears",
|
||||
"years",
|
||||
"months",
|
||||
"weeks",
|
||||
"days",
|
||||
"milliseconds\0",
|
||||
"mill\u0131seconds",
|
||||
"SECONDS",
|
||||
"other string",
|
||||
];
|
||||
for (const smallestUnit of badValues) {
|
||||
assert.throws(RangeError, () => time.round(smallestUnit),
|
||||
`"${smallestUnit}" is not a valid value for smallest unit`);
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.plaintime.prototype.round
|
||||
description: Specifically disallowed units for the smallestUnit option
|
||||
features: [Temporal, arrow-function]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.PlainTime(12, 34, 56, 789, 999, 999);
|
||||
const invalidUnits = [
|
||||
"era",
|
||||
"eras",
|
||||
"year",
|
||||
"month",
|
||||
"week",
|
||||
"years",
|
||||
"months",
|
||||
"weeks",
|
||||
"day",
|
||||
"days",
|
||||
];
|
||||
invalidUnits.forEach((smallestUnit) => {
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.round({ smallestUnit }),
|
||||
`{ smallestUnit: "${smallestUnit}" } should not be allowed as an argument to round`
|
||||
);
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.round(smallestUnit),
|
||||
`"${smallestUnit}" should not be allowed as an argument to round`
|
||||
);
|
||||
});
|
33
test/built-ins/Temporal/ZonedDateTime/prototype/round/roundto-invalid-string.js
vendored
Normal file
33
test/built-ins/Temporal/ZonedDateTime/prototype/round/roundto-invalid-string.js
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
// 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.round
|
||||
description: RangeError thrown when smallestUnit option not one of the allowed string values
|
||||
features: [Temporal]
|
||||
---*/
|
||||
|
||||
const datetime = new Temporal.ZonedDateTime(1_000_000_000_123_987_500n, "UTC");
|
||||
const badValues = [
|
||||
"era",
|
||||
"eraYear",
|
||||
"year",
|
||||
"month",
|
||||
"week",
|
||||
"millisecond\0",
|
||||
"mill\u0131second",
|
||||
"SECOND",
|
||||
"eras",
|
||||
"eraYears",
|
||||
"years",
|
||||
"months",
|
||||
"weeks",
|
||||
"milliseconds\0",
|
||||
"mill\u0131seconds",
|
||||
"SECONDS",
|
||||
"other string",
|
||||
];
|
||||
for (const smallestUnit of badValues) {
|
||||
assert.throws(RangeError, () => datetime.round(smallestUnit),
|
||||
`"${smallestUnit}" is not a valid value for smallest unit`);
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
// Copyright (C) 2021 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.zoneddatetime.prototype.round
|
||||
description: Specifically disallowed units for the smallestUnit option
|
||||
features: [Temporal, arrow-function]
|
||||
---*/
|
||||
|
||||
const instance = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC");
|
||||
const invalidUnits = [
|
||||
"era",
|
||||
"eras",
|
||||
"year",
|
||||
"month",
|
||||
"week",
|
||||
"years",
|
||||
"months",
|
||||
"weeks",
|
||||
];
|
||||
invalidUnits.forEach((smallestUnit) => {
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.round({ smallestUnit }),
|
||||
`{ smallestUnit: "${smallestUnit}" } should not be allowed as an argument to round`
|
||||
);
|
||||
assert.throws(
|
||||
RangeError,
|
||||
() => instance.round(smallestUnit),
|
||||
`"${smallestUnit}" should not be allowed as an argument to round`
|
||||
);
|
||||
});
|
Loading…
Reference in New Issue