Debian Codegraph @

tests/auto/qml/ecmascripttests/test262/test/intl402/DateTimeFormat/required-date-time-formats.js

raw
1 // Copyright 2012 Mozilla Corporation. All rights reserved.
2 // This code is governed by the license found in the LICENSE file.
3
4 /*---
5 es5id: 12.2.3_c
6 description: >
7 Tests that Intl.DateTimeFormat provides the required date-time
8 format component subsets.
9 author: Norbert Lindenberg
10 includes: [testIntl.js]
11 ---*/
12
13 var locales = ["de-DE", "en-US", "hi-IN", "id-ID", "ja-JP", "th-TH", "zh-Hans-CN", "zh-Hant-TW", "zxx"];
14 var subsets = [
15 {weekday: "long", year: "numeric", month: "numeric", day: "numeric",
16 hour: "numeric", minute: "numeric", second: "numeric"},
17 {weekday: "long", year: "numeric", month: "numeric", day: "numeric"},
18 {year: "numeric", month: "numeric", day: "numeric"},
19 {year: "numeric", month: "numeric"},
20 {month: "numeric", day: "numeric"},
21 {hour: "numeric", minute: "numeric", second: "numeric"},
22 {hour: "numeric", minute: "numeric"}
23 ];
24
25 locales.forEach(function (locale) {
26 subsets.forEach(function (subset) {
27 var format = new Intl.DateTimeFormat([locale], subset);
28 var actual = format.resolvedOptions();
29 getDateTimeComponents().forEach(function (component) {
30 if (actual.hasOwnProperty(component)) {
31 assert(subset.hasOwnProperty(component),
32 "Unrequested component " + component +
33 " added to requested subset " + JSON.stringify(subset) +
34 "; locale " + locale + ".");
35 assert.notSameValue(getDateTimeComponentValues(component).indexOf(actual[component]), -1,
36 "Invalid value " + actual[component] + " for date-time component " + component + "." +
37 " (Testing locale " + locale + "; subset " + JSON.stringify(subset) + ")");
38 } else {
39 assert.sameValue(subset.hasOwnProperty(component), false,
40 "Missing component " + component +
41 " from requested subset " + JSON.stringify(subset) +
42 "; locale " + locale + ".");
43 }
44 });
45 });
46 });