js/src/tests/test262/intl402/ch10/10.1/10.1.1_19_c.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 // Copyright 2012 Mozilla Corporation. All rights reserved.
     2 // This code is governed by the BSD license found in the LICENSE file.
     4 /**
     5  * @description Tests that the options numeric and caseFirst can be
     6  *     set through either the locale or the options.
     7  * @author Norbert Lindenberg
     8  */
    10 $INCLUDE("testIntl.js");
    12 var options = [
    13     {key: "kn", property: "numeric", type: "boolean", values: [true, false]},
    14     {key: "kf", property: "caseFirst", type: "string", values: ["upper", "lower", "false"]}
    15 ];
    17 options.forEach(function (option) {
    18     var defaultLocale = new Intl.Collator().resolvedOptions().locale;
    19     var collator, opt, result;
    21     // find out which values are supported for a property in the default locale
    22     var supportedValues = [];
    23     option.values.forEach(function (value) {
    24         opt = {};
    25         opt[option.property] = value;
    26         collator = new Intl.Collator([defaultLocale], opt);
    27         result = collator.resolvedOptions()[option.property];
    28         if (result !== undefined && supportedValues.indexOf(result) === -1) {
    29             supportedValues.push(result);
    30         }
    31     });
    33     // verify that the supported values can also be set through the locale
    34     supportedValues.forEach(function (value) {
    35         collator = new Intl.Collator([defaultLocale + "-u-" + option.key + "-" + value]);
    36         result = collator.resolvedOptions()[option.property];
    37         if (result !== value) {
    38             $ERROR("Property " + option.property + " couldn't be set through locale extension key " +
    39                 option.key + "; requested value: " + value + "; actual value: " + result + ".");
    40         }
    41     });
    43     // verify that the options setting overrides the locale setting
    44     supportedValues.forEach(function (value) {
    45         var otherValue;
    46         option.values.forEach(function (possibleValue) {
    47             if (possibleValue !== value) {
    48                 otherValue = possibleValue;
    49             }
    50         });
    51         if (otherValue !== undefined) {
    52             opt = {};
    53             opt[option.property] = value;
    54             collator = new Intl.Collator([defaultLocale + "-u-" + option.key + "-" + otherValue], opt);
    55             result = collator.resolvedOptions()[option.property];
    56             if (result !== value) {
    57                 $ERROR("Options value for property " + option.property + " doesn't override locale extension key " +
    58                     option.key + "; requested value: " + value + "; actual value: " + result + ".");
    59             }
    60         }
    61     });
    62 });

mercurial