Skip to content

Commit

Permalink
Temporal: Add tests for PlainTime#{toJSON/toString}.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ms2ger authored and ptomato committed May 19, 2022
1 parent 912559f commit b8ab706
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 14 deletions.
23 changes: 23 additions & 0 deletions test/built-ins/Temporal/PlainTime/prototype/toJSON/basic.js
Original file line number Diff line number Diff line change
@@ -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");
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit b8ab706

Please sign in to comment.