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