mirror of
https://github.com/tc39/test262.git
synced 2025-12-19 03:33:44 +01:00
Temporal: Update duration tests to cover the largest possible ms, µs, and ns values
This commit is contained in:
parent
8a879d7a6f
commit
45e9824a32
@ -8,9 +8,26 @@ description: >
|
|||||||
features: [Temporal]
|
features: [Temporal]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
// Largest temporal unit is "second".
|
const maxSec = Number.MAX_SAFE_INTEGER;
|
||||||
const duration = Temporal.Duration.from({seconds: Number.MAX_SAFE_INTEGER});
|
const maxMs = 9_007_199_254_740_991_487;
|
||||||
|
const maxUs = 9_007_199_254_740_991_475_711;
|
||||||
|
const maxNs = 9_007_199_254_740_991_463_129_087;
|
||||||
|
|
||||||
assert.throws(RangeError, () => {
|
const durations = [
|
||||||
|
Temporal.Duration.from({seconds: maxSec}),
|
||||||
|
Temporal.Duration.from({milliseconds: maxMs}),
|
||||||
|
Temporal.Duration.from({microseconds: maxUs}),
|
||||||
|
Temporal.Duration.from({nanoseconds: maxNs}),
|
||||||
|
Temporal.Duration.from({seconds: -maxSec}),
|
||||||
|
Temporal.Duration.from({milliseconds: -maxMs}),
|
||||||
|
Temporal.Duration.from({microseconds: -maxUs}),
|
||||||
|
Temporal.Duration.from({nanoseconds: -maxNs}),
|
||||||
|
]
|
||||||
|
|
||||||
|
for (let duration of durations) {
|
||||||
|
assert.throws(RangeError, () => {
|
||||||
duration.add(duration);
|
duration.add(duration);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -9,8 +9,44 @@ description: >
|
|||||||
features: [Temporal]
|
features: [Temporal]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
const d = new Temporal.Duration(0, 0, 0, 0, 0, 0, /* s = */ Number.MAX_SAFE_INTEGER, 0, 0, /* ns = */ 999_999_999);
|
/*
|
||||||
assert.throws(RangeError, () => d.round({
|
const maxMs = 9_007_199_254_740_991_487;
|
||||||
|
const maxUs = 9_007_199_254_740_991_475_711;
|
||||||
|
const maxNs = 9_007_199_254_740_991_463_129_087;
|
||||||
|
*/
|
||||||
|
|
||||||
|
const ms = new Temporal.Duration(0, 0, 0, 0, 0, 0, /* s = */ Number.MAX_SAFE_INTEGER, /* ms = */ 488, 0, 0);
|
||||||
|
assert.throws(RangeError, () => ms.round({
|
||||||
largestUnit: "nanoseconds",
|
largestUnit: "nanoseconds",
|
||||||
roundingIncrement: 1,
|
roundingIncrement: 1,
|
||||||
}), "nanoseconds component after balancing as a float64-representable integer is out of range");
|
}), "nanoseconds component after balancing as a float64-representable integer is out of range (maximum milliseconds)");
|
||||||
|
|
||||||
|
const us = new Temporal.Duration(0, 0, 0, 0, 0, 0, /* s = */ Number.MAX_SAFE_INTEGER, 0, /* us = */ 475_712, 0);
|
||||||
|
assert.throws(RangeError, () => ms.round({
|
||||||
|
largestUnit: "nanoseconds",
|
||||||
|
roundingIncrement: 1,
|
||||||
|
}), "nanoseconds component after balancing as a float64-representable integer is out of range (maximum microseconds)");
|
||||||
|
|
||||||
|
const ns = new Temporal.Duration(0, 0, 0, 0, 0, 0, /* s = */ Number.MAX_SAFE_INTEGER, 0, 0, /* ns = */ 463_129_088);
|
||||||
|
assert.throws(RangeError, () => ns.round({
|
||||||
|
largestUnit: "nanoseconds",
|
||||||
|
roundingIncrement: 1,
|
||||||
|
}), "nanoseconds component after balancing as a float64-representable integer is out of range (maximum nanoseconds)");
|
||||||
|
|
||||||
|
const msMin = new Temporal.Duration(0, 0, 0, 0, 0, 0, /* s = */ -Number.MAX_SAFE_INTEGER, /* ms = */ -487, 0, 0);
|
||||||
|
assert.throws(RangeError, () => msMin.round({
|
||||||
|
largestUnit: "nanoseconds",
|
||||||
|
roundingIncrement: 1,
|
||||||
|
}), "nanoseconds component after balancing as a float64-representable integer is out of range (minimum milliseconds)");
|
||||||
|
|
||||||
|
const usMin = new Temporal.Duration(0, 0, 0, 0, 0, 0, /* s = */ -Number.MAX_SAFE_INTEGER, 0, /* us = */ -475_711, 0);
|
||||||
|
assert.throws(RangeError, () => usMin.round({
|
||||||
|
largestUnit: "nanoseconds",
|
||||||
|
roundingIncrement: 1,
|
||||||
|
}), "nanoseconds component after balancing as a float64-representable integer is out of range (minimum microseconds)");
|
||||||
|
|
||||||
|
const nsMin = new Temporal.Duration(0, 0, 0, 0, 0, 0, /* s = */ -Number.MAX_SAFE_INTEGER, 0, 0, /* ns = */ -463_129_088);
|
||||||
|
assert.throws(RangeError, () => nsMin.round({
|
||||||
|
largestUnit: "nanoseconds",
|
||||||
|
roundingIncrement: 1,
|
||||||
|
}), "nanoseconds component after balancing as a float64-representable integer is out of range (minimum nanoseconds)");
|
||||||
|
|||||||
@ -8,9 +8,20 @@ description: >
|
|||||||
features: [Temporal]
|
features: [Temporal]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
var duration = Temporal.Duration.from({
|
const maxMs = 9_007_199_254_740_991_487;
|
||||||
seconds: Number.MAX_SAFE_INTEGER,
|
const maxUs = 9_007_199_254_740_991_475_711;
|
||||||
});
|
const maxNs = 9_007_199_254_740_991_463_129_087;
|
||||||
|
|
||||||
|
const durations = [
|
||||||
|
Temporal.Duration.from({ seconds: Number.MAX_SAFE_INTEGER }),
|
||||||
|
Temporal.Duration.from({ milliseconds: maxMs }),
|
||||||
|
Temporal.Duration.from({ microseconds: maxUs }),
|
||||||
|
Temporal.Duration.from({ nanoseconds: maxNs }),
|
||||||
|
Temporal.Duration.from({ seconds: -Number.MAX_SAFE_INTEGER }),
|
||||||
|
Temporal.Duration.from({ milliseconds: -maxMs }),
|
||||||
|
Temporal.Duration.from({ microseconds: -maxUs }),
|
||||||
|
Temporal.Duration.from({ nanoseconds: -maxNs }),
|
||||||
|
];
|
||||||
|
|
||||||
var zonedDateTime = new Temporal.ZonedDateTime(0n, "UTC");
|
var zonedDateTime = new Temporal.ZonedDateTime(0n, "UTC");
|
||||||
|
|
||||||
@ -20,4 +31,6 @@ var options = {
|
|||||||
relativeTo: zonedDateTime,
|
relativeTo: zonedDateTime,
|
||||||
};
|
};
|
||||||
|
|
||||||
assert.throws(RangeError, () => duration.round(options));
|
for (let duration of durations) {
|
||||||
|
assert.throws(RangeError, () => duration.round(options));
|
||||||
|
}
|
||||||
|
|||||||
@ -8,10 +8,24 @@ description: >
|
|||||||
features: [Temporal]
|
features: [Temporal]
|
||||||
---*/
|
---*/
|
||||||
|
|
||||||
// Largest temporal unit is "second".
|
const maxSec = Number.MAX_SAFE_INTEGER;
|
||||||
const duration1 = Temporal.Duration.from({seconds: Number.MAX_SAFE_INTEGER});
|
const maxMs = 9_007_199_254_740_991_487;
|
||||||
const duration2 = Temporal.Duration.from({seconds: -Number.MAX_SAFE_INTEGER});
|
const maxUs = 9_007_199_254_740_991_475_711;
|
||||||
|
const maxNs = 9_007_199_254_740_991_463_129_087;
|
||||||
|
|
||||||
assert.throws(RangeError, () => {
|
const durations = [
|
||||||
duration1.subtract(duration2);
|
Temporal.Duration.from({seconds: maxSec}),
|
||||||
});
|
Temporal.Duration.from({milliseconds: maxMs}),
|
||||||
|
Temporal.Duration.from({microseconds: maxUs}),
|
||||||
|
Temporal.Duration.from({nanoseconds: maxNs}),
|
||||||
|
Temporal.Duration.from({seconds: -maxSec}),
|
||||||
|
Temporal.Duration.from({milliseconds: -maxMs}),
|
||||||
|
Temporal.Duration.from({microseconds: -maxUs}),
|
||||||
|
Temporal.Duration.from({nanoseconds: -maxNs}),
|
||||||
|
];
|
||||||
|
|
||||||
|
for (let duration of durations) {
|
||||||
|
assert.throws(RangeError, () => {
|
||||||
|
duration.subtract(duration.negated());
|
||||||
|
}, `subtracting the negation of a large duration from the duration is out of bounds: ${duration}`);
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user