2022-05-03 17:19:32 +02:00
|
|
|
// Copyright 2022 Igalia, S.L. All rights reserved.
|
|
|
|
// This code is governed by the BSD license found in the LICENSE file.
|
|
|
|
|
|
|
|
/*---
|
|
|
|
esid: sec-Intl.DurationFormat
|
|
|
|
description: Checks handling of valid values for the style option to the DurationFormat constructor.
|
|
|
|
info: |
|
|
|
|
InitializeDurationFormat (DurationFormat, locales, options)
|
|
|
|
(...)
|
Fix DurationFormat default tests (#3640)
1. add the test for "seconds"
2. since the default value for "style" is "long", baseStyle for GetDurationUnitOptions is "long" and therefore the
last argument in testOption should be "long"
3. the valid values for "days" does not contains "numeric", and "2-digit". remove them.
4. the valid values for "milliseconds", "microseconds" and "nanoseconds" does not contains "2-digit". remove it.
See https://tc39.es/proposal-intl-duration-format/#table-duration-components about the valid value
notice the last colum is for "Digital Default" while the baseStyle is "digital" but the set up does not set it that way, the default value for "style" is "long" as in
```
13. Let style be ? GetOption(options, "style", "string", « "long", "short", "narrow", "digital" », "long").
```
of https://tc39.es/proposal-intl-duration-format/#sec-Intl.DurationFormat
* Sync to PR 121
Change default from "long" to "short"
2022-09-14 21:51:40 +02:00
|
|
|
13. Let style be ? GetOption(options, "style", "string", « "long", "short", "narrow", "digital" », "short").
|
2022-05-03 17:19:32 +02:00
|
|
|
14. Set durationFormat.[[Style]] to style.
|
|
|
|
features: [Intl.DurationFormat]
|
|
|
|
---*/
|
|
|
|
|
|
|
|
const validOptions = [
|
Fix DurationFormat default tests (#3640)
1. add the test for "seconds"
2. since the default value for "style" is "long", baseStyle for GetDurationUnitOptions is "long" and therefore the
last argument in testOption should be "long"
3. the valid values for "days" does not contains "numeric", and "2-digit". remove them.
4. the valid values for "milliseconds", "microseconds" and "nanoseconds" does not contains "2-digit". remove it.
See https://tc39.es/proposal-intl-duration-format/#table-duration-components about the valid value
notice the last colum is for "Digital Default" while the baseStyle is "digital" but the set up does not set it that way, the default value for "style" is "long" as in
```
13. Let style be ? GetOption(options, "style", "string", « "long", "short", "narrow", "digital" », "long").
```
of https://tc39.es/proposal-intl-duration-format/#sec-Intl.DurationFormat
* Sync to PR 121
Change default from "long" to "short"
2022-09-14 21:51:40 +02:00
|
|
|
[undefined, "short"],
|
2022-05-03 17:19:32 +02:00
|
|
|
["long", "long"],
|
|
|
|
["short", "short"],
|
|
|
|
["narrow", "narrow"],
|
|
|
|
["digital", "digital"],
|
|
|
|
[{ toString() { return "short"; } }, "short"],
|
|
|
|
[{ toString() { return "long"; } }, "long"],
|
|
|
|
[{ toString() { return "narrow"; } }, "narrow"],
|
|
|
|
[{ toString() { return "digital"; } }, "digital"],
|
|
|
|
];
|
|
|
|
|
|
|
|
for (const [validOption, expected] of validOptions) {
|
|
|
|
const df = new Intl.DurationFormat([], {"style": validOption});
|
|
|
|
const resolvedOptions = df.resolvedOptions();
|
|
|
|
assert.sameValue(resolvedOptions.style, expected);
|
|
|
|
}
|