Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
1 // Copyright 2012 Mozilla Corporation. All rights reserved.
2 // This code is governed by the license found in the LICENSE file.
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 */
10 $INCLUDE("testIntl.js");
12 var locales = ["ja-JP", "zh-Hans-CN", "zh-Hant-TW"];
13 var input = new Date(Date.parse("1989-11-09T17:57:00Z"));
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);
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 };
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 });