Temporal: Add tests for PlainTime#{toJSON/toString}.

This commit is contained in:
Ms2ger 2022-05-19 14:59:37 +02:00 committed by Philip Chimento
parent 912559f683
commit b8ab7063b0
4 changed files with 34 additions and 14 deletions

View File

@ -0,0 +1,23 @@
// 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.tojson
description: Basic behavior for toJSON
features: [Temporal]
---*/
const tests = [
[new Temporal.PlainTime(5, 3, 1), "05:03:01"],
[new Temporal.PlainTime(15, 23), "15:23:00"],
[new Temporal.PlainTime(15, 23, 30), "15:23:30"],
[new Temporal.PlainTime(15, 23, 30, 123, 400), "15:23:30.1234"],
];
const options = new Proxy({}, {
get() { throw new Test262Error("should not get properties off argument") }
});
for (const [time, expected] of tests) {
assert.sameValue(time.toJSON(), expected, "toJSON without argument");
assert.sameValue(time.toJSON(options), expected, "toJSON with argument");
}

View File

@ -7,14 +7,11 @@ description: auto value for fractionalSecondDigits option
features: [Temporal]
---*/
const zeroSeconds = new Temporal.PlainTime(15, 23);
const wholeSeconds = new Temporal.PlainTime(15, 23, 30);
const subSeconds = new Temporal.PlainTime(15, 23, 30, 123, 400);
const tests = [
[zeroSeconds, "15:23:00"],
[wholeSeconds, "15:23:30"],
[subSeconds, "15:23:30.1234"],
[new Temporal.PlainTime(5, 3, 1), "05:03:01"],
[new Temporal.PlainTime(15, 23), "15:23:00"],
[new Temporal.PlainTime(15, 23, 30), "15:23:30"],
[new Temporal.PlainTime(15, 23, 30, 123, 400), "15:23:30.1234"],
];
for (const [time, expected] of tests) {

View File

@ -7,10 +7,13 @@ description: Number for fractionalSecondDigits option
features: [Temporal]
---*/
const fewSeconds = new Temporal.PlainTime(5, 3, 1);
const zeroSeconds = new Temporal.PlainTime(15, 23);
const wholeSeconds = new Temporal.PlainTime(15, 23, 30);
const subSeconds = new Temporal.PlainTime(15, 23, 30, 123, 400);
assert.sameValue(fewSeconds.toString({ fractionalSecondDigits: 0 }), "05:03:01",
"pads parts with 0");
assert.sameValue(subSeconds.toString({ fractionalSecondDigits: 0 }), "15:23:30",
"truncates 4 decimal places to 0");
assert.sameValue(zeroSeconds.toString({ fractionalSecondDigits: 2 }), "15:23:00.00",

View File

@ -16,14 +16,11 @@ info: |
features: [Temporal]
---*/
const zeroSeconds = new Temporal.PlainTime(15, 23);
const wholeSeconds = new Temporal.PlainTime(15, 23, 30);
const subSeconds = new Temporal.PlainTime(15, 23, 30, 123, 400);
const tests = [
[zeroSeconds, "15:23:00"],
[wholeSeconds, "15:23:30"],
[subSeconds, "15:23:30.1234"],
[new Temporal.PlainTime(5, 3, 1), "05:03:01"],
[new Temporal.PlainTime(15, 23), "15:23:00"],
[new Temporal.PlainTime(15, 23, 30), "15:23:30"],
[new Temporal.PlainTime(15, 23, 30, 123, 400), "15:23:30.1234"],
];
for (const [time, expected] of tests) {