js/src/tests/test262/intl402/ch06/6.2/6.2.3.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.

     1 // Copyright 2011-2012 Norbert Lindenberg. All rights reserved.
     2 // Copyright 2012  Mozilla Corporation. All rights reserved.
     3 // This code is governed by the BSD license found in the LICENSE file.
     5 /**
     6  * @description Tests that language tags are canonicalized in return values.
     7  * @author Norbert Lindenberg
     8  */
    10 $INCLUDE("testIntl.js");
    12 var canonicalizedTags = {
    13     "de": ["de"],
    14     "de-DE": ["de-DE", "de"],
    15     "DE-de": ["de-DE", "de"],
    16     "cmn": ["cmn"],
    17     "CMN-hANS": ["cmn-Hans", "cmn"],
    18     "cmn-hans-cn": ["cmn-Hans-CN", "cmn-Hans", "cmn"],
    19     "es-419": ["es-419", "es"],
    20     "es-419-u-nu-latn": ["es-419-u-nu-latn", "es-419", "es", "es-u-nu-latn"],
    21     // -u-ca is incomplete, so it will not show up in resolvedOptions().locale
    22     "cmn-hans-cn-u-ca-t-ca-x-t-u": ["cmn-Hans-CN-t-ca-u-ca-x-t-u", "cmn-Hans-CN-t-ca-x-t-u", "cmn-Hans-CN-t-ca-x-t", "cmn-Hans-CN-t-ca", "cmn-Hans-CN", "cmn-Hans", "cmn"],
    23     "enochian-enochian": ["enochian-enochian", "enochian"],
    24     "de-gregory-u-ca-gregory": ["de-gregory-u-ca-gregory", "de-gregory", "de-u-ca-gregory", "de"],
    25     "no-nyn": ["nn"],
    26     "i-klingon": ["tlh"],
    27     "sgn-GR": ["gss"],
    28     "ji": ["yi"],
    29     "de-DD": ["de-DE", "de"],
    30     "zh-hak-CN": ["hak-CN", "hak"],
    31     "sgn-ils": ["ils"],
    32     "in": ["id"],
    33     "x-foo": ["x-foo"]
    34 };
    36 // make sure the data above is correct
    37 Object.getOwnPropertyNames(canonicalizedTags).forEach(function (tag) {
    38     canonicalizedTags[tag].forEach(function (canonicalTag) {
    39         if (!isCanonicalizedStructurallyValidLanguageTag(canonicalTag)) {
    40             $ERROR("Test data \"" + canonicalTag + "\" is not canonicalized and structurally valid language tag.");
    41         }
    42     });
    43 });
    45 // now the actual test
    46 testWithIntlConstructors(function (Constructor) {
    47     var defaultLocale = new Constructor().resolvedOptions().locale;
    48     Object.getOwnPropertyNames(canonicalizedTags).forEach(function (tag) {
    49         // use lookup locale matcher to keep the set of possible return values predictable
    51         // Variant 1: construct an object and see whether its locale is canonicalized.
    52         // In this variant, shortened forms or the default locale may be returned
    53         var object = new Constructor([tag], {localeMatcher: "lookup"});
    54         var locale = object.resolvedOptions().locale;
    55         if (canonicalizedTags[tag].indexOf(locale) === -1 && locale !== defaultLocale) {
    56             $ERROR("For " + tag + " got " + locale + "; expected one of " +
    57                 canonicalizedTags[tag].join(", ") + ".");
    58         }
    60         // Variant 2: get the supported locales. If the tag is supported, it should be returned canonicalized but unshortened
    61         var supported = Constructor.supportedLocalesOf([tag]);
    62         if (supported.length > 0 && supported[0] !== canonicalizedTags[tag][0]) {
    63             $ERROR("For " + tag + " got " + supported[0] + "; expected " +
    64                 canonicalizedTags[tag][0] + ".");
    65         }            
    66     });
    67     return true;
    68 });

mercurial