michael@0: // Copyright 2012 Mozilla Corporation. All rights reserved. michael@0: // This code is governed by the BSD license found in the LICENSE file. michael@0: michael@0: /** michael@0: * @description Tests that locales that are reported by resolvedOptions michael@0: * are also reported by supportedLocalesOf. michael@0: * @author Norbert Lindenberg michael@0: */ michael@0: michael@0: $INCLUDE("testIntl.js"); michael@0: michael@0: testWithIntlConstructors(function (Constructor) { michael@0: var info = getLocaleSupportInfo(Constructor); michael@0: // this test should work equally for both matching algorithms michael@0: ["lookup", "best fit"].forEach(function (matcher) { michael@0: var supportedByConstructor = info.supported.concat(info.byFallback); michael@0: var supported = Constructor.supportedLocalesOf(supportedByConstructor, michael@0: {localeMatcher: matcher}); michael@0: // we could check the length first, but it's probably more interesting which locales are missing michael@0: var i = 0; michael@0: var limit = Math.min(supportedByConstructor.length, supported.length); michael@0: while (i < limit && supportedByConstructor[i] === supported[i]) { michael@0: i++; michael@0: } michael@0: if (i < supportedByConstructor.length) { michael@0: $ERROR("Locale " + supportedByConstructor[i] + michael@0: " is returned by resolvedOptions but not by supportedLocalesOf."); michael@0: } else if (i < supported.length) { michael@0: $ERROR("Locale " + supported[i] + michael@0: " is returned by supportedLocalesOf but not by resolvedOptions."); michael@0: } michael@0: }); michael@0: michael@0: // this test is only valid for lookup - best fit may find additional locales supported michael@0: var unsupportedByConstructor = info.unsupported; michael@0: var supported = Constructor.supportedLocalesOf(unsupportedByConstructor, michael@0: {localeMatcher: "lookup"}); michael@0: if (supported.length > 0) { michael@0: $ERROR("Locale " + supported[0] + michael@0: " is returned by supportedLocalesOf but not by resolvedOptions."); michael@0: } michael@0: michael@0: return true; michael@0: }); michael@0: