michael@0: // Copyright 2012 Mozilla Corporation. All rights reserved. michael@0: // This code is governed by the license found in the LICENSE file. michael@0: michael@0: /** michael@0: * @description Tests that Intl.Collator does not accept Unicode locale michael@0: * extension keys and values that are not allowed. michael@0: * @author Norbert Lindenberg michael@0: */ michael@0: michael@0: $INCLUDE("testIntl.js"); michael@0: michael@0: var testArray = [ michael@0: "hello", "你好", "こんにちは", michael@0: "pêche", "peché", "1", "9", "10", michael@0: "ụ\u031B", "u\u031B\u0323", "ư\u0323", "u\u0323\u031B", michael@0: "Å", "Å", "A\u030A" michael@0: ]; michael@0: michael@0: var defaultCollator = new Intl.Collator(); michael@0: var defaultOptions = defaultCollator.resolvedOptions(); michael@0: var defaultOptionsJSON = JSON.stringify(defaultOptions); michael@0: var defaultLocale = defaultOptions.locale; michael@0: var defaultSortedArray = testArray.slice(0).sort(defaultCollator.compare); michael@0: michael@0: var keyValues = { michael@0: "co": ["standard", "search", "invalid"], michael@0: "ka": ["noignore", "shifted", "invalid"], michael@0: "kb": ["true", "false", "invalid"], michael@0: "kc": ["true", "false", "invalid"], michael@0: "kh": ["true", "false", "invalid"], michael@0: "kk": ["true", "false", "invalid"], michael@0: "kr": ["latn-hira-hani", "hani-hira-latn", "invalid"], michael@0: "ks": ["level1", "level2", "level3", "level4", "identic", "invalid"], michael@0: "vt": ["1234-5678-9abc-edf0", "invalid"] michael@0: }; michael@0: michael@0: Object.getOwnPropertyNames(keyValues).forEach(function (key) { michael@0: keyValues[key].forEach(function (value) { michael@0: var collator = new Intl.Collator([defaultLocale + "-u-" + key + "-" + value]); michael@0: var options = collator.resolvedOptions(); michael@0: if (options.locale !== defaultLocale) { michael@0: $ERROR("Locale " + options.locale + " is affected by key " + michael@0: key + "; value " + value + "."); michael@0: } michael@0: if (JSON.stringify(options) !== defaultOptionsJSON) { michael@0: $ERROR("Resolved options " + JSON.stringify(options) + " are affected by key " + michael@0: key + "; value " + value + "."); michael@0: } michael@0: testArraysAreSame(defaultSortedArray, testArray.sort(collator.compare)); michael@0: }); michael@0: }); michael@0: