js/src/tests/test262/intl402/ch09/9.2/9.2.1_3.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/test262/intl402/ch09/9.2/9.2.1_3.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,87 @@
     1.4 +// Copyright 2012 Mozilla Corporation. All rights reserved.
     1.5 +// This code is governed by the BSD license found in the LICENSE file.
     1.6 +
     1.7 +/**
     1.8 + * @description Tests that a single string instead of a locale list is treated
     1.9 + *     as the locale list containing that string.
    1.10 + * @author Norbert Lindenberg
    1.11 + */
    1.12 +
    1.13 +$INCLUDE("testIntl.js");
    1.14 +
    1.15 +var validAndInvalidLanguageTags = [
    1.16 +    "de", // ISO 639 language code
    1.17 +    "de-DE", // + ISO 3166-1 country code
    1.18 +    "DE-de", // tags are case-insensitive
    1.19 +    "cmn", // ISO 639 language code
    1.20 +    "cmn-Hans", // + script code
    1.21 +    "CMN-hANS", // tags are case-insensitive
    1.22 +    "cmn-hans-cn", // + ISO 3166-1 country code
    1.23 +    "es-419", // + UN M.49 region code
    1.24 +    "es-419-u-nu-latn-cu-bob", // + Unicode locale extension sequence
    1.25 +    "i-klingon", // grandfathered tag
    1.26 +    "cmn-hans-cn-t-ca-u-ca-x-t-u", // singleton subtags can also be used as private use subtags
    1.27 +    "enochian-enochian", // language and variant subtags may be the same
    1.28 +    "de-gregory-u-ca-gregory", // variant and extension subtags may be the same
    1.29 +    "de_DE",
    1.30 +    "DE_de",
    1.31 +    "cmn_Hans",
    1.32 +    "cmn-hans_cn",
    1.33 +    "es_419",
    1.34 +    "es-419-u-nu-latn-cu_bob",
    1.35 +    "i_klingon",
    1.36 +    "cmn-hans-cn-t-ca-u-ca-x_t-u",
    1.37 +    "enochian_enochian",
    1.38 +    "de-gregory_u-ca-gregory",
    1.39 +    "i", // singleton alone
    1.40 +    "x", // private use without subtag
    1.41 +    "u", // extension singleton in first place
    1.42 +    "419", // region code in first place
    1.43 +    "u-nu-latn-cu-bob", // extension sequence without language
    1.44 +    "hans-cmn-cn", // "hans" could theoretically be a 4-letter language code,
    1.45 +                   // but those can't be followed by extlang codes.
    1.46 +    "cmn-hans-cn-u-u", // duplicate singleton
    1.47 +    "cmn-hans-cn-t-u-ca-u", // duplicate singleton
    1.48 +    "de-gregory-gregory" // duplicate variant
    1.49 +];
    1.50 +
    1.51 +testWithIntlConstructors(function (Constructor) {
    1.52 +    validAndInvalidLanguageTags.forEach(function (locale) {
    1.53 +        var obj1, obj2, locale1, locale2, error1, error2;
    1.54 +        try {
    1.55 +            obj1 = new Constructor(locale);
    1.56 +            locale1 = obj1.resolvedOptions().locale;
    1.57 +        } catch (e) {
    1.58 +            error1 = e;
    1.59 +        }
    1.60 +        try {
    1.61 +            obj2 = new Constructor([locale]);
    1.62 +            locale2 = obj2.resolvedOptions().locale;
    1.63 +        } catch (e) {
    1.64 +            error2 = e;
    1.65 +        }
    1.66 +
    1.67 +        if ((error1 === undefined) !== (error2 === undefined)) {
    1.68 +            if (error1 === undefined) {
    1.69 +                $ERROR("Single locale string " + locale +
    1.70 +                    " was accepted, but locale list containing that string wasn't.");
    1.71 +            } else {
    1.72 +                $ERROR("Single locale string " + locale +
    1.73 +                    " was rejected, but locale list containing that string wasn't.");
    1.74 +            }
    1.75 +        } else if (error1 === undefined) {
    1.76 +             if (locale1 !== locale2) {
    1.77 +                $ERROR("Single locale string " + locale + " results in " + locale1 +
    1.78 +                    ", but locale list [" + locale + "] results in " + locale2 + ".");
    1.79 +             }
    1.80 +        } else {
    1.81 +            if (error1.name !== error2.name) {
    1.82 +                $ERROR("Single locale string " + locale + " results in error " + error1.name +
    1.83 +                    ", but locale list [" + locale + "] results in error " + error2.name + ".");
    1.84 +             }
    1.85 +        }
    1.86 +    });
    1.87 +    
    1.88 +    return true;
    1.89 +});
    1.90 +

mercurial