Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
michael@0 | 1 | // Copyright 2012 Mozilla Corporation. All rights reserved. |
michael@0 | 2 | // This code is governed by the BSD license found in the LICENSE file. |
michael@0 | 3 | |
michael@0 | 4 | /** |
michael@0 | 5 | * @description Tests that the options numeric and caseFirst can be |
michael@0 | 6 | * set through either the locale or the options. |
michael@0 | 7 | * @author Norbert Lindenberg |
michael@0 | 8 | */ |
michael@0 | 9 | |
michael@0 | 10 | $INCLUDE("testIntl.js"); |
michael@0 | 11 | |
michael@0 | 12 | var options = [ |
michael@0 | 13 | {key: "kn", property: "numeric", type: "boolean", values: [true, false]}, |
michael@0 | 14 | {key: "kf", property: "caseFirst", type: "string", values: ["upper", "lower", "false"]} |
michael@0 | 15 | ]; |
michael@0 | 16 | |
michael@0 | 17 | options.forEach(function (option) { |
michael@0 | 18 | var defaultLocale = new Intl.Collator().resolvedOptions().locale; |
michael@0 | 19 | var collator, opt, result; |
michael@0 | 20 | |
michael@0 | 21 | // find out which values are supported for a property in the default locale |
michael@0 | 22 | var supportedValues = []; |
michael@0 | 23 | option.values.forEach(function (value) { |
michael@0 | 24 | opt = {}; |
michael@0 | 25 | opt[option.property] = value; |
michael@0 | 26 | collator = new Intl.Collator([defaultLocale], opt); |
michael@0 | 27 | result = collator.resolvedOptions()[option.property]; |
michael@0 | 28 | if (result !== undefined && supportedValues.indexOf(result) === -1) { |
michael@0 | 29 | supportedValues.push(result); |
michael@0 | 30 | } |
michael@0 | 31 | }); |
michael@0 | 32 | |
michael@0 | 33 | // verify that the supported values can also be set through the locale |
michael@0 | 34 | supportedValues.forEach(function (value) { |
michael@0 | 35 | collator = new Intl.Collator([defaultLocale + "-u-" + option.key + "-" + value]); |
michael@0 | 36 | result = collator.resolvedOptions()[option.property]; |
michael@0 | 37 | if (result !== value) { |
michael@0 | 38 | $ERROR("Property " + option.property + " couldn't be set through locale extension key " + |
michael@0 | 39 | option.key + "; requested value: " + value + "; actual value: " + result + "."); |
michael@0 | 40 | } |
michael@0 | 41 | }); |
michael@0 | 42 | |
michael@0 | 43 | // verify that the options setting overrides the locale setting |
michael@0 | 44 | supportedValues.forEach(function (value) { |
michael@0 | 45 | var otherValue; |
michael@0 | 46 | option.values.forEach(function (possibleValue) { |
michael@0 | 47 | if (possibleValue !== value) { |
michael@0 | 48 | otherValue = possibleValue; |
michael@0 | 49 | } |
michael@0 | 50 | }); |
michael@0 | 51 | if (otherValue !== undefined) { |
michael@0 | 52 | opt = {}; |
michael@0 | 53 | opt[option.property] = value; |
michael@0 | 54 | collator = new Intl.Collator([defaultLocale + "-u-" + option.key + "-" + otherValue], opt); |
michael@0 | 55 | result = collator.resolvedOptions()[option.property]; |
michael@0 | 56 | if (result !== value) { |
michael@0 | 57 | $ERROR("Options value for property " + option.property + " doesn't override locale extension key " + |
michael@0 | 58 | option.key + "; requested value: " + value + "; actual value: " + result + "."); |
michael@0 | 59 | } |
michael@0 | 60 | } |
michael@0 | 61 | }); |
michael@0 | 62 | }); |
michael@0 | 63 |