numeric-and-caseFirst.js (2334B)
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 es5id: 10.1.1_19_c 6 description: > 7 Tests that the options numeric and caseFirst can be set through 8 either the locale or the options. 9 author: Norbert Lindenberg 10 ---*/ 11 12 var options = [ 13 {key: "kn", property: "numeric", type: "boolean", values: [true, false]}, 14 {key: "kf", property: "caseFirst", type: "string", values: ["upper", "lower", "false"]} 15 ]; 16 17 options.forEach(function (option) { 18 var defaultLocale = new Intl.Collator().resolvedOptions().locale; 19 var collator, opt, result; 20 21 // find out which values are supported for a property in the default locale 22 var supportedValues = []; 23 option.values.forEach(function (value) { 24 opt = {}; 25 opt[option.property] = value; 26 collator = new Intl.Collator([defaultLocale], opt); 27 result = collator.resolvedOptions()[option.property]; 28 if (result !== undefined && supportedValues.indexOf(result) === -1) { 29 supportedValues.push(result); 30 } 31 }); 32 33 // verify that the supported values can also be set through the locale 34 supportedValues.forEach(function (value) { 35 collator = new Intl.Collator([defaultLocale + "-u-" + option.key + "-" + value]); 36 result = collator.resolvedOptions()[option.property]; 37 assert.sameValue(result, value, "Property " + option.property + " couldn't be set through locale extension key " + option.key + "."); 38 }); 39 40 // verify that the options setting overrides the locale setting 41 supportedValues.forEach(function (value) { 42 var otherValue; 43 option.values.forEach(function (possibleValue) { 44 if (possibleValue !== value) { 45 otherValue = possibleValue; 46 } 47 }); 48 if (otherValue !== undefined) { 49 opt = {}; 50 opt[option.property] = value; 51 collator = new Intl.Collator([defaultLocale + "-u-" + option.key + "-" + otherValue], opt); 52 result = collator.resolvedOptions()[option.property]; 53 assert.sameValue(result, value, "Options value for property " + option.property + " doesn't override locale extension key " + option.key + "."); 54 } 55 }); 56 }); 57 58 reportCompare(0, 0);