|
1 | | -import { getLocalizedListComparer } from "./sorting"; |
| 1 | +import { getLocaleCollator, getLocalizedListComparer } from "./sorting"; |
2 | 2 |
|
3 | 3 | describe("getLocalizedListComparer", () => { |
4 | 4 | it("uses pinyin collation for zh-Hans when supported", () => { |
5 | | - const resolvedLocale = new Intl.Collator( |
6 | | - "zh-Hans-u-co-pinyin", |
7 | | - ).resolvedOptions().locale; |
| 5 | + const collator = getLocaleCollator("zh-Hans"); |
8 | 6 |
|
9 | | - if (resolvedLocale.includes("-pinyin")) { |
10 | | - expect( |
11 | | - ["中国", "法国", "德国", "阿富汗"].sort( |
12 | | - getLocalizedListComparer("zh-Hans"), |
13 | | - ), |
14 | | - ).toEqual(["阿富汗", "德国", "法国", "中国"]); |
| 7 | + if (collator.resolvedOptions().locale.includes("-pinyin")) { |
| 8 | + expect(["中国", "法国", "德国", "阿富汗"].sort(collator.compare)).toEqual( |
| 9 | + ["阿富汗", "德国", "法国", "中国"], |
| 10 | + ); |
15 | 11 | } |
16 | 12 | }); |
17 | 13 |
|
18 | 14 | it("uses stroke collation for zh-Hant when supported", () => { |
19 | | - const resolvedLocale = new Intl.Collator( |
20 | | - "zh-Hant-u-co-stroke", |
21 | | - ).resolvedOptions().locale; |
| 15 | + const collator = getLocaleCollator("zh-Hant"); |
22 | 16 |
|
23 | | - if (resolvedLocale.includes("-stroke")) { |
24 | | - expect( |
25 | | - ["德國", "法國", "中國", "加拿大"].sort( |
26 | | - getLocalizedListComparer("zh-Hant"), |
27 | | - ), |
28 | | - ).toEqual(["中國", "加拿大", "法國", "德國"]); |
| 17 | + if (collator.resolvedOptions().locale.includes("-stroke")) { |
| 18 | + expect(["德國", "法國", "中國", "加拿大"].sort(collator.compare)).toEqual( |
| 19 | + ["中國", "加拿大", "法國", "德國"], |
| 20 | + ); |
29 | 21 | } |
30 | 22 | }); |
31 | 23 |
|
|
0 commit comments