test262/test/built-ins/Temporal/Duration/compare/argument-string-fractional-units-rounding-mode.js
Philip Chimento 7b45a862b1 Test rounding mode in Duration strings with fractional units
https://github.com/tc39/proposal-temporal/pull/1907 was a bug that caused
negative Duration strings with fractional units to be rounded incorrectly.
Add tests that ensure the rounding mode is correct.

This was a normative change that achieved consensus at the December 2021
TC39 meeting.
2022-02-08 15:43:25 -05:00

21 lines
1.0 KiB
JavaScript

// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.duration.compare
description: Strings with fractional duration units are rounded with the correct rounding mode
features: [Temporal]
---*/
const expectedPos = new Temporal.Duration(0, 0, 0, 0, 1, 1, 52, 500);
const expectedNeg = new Temporal.Duration(0, 0, 0, 0, -1, -1, -52, -500);
assert.sameValue(Temporal.Duration.compare("PT1.03125H", expectedPos), 0,
"positive fractional units rounded with correct rounding mode (first argument)");
assert.sameValue(Temporal.Duration.compare("-PT1.03125H", expectedNeg), 0,
"negative fractional units rounded with correct rounding mode (first argument)");
assert.sameValue(Temporal.Duration.compare(expectedPos, "PT1.03125H"), 0,
"positive fractional units rounded with correct rounding mode (second argument)");
assert.sameValue(Temporal.Duration.compare(expectedNeg, "-PT1.03125H"), 0,
"negative fractional units rounded with correct rounding mode (second argument)");