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

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

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

mercurial