-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1855749 - Part 3: Correctly handle ignorePunctuation option. r=dm…
…inor The default value for `GetOption` in `InitializeCollator` is changed from `false` to `undefined` to avoid having to `intl_isIgnorePunctuation` in the constructor function. The corresponding spec PR is <tc39/ecma402#833>, but our behaviour is already not strictly spec-compliant as described in <tc39/ecma402#832>, so it seems reasonable to simply implement the spec PR ahead of time. (We don't want to "fix" our implementation to strictly follow the spec without the PR, because that could be web-incompatible resp. at least disruptive for Thai users, which currently already get the expected behaviour where punctuation characters are ignored in Thai.) Differential Revision: https://phabricator.services.mozilla.com/D189545 UltraBlame original commit: bcf3b4652f995f4f52792d5897cd2d905d5a029f
- Loading branch information
Showing
4 changed files
with
68 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
|
||
|
||
function testPunctuation(col, expectedIgnorePunctuation) { | ||
let ignorePunctuation = col.resolvedOptions().ignorePunctuation; | ||
assertEq(ignorePunctuation, expectedIgnorePunctuation); | ||
|
||
|
||
assertEq(col.compare("", "*"), ignorePunctuation ? 0 : -1); | ||
|
||
|
||
assertEq(col.compare("", " "), ignorePunctuation ? 0 : -1); | ||
} | ||
|
||
const locales = [ | ||
"en", "de", "fr", "it", "es", "ar", "zh", "ja", | ||
|
||
|
||
"th", "th-Thai", "th-TH", "th-u-kf-false", | ||
]; | ||
|
||
for (let locale of locales) { | ||
|
||
let isThai = new Intl.Locale(locale).language === "th"; | ||
|
||
|
||
testPunctuation(new Intl.Collator(locale, {}), isThai); | ||
|
||
|
||
for (let ignorePunctuation of [true, false]) { | ||
testPunctuation(new Intl.Collator(locale, {ignorePunctuation}), ignorePunctuation); | ||
} | ||
} | ||
|
||
if (typeof getDefaultLocale === "undefined") { | ||
var getDefaultLocale = SpecialPowers.Cu.getJSTestingFunctions().getDefaultLocale; | ||
} | ||
if (typeof setDefaultLocale === "undefined") { | ||
var setDefaultLocale = SpecialPowers.Cu.getJSTestingFunctions().setDefaultLocale; | ||
} | ||
|
||
const defaultLocale = getDefaultLocale(); | ||
|
||
function withLocale(locale, fn) { | ||
setDefaultLocale(locale); | ||
try { | ||
fn(); | ||
} finally { | ||
setDefaultLocale(defaultLocale); | ||
} | ||
} | ||
|
||
|
||
for (let locale of ["th", "th-TH"]) { | ||
withLocale(locale, () => { | ||
testPunctuation(new Intl.Collator(undefined, {}), true); | ||
}); | ||
} | ||
|
||
if (typeof reportCompare === "function") | ||
reportCompare(true, true); |