|
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 * @description Tests that structurally valid language tags are accepted. |
|
6 * @author Norbert Lindenberg |
|
7 */ |
|
8 |
|
9 $INCLUDE("testIntl.js"); |
|
10 |
|
11 var validLanguageTags = [ |
|
12 "de", // ISO 639 language code |
|
13 "de-DE", // + ISO 3166-1 country code |
|
14 "DE-de", // tags are case-insensitive |
|
15 "cmn", // ISO 639 language code |
|
16 "cmn-Hans", // + script code |
|
17 "CMN-hANS", // tags are case-insensitive |
|
18 "cmn-hans-cn", // + ISO 3166-1 country code |
|
19 "es-419", // + UN M.49 region code |
|
20 "es-419-u-nu-latn-cu-bob", // + Unicode locale extension sequence |
|
21 "i-klingon", // grandfathered tag |
|
22 "cmn-hans-cn-t-ca-u-ca-x-t-u", // singleton subtags can also be used as private use subtags |
|
23 "enochian-enochian", // language and variant subtags may be the same |
|
24 "de-gregory-u-ca-gregory", // variant and extension subtags may be the same |
|
25 "aa-a-foo-x-a-foo-bar", // variant subtags can also be used as private use subtags |
|
26 "x-en-US-12345", // anything goes in private use tags |
|
27 "x-12345-12345-en-US", |
|
28 "x-en-US-12345-12345", |
|
29 "x-en-u-foo", |
|
30 "x-en-u-foo-u-bar" |
|
31 ]; |
|
32 |
|
33 testWithIntlConstructors(function (Constructor) { |
|
34 validLanguageTags.forEach(function (tag) { |
|
35 // this must not throw an exception for a valid language tag |
|
36 var obj = new Constructor([tag]); |
|
37 }); |
|
38 return true; |
|
39 }); |
|
40 |