Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
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 a single string instead of a locale list is treated
6 * as the locale list containing that string.
7 * @author Norbert Lindenberg
8 */
10 $INCLUDE("testIntl.js");
12 var validAndInvalidLanguageTags = [
13 "de", // ISO 639 language code
14 "de-DE", // + ISO 3166-1 country code
15 "DE-de", // tags are case-insensitive
16 "cmn", // ISO 639 language code
17 "cmn-Hans", // + script code
18 "CMN-hANS", // tags are case-insensitive
19 "cmn-hans-cn", // + ISO 3166-1 country code
20 "es-419", // + UN M.49 region code
21 "es-419-u-nu-latn-cu-bob", // + Unicode locale extension sequence
22 "i-klingon", // grandfathered tag
23 "cmn-hans-cn-t-ca-u-ca-x-t-u", // singleton subtags can also be used as private use subtags
24 "enochian-enochian", // language and variant subtags may be the same
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 ];
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 }
64 if ((error1 === undefined) !== (error2 === undefined)) {
65 if (error1 === undefined) {
66 $ERROR("Single locale string " + locale +
67 " was accepted, but locale list containing that string wasn't.");
68 } else {
69 $ERROR("Single locale string " + locale +
70 " was rejected, but locale list containing that string wasn't.");
71 }
72 } else if (error1 === undefined) {
73 if (locale1 !== locale2) {
74 $ERROR("Single locale string " + locale + " results in " + locale1 +
75 ", but locale list [" + locale + "] results in " + locale2 + ".");
76 }
77 } else {
78 if (error1.name !== error2.name) {
79 $ERROR("Single locale string " + locale + " results in error " + error1.name +
80 ", but locale list [" + locale + "] results in error " + error2.name + ".");
81 }
82 }
83 });
85 return true;
86 });