mirror of https://github.com/tc39/test262.git
Update numeric-hour-with-zero-minutes-and-non-zero-seconds for new default display of sub-hours units
Numeric "minute" and "seconds" units now default to "always" display, so we have to add an additional test to cover when "auto" display is used. Additionally add more inputs to cover all possible test combinations.
This commit is contained in:
parent
19d2a38558
commit
859b5c67ef
|
@ -0,0 +1,55 @@
|
|||
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-Intl.DurationFormat.prototype.format
|
||||
description: >
|
||||
The correct separator is used for numeric hours with zero minutes and non-zero (sub-)seconds.
|
||||
locale: [en-US]
|
||||
includes: [testIntl.js]
|
||||
features: [Intl.DurationFormat]
|
||||
---*/
|
||||
|
||||
const df = new Intl.DurationFormat("en", {
|
||||
// hours must be numeric, so that a time separator is used for the following units.
|
||||
hours: "numeric",
|
||||
|
||||
// Use "auto" display for sub-hours units.
|
||||
minutesDisplay: "auto",
|
||||
secondsDisplay: "auto",
|
||||
|
||||
// Zero fractional digits to omit sub-second units.
|
||||
fractionalDigits: 0,
|
||||
});
|
||||
|
||||
const durations = [
|
||||
// Test all eight possible combinations for zero and non-zero hours, minutes,
|
||||
// and seconds.
|
||||
{hours: 0, minutes: 0, seconds: 0},
|
||||
{hours: 0, minutes: 0, seconds: 1},
|
||||
{hours: 0, minutes: 1, seconds: 0},
|
||||
{hours: 0, minutes: 1, seconds: 1},
|
||||
{hours: 1, minutes: 0, seconds: 0},
|
||||
{hours: 1, minutes: 0, seconds: 1},
|
||||
{hours: 1, minutes: 1, seconds: 0},
|
||||
{hours: 1, minutes: 1, seconds: 1},
|
||||
|
||||
// Additionally test when hours is non-zero and a sub-seconds unit is non-zero,
|
||||
// but minutes and seconds are both zero.
|
||||
//
|
||||
// Note: The "fractionalDigits" option is not taken into account when computing
|
||||
// whether the seconds unit should appear in the output.
|
||||
{hours: 1, minutes: 0, seconds: 0, milliseconds: 1},
|
||||
{hours: 1, minutes: 0, seconds: 0, microseconds: 1},
|
||||
{hours: 1, minutes: 0, seconds: 0, nanoseconds: 1},
|
||||
];
|
||||
|
||||
for (const duration of durations) {
|
||||
const expected = formatDurationFormatPattern(df, duration);
|
||||
|
||||
assert.sameValue(
|
||||
df.format(duration),
|
||||
expected,
|
||||
`Duration is ${JSON.stringify(duration)}`
|
||||
);
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-Intl.DurationFormat.prototype.format
|
||||
description: >
|
||||
The correct separator is used for numeric hours with zero minutes and non-zero (sub-)seconds.
|
||||
locale: [en-US]
|
||||
includes: [testIntl.js]
|
||||
features: [Intl.DurationFormat]
|
||||
---*/
|
||||
|
||||
const df = new Intl.DurationFormat("en", {
|
||||
// hours must be numeric, so that a time separator is used for the following units.
|
||||
hours: "numeric",
|
||||
|
||||
// Use "auto" display for sub-hours units.
|
||||
minutesDisplay: "auto",
|
||||
secondsDisplay: "auto",
|
||||
});
|
||||
|
||||
const durations = [
|
||||
// Test all eight possible combinations for zero and non-zero hours, minutes,
|
||||
// and seconds.
|
||||
{hours: 0, minutes: 0, seconds: 0},
|
||||
{hours: 0, minutes: 0, seconds: 1},
|
||||
{hours: 0, minutes: 1, seconds: 0},
|
||||
{hours: 0, minutes: 1, seconds: 1},
|
||||
{hours: 1, minutes: 0, seconds: 0},
|
||||
{hours: 1, minutes: 0, seconds: 1},
|
||||
{hours: 1, minutes: 1, seconds: 0},
|
||||
{hours: 1, minutes: 1, seconds: 1},
|
||||
|
||||
// Additionally test when hours is non-zero and a sub-seconds unit is non-zero,
|
||||
// but minutes and seconds are both zero.
|
||||
{hours: 1, minutes: 0, seconds: 0, milliseconds: 1},
|
||||
{hours: 1, minutes: 0, seconds: 0, microseconds: 1},
|
||||
{hours: 1, minutes: 0, seconds: 0, nanoseconds: 1},
|
||||
];
|
||||
|
||||
for (const duration of durations) {
|
||||
const expected = formatDurationFormatPattern(df, duration);
|
||||
|
||||
assert.sameValue(
|
||||
df.format(duration),
|
||||
expected,
|
||||
`Duration is ${JSON.stringify(duration)}`
|
||||
);
|
||||
}
|
|
@ -15,16 +15,31 @@ const df = new Intl.DurationFormat("en", {
|
|||
hours: "numeric",
|
||||
});
|
||||
|
||||
const duration = {
|
||||
hours: 1,
|
||||
minutes: 0,
|
||||
seconds: 3,
|
||||
};
|
||||
const durations = [
|
||||
// Test all eight possible combinations for zero and non-zero hours, minutes,
|
||||
// and seconds.
|
||||
{hours: 0, minutes: 0, seconds: 0},
|
||||
{hours: 0, minutes: 0, seconds: 1},
|
||||
{hours: 0, minutes: 1, seconds: 0},
|
||||
{hours: 0, minutes: 1, seconds: 1},
|
||||
{hours: 1, minutes: 0, seconds: 0},
|
||||
{hours: 1, minutes: 0, seconds: 1},
|
||||
{hours: 1, minutes: 1, seconds: 0},
|
||||
{hours: 1, minutes: 1, seconds: 1},
|
||||
|
||||
const expected = formatDurationFormatPattern(df, duration);
|
||||
// Additionally test when hours is non-zero and a sub-seconds unit is non-zero,
|
||||
// but minutes and seconds are both zero.
|
||||
{hours: 1, minutes: 0, seconds: 0, milliseconds: 1},
|
||||
{hours: 1, minutes: 0, seconds: 0, microseconds: 1},
|
||||
{hours: 1, minutes: 0, seconds: 0, nanoseconds: 1},
|
||||
];
|
||||
|
||||
assert.sameValue(
|
||||
df.format(duration),
|
||||
expected,
|
||||
`Minutes always displayed when between displayed hours and seconds, even if minutes is 0`
|
||||
);
|
||||
for (const duration of durations) {
|
||||
const expected = formatDurationFormatPattern(df, duration);
|
||||
|
||||
assert.sameValue(
|
||||
df.format(duration),
|
||||
expected,
|
||||
`Duration is ${JSON.stringify(duration)}`
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue