Debian Codegraph @

js/src/tests/non262/Intl/Collator/ignorePunctuation.js

raw
1 // |reftest| skip-if(!this.hasOwnProperty("Intl"))
2
3 function testPunctuation(col, expectedIgnorePunctuation) {
4 let ignorePunctuation = col.resolvedOptions().ignorePunctuation;
5 assertEq(ignorePunctuation, expectedIgnorePunctuation);
6
7 // Punctuation is ignored iff |ignorePunctuation| is true.
8 assertEq(col.compare("", "*"), ignorePunctuation ? 0 : -1);
9
10 // Whitespace is also ignored when |ignorePunctuation| is true due to ICU limitations.
11 assertEq(col.compare("", " "), ignorePunctuation ? 0 : -1);
12 }
13
14 const locales = [
15 "en", "de", "fr", "it", "es", "ar", "zh", "ja",
16
17 // Thai, including some subtags.
18 "th", "th-Thai", "th-TH", "th-u-kf-false",
19 ];
20
21 for (let locale of locales) {
22 // Thai ignores punctuation by default.
23 let isThai = new Intl.Locale(locale).language === "th";
24
25 // Using default "ignorePunctuation" option.
26 testPunctuation(new Intl.Collator(locale, {}), isThai);
27
28 // Using explicit "ignorePunctuation" option.
29 for (let ignorePunctuation of [true, false]) {
30 testPunctuation(new Intl.Collator(locale, {ignorePunctuation}), ignorePunctuation);
31 }
32 }
33
34 if (typeof getDefaultLocale === "undefined") {
35 var getDefaultLocale = SpecialPowers.Cu.getJSTestingFunctions().getDefaultLocale;
36 }
37 if (typeof setDefaultLocale === "undefined") {
38 var setDefaultLocale = SpecialPowers.Cu.getJSTestingFunctions().setDefaultLocale;
39 }
40
41 const defaultLocale = getDefaultLocale();
42
43 function withLocale(locale, fn) {
44 setDefaultLocale(locale);
45 try {
46 fn();
47 } finally {
48 setDefaultLocale(defaultLocale);
49 }
50 }
51
52 // Ensure this works correctly when Thai is the default locale.
53 for (let locale of ["th", "th-TH"]) {
54 withLocale(locale, () => {
55 testPunctuation(new Intl.Collator(undefined, {}), true);
56 });
57 }
58
59 if (typeof reportCompare === "function")
60 reportCompare(true, true);