From b8ab7063b013dba8d93267e3340bb68295a2c0d4 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 19 May 2022 14:59:37 +0200 Subject: [PATCH] Temporal: Add tests for PlainTime#{toJSON/toString}. --- .../PlainTime/prototype/toJSON/basic.js | 23 +++++++++++++++++++ .../toString/fractionalseconddigits-auto.js | 11 ++++----- .../toString/fractionalseconddigits-number.js | 3 +++ .../fractionalseconddigits-undefined.js | 11 ++++----- 4 files changed, 34 insertions(+), 14 deletions(-) create mode 100644 test/built-ins/Temporal/PlainTime/prototype/toJSON/basic.js diff --git a/test/built-ins/Temporal/PlainTime/prototype/toJSON/basic.js b/test/built-ins/Temporal/PlainTime/prototype/toJSON/basic.js new file mode 100644 index 0000000000..6d9c606b2e --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/toJSON/basic.js @@ -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"); +} diff --git a/test/built-ins/Temporal/PlainTime/prototype/toString/fractionalseconddigits-auto.js b/test/built-ins/Temporal/PlainTime/prototype/toString/fractionalseconddigits-auto.js index 2c90ffaa47..2440b00a2e 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/toString/fractionalseconddigits-auto.js +++ b/test/built-ins/Temporal/PlainTime/prototype/toString/fractionalseconddigits-auto.js @@ -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) { diff --git a/test/built-ins/Temporal/PlainTime/prototype/toString/fractionalseconddigits-number.js b/test/built-ins/Temporal/PlainTime/prototype/toString/fractionalseconddigits-number.js index 0ea1eb838e..0dd96d55fd 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/toString/fractionalseconddigits-number.js +++ b/test/built-ins/Temporal/PlainTime/prototype/toString/fractionalseconddigits-number.js @@ -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", diff --git a/test/built-ins/Temporal/PlainTime/prototype/toString/fractionalseconddigits-undefined.js b/test/built-ins/Temporal/PlainTime/prototype/toString/fractionalseconddigits-undefined.js index 6c33c55f7f..b8014a6e76 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/toString/fractionalseconddigits-undefined.js +++ b/test/built-ins/Temporal/PlainTime/prototype/toString/fractionalseconddigits-undefined.js @@ -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) {