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 the option localeMatcher is processed correctly. michael@0: * @author Norbert Lindenberg michael@0: */ michael@0: michael@0: $INCLUDE("testIntl.js"); michael@0: michael@0: testWithIntlConstructors(function (Constructor) { michael@0: var defaultLocale = new Constructor().resolvedOptions().locale; michael@0: michael@0: var validValues = [undefined, "lookup", "best fit", {toString: function () { return "lookup"; }}]; michael@0: validValues.forEach(function (value) { michael@0: var supported = Constructor.supportedLocalesOf([defaultLocale], {localeMatcher: value}); michael@0: }); michael@0: michael@0: var invalidValues = [null, 0, 5, NaN, true, false, "invalid"]; michael@0: invalidValues.forEach(function (value) { michael@0: var error; michael@0: try { michael@0: var supported = Constructor.supportedLocalesOf([defaultLocale], {localeMatcher: value}); michael@0: } catch (e) { michael@0: error = e; michael@0: } michael@0: if (error === undefined) { michael@0: $ERROR("Invalid localeMatcher value " + value + " was not rejected."); michael@0: } else if (error.name !== "RangeError") { michael@0: $ERROR("Invalid localeMatcher value " + value + " was rejected with wrong error " + error.name + "."); michael@0: } michael@0: }); michael@0: michael@0: return true; michael@0: }); michael@0: