Port tests for PlainTime.

This commit is contained in:
Ms2ger 2022-02-09 16:57:37 +01:00 committed by Rick Waldron
parent 8851f084b6
commit 0370240141
42 changed files with 600 additions and 22 deletions

View File

@ -0,0 +1,19 @@
// 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.compare
description: compare() casts its arguments
features: [Temporal]
---*/
const t1 = Temporal.PlainTime.from("08:44:15.321");
const t2 = Temporal.PlainTime.from("14:23:30.123");
assert.sameValue(Temporal.PlainTime.compare({ hour: 16, minute: 34 }, t2), 1, "one object");
assert.sameValue(Temporal.PlainTime.compare("16:34", t2), 1, "one string");
assert.throws(TypeError, () => Temporal.PlainTime.compare({ hours: 16 }, t2), "one missing property");
assert.sameValue(Temporal.PlainTime.compare(t1, { hour: 16, minute: 34 }), -1, "two object");
assert.sameValue(Temporal.PlainTime.compare(t1, "16:34"), -1, "two string");
assert.throws(TypeError, () => Temporal.PlainTime.compare(t1, { hours: 16 }), "two missing property");

View File

@ -0,0 +1,17 @@
// 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.compare
description: Basic tests for compare()
features: [Temporal]
---*/
const t1 = Temporal.PlainTime.from("08:44:15.321");
const t1bis = Temporal.PlainTime.from("08:44:15.321");
const t2 = Temporal.PlainTime.from("14:23:30.123");
assert.sameValue(Temporal.PlainTime.compare(t1, t1), 0, "same object");
assert.sameValue(Temporal.PlainTime.compare(t1, t1bis), 0, "different object");
assert.sameValue(Temporal.PlainTime.compare(t1, t2), -1, "before");
assert.sameValue(Temporal.PlainTime.compare(t2, t1), 1, "after");

View File

@ -0,0 +1,14 @@
// 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.from
description: Fast path for converting Temporal.PlainDateTime to Temporal.PlainDate by reading internal slots
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
TemporalHelpers.checkPlainDateTimeConversionFastPath((plainDateTime) => {
const result = Temporal.PlainTime.from(plainDateTime);
TemporalHelpers.assertPlainTime(result, 12, 34, 56, 987, 654, 321);
});

View File

@ -0,0 +1,14 @@
// 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.from
description: A PlainTime object is copied, not returned directly
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
const plainTime = Temporal.PlainTime.from("11:42:00");
const result = Temporal.PlainTime.from(plainTime);
assert.notSameValue(result, plainTime);
TemporalHelpers.assertPlainTime(result, 11, 42, 0, 0, 0, 0);

View File

@ -0,0 +1,26 @@
// 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.from
description: overflow property is extracted with ISO-invalid string argument.
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
const expected = [
"get overflow",
"get overflow.toString",
"call overflow.toString",
];
let actual = [];
const object = {
get overflow() {
actual.push("get overflow");
return TemporalHelpers.toPrimitiveObserver(actual, "constrain", "overflow");
}
};
assert.throws(RangeError, () => Temporal.PlainTime.from("24:60", object));
assert.compareArray(actual, expected);

View File

@ -0,0 +1,11 @@
// 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.from
description: RangeError thrown if a string argument has trailing junk
features: [Temporal, arrow-function]
---*/
const arg = "15:23:30.100junk";
assert.throws(RangeError, () => Temporal.PlainTime.from(arg));

View File

@ -0,0 +1,57 @@
// 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.from
description: Various ISO strings supported
includes: [compareArray.js, temporalHelpers.js]
features: [Temporal]
---*/
const tests = [
["15:23", 15, 23, 0, 0, 0, 0],
["15:23:30", 15, 23, 30, 0, 0, 0],
["15:23:30.123", 15, 23, 30, 123, 0, 0],
["15:23:30.123456", 15, 23, 30, 123, 456, 0],
["15:23:30.123456789", 15, 23, 30, 123, 456, 789],
["1976-11-18T15:23:30.1", 15, 23, 30, 100, 0, 0],
["1976-11-18T15:23:30.12", 15, 23, 30, 120, 0, 0],
["1976-11-18T15:23:30.123", 15, 23, 30, 123, 0, 0],
["1976-11-18T15:23:30.1234", 15, 23, 30, 123, 400, 0],
["1976-11-18T15:23:30.12345", 15, 23, 30, 123, 450, 0],
["1976-11-18T15:23:30.123456", 15, 23, 30, 123, 456, 0],
["1976-11-18T15:23:30.1234567", 15, 23, 30, 123, 456, 700],
["1976-11-18T15:23:30.12345678", 15, 23, 30, 123, 456, 780],
["1976-11-18T15:23:30.123456789", 15, 23, 30, 123, 456, 789],
["1976-11-18T15:23:30,12", 15, 23, 30, 120, 0, 0],
["1976-11-18T15:23:30.12\u221202:00", 15, 23, 30, 120, 0, 0],
["152330", 15, 23, 30, 0, 0, 0],
["152330.1", 15, 23, 30, 100, 0, 0],
["152330-08", 15, 23, 30, 0, 0, 0],
["152330.1-08", 15, 23, 30, 100, 0, 0],
["152330-0800", 15, 23, 30, 0, 0, 0],
["152330.1-0800", 15, 23, 30, 100, 0, 0],
["1976-11-18T152330.1+00:00", 15, 23, 30, 100, 0, 0],
["19761118T15:23:30.1+00:00", 15, 23, 30, 100, 0, 0],
["1976-11-18T15:23:30.1+0000", 15, 23, 30, 100, 0, 0],
["1976-11-18T152330.1+0000", 15, 23, 30, 100, 0, 0],
["19761118T15:23:30.1+0000", 15, 23, 30, 100, 0, 0],
["19761118T152330.1+00:00", 15, 23, 30, 100, 0, 0],
["19761118T152330.1+0000", 15, 23, 30, 100, 0, 0],
["+001976-11-18T152330.1+00:00", 15, 23, 30, 100, 0, 0],
["+0019761118T15:23:30.1+00:00", 15, 23, 30, 100, 0, 0],
["+001976-11-18T15:23:30.1+0000", 15, 23, 30, 100, 0, 0],
["+001976-11-18T152330.1+0000", 15, 23, 30, 100, 0, 0],
["+0019761118T15:23:30.1+0000", 15, 23, 30, 100, 0, 0],
["+0019761118T152330.1+00:00", 15, 23, 30, 100, 0, 0],
["+0019761118T152330.1+0000", 15, 23, 30, 100, 0, 0],
["15", 15, 0, 0, 0, 0, 0],
["T15:23:30", 15, 23, 30, 0, 0, 0],
["t152330", 15, 23, 30, 0, 0, 0],
];
for (const [input, ...expected] of tests) {
const result = Temporal.PlainTime.from(input);
assert.sameValue(expected.length, 6, input);
TemporalHelpers.assertPlainTime(result, ...expected, input);
}

View File

@ -0,0 +1,14 @@
// 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.from
description: TypeError thrown when a primitive is passed as the options argument
features: [Temporal]
---*/
const values = [null, true, "hello", Symbol("foo"), 1, 1n];
for (const badOptions of values) {
assert.throws(TypeError, () => Temporal.PlainTime.from({ hours: 12 }, badOptions));
}

View File

@ -20,5 +20,7 @@ const validValues = [
"12:00",
];
validValues.forEach((value) => {
assert.throws(RangeError, () => Temporal.PlainTime.from(value, { overflow: "other string" }));
["", "CONSTRAIN", "balance", "other string", "constra\u0131n"].forEach((overflow) => {
assert.throws(RangeError, () => Temporal.PlainTime.from(value, { overflow }));
});
});

View File

@ -24,6 +24,8 @@ validValues.forEach((value) => {
TemporalHelpers.assertPlainTime(explicit, 12, 0, 0, 0, 0, 0, "overflow is ignored");
const implicit = Temporal.PlainTime.from(value, {});
TemporalHelpers.assertPlainTime(implicit, 12, 0, 0, 0, 0, 0, "overflow is ignored");
const lambda = Temporal.PlainTime.from(value, () => {});
TemporalHelpers.assertPlainTime(lambda, 12, 0, 0, 0, 0, 0, "overflow is ignored");
});
const propertyBag = { hour: 26 };
@ -31,3 +33,5 @@ const explicit = Temporal.PlainTime.from(propertyBag, { overflow: undefined });
TemporalHelpers.assertPlainTime(explicit, 23, 0, 0, 0, 0, 0, "default overflow is constrain");
const implicit = Temporal.PlainTime.from(propertyBag, {});
TemporalHelpers.assertPlainTime(implicit, 23, 0, 0, 0, 0, 0, "default overflow is constrain");
const lambda = Temporal.PlainTime.from(propertyBag, () => {});
TemporalHelpers.assertPlainTime(lambda, 23, 0, 0, 0, 0, 0, "default overflow is constrain");

View File

@ -0,0 +1,13 @@
// 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.add
description: Mixed positive and negative values or missing properties always throw
features: [Temporal]
---*/
const plainTime = new Temporal.PlainTime(12, 34, 56, 123, 987, 500);
assert.throws(RangeError, () => plainTime.add({ hours: 1, minutes: -6 }), "mixed signs");
assert.throws(TypeError, () => plainTime.add({}), "no properties");
assert.throws(TypeError, () => plainTime.add({ hour: 12 }), "only singular 'hour' property");

View File

@ -0,0 +1,29 @@
// 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.add
description: Options argument is ignored.
includes: [temporalHelpers.js]
features: [Symbol, Temporal]
---*/
const values = [
undefined,
null,
true,
"hello",
Symbol("foo"),
1,
1n,
{},
() => {},
{ get overflow() { throw new Test262Error("should not get overflow") } },
];
const time = Temporal.PlainTime.from("15:23:30.123456789");
for (const options of values) {
TemporalHelpers.assertPlainTime(time.add({ hours: 1 }, options),
16, 23, 30, 123, 456, 789);
}

View File

@ -0,0 +1,17 @@
// 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.equals
description: equals() casts its argument
features: [Temporal]
---*/
const t1 = Temporal.PlainTime.from("08:44:15.321");
assert.sameValue(t1.equals({ hour: 14, minute: 23, second: 30, millisecond: 123 }), false, "object");
assert.sameValue(t1.equals({ hour: 8, minute: 44, second: 15, millisecond: 321 }), true, "object");
assert.sameValue(t1.equals("14:23:30.123"), false, "string");
assert.sameValue(t1.equals("08:44:15.321"), true, "string");
assert.throws(TypeError, () => t1.equals({}), "no properties");
assert.throws(TypeError, () => t1.equals({ hours: 8 }), "only plural property");

View File

@ -0,0 +1,15 @@
// 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.equals
description: Basic tests for equals()
features: [Temporal]
---*/
const t1 = Temporal.PlainTime.from("08:44:15.321");
const t1bis = Temporal.PlainTime.from("08:44:15.321");
const t2 = Temporal.PlainTime.from("14:23:30.123");
assert.sameValue(t1.equals(t1), true, "same object");
assert.sameValue(t1.equals(t1bis), true, "different object");
assert.sameValue(t1.equals(t2), false, "different times");

View File

@ -8,4 +8,6 @@ features: [Temporal]
---*/
const time = new Temporal.PlainTime(12, 34, 56, 123, 987, 500);
assert.throws(RangeError, () => time.round({ smallestUnit: "microsecond", roundingMode: "other string" }));
for (const roundingMode of ["other string", "cile", "CEIL", "ce\u0131l"]) {
assert.throws(RangeError, () => time.round({ smallestUnit: "microsecond", roundingMode }));
}

View File

@ -0,0 +1,16 @@
// 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.since
description: TypeError thrown when a primitive is passed as the options argument
features: [Temporal]
---*/
const values = [null, true, "hello", Symbol("foo"), 1, 1n];
const time = new Temporal.PlainTime(15, 23, 30, 123, 456, 789);
const one = new Temporal.PlainTime(16, 23, 30, 123, 456, 789);
for (const badOptions of values) {
assert.throws(TypeError, () => time.since(one, badOptions));
}

View File

@ -9,4 +9,7 @@ features: [Temporal]
const earlier = new Temporal.PlainTime(12, 34, 56, 0, 0, 0);
const later = new Temporal.PlainTime(13, 35, 57, 123, 987, 500);
assert.throws(RangeError, () => later.since(earlier, { smallestUnit: "microsecond", roundingMode: "other string" }));
for (const roundingMode of ["other string", "cile", "CEIL", "ce\u0131l"]) {
assert.throws(RangeError, () => later.since(earlier, { smallestUnit: "microsecond", roundingMode }));
}

View File

@ -15,3 +15,5 @@ const explicit = later.since(earlier, { smallestUnit: undefined });
TemporalHelpers.assertDuration(explicit, 0, 0, 0, 0, 1, 1, 1, 987, 654, 321, "default smallestUnit is nanosecond");
const implicit = later.since(earlier, {});
TemporalHelpers.assertDuration(implicit, 0, 0, 0, 0, 1, 1, 1, 987, 654, 321, "default smallestUnit is nanosecond");
const lambda = later.since(earlier, () => {});
TemporalHelpers.assertDuration(lambda, 0, 0, 0, 0, 1, 1, 1, 987, 654, 321, "default smallestUnit is nanosecond");

View File

@ -0,0 +1,13 @@
// 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.subtract
description: Mixed positive and negative values or missing properties always throw
features: [Temporal]
---*/
const plainTime = new Temporal.PlainTime(12, 34, 56, 123, 987, 500);
assert.throws(RangeError, () => plainTime.subtract({ hours: 1, minutes: -6 }), "mixed signs");
assert.throws(TypeError, () => plainTime.subtract({}), "no properties");
assert.throws(TypeError, () => plainTime.subtract({ hour: 12 }), "only singular 'hour' property");

View File

@ -0,0 +1,29 @@
// 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.subtract
description: Options argument is ignored.
includes: [temporalHelpers.js]
features: [Symbol, Temporal]
---*/
const values = [
undefined,
null,
true,
"hello",
Symbol("foo"),
1,
1n,
{},
() => {},
{ get overflow() { throw new Test262Error("should not get overflow") } },
];
const time = Temporal.PlainTime.from("15:23:30.123456789");
for (const options of values) {
TemporalHelpers.assertPlainTime(time.subtract({ hours: 1 }, options),
14, 23, 30, 123, 456, 789);
}

View File

@ -0,0 +1,15 @@
// 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.tostring
description: Basic tests for toString()
features: [Temporal]
---*/
assert.sameValue(new Temporal.PlainTime(15, 23).toString(), "15:23:00");
assert.sameValue(new Temporal.PlainTime(15, 23, 30).toString(), "15:23:30");
assert.sameValue(new Temporal.PlainTime(15, 23, 30, 123).toString(), "15:23:30.123");
assert.sameValue(new Temporal.PlainTime(15, 23, 30, 123, 400).toString(), "15:23:30.1234");
assert.sameValue(new Temporal.PlainTime(15, 23, 30, 123, 456).toString(), "15:23:30.123456");
assert.sameValue(new Temporal.PlainTime(15, 23, 30, 123, 456, 789).toString(), "15:23:30.123456789");

View File

@ -0,0 +1,19 @@
// 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.tostring
description: auto value for fractionalSecondDigits option
features: [Temporal]
---*/
const tests = [
["15:23", "15:23:00"],
["15:23:30", "15:23:30"],
["15:23:30.1234", "15:23:30.1234"],
];
for (const [input, expected] of tests) {
const plainTime = Temporal.PlainTime.from(input);
assert.sameValue(plainTime.toString({ fractionalSecondDigits: "auto" }), expected);
}

View File

@ -16,4 +16,6 @@ features: [Temporal]
const time = new Temporal.PlainTime(12, 34, 56, 987, 650, 0);
assert.throws(RangeError, () => time.toString({ fractionalSecondDigits: "other string" }));
for (const fractionalSecondDigits of ["other string", "AUTO", "not-auto", "autos"]) {
assert.throws(RangeError, () => time.toString({ fractionalSecondDigits }));
}

View File

@ -0,0 +1,22 @@
// 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.tostring
description: Number for fractionalSecondDigits option
features: [Temporal]
---*/
const t1 = Temporal.PlainTime.from("15:23");
const t2 = Temporal.PlainTime.from("15:23:30");
const t3 = Temporal.PlainTime.from("15:23:30.1234");
assert.sameValue(t3.toString({ fractionalSecondDigits: 0 }), "15:23:30");
assert.sameValue(t1.toString({ fractionalSecondDigits: 2 }), "15:23:00.00");
assert.sameValue(t2.toString({ fractionalSecondDigits: 2 }), "15:23:30.00");
assert.sameValue(t3.toString({ fractionalSecondDigits: 2 }), "15:23:30.12");
assert.sameValue(t3.toString({ fractionalSecondDigits: 3 }), "15:23:30.123");
assert.sameValue(t3.toString({ fractionalSecondDigits: 6 }), "15:23:30.123400");
assert.sameValue(t1.toString({ fractionalSecondDigits: 7 }), "15:23:00.0000000");
assert.sameValue(t2.toString({ fractionalSecondDigits: 7 }), "15:23:30.0000000");
assert.sameValue(t3.toString({ fractionalSecondDigits: 7 }), "15:23:30.1234000");
assert.sameValue(t3.toString({ fractionalSecondDigits: 9 }), "15:23:30.123400000");

View File

@ -16,5 +16,7 @@ features: [Temporal]
const time = new Temporal.PlainTime(12, 34, 56, 987, 650, 0);
assert.throws(RangeError, () => time.toString({ fractionalSecondDigits: -Infinity }));
assert.throws(RangeError, () => time.toString({ fractionalSecondDigits: -1 }));
assert.throws(RangeError, () => time.toString({ fractionalSecondDigits: 10 }));
assert.throws(RangeError, () => time.toString({ fractionalSecondDigits: Infinity }));

View File

@ -16,10 +16,21 @@ info: |
features: [Temporal]
---*/
const time = new Temporal.PlainTime(12, 34, 56, 987, 650, 0);
const tests = [
["15:23", "15:23:00"],
["15:23:30", "15:23:30"],
["15:23:30.1234", "15:23:30.1234"],
];
const explicit = time.toString({ fractionalSecondDigits: undefined });
assert.sameValue(explicit, "12:34:56.98765", "default fractionalSecondDigits is auto");
for (const [input, expected] of tests) {
const time = Temporal.PlainTime.from(input);
const implicit = time.toString({});
assert.sameValue(implicit, "12:34:56.98765", "default fractionalSecondDigits is auto");
const explicit = time.toString({ fractionalSecondDigits: undefined });
assert.sameValue(explicit, expected, "default fractionalSecondDigits is auto");
const implicit = time.toString({});
assert.sameValue(implicit, expected, "default fractionalSecondDigits is auto");
const lambda = time.toString(() => {});
assert.sameValue(lambda, expected, "default fractionalSecondDigits is auto");
}

View File

@ -0,0 +1,15 @@
// 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.tostring
description: TypeError thrown when a primitive is passed as the options argument
features: [Temporal]
---*/
const instance = Temporal.PlainTime.from("12:56:32");
const values = [null, true, "hello", Symbol("foo"), 1, 1n];
for (const badOptions of values) {
assert.throws(TypeError, () => instance.toString(badOptions));
}

View File

@ -7,14 +7,18 @@ description: Verify that undefined options are handled correctly.
features: [Temporal]
---*/
const time = new Temporal.PlainTime(12, 34, 56, 987, 650);
const expected = "12:34:56.98765";
const tests = [
["15:23", "15:23:00"],
["15:23:30", "15:23:30"],
["15:23:30.1234", "15:23:30.1234"],
];
const explicit = time.toString(undefined);
assert.sameValue(explicit, expected, "default precision is auto and no rounding");
for (const [input, expected] of tests) {
const time = Temporal.PlainTime.from(input);
const propertyImplicit = time.toString({});
assert.sameValue(propertyImplicit, expected, "default precision is auto and no rounding");
const explicit = time.toString(undefined);
assert.sameValue(explicit, expected, "default precision is auto and no rounding");
const implicit = time.toString();
assert.sameValue(implicit, expected, "default precision is auto and no rounding");
const implicit = time.toString();
assert.sameValue(implicit, expected, "default precision is auto and no rounding");
}

View File

@ -0,0 +1,13 @@
// 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.tostring
description: Rounding can cross midnight
features: [Temporal]
---*/
const plainTime = Temporal.PlainTime.from("23:59:59.999999999");
for (const roundingMode of ["ceil", "halfExpand"]) {
assert.sameValue(plainTime.toString({ fractionalSecondDigits: 8, roundingMode }), "00:00:00.00000000");
}

View File

@ -0,0 +1,19 @@
// 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.tostring
description: ceil value for roundingMode option
features: [Temporal]
---*/
const time = new Temporal.PlainTime(12, 34, 56, 123, 987, 500);
const result1 = time.toString({ smallestUnit: "microsecond", roundingMode: "ceil" });
assert.sameValue(result1, "12:34:56.123988", "roundingMode is ceil");
const result2 = time.toString({ smallestUnit: "millisecond", roundingMode: "ceil" });
assert.sameValue(result2, "12:34:56.124", "roundingMode is ceil");
const result3 = time.toString({ smallestUnit: "second", roundingMode: "ceil" });
assert.sameValue(result3, "12:34:57", "roundingMode is ceil");

View File

@ -0,0 +1,19 @@
// 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.tostring
description: floor value for roundingMode option
features: [Temporal]
---*/
const time = new Temporal.PlainTime(12, 34, 56, 123, 987, 500);
const result1 = time.toString({ smallestUnit: "microsecond", roundingMode: "floor" });
assert.sameValue(result1, "12:34:56.123987", "roundingMode is floor");
const result2 = time.toString({ smallestUnit: "millisecond", roundingMode: "floor" });
assert.sameValue(result2, "12:34:56.123", "roundingMode is floor");
const result3 = time.toString({ smallestUnit: "second", roundingMode: "floor" });
assert.sameValue(result3, "12:34:56", "roundingMode is floor");

View File

@ -0,0 +1,19 @@
// 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.tostring
description: halfExpand value for roundingMode option
features: [Temporal]
---*/
const time = new Temporal.PlainTime(12, 34, 56, 123, 987, 500);
const result1 = time.toString({ smallestUnit: "microsecond", roundingMode: "halfExpand" });
assert.sameValue(result1, "12:34:56.123988", "roundingMode is halfExpand");
const result2 = time.toString({ smallestUnit: "millisecond", roundingMode: "halfExpand" });
assert.sameValue(result2, "12:34:56.124", "roundingMode is halfExpand");
const result3 = time.toString({ smallestUnit: "second", roundingMode: "halfExpand" });
assert.sameValue(result3, "12:34:56", "roundingMode is halfExpand");

View File

@ -8,4 +8,6 @@ features: [Temporal]
---*/
const time = new Temporal.PlainTime(12, 34, 56, 123, 987, 500);
assert.throws(RangeError, () => time.toString({ smallestUnit: "microsecond", roundingMode: "other string" }));
for (const roundingMode of ["other string", "cile", "CEIL", "ce\u0131l"]) {
assert.throws(RangeError, () => time.toString({ smallestUnit: "microsecond", roundingMode }));
}

View File

@ -0,0 +1,19 @@
// 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.tostring
description: trunc value for roundingMode option
features: [Temporal]
---*/
const time = new Temporal.PlainTime(12, 34, 56, 123, 987, 500);
const result1 = time.toString({ smallestUnit: "microsecond", roundingMode: "trunc" });
assert.sameValue(result1, "12:34:56.123987", "roundingMode is trunc");
const result2 = time.toString({ smallestUnit: "millisecond", roundingMode: "trunc" });
assert.sameValue(result2, "12:34:56.123", "roundingMode is trunc");
const result3 = time.toString({ smallestUnit: "second", roundingMode: "trunc" });
assert.sameValue(result3, "12:34:56", "roundingMode is trunc");

View File

@ -0,0 +1,31 @@
// 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.tostring
description: fractionalSecondDigits option is not used with smallestUnit present
features: [Temporal]
---*/
const time = new Temporal.PlainTime(12, 34, 56, 789, 999, 999);
const tests = [
["minute", "12:34"],
["second", "12:34:56"],
["millisecond", "12:34:56.789"],
["microsecond", "12:34:56.789999"],
["nanosecond", "12:34:56.789999999"],
];
for (const [smallestUnit, expected] of tests) {
const string = time.toString({
smallestUnit,
get fractionalSecondDigits() { throw new Test262Error("should not get fractionalSecondDigits") }
});
assert.sameValue(string, expected, smallestUnit);
}
assert.throws(RangeError, () => time.toString({
smallestUnit: "hour",
get fractionalSecondDigits() { throw new Test262Error("should not get fractionalSecondDigits") }
}));

View File

@ -8,4 +8,6 @@ features: [Temporal]
---*/
const time = new Temporal.PlainTime(12, 34, 56, 123, 987, 500);
assert.throws(RangeError, () => time.toString({ smallestUnit: "other string" }));
for (const smallestUnit of ["era", "year", "month", "day", "hour", "nonsense", "other string", "m\u0131nute", "SECOND"]) {
assert.throws(RangeError, () => time.toString({ smallestUnit }));
}

View File

@ -8,13 +8,19 @@ features: [Temporal]
---*/
const time = new Temporal.PlainTime(12, 34, 56, 789, 999, 999);
assert.sameValue(time.toString({ smallestUnit: "minute" }), "12:34");
assert.sameValue(time.toString({ smallestUnit: "second" }), "12:34:56");
assert.sameValue(time.toString({ smallestUnit: "millisecond" }), "12:34:56.789");
assert.sameValue(time.toString({ smallestUnit: "microsecond" }), "12:34:56.789999");
assert.sameValue(time.toString({ smallestUnit: "nanosecond" }), "12:34:56.789999999");
const time2 = new Temporal.PlainTime(12, 34);
assert.sameValue(time2.toString({ smallestUnit: "minute" }), "12:34");
assert.sameValue(time2.toString({ smallestUnit: "second" }), "12:34:00");
assert.sameValue(time2.toString({ smallestUnit: "millisecond" }), "12:34:00.000");
assert.sameValue(time2.toString({ smallestUnit: "microsecond" }), "12:34:00.000000");
assert.sameValue(time2.toString({ smallestUnit: "nanosecond" }), "12:34:00.000000000");
const notValid = [
"year",
"month",

View File

@ -0,0 +1,16 @@
// 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.until
description: TypeError thrown when a primitive is passed as the options argument
features: [Temporal]
---*/
const values = [null, true, "hello", Symbol("foo"), 1, 1n];
const time = new Temporal.PlainTime(15, 23, 30, 123, 456, 789);
const one = new Temporal.PlainTime(16, 23, 30, 123, 456, 789);
for (const badOptions of values) {
assert.throws(TypeError, () => time.until(one, badOptions));
}

View File

@ -14,6 +14,6 @@ const explicit = earlier.until(later, undefined);
assert.sameValue(explicit.hours, 6, "default largest unit is hours");
assert.sameValue(explicit.nanoseconds, 1, "default smallest unit is nanoseconds and no rounding");
const implicit = earlier.until(later, undefined);
const implicit = earlier.until(later);
assert.sameValue(implicit.hours, 6, "default largest unit is hours");
assert.sameValue(implicit.nanoseconds, 1, "default smallest unit is nanoseconds and no rounding");

View File

@ -9,4 +9,6 @@ features: [Temporal]
const earlier = new Temporal.PlainTime(12, 34, 56, 0, 0, 0);
const later = new Temporal.PlainTime(13, 35, 57, 123, 987, 500);
assert.throws(RangeError, () => earlier.until(later, { smallestUnit: "microsecond", roundingMode: "other string" }));
for (const roundingMode of ["other string", "cile", "CEIL", "ce\u0131l"]) {
assert.throws(RangeError, () => earlier.until(later, { smallestUnit: "microsecond", roundingMode }));
}

View File

@ -15,3 +15,5 @@ const explicit = earlier.until(later, { smallestUnit: undefined });
TemporalHelpers.assertDuration(explicit, 0, 0, 0, 0, 1, 1, 1, 987, 654, 321, "default smallestUnit is nanosecond");
const implicit = earlier.until(later, {});
TemporalHelpers.assertDuration(implicit, 0, 0, 0, 0, 1, 1, 1, 987, 654, 321, "default smallestUnit is nanosecond");
const lambda = earlier.until(later, () => {});
TemporalHelpers.assertDuration(lambda, 0, 0, 0, 0, 1, 1, 1, 987, 654, 321, "default smallestUnit is nanosecond");

View File

@ -0,0 +1,21 @@
// 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.valueof
description: Basic tests for valueOf().
features: [Temporal]
---*/
const plainTime = Temporal.PlainTime.from("09:36:29.123456789");
const plainTime2 = Temporal.PlainTime.from("09:36:29.123456789");
assert.throws(TypeError, () => plainTime.valueOf(), "valueOf");
assert.throws(TypeError, () => plainTime < plainTime, "<");
assert.throws(TypeError, () => plainTime <= plainTime, "<=");
assert.throws(TypeError, () => plainTime > plainTime, ">");
assert.throws(TypeError, () => plainTime >= plainTime, ">=");
assert.sameValue(plainTime === plainTime, true, "===");
assert.sameValue(plainTime === plainTime2, false, "===");
assert.sameValue(plainTime !== plainTime, false, "!==");
assert.sameValue(plainTime !== plainTime2, true, "!==");