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 a single string instead of a locale list is treated michael@0: * as the locale list containing that string. michael@0: * @author Norbert Lindenberg michael@0: */ michael@0: michael@0: $INCLUDE("testIntl.js"); michael@0: michael@0: var validAndInvalidLanguageTags = [ michael@0: "de", // ISO 639 language code michael@0: "de-DE", // + ISO 3166-1 country code michael@0: "DE-de", // tags are case-insensitive michael@0: "cmn", // ISO 639 language code michael@0: "cmn-Hans", // + script code michael@0: "CMN-hANS", // tags are case-insensitive michael@0: "cmn-hans-cn", // + ISO 3166-1 country code michael@0: "es-419", // + UN M.49 region code michael@0: "es-419-u-nu-latn-cu-bob", // + Unicode locale extension sequence michael@0: "i-klingon", // grandfathered tag michael@0: "cmn-hans-cn-t-ca-u-ca-x-t-u", // singleton subtags can also be used as private use subtags michael@0: "enochian-enochian", // language and variant subtags may be the same michael@0: "de-gregory-u-ca-gregory", // variant and extension subtags may be the same michael@0: "de_DE", michael@0: "DE_de", michael@0: "cmn_Hans", michael@0: "cmn-hans_cn", michael@0: "es_419", michael@0: "es-419-u-nu-latn-cu_bob", michael@0: "i_klingon", michael@0: "cmn-hans-cn-t-ca-u-ca-x_t-u", michael@0: "enochian_enochian", michael@0: "de-gregory_u-ca-gregory", michael@0: "i", // singleton alone michael@0: "x", // private use without subtag michael@0: "u", // extension singleton in first place michael@0: "419", // region code in first place michael@0: "u-nu-latn-cu-bob", // extension sequence without language michael@0: "hans-cmn-cn", // "hans" could theoretically be a 4-letter language code, michael@0: // but those can't be followed by extlang codes. michael@0: "cmn-hans-cn-u-u", // duplicate singleton michael@0: "cmn-hans-cn-t-u-ca-u", // duplicate singleton michael@0: "de-gregory-gregory" // duplicate variant michael@0: ]; michael@0: michael@0: testWithIntlConstructors(function (Constructor) { michael@0: validAndInvalidLanguageTags.forEach(function (locale) { michael@0: var obj1, obj2, locale1, locale2, error1, error2; michael@0: try { michael@0: obj1 = new Constructor(locale); michael@0: locale1 = obj1.resolvedOptions().locale; michael@0: } catch (e) { michael@0: error1 = e; michael@0: } michael@0: try { michael@0: obj2 = new Constructor([locale]); michael@0: locale2 = obj2.resolvedOptions().locale; michael@0: } catch (e) { michael@0: error2 = e; michael@0: } michael@0: michael@0: if ((error1 === undefined) !== (error2 === undefined)) { michael@0: if (error1 === undefined) { michael@0: $ERROR("Single locale string " + locale + michael@0: " was accepted, but locale list containing that string wasn't."); michael@0: } else { michael@0: $ERROR("Single locale string " + locale + michael@0: " was rejected, but locale list containing that string wasn't."); michael@0: } michael@0: } else if (error1 === undefined) { michael@0: if (locale1 !== locale2) { michael@0: $ERROR("Single locale string " + locale + " results in " + locale1 + michael@0: ", but locale list [" + locale + "] results in " + locale2 + "."); michael@0: } michael@0: } else { michael@0: if (error1.name !== error2.name) { michael@0: $ERROR("Single locale string " + locale + " results in error " + error1.name + michael@0: ", but locale list [" + locale + "] results in error " + error2.name + "."); michael@0: } michael@0: } michael@0: }); michael@0: michael@0: return true; michael@0: }); michael@0: