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 options numeric and caseFirst can be michael@0: * set through either the locale or the options. michael@0: * @author Norbert Lindenberg michael@0: */ michael@0: michael@0: $INCLUDE("testIntl.js"); michael@0: michael@0: var options = [ michael@0: {key: "kn", property: "numeric", type: "boolean", values: [true, false]}, michael@0: {key: "kf", property: "caseFirst", type: "string", values: ["upper", "lower", "false"]} michael@0: ]; michael@0: michael@0: options.forEach(function (option) { michael@0: var defaultLocale = new Intl.Collator().resolvedOptions().locale; michael@0: var collator, opt, result; michael@0: michael@0: // find out which values are supported for a property in the default locale michael@0: var supportedValues = []; michael@0: option.values.forEach(function (value) { michael@0: opt = {}; michael@0: opt[option.property] = value; michael@0: collator = new Intl.Collator([defaultLocale], opt); michael@0: result = collator.resolvedOptions()[option.property]; michael@0: if (result !== undefined && supportedValues.indexOf(result) === -1) { michael@0: supportedValues.push(result); michael@0: } michael@0: }); michael@0: michael@0: // verify that the supported values can also be set through the locale michael@0: supportedValues.forEach(function (value) { michael@0: collator = new Intl.Collator([defaultLocale + "-u-" + option.key + "-" + value]); michael@0: result = collator.resolvedOptions()[option.property]; michael@0: if (result !== value) { michael@0: $ERROR("Property " + option.property + " couldn't be set through locale extension key " + michael@0: option.key + "; requested value: " + value + "; actual value: " + result + "."); michael@0: } michael@0: }); michael@0: michael@0: // verify that the options setting overrides the locale setting michael@0: supportedValues.forEach(function (value) { michael@0: var otherValue; michael@0: option.values.forEach(function (possibleValue) { michael@0: if (possibleValue !== value) { michael@0: otherValue = possibleValue; michael@0: } michael@0: }); michael@0: if (otherValue !== undefined) { michael@0: opt = {}; michael@0: opt[option.property] = value; michael@0: collator = new Intl.Collator([defaultLocale + "-u-" + option.key + "-" + otherValue], opt); michael@0: result = collator.resolvedOptions()[option.property]; michael@0: if (result !== value) { michael@0: $ERROR("Options value for property " + option.property + " doesn't override locale extension key " + michael@0: option.key + "; requested value: " + value + "; actual value: " + result + "."); michael@0: } michael@0: } michael@0: }); michael@0: }); michael@0: