mirror of https://github.com/tc39/test262.git
Add more tests for DateTimeFormat.hourCycle/hour12. (#2385)
In particular, when using dateStyle/timeStyle. See also <https://github.com/tc39/proposal-intl-datetime-style/issues/34>.
This commit is contained in:
parent
146ef7db57
commit
4b6efea2c6
67
test/intl402/DateTimeFormat/prototype/resolvedOptions/hourCycle-dateStyle.js
vendored
Normal file
67
test/intl402/DateTimeFormat/prototype/resolvedOptions/hourCycle-dateStyle.js
vendored
Normal file
|
@ -0,0 +1,67 @@
|
|||
// Copyright 2019 Mozilla Corporation, Igalia S.L. All rights reserved.
|
||||
// This code is governed by the license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-Intl.DateTimeFormat.prototype.resolvedOptions
|
||||
description: >
|
||||
Intl.DateTimeFormat.prototype.resolvedOptions properly
|
||||
reflect hourCycle settings when using dateStyle.
|
||||
features: [Intl.DateTimeFormat-datetimestyle]
|
||||
---*/
|
||||
|
||||
const hcValues = ["h11", "h12", "h23", "h24"];
|
||||
const hour12Values = ["h11", "h12"];
|
||||
|
||||
for (const dateStyle of ["full", "long", "medium", "short"]) {
|
||||
assert.sameValue(new Intl.DateTimeFormat([], { dateStyle }).resolvedOptions().dateStyle,
|
||||
dateStyle,
|
||||
`Should support dateStyle=${dateStyle}`);
|
||||
|
||||
/* Values passed via unicode extension key work */
|
||||
|
||||
for (const hcValue of hcValues) {
|
||||
const resolvedOptions = new Intl.DateTimeFormat(`de-u-hc-${hcValue}`, {
|
||||
dateStyle,
|
||||
}).resolvedOptions();
|
||||
|
||||
assert.sameValue(resolvedOptions.hourCycle, undefined);
|
||||
assert.sameValue(resolvedOptions.hour12, undefined);
|
||||
}
|
||||
|
||||
/* Values passed via options work */
|
||||
|
||||
for (const hcValue of hcValues) {
|
||||
const resolvedOptions = new Intl.DateTimeFormat("en-US", {
|
||||
dateStyle,
|
||||
hourCycle: hcValue
|
||||
}).resolvedOptions();
|
||||
|
||||
assert.sameValue(resolvedOptions.hourCycle, undefined);
|
||||
assert.sameValue(resolvedOptions.hour12, undefined);
|
||||
}
|
||||
|
||||
let resolvedOptions = new Intl.DateTimeFormat("en-US-u-hc-h12", {
|
||||
dateStyle,
|
||||
hourCycle: "h23"
|
||||
}).resolvedOptions();
|
||||
|
||||
assert.sameValue(resolvedOptions.hourCycle, undefined);
|
||||
assert.sameValue(resolvedOptions.hour12, undefined);
|
||||
|
||||
resolvedOptions = new Intl.DateTimeFormat("fr", {
|
||||
dateStyle,
|
||||
hour12: true,
|
||||
hourCycle: "h23"
|
||||
}).resolvedOptions();
|
||||
|
||||
assert.sameValue(resolvedOptions.hourCycle, undefined);
|
||||
assert.sameValue(resolvedOptions.hour12, undefined);
|
||||
|
||||
resolvedOptions = new Intl.DateTimeFormat("fr-u-hc-h24", {
|
||||
dateStyle,
|
||||
hour12: true,
|
||||
}).resolvedOptions();
|
||||
|
||||
assert.sameValue(resolvedOptions.hourCycle, undefined);
|
||||
assert.sameValue(resolvedOptions.hour12, undefined);
|
||||
}
|
87
test/intl402/DateTimeFormat/prototype/resolvedOptions/hourCycle-timeStyle.js
vendored
Normal file
87
test/intl402/DateTimeFormat/prototype/resolvedOptions/hourCycle-timeStyle.js
vendored
Normal file
|
@ -0,0 +1,87 @@
|
|||
// Copyright 2019 Mozilla Corporation, Igalia S.L. All rights reserved.
|
||||
// This code is governed by the license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-Intl.DateTimeFormat.prototype.resolvedOptions
|
||||
description: >
|
||||
Intl.DateTimeFormat.prototype.resolvedOptions properly
|
||||
reflect hourCycle settings when using timeStyle.
|
||||
includes: [propertyHelper.js]
|
||||
features: [Intl.DateTimeFormat-datetimestyle]
|
||||
---*/
|
||||
|
||||
const hcValues = ["h11", "h12", "h23", "h24"];
|
||||
const hour12Values = ["h11", "h12"];
|
||||
const dataPropertyDesc = { writable: true, enumerable: true, configurable: true };
|
||||
|
||||
for (const timeStyle of ["full", "long", "medium", "short"]) {
|
||||
assert.sameValue(new Intl.DateTimeFormat([], { timeStyle }).resolvedOptions().timeStyle,
|
||||
timeStyle,
|
||||
`Should support timeStyle=${timeStyle}`);
|
||||
|
||||
/* Values passed via unicode extension key work */
|
||||
|
||||
for (const hcValue of hcValues) {
|
||||
const resolvedOptions = new Intl.DateTimeFormat(`de-u-hc-${hcValue}`, {
|
||||
timeStyle,
|
||||
}).resolvedOptions();
|
||||
|
||||
assert.sameValue(resolvedOptions.hourCycle, hcValue);
|
||||
assert.sameValue(resolvedOptions.hour12, hour12Values.includes(hcValue));
|
||||
}
|
||||
|
||||
/* Values passed via options work */
|
||||
|
||||
for (const hcValue of hcValues) {
|
||||
const resolvedOptions = new Intl.DateTimeFormat("en-US", {
|
||||
timeStyle,
|
||||
hourCycle: hcValue
|
||||
}).resolvedOptions();
|
||||
|
||||
assert.sameValue(resolvedOptions.hourCycle, hcValue);
|
||||
assert.sameValue(resolvedOptions.hour12, hour12Values.includes(hcValue));
|
||||
|
||||
verifyProperty(resolvedOptions, "hourCycle", dataPropertyDesc);
|
||||
verifyProperty(resolvedOptions, "hour12", dataPropertyDesc);
|
||||
}
|
||||
|
||||
/* When both extension key and option is passed, option takes precedence */
|
||||
|
||||
let resolvedOptions = new Intl.DateTimeFormat("en-US-u-hc-h12", {
|
||||
timeStyle,
|
||||
hourCycle: "h23"
|
||||
}).resolvedOptions();
|
||||
|
||||
assert.sameValue(resolvedOptions.hourCycle, "h23");
|
||||
assert.sameValue(resolvedOptions.hour12, false);
|
||||
|
||||
verifyProperty(resolvedOptions, "hourCycle", dataPropertyDesc);
|
||||
verifyProperty(resolvedOptions, "hour12", dataPropertyDesc);
|
||||
|
||||
/* When hour12 and hourCycle are set, hour12 takes precedence */
|
||||
|
||||
resolvedOptions = new Intl.DateTimeFormat("fr", {
|
||||
timeStyle,
|
||||
hour12: true,
|
||||
hourCycle: "h23"
|
||||
}).resolvedOptions();
|
||||
|
||||
assert(hour12Values.includes(resolvedOptions.hourCycle));
|
||||
assert.sameValue(resolvedOptions.hour12, true);
|
||||
|
||||
verifyProperty(resolvedOptions, "hourCycle", dataPropertyDesc);
|
||||
verifyProperty(resolvedOptions, "hour12", dataPropertyDesc);
|
||||
|
||||
/* When hour12 and extension key are set, hour12 takes precedence */
|
||||
|
||||
resolvedOptions = new Intl.DateTimeFormat("fr-u-hc-h24", {
|
||||
timeStyle,
|
||||
hour12: true,
|
||||
}).resolvedOptions();
|
||||
|
||||
assert(hour12Values.includes(resolvedOptions.hourCycle));
|
||||
assert.sameValue(resolvedOptions.hour12, true);
|
||||
|
||||
verifyProperty(resolvedOptions, "hourCycle", dataPropertyDesc);
|
||||
verifyProperty(resolvedOptions, "hour12", dataPropertyDesc);
|
||||
}
|
|
@ -85,3 +85,15 @@ assert.sameValue(resolvedOptions.hour12, true);
|
|||
|
||||
verifyProperty(resolvedOptions, 'hourCycle', dataPropertyDesc);
|
||||
verifyProperty(resolvedOptions, 'hour12', dataPropertyDesc);
|
||||
|
||||
/* When the hour is not in the pattern, hourCycle and hour12 are not defined. */
|
||||
|
||||
resolvedOptions = new Intl.DateTimeFormat("fr", {
|
||||
hourCycle: "h12",
|
||||
hour12: false,
|
||||
}).resolvedOptions();
|
||||
|
||||
assert.sameValue(resolvedOptions.hour, undefined,
|
||||
"Precondition: hour should not be included by default");
|
||||
assert.sameValue(resolvedOptions.hourCycle, undefined);
|
||||
assert.sameValue(resolvedOptions.hour12, undefined);
|
||||
|
|
Loading…
Reference in New Issue