Temporal: Move tests out of staging/Temporal/Duration/old and into test/built-ins

This commit is contained in:
Tim Chevalier 2024-10-28 12:02:04 -07:00 committed by Philip Chimento
parent 3f0a24f4f6
commit b8c29a05b5
7 changed files with 75 additions and 62 deletions

View File

@ -0,0 +1,13 @@
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.duration.compare
description: Temporal.Duration.compare() does not lose precision when totaling everything down to nanoseconds.
features: [Temporal]
---*/
const days200 = new Temporal.Duration(0, 0, 0, 200);
const days200oneNanosecond = new Temporal.Duration(0, 0, 0, 200, 0, 0, 0, 0, 0, 1);
assert.notSameValue(Temporal.Duration.compare(days200, days200oneNanosecond), 0);

View File

@ -0,0 +1,36 @@
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.duration.from
description: Minimum value is zero.
includes: [temporalHelpers.js]
features: [Temporal]
---*/
const units = [
"years",
"months",
"weeks",
"days",
"hours",
"minutes",
"seconds",
"milliseconds",
"microseconds",
"nanoseconds"
];
units.forEach(unit => TemporalHelpers.assertDuration(Temporal.Duration.from({ [unit]: 0 }),
0, 0, 0, 0, 0, 0, 0, 0, 0, 0));
[
"P0Y",
"P0M",
"P0W",
"P0D",
"PT0H",
"PT0M",
"PT0S"
].forEach(str => TemporalHelpers.assertDuration(Temporal.Duration.from(str),
0, 0, 0, 0, 0, 0, 0, 0, 0, 0));

View File

@ -0,0 +1,12 @@
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
includes: [temporalHelpers.js]
esid: sec-temporal.duration
description: Minimum value is zero.
features: [Temporal]
---*/
TemporalHelpers.assertDuration(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

View File

@ -0,0 +1,14 @@
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.duration.prototype.tostring
description: Serializing balance doesn't lose precision when values are precise.
features: [Temporal]
---*/
const d = new Temporal.Duration(0, 0, 0, 0, 0, 0, 0,
Number.MAX_SAFE_INTEGER,
Number.MAX_SAFE_INTEGER, 0);
assert.sameValue(d.toString(), "PT9016206453995.731991S");

View File

@ -1,13 +0,0 @@
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal-duration-objects
description: Temporal.Duration.compare() does not lose precision when totaling everything down to nanoseconds
features: [Temporal]
---*/
assert.notSameValue(Temporal.Duration.compare({ days: 200 }, {
days: 200,
nanoseconds: 1
}), 0);

View File

@ -1,34 +0,0 @@
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal-duration-objects
description: min/max values
features: [Temporal]
---*/
var units = [
"years",
"months",
"weeks",
"days",
"hours",
"minutes",
"seconds",
"milliseconds",
"microseconds",
"nanoseconds"
];
// minimum is zero
assert.sameValue(`${ new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, 0) }`, "PT0S");
units.forEach(unit => assert.sameValue(`${ Temporal.Duration.from({ [unit]: 0 }) }`, "PT0S"));
[
"P0Y",
"P0M",
"P0W",
"P0D",
"PT0H",
"PT0M",
"PT0S"
].forEach(str => assert.sameValue(`${ Temporal.Duration.from(str) }`, "PT0S"));

View File

@ -1,15 +0,0 @@
// Copyright (C) 2018 Bloomberg LP. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal-duration-objects
description: toString() works as expected
features: [Temporal]
---*/
// serializing balance doesn't lose precision when values are precise
var d = Temporal.Duration.from({
milliseconds: Number.MAX_SAFE_INTEGER,
microseconds: Number.MAX_SAFE_INTEGER
});
assert.sameValue(`${ d }`, "PT9016206453995.731991S");