Repository navigation
Add coverage for uvalue "true" and "yes" - #5016
Conversation
Ensure `yes` is only canonicalized to `true` for some ukeys.
|
"constructor-unicode-extension-uvalue-yes.js" fails in JSC and V8 because of ICU4C bugs. |
|
No other test file in "test/intl402" mentions either |
jugglinmike
left a comment
There was a problem hiding this comment.
No conflicts and no overlap with more recent additions; this all looks good to me!
For those curious: here's the source for which fields have "yes" canonicalized to "true".
(We're missing a bit of coverage, but this patch has waited long enough--I'll follow up with one of my own.)
| // Generate all possible `ukey` values. | ||
| function* ukeys() { | ||
| const lowerA = 'a'.charCodeAt(0); | ||
| const lowerZ = 'z'.charCodeAt(0); | ||
|
|
||
| for (let first = lowerA; first <= lowerZ; ++first) { | ||
| for (let second = lowerA; second <= lowerZ; ++second) { | ||
| yield String.fromCharCode(first, second); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
ukey can start with a digit.
| // Generate all possible `ukey` values. | |
| function* ukeys() { | |
| const lowerA = 'a'.charCodeAt(0); | |
| const lowerZ = 'z'.charCodeAt(0); | |
| for (let first = lowerA; first <= lowerZ; ++first) { | |
| for (let second = lowerA; second <= lowerZ; ++second) { | |
| yield String.fromCharCode(first, second); | |
| } | |
| } | |
| } | |
| // Generate all possible `ukey` values. | |
| // https://unicode.org/reports/tr35/#ukey | |
| function* ukeys() { | |
| const lowerAlpha = 'abcdefghijklmnopqrstuvwxyz'; | |
| const lowerAlphanum = lowerAlpha + '0123456789'; | |
| for (let i = 0; i < lowerAlphanum.length; ++i) { | |
| for (let j = 0; j < lowerAlpha.length; ++j) { | |
| yield lowerAlphanum[i] + lowerAlpha[j]; | |
| } | |
| } | |
| } |
| assert.sameValue( | ||
| new Intl.Locale(`en-u-${ukey}-true`).toString(), | ||
| `en-u-${ukey}`, | ||
| `new Intl.Locale("en-u-${ukey}-true").toString() returns "en-u-${ukey}"` | ||
| ); |
There was a problem hiding this comment.
Suggestion:
| assert.sameValue( | |
| new Intl.Locale(`en-u-${ukey}-true`).toString(), | |
| `en-u-${ukey}`, | |
| `new Intl.Locale("en-u-${ukey}-true").toString() returns "en-u-${ukey}"` | |
| ); | |
| const localeId = `en-u-${ukey}-true`; | |
| const normalizedLocaleId = `en-u-${ukey}`; | |
| assert.sameValue( | |
| new Intl.Locale(localeId).toString(), | |
| normalizedLocaleId, | |
| `new Intl.Locale("${localeId}").toString() must be "${normalizedLocaleId}"` | |
| ); |
| function canonicalizeUValue(ukey, uvalue) { | ||
| assert.sameValue(uvalue, "yes", "unexpected uvalue"); | ||
|
|
||
| switch (ukey) { | ||
| case "kb": | ||
| case "kc": | ||
| case "kh": | ||
| case "kk": | ||
| case "kn": | ||
| // Canonicalized to "true", which then gets removed. | ||
| return ""; | ||
| default: | ||
| return uvalue; | ||
| } | ||
| } | ||
|
|
||
| for (let ukey of ukeys()) { | ||
| let canonicalized = new Intl.Locale(`en-u-${ukey}-yes`).toString(); | ||
|
|
||
| if (canonicalizeUValue(ukey, "yes") === "yes") { | ||
| assert.sameValue( | ||
| canonicalized, | ||
| `en-u-${ukey}-yes`, | ||
| `new Intl.Locale("en-u-${ukey}-yes").toString() returns "en-u-${ukey}-yes"` | ||
| ); | ||
| } else { | ||
| assert.sameValue( | ||
| canonicalized, | ||
| `en-u-${ukey}`, | ||
| `new Intl.Locale("en-u-${ukey}-yes").toString() returns "en-u-${ukey}"` | ||
| ); | ||
| } | ||
| } |
There was a problem hiding this comment.
Suggestion:
| function canonicalizeUValue(ukey, uvalue) { | |
| assert.sameValue(uvalue, "yes", "unexpected uvalue"); | |
| switch (ukey) { | |
| case "kb": | |
| case "kc": | |
| case "kh": | |
| case "kk": | |
| case "kn": | |
| // Canonicalized to "true", which then gets removed. | |
| return ""; | |
| default: | |
| return uvalue; | |
| } | |
| } | |
| for (let ukey of ukeys()) { | |
| let canonicalized = new Intl.Locale(`en-u-${ukey}-yes`).toString(); | |
| if (canonicalizeUValue(ukey, "yes") === "yes") { | |
| assert.sameValue( | |
| canonicalized, | |
| `en-u-${ukey}-yes`, | |
| `new Intl.Locale("en-u-${ukey}-yes").toString() returns "en-u-${ukey}-yes"` | |
| ); | |
| } else { | |
| assert.sameValue( | |
| canonicalized, | |
| `en-u-${ukey}`, | |
| `new Intl.Locale("en-u-${ukey}-yes").toString() returns "en-u-${ukey}"` | |
| ); | |
| } | |
| } | |
| // Whether ukey has a "yes" alias for "true" in | |
| // https://github.com/unicode-org/cldr/blob/maint/maint-48/common/bcp47/collation.xml | |
| function hasAlias(ukey) { | |
| return ukey === "kb" || ukey === "kc" || ukey === "kh" || ukey === "kk" || ukey === "kn"; | |
| } | |
| for (let ukey of ukeys()) { | |
| const localeId = `en-u-${ukey}-yes`; | |
| const normalizedLocaleId = hasAlias(ukey) ? `en-u-${ukey}` : localeId; | |
| assert.sameValue( | |
| new Intl.Locale(localeId).toString(), | |
| normalizedLocaleId, | |
| `new Intl.Locale("${localeId}").toString() must be "${normalizedLocaleId}"` | |
| ); | |
| } |
| // Generate all possible `ukey` values. | ||
| function* ukeys() { | ||
| const lowerA = 'a'.charCodeAt(0); | ||
| const lowerZ = 'z'.charCodeAt(0); | ||
|
|
||
| for (let first = lowerA; first <= lowerZ; ++first) { | ||
| for (let second = lowerA; second <= lowerZ; ++second) { | ||
| yield String.fromCharCode(first, second); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
| // Generate all possible `ukey` values. | |
| function* ukeys() { | |
| const lowerA = 'a'.charCodeAt(0); | |
| const lowerZ = 'z'.charCodeAt(0); | |
| for (let first = lowerA; first <= lowerZ; ++first) { | |
| for (let second = lowerA; second <= lowerZ; ++second) { | |
| yield String.fromCharCode(first, second); | |
| } | |
| } | |
| } | |
| // Generate all possible `ukey` values. | |
| // https://unicode.org/reports/tr35/#ukey | |
| function* ukeys() { | |
| const lowerAlpha = 'abcdefghijklmnopqrstuvwxyz'; | |
| const lowerAlphanum = lowerAlpha + '0123456789'; | |
| for (let i = 0; i < lowerAlphanum.length; ++i) { | |
| for (let j = 0; j < lowerAlpha.length; ++j) { | |
| yield lowerAlphanum[i] + lowerAlpha[j]; | |
| } | |
| } | |
| } |
| description: > | ||
| Remove any uvalue (aka type) equal to "true". |
There was a problem hiding this comment.
| description: > | |
| Remove any uvalue (aka type) equal to "true". | |
| description: > | |
| Remove any uvalue (aka type) equal to "yes" if and only if "yes" is an alias for "true". |
|
@gibson042 A few details make this a good candidate for landing as-is: your suggestions are additive rather than corrective, this has been waiting for some time, @anba's public contribution history suggests they may not be available right now, and I have immediate availability to make the requested changes. Would you be open to landing this patch as-is with the understanding that I will submit a follow-up later today? |
|
@jugglinmike Yes, I left a comment rather than a request for changes specifically to avoid blocking. |
|
Right on! |
|
Follow-up patch: #5138 |
This patch was originally authored by Richard Gibson: #5016
Ensure
yesis only canonicalized totruefor some ukeys.