constructor-non-iana-canon.js (3385B)
1 // Copyright 2018 André Bargull; Igalia, S.L. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 esid: sec-intl.locale 6 description: > 7 Verifies canonicalization, minimization and maximization of specific tags. 8 info: | 9 ApplyOptionsToTag( tag, options ) 10 10. Return CanonicalizeLanguageTag(tag). 11 12 Intl.Locale.prototype.maximize () 13 3. Let maximal be the result of the Add Likely Subtags algorithm applied to loc.[[Locale]]. 14 15 Intl.Locale.prototype.minimize () 16 3. Let minimal be the result of the Remove Likely Subtags algorithm applied to loc.[[Locale]]. 17 features: [Intl.Locale] 18 ---*/ 19 20 // Test some language tags where we know that either CLDR or ICU produce 21 // different results compared to the canonicalization specified in RFC 5646. 22 var testData = [ 23 { 24 tag: "mo", 25 canonical: "ro", 26 maximized: "ro-Latn-RO", 27 }, 28 { 29 tag: "es-ES-preeuro", 30 maximized: "es-Latn-ES-preeuro", 31 minimized: "es-preeuro", 32 }, 33 { 34 tag: "uz-UZ-cyrillic", 35 maximized: "uz-Latn-UZ-cyrillic", 36 minimized: "uz-cyrillic", 37 }, 38 { 39 tag: "posix", 40 }, 41 { 42 tag: "hi-direct", 43 maximized: "hi-Deva-IN-direct", 44 }, 45 { 46 tag: "zh-pinyin", 47 maximized: "zh-Hans-CN-pinyin", 48 }, 49 { 50 tag: "zh-stroke", 51 maximized: "zh-Hans-CN-stroke", 52 }, 53 { 54 tag: "aar-x-private", 55 // "aar" should be canonicalized into "aa" because "aar" matches the type attribute of 56 // a languageAlias element in 57 // https://www.unicode.org/repos/cldr/trunk/common/supplemental/supplementalMetadata.xml 58 canonical: "aa-x-private", 59 maximized: "aa-Latn-ET-x-private", 60 }, 61 { 62 tag: "heb-x-private", 63 // "heb" should be canonicalized into "he" because "heb" matches the type attribute of 64 // a languageAlias element in 65 // https://www.unicode.org/repos/cldr/trunk/common/supplemental/supplementalMetadata.xml 66 canonical: "he-x-private", 67 maximized: "he-Hebr-IL-x-private", 68 }, 69 { 70 tag: "de-u-kf", 71 maximized: "de-Latn-DE-u-kf", 72 }, 73 { 74 tag: "ces", 75 // "ces" should be canonicalized into "cs" because "ces" matches the type attribute of 76 // a languageAlias element in 77 // https://www.unicode.org/repos/cldr/trunk/common/supplemental/supplementalMetadata.xml 78 canonical: "cs", 79 maximized: "cs-Latn-CZ", 80 }, 81 { 82 tag: "hy-arevela", 83 canonical: "hy", 84 maximized: "hy-Armn-AM", 85 }, 86 { 87 tag: "hy-arevmda", 88 canonical: "hyw", 89 maximized: "hyw-Armn-AM", 90 }, 91 ]; 92 93 for (const {tag, canonical = tag, maximized = canonical, minimized = canonical} of testData) { 94 const loc = new Intl.Locale(tag); 95 assert.sameValue( 96 new Intl.Locale(tag).toString(), 97 canonical, 98 `new Intl.Locale("${tag}").toString() returns "${canonical}"` 99 ); 100 assert.sameValue( 101 new Intl.Locale(tag).maximize().toString(), 102 maximized, 103 `new Intl.Locale("${tag}").maximize().toString() returns "${maximized}"` 104 ); 105 assert.sameValue( 106 new Intl.Locale(tag).minimize().toString(), 107 minimized, 108 `new Intl.Locale("${tag}").minimize().toString() returns "${minimized}"` 109 ); 110 } 111 112 reportCompare(0, 0);