| 1 |
// Copyright 2020 Mozilla Corporation. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
esid: sec-resolvelocale |
| 6 |
description: > |
| 7 |
Values provided as properties of the options-argument to the Locale |
| 8 |
constructor are converted to canonical form. |
| 9 |
info: | |
| 10 |
ResolveLocale ( availableLocales, requestedLocales, options, relevantExtensionKeys, localeData ) |
| 11 |
|
| 12 |
... |
| 13 |
9.i.iii.1. Let optionsValue be the string optionsValue after performing the algorithm steps to transform Unicode extension values to canonical syntax per Unicode Technical Standard #35 LDML § 3.2.1 Canonical Unicode Locale Identifiers, treating key as ukey and optionsValue as uvalue productions. |
| 14 |
9.i.iii.2. Let optionsValue be the string optionsValue after performing the algorithm steps to replace Unicode extension values with their canonical form per Unicode Technical Standard #35 LDML § 3.2.1 Canonical Unicode Locale Identifiers, treating key as ukey and optionsValue as uvalue productions. |
| 15 |
... |
| 16 |
|
| 17 |
features: [Intl.Locale] |
| 18 |
---*/ |
| 19 |
|
| 20 |
const keyValueTests = [ |
| 21 |
{ |
| 22 |
key: "ca", |
| 23 |
option: "calendar", |
| 24 |
tests: [ |
| 25 |
["islamicc", "islamic-civil"], |
| 26 |
["ethiopic-amete-alem", "ethioaa"], |
| 27 |
], |
| 28 |
}, |
| 29 |
]; |
| 30 |
|
| 31 |
for (const { key, option, tests } of keyValueTests) { |
| 32 |
for (const [noncanonical, canonical] of tests) { |
| 33 |
let canonicalInLocale = |
| 34 |
new Intl.Locale(`en-u-${key}-${canonical}`); |
| 35 |
|
| 36 |
assert.sameValue( |
| 37 |
canonicalInLocale[option], |
| 38 |
canonical, |
| 39 |
`new Intl.Locale("en-u-${key}-${canonical}").${option} returns ${canonical}` |
| 40 |
); |
| 41 |
|
| 42 |
let canonicalInOption = |
| 43 |
new Intl.Locale(`en`, { [option]: canonical }); |
| 44 |
|
| 45 |
assert.sameValue( |
| 46 |
canonicalInOption[option], |
| 47 |
canonical, |
| 48 |
`new Intl.Locale("en", { ${option}: "${canonical}" }).${option} returns ${canonical}` |
| 49 |
); |
| 50 |
|
| 51 |
let noncanonicalInLocale = |
| 52 |
new Intl.Locale(`en-u-${key}-${noncanonical}`); |
| 53 |
|
| 54 |
assert.sameValue( |
| 55 |
noncanonicalInLocale[option], |
| 56 |
canonical, |
| 57 |
`new Intl.Locale("en-u-${key}-${noncanonical}").${option} returns ${canonical}` |
| 58 |
); |
| 59 |
|
| 60 |
let noncanonicalInOption = |
| 61 |
new Intl.Locale(`en`, { [option]: noncanonical }); |
| 62 |
|
| 63 |
assert.sameValue( |
| 64 |
noncanonicalInOption[option], |
| 65 |
canonical, |
| 66 |
`new Intl.Locale("en", { ${option}: "${noncanonical}" }).${option} returns ${canonical}` |
| 67 |
); |
| 68 |
} |
| 69 |
} |
| 70 |
|
| 71 |
reportCompare(0, 0); |