js/src/tests/test262/intl402/ch09/9.2/9.2.1_3.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.

michael@0 1 // Copyright 2012 Mozilla Corporation. All rights reserved.
michael@0 2 // This code is governed by the BSD license found in the LICENSE file.
michael@0 3
michael@0 4 /**
michael@0 5 * @description Tests that a single string instead of a locale list is treated
michael@0 6 * as the locale list containing that string.
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 validAndInvalidLanguageTags = [
michael@0 13 "de", // ISO 639 language code
michael@0 14 "de-DE", // + ISO 3166-1 country code
michael@0 15 "DE-de", // tags are case-insensitive
michael@0 16 "cmn", // ISO 639 language code
michael@0 17 "cmn-Hans", // + script code
michael@0 18 "CMN-hANS", // tags are case-insensitive
michael@0 19 "cmn-hans-cn", // + ISO 3166-1 country code
michael@0 20 "es-419", // + UN M.49 region code
michael@0 21 "es-419-u-nu-latn-cu-bob", // + Unicode locale extension sequence
michael@0 22 "i-klingon", // grandfathered tag
michael@0 23 "cmn-hans-cn-t-ca-u-ca-x-t-u", // singleton subtags can also be used as private use subtags
michael@0 24 "enochian-enochian", // language and variant subtags may be the same
michael@0 25 "de-gregory-u-ca-gregory", // variant and extension subtags may be the same
michael@0 26 "de_DE",
michael@0 27 "DE_de",
michael@0 28 "cmn_Hans",
michael@0 29 "cmn-hans_cn",
michael@0 30 "es_419",
michael@0 31 "es-419-u-nu-latn-cu_bob",
michael@0 32 "i_klingon",
michael@0 33 "cmn-hans-cn-t-ca-u-ca-x_t-u",
michael@0 34 "enochian_enochian",
michael@0 35 "de-gregory_u-ca-gregory",
michael@0 36 "i", // singleton alone
michael@0 37 "x", // private use without subtag
michael@0 38 "u", // extension singleton in first place
michael@0 39 "419", // region code in first place
michael@0 40 "u-nu-latn-cu-bob", // extension sequence without language
michael@0 41 "hans-cmn-cn", // "hans" could theoretically be a 4-letter language code,
michael@0 42 // but those can't be followed by extlang codes.
michael@0 43 "cmn-hans-cn-u-u", // duplicate singleton
michael@0 44 "cmn-hans-cn-t-u-ca-u", // duplicate singleton
michael@0 45 "de-gregory-gregory" // duplicate variant
michael@0 46 ];
michael@0 47
michael@0 48 testWithIntlConstructors(function (Constructor) {
michael@0 49 validAndInvalidLanguageTags.forEach(function (locale) {
michael@0 50 var obj1, obj2, locale1, locale2, error1, error2;
michael@0 51 try {
michael@0 52 obj1 = new Constructor(locale);
michael@0 53 locale1 = obj1.resolvedOptions().locale;
michael@0 54 } catch (e) {
michael@0 55 error1 = e;
michael@0 56 }
michael@0 57 try {
michael@0 58 obj2 = new Constructor([locale]);
michael@0 59 locale2 = obj2.resolvedOptions().locale;
michael@0 60 } catch (e) {
michael@0 61 error2 = e;
michael@0 62 }
michael@0 63
michael@0 64 if ((error1 === undefined) !== (error2 === undefined)) {
michael@0 65 if (error1 === undefined) {
michael@0 66 $ERROR("Single locale string " + locale +
michael@0 67 " was accepted, but locale list containing that string wasn't.");
michael@0 68 } else {
michael@0 69 $ERROR("Single locale string " + locale +
michael@0 70 " was rejected, but locale list containing that string wasn't.");
michael@0 71 }
michael@0 72 } else if (error1 === undefined) {
michael@0 73 if (locale1 !== locale2) {
michael@0 74 $ERROR("Single locale string " + locale + " results in " + locale1 +
michael@0 75 ", but locale list [" + locale + "] results in " + locale2 + ".");
michael@0 76 }
michael@0 77 } else {
michael@0 78 if (error1.name !== error2.name) {
michael@0 79 $ERROR("Single locale string " + locale + " results in error " + error1.name +
michael@0 80 ", but locale list [" + locale + "] results in error " + error2.name + ".");
michael@0 81 }
michael@0 82 }
michael@0 83 });
michael@0 84
michael@0 85 return true;
michael@0 86 });
michael@0 87

mercurial