Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Initial tests for Intl.DateTimeFormat quarter/dayPeriod/fractionalSec…
…ondDigits (#2194)
- Loading branch information
Showing
with
582 additions
and 0 deletions.
- +12 −0 features.txt
- +29 −0 test/intl402/DateTimeFormat/constructor-options-dayPeriod-invalid.js
- +35 −0 test/intl402/DateTimeFormat/constructor-options-dayPeriod-valid.js
- +35 −0 test/intl402/DateTimeFormat/constructor-options-fractionalSecondDigits-invalid.js
- +42 −0 test/intl402/DateTimeFormat/constructor-options-fractionalSecondDigits-valid.js
- +48 −0 test/intl402/DateTimeFormat/constructor-options-order-dayPeriod.js
- +68 −0 test/intl402/DateTimeFormat/constructor-options-order-fractionalSecondDigits.js
- +44 −0 test/intl402/DateTimeFormat/constructor-options-order-quarter.js
- +29 −0 test/intl402/DateTimeFormat/constructor-options-quarter-invalid.js
- +35 −0 test/intl402/DateTimeFormat/constructor-options-quarter-valid.js
- +24 −0 test/intl402/DateTimeFormat/constructor-options-throwing-getters-dayPeriod.js
- +24 −0 test/intl402/DateTimeFormat/constructor-options-throwing-getters-fractionalSecondDigits.js
- +24 −0 test/intl402/DateTimeFormat/constructor-options-throwing-getters-quarter.js
- +29 −0 test/intl402/DateTimeFormat/prototype/resolvedOptions/order-dayPeriod.js
- +27 −0 test/intl402/DateTimeFormat/prototype/resolvedOptions/order-fractionalSecondDigits.js
- +29 −0 test/intl402/DateTimeFormat/prototype/resolvedOptions/order-quarter.js
- +16 −0 test/intl402/DateTimeFormat/taint-Object-prototype-dayPeriod.js
- +16 −0 test/intl402/DateTimeFormat/taint-Object-prototype-fractionalSecondDigits.js
- +16 −0 test/intl402/DateTimeFormat/taint-Object-prototype-quarter.js
| @@ -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); | ||
| } | ||
| } |
Oops, something went wrong.