|
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 locales that are reported by resolvedOptions |
|
6 * are also reported by supportedLocalesOf. |
|
7 * @author Norbert Lindenberg |
|
8 */ |
|
9 |
|
10 $INCLUDE("testIntl.js"); |
|
11 |
|
12 testWithIntlConstructors(function (Constructor) { |
|
13 var info = getLocaleSupportInfo(Constructor); |
|
14 // this test should work equally for both matching algorithms |
|
15 ["lookup", "best fit"].forEach(function (matcher) { |
|
16 var supportedByConstructor = info.supported.concat(info.byFallback); |
|
17 var supported = Constructor.supportedLocalesOf(supportedByConstructor, |
|
18 {localeMatcher: matcher}); |
|
19 // we could check the length first, but it's probably more interesting which locales are missing |
|
20 var i = 0; |
|
21 var limit = Math.min(supportedByConstructor.length, supported.length); |
|
22 while (i < limit && supportedByConstructor[i] === supported[i]) { |
|
23 i++; |
|
24 } |
|
25 if (i < supportedByConstructor.length) { |
|
26 $ERROR("Locale " + supportedByConstructor[i] + |
|
27 " is returned by resolvedOptions but not by supportedLocalesOf."); |
|
28 } else if (i < supported.length) { |
|
29 $ERROR("Locale " + supported[i] + |
|
30 " is returned by supportedLocalesOf but not by resolvedOptions."); |
|
31 } |
|
32 }); |
|
33 |
|
34 // this test is only valid for lookup - best fit may find additional locales supported |
|
35 var unsupportedByConstructor = info.unsupported; |
|
36 var supported = Constructor.supportedLocalesOf(unsupportedByConstructor, |
|
37 {localeMatcher: "lookup"}); |
|
38 if (supported.length > 0) { |
|
39 $ERROR("Locale " + supported[0] + |
|
40 " is returned by supportedLocalesOf but not by resolvedOptions."); |
|
41 } |
|
42 |
|
43 return true; |
|
44 }); |
|
45 |