js/src/tests/test262/intl402/ch12/12.2/12.2.3_b.js

branch
TOR_BUG_3246
changeset 6
8bccb770b82d
equal deleted inserted replaced
-1:000000000000 0:8d2323a224bc
1 // Copyright 2012 Mozilla Corporation. All rights reserved.
2 // This code is governed by the license found in the LICENSE file.
3
4 /**
5 * @description Tests that Intl.DateTimeFormat does not accept Unicode locale
6 * extension keys and values that are not allowed.
7 * @author Norbert Lindenberg
8 */
9
10 $INCLUDE("testIntl.js");
11
12 var locales = ["ja-JP", "zh-Hans-CN", "zh-Hant-TW"];
13 var input = new Date(Date.parse("1989-11-09T17:57:00Z"));
14
15 locales.forEach(function (locale) {
16 var defaultDateTimeFormat = new Intl.DateTimeFormat([locale]);
17 var defaultOptions = defaultDateTimeFormat.resolvedOptions();
18 var defaultOptionsJSON = JSON.stringify(defaultOptions);
19 var defaultLocale = defaultOptions.locale;
20 var defaultFormatted = defaultDateTimeFormat.format(input);
21
22 var keyValues = {
23 "cu": ["USD", "EUR", "JPY", "CNY", "TWD", "invalid"], // DateTimeFormat internally uses NumberFormat
24 "nu": ["native", "traditio", "finance", "invalid"],
25 "tz": ["usnavajo", "utcw01", "aumel", "uslax", "usnyc", "deber", "invalid"]
26 };
27
28 Object.getOwnPropertyNames(keyValues).forEach(function (key) {
29 keyValues[key].forEach(function (value) {
30 var dateTimeFormat = new Intl.DateTimeFormat([locale + "-u-" + key + "-" + value]);
31 var options = dateTimeFormat.resolvedOptions();
32 if (options.locale !== defaultLocale) {
33 $ERROR("Locale " + options.locale + " is affected by key " +
34 key + "; value " + value + ".");
35 }
36 if (JSON.stringify(options) !== defaultOptionsJSON) {
37 $ERROR("Resolved options " + JSON.stringify(options) + " are affected by key " +
38 key + "; value " + value + ".");
39 }
40 if (defaultFormatted !== dateTimeFormat.format(input)) {
41 $ERROR("Formatted value " + dateTimeFormat.format(input) + " is affected by key " +
42 key + "; value " + value + ".");
43 }
44 });
45 });
46 });
47

mercurial