Skip to content

Commit

Permalink
Temporal: Tests for absolute value bug in duration rounding no-op con…
Browse files Browse the repository at this point in the history
…ditions

Repeat all the existing tests for no-op duration rounding operations, but
with negative durations.
  • Loading branch information
ptomato committed Oct 4, 2023
1 parent 37b6fe3 commit d26e3eb
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ for (const [duration, options, descr] of noopRoundingOperations) {
const result = duration.round(options);
assert.notSameValue(result, duration, "rounding result should be a new object");
TemporalHelpers.assertDurationsEqual(result, duration, `rounding should be a no-op with ${descr}`);

const negDuration = duration.negated();
const negResult = negDuration.round(options);
assert.notSameValue(negResult, negDuration, "rounding result should be a new object (negative)");
TemporalHelpers.assertDurationsEqual(negResult, negDuration, `rounding should be a no-op with ${descr} (negative)`);
}

// These operations are not no-op rounding operations, but still should not call
Expand All @@ -54,6 +59,17 @@ for (const [duration, options, descr] of roundingOperationsNotCallingCalendarMet
}
}
assert(!equal, `round result ${result} should be different from ${duration} with ${descr}`);

const negDuration = duration.negated();
const negResult = negDuration.round(options);
equal = true;
for (const prop of ['years', 'months', 'weeks', 'days', 'hours', 'minutes', 'seconds', 'milliseconds', 'microseconds', 'nanoseconds']) {
if (negResult[prop] !== negDuration[prop]) {
equal = false;
break;
}
}
assert(!equal, `round result ${negResult} should be different from ${negDuration} with ${descr} (negative)`);
}

// These operations should not be short-circuited because they have to call
Expand All @@ -66,4 +82,5 @@ const roundingOperationsCallingCalendarMethods = [

for (const [duration, options, descr] of roundingOperationsCallingCalendarMethods) {
assert.throws(Test262Error, () => duration.round(options), `rounding should not be a no-op with ${descr}`);
assert.throws(Test262Error, () => duration.negated().round(options), `rounding should not be a no-op with ${descr} (negative)`);
}

0 comments on commit d26e3eb

Please sign in to comment.