Skip to content
Permalink
Browse files
Initial tests for Intl.DateTimeFormat quarter/dayPeriod/fractionalSec…
…ondDigits (#2194)
  • Loading branch information
FrankYFTang authored and leobalter committed Jun 12, 2019
1 parent f7a3f63 commit 49eee8bf9d69e3e137e9a196f6e0906a7c6a2cd4
Showing with 582 additions and 0 deletions.
  1. +12 −0 features.txt
  2. +29 −0 test/intl402/DateTimeFormat/constructor-options-dayPeriod-invalid.js
  3. +35 −0 test/intl402/DateTimeFormat/constructor-options-dayPeriod-valid.js
  4. +35 −0 test/intl402/DateTimeFormat/constructor-options-fractionalSecondDigits-invalid.js
  5. +42 −0 test/intl402/DateTimeFormat/constructor-options-fractionalSecondDigits-valid.js
  6. +48 −0 test/intl402/DateTimeFormat/constructor-options-order-dayPeriod.js
  7. +68 −0 test/intl402/DateTimeFormat/constructor-options-order-fractionalSecondDigits.js
  8. +44 −0 test/intl402/DateTimeFormat/constructor-options-order-quarter.js
  9. +29 −0 test/intl402/DateTimeFormat/constructor-options-quarter-invalid.js
  10. +35 −0 test/intl402/DateTimeFormat/constructor-options-quarter-valid.js
  11. +24 −0 test/intl402/DateTimeFormat/constructor-options-throwing-getters-dayPeriod.js
  12. +24 −0 test/intl402/DateTimeFormat/constructor-options-throwing-getters-fractionalSecondDigits.js
  13. +24 −0 test/intl402/DateTimeFormat/constructor-options-throwing-getters-quarter.js
  14. +29 −0 test/intl402/DateTimeFormat/prototype/resolvedOptions/order-dayPeriod.js
  15. +27 −0 test/intl402/DateTimeFormat/prototype/resolvedOptions/order-fractionalSecondDigits.js
  16. +29 −0 test/intl402/DateTimeFormat/prototype/resolvedOptions/order-quarter.js
  17. +16 −0 test/intl402/DateTimeFormat/taint-Object-prototype-dayPeriod.js
  18. +16 −0 test/intl402/DateTimeFormat/taint-Object-prototype-fractionalSecondDigits.js
  19. +16 −0 test/intl402/DateTimeFormat/taint-Object-prototype-quarter.js
@@ -100,6 +100,18 @@ Intl.DateTimeFormat-datetimestyle
# https://github.com/tc39/proposal-intl-DateTimeFormat-formatRange
Intl.DateTimeFormat-formatRange

# Intl.DateTimeFormat: add 'dayPeriod' option
# https://github.com/tc39/ecma402/pull/346
Intl.DateTimeFormat-dayPeriod

# Intl.DateTimeFormat: add 'quarter' option
# https://github.com/tc39/ecma402/pull/346
Intl.DateTimeFormat-quarter

# Intl.DateTimeFormat: add 'fractionalSecondDigits' option
# https://github.com/tc39/ecma402/pull/347
Intl.DateTimeFormat-fractionalSecondDigits

# Global
# https://github.com/tc39/proposal-global
globalThis
@@ -0,0 +1,29 @@
// Copyright 2019 Google Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-initializedatetimeformat
description: >
Checks error cases for the options argument to the DateTimeFormat constructor.
info: |
[[DayPeriod]] `"dayPeriod"` `"narrow"`, `"short"`, `"long"`
InitializeDateTimeFormat ( dateTimeFormat, locales, options )
...
features: [Intl.DateTimeFormat-dayPeriod]
---*/


const invalidOptions = [
"",
"LONG",
" long",
"short ",
"full",
"numeric",
];
for (const dayPeriod of invalidOptions) {
assert.throws(RangeError, function() {
new Intl.DateTimeFormat("en", { dayPeriod });
}, `new Intl.DateTimeFormat("en", { dayPeriod: "${dayPeriod}" }) throws RangeError`);
}
@@ -0,0 +1,35 @@
// Copyright 2019 Google Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-initializedatetimeformat
description: >
Checks handling of the options argument to the DateTimeFormat constructor.
info: |
[[DayPeriod]] `"dayPeriod"` `"narrow"`, `"short"`, `"long"`
InitializeDateTimeFormat ( dateTimeFormat, locales, options )
...
features: [Intl.DateTimeFormat-dayPeriod]
---*/


const validOptions = [
[undefined, undefined],
["long", "long"],
["short", "short"],
["narrow", "narrow"],
[{ toString() { return "narrow"; } }, "narrow"],
[{ valueOf() { return "long"; }, toString: undefined }, "long"],
];
for (const [dayPeriod, expected] of validOptions) {
const dtf = new Intl.DateTimeFormat("en", { dayPeriod });
const options = dtf.resolvedOptions();
assert.sameValue(options.dayPeriod, expected);
const propdesc = Object.getOwnPropertyDescriptor(options, "dayPeriod");
if (expected === undefined) {
assert.sameValue(propdesc, undefined);
} else {
assert.sameValue(propdesc.value, expected);
}
}
@@ -0,0 +1,35 @@
// Copyright 2019 Google Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-initializedatetimeformat
description: >
Checks error cases for the options argument to the DateTimeFormat constructor.
info: |
InitializeDateTimeFormat ( dateTimeFormat, locales, options )
23. Let _opt_.[[FractionalSecondDigits]] be ? GetNumberOption(_options_, `"fractionalSecondDigits"`, 0, 3, 0).
...
features: [Intl.DateTimeFormat-fractionalSecondDigits]
---*/


const invalidOptions = [
"LONG",
" long",
"short ",
"full",
"numeric",
-1,
4,
"4",
"-1",
-0.00001,
3.000001,
];
for (const fractionalSecondDigits of invalidOptions) {
assert.throws(RangeError, function() {
new Intl.DateTimeFormat("en", { fractionalSecondDigits });
},
`new Intl.DateTimeFormat("en", { fractionalSecondDigits: "${fractionalSecondDigits}" }) throws RangeError`);
}
@@ -0,0 +1,42 @@
// Copyright 2019 Google Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-initializedatetimeformat
description: >
Checks handling of the options argument to the DateTimeFormat constructor.
info: |
InitializeDateTimeFormat ( dateTimeFormat, locales, options )
23. Let _opt_.[[FractionalSecondDigits]] be ? GetNumberOption(_options_, `"fractionalSecondDigits"`, 0, 3, 0).
features: [Intl.DateTimeFormat-fractionalSecondDigits]
---*/


const validOptions = [
[undefined, 0],
[-0, 0],
[0, 0],
["0", 0],
[1, 1],
["1", 1],
[2, 2],
["2", 2],
[3, 3],
["3", 3],
[2.9, 2],
["2.9", 2],
[0.00001, 0],
[{ toString() { return "3"; } }, 3],
[{ valueOf() { return -0; }, toString: undefined }, 0],
];
for (const [fractionalSecondDigits, expected] of validOptions) {
const dtf = new Intl.DateTimeFormat("en", { fractionalSecondDigits });
const options = dtf.resolvedOptions();
assert.sameValue(options.fractionalSecondDigits, expected);
const propdesc = Object.getOwnPropertyDescriptor(options, "fractionalSecondDigits");
if (expected === undefined) {
assert.sameValue(propdesc, undefined);
} else {
assert.sameValue(propdesc.value, expected);
}
}
@@ -0,0 +1,48 @@
// Copyright 2019 Googe Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-initializedatetimeformat
description: Checks the order of getting options of 'dayPeriod' for the DateTimeFormat constructor.
info: |
ToDateTimeOptions ( options, required, defaults )
4. If required is "date" or "any", then
a. For each of the property names "weekday", "year", "month", "day", "dayPeriod" do
5. If required is "time" or "any", then
a. For each of the property names "hour", "minute", "second", do
includes: [compareArray.js]
features: [Intl.DateTimeFormat-dayPeriod]
---*/

// Just need to ensure dayPeriod are get between day and hour.
const expected = [
// ToDateTimeOptions step 4.
"day", "dayPeriod",
// ToDateTimeOptions step 5.
"hour",
// InitializeDateTimeFormat step 22.
"day",
"dayPeriod",
"hour"
];

const actual = [];

const options = {
get day() {
actual.push("day");
return "numeric";
},
get dayPeriod() {
actual.push("dayPeriod");
return "long";
},
get hour() {
actual.push("hour");
return "numeric";
},
};

new Intl.DateTimeFormat("en", options);
assert.compareArray(actual, expected);
@@ -0,0 +1,68 @@
// Copyright 2019 Googe Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-initializedatetimeformat
description: Checks the order of getting options of 'fractionalSecondDigits' for the DateTimeFormat constructor.
info: |
ToDateTimeOptions ( options, required, defaults )
5. If required is "time" or "any", then
a. For each of the property names "hour", "minute", "second", "fractionalSecondDigits", do
InitializeDateTimeFormat ( dateTimeFormat, locales, options )
2. Let options be ? ToDateTimeOptions(options, "any", "date").
4. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
22. For each row of Table 5, except the header row, do
a. Let value be ? GetOption(options, prop, "string", « the strings given in the Values column of the row », undefined).
23. Let _opt_.[[FractionalSecondDigits]] be ? GetNumberOption(_options_, `"fractionalSecondDigits"`, 0, 3, 0).
26. Let matcher be ? GetOption(options, "formatMatcher", "string", « "basic", "best fit" », "best fit").
includes: [compareArray.js]
features: [Intl.DateTimeFormat-fractionalSecondDigits]
---*/

// Just need to ensure fractionalSecondDigits are get
// between second and localeMatcher the first time and
// between timeZoneName and formatMatcher the second time.
const expected = [
// InitializeDateTimeFormat step 2.
// ToDateTimeOptions step 5.
"second", "fractionalSecondDigits",
// InitializeDateTimeFormat step 4.
"localeMatcher",
// InitializeDateTimeFormat step 22.
"second",
"timeZoneName",
// InitializeDateTimeFormat step 23.
"fractionalSecondDigits",
// InitializeDateTimeFormat step 26.
"formatMatcher",
];

const actual = [];

const options = {
get second() {
actual.push("second");
return "numeric";
},
get fractionalSecondDigits() {
actual.push("fractionalSecondDigits");
return undefined;
},
get localeMatcher() {
actual.push("localeMatcher");
return undefined;
},
get timeZoneName() {
actual.push("timeZoneName");
return undefined;
},
get formatMatcher() {
actual.push("formatMatcher");
return undefined;
},
};

new Intl.DateTimeFormat("en", options);
assert.compareArray(actual, expected);
@@ -0,0 +1,44 @@
// Copyright 2019 Googe Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-initializedatetimeformat
description: Checks the order of getting options of 'quarter' for the DateTimeFormat constructor.
info: |
ToDateTimeOptions ( options, required, defaults )
4. If required is "date" or "any", then
a. For each of the property names "weekday", "year", "quarter", "month", "day", do
includes: [compareArray.js]
features: [Intl.DateTimeFormat-quarter]
---*/

// Just need to ensure quarter are get between year and month.
const expected = [
// ToDateTimeOptions step 4.
"year", "quarter", "month",
// InitializeDateTimeFormat step 22.
"year",
"quarter",
"month"
];

const actual = [];

const options = {
get month() {
actual.push("month");
return "numeric";
},
get quarter() {
actual.push("quarter");
return "long";
},
get year() {
actual.push("year");
return "numeric";
},
};

new Intl.DateTimeFormat("en", options);
assert.compareArray(actual, expected);
@@ -0,0 +1,29 @@
// Copyright 2019 Google Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-initializedatetimeformat
description: >
Checks error cases for the options argument to the DateTimeFormat constructor.
info: |
[[Quarter]] `"quarter"` `"narrow"`, `"short"`, `"long"`
InitializeDateTimeFormat ( dateTimeFormat, locales, options )
...
features: [Intl.DateTimeFormat-quarter]
---*/


const invalidOptions = [
"",
"LONG",
" long",
"short ",
"full",
"numeric",
];
for (const quarter of invalidOptions) {
assert.throws(RangeError, function() {
new Intl.DateTimeFormat("en", { quarter });
}, `new Intl.DateTimeFormat("en", { quarter: "${quarter}" }) throws RangeError`);
}
@@ -0,0 +1,35 @@
// Copyright 2019 Google Inc. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-initializedatetimeformat
description: >
Checks handling of the options argument to the DateTimeFormat constructor.
info: |
[[Quarter]] `"quarter"` `"narrow"`, `"short"`, `"long"`
InitializeDateTimeFormat ( dateTimeFormat, locales, options )
...
features: [Intl.DateTimeFormat-quarter]
---*/


const validOptions = [
[undefined, undefined],
["long", "long"],
["short", "short"],
["narrow", "narrow"],
[{ toString() { return "narrow"; } }, "narrow"],
[{ valueOf() { return "long"; }, toString: undefined }, "long"],
];
for (const [quarter, expected] of validOptions) {
const dtf = new Intl.DateTimeFormat("en", { quarter });
const options = dtf.resolvedOptions();
assert.sameValue(options.quarter, expected);
const propdesc = Object.getOwnPropertyDescriptor(options, "quarter");
if (expected === undefined) {
assert.sameValue(propdesc, undefined);
} else {
assert.sameValue(propdesc.value, expected);
}
}

0 comments on commit 49eee8b

Please sign in to comment.