Skip to content

Commit 009fedd

Browse files
committed
test: Improve test coverage.
1 parent 91cc74d commit 009fedd

File tree

2 files changed

+59
-38
lines changed

2 files changed

+59
-38
lines changed

src/utils/get-plural-index.ts

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,6 @@
77
*/
88
export function getPluralIndex(lang: string, number: number): number {
99
switch (lang.replace('_', '-')) {
10-
case 'az':
11-
case 'az-AZ':
12-
case 'bo':
13-
case 'bo-CN':
14-
case 'bo-IN':
15-
case 'dz':
16-
case 'dz-BT':
17-
case 'id':
18-
case 'id-ID':
19-
case 'ja':
20-
case 'ja-JP':
21-
case 'jv':
22-
case 'ka':
23-
case 'ka-GE':
24-
case 'km':
25-
case 'km-KH':
26-
case 'kn':
27-
case 'kn-IN':
28-
case 'ko':
29-
case 'ko-KR':
30-
case 'ms':
31-
case 'ms-MY':
32-
case 'th':
33-
case 'th-TH':
34-
case 'tr':
35-
case 'tr-CY':
36-
case 'tr-TR':
37-
case 'vi':
38-
case 'vi-VN':
39-
case 'zh':
40-
case 'zh-CN':
41-
case 'zh-HK':
42-
case 'zh-SG':
43-
case 'zh-TW':
44-
return 0
4510
case 'af':
4611
case 'af-ZA':
4712
case 'bn':

test/plurization.test.ts

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { trans_choice, transChoice, wTransChoice, loadLanguageAsync } from '../src';
2+
import { choose } from '../src/pluralization';
23

34
it.each([
45
['first', 'first', 1],
@@ -72,7 +73,6 @@ it('translates even using an alias "trans_choice"', async () => {
7273
.toBe('há 3 minutos');
7374
})
7475

75-
7676
it('translates "wTransChoice" and test language change values', async () => {
7777
await global.mountPlugin()
7878

@@ -81,8 +81,64 @@ it('translates "wTransChoice" and test language change values', async () => {
8181
.toBe('há 3 minutos');
8282

8383
await loadLanguageAsync('en');
84-
84+
8585
expect(translation.value)
8686
.toBe('3 minutes ago');
87-
8887
})
88+
89+
it.each([
90+
['en-US', 0, 'second'],
91+
['en_US', 1, 'first'],
92+
['en', 2, 'second'],
93+
['fr', 0, 'first'],
94+
['fr', 1, 'first'],
95+
['fr', 2, 'second'],
96+
['be', 0, 'third'],
97+
['be', 1, 'first'],
98+
['be', 3, 'second'],
99+
['sk', 0, 'third'],
100+
['sk', 1, 'first'],
101+
['sk', 2, 'second'],
102+
['ga', 0, 'third'],
103+
['ga', 1, 'first'],
104+
['ga', 2, 'second'],
105+
['lt', 0, 'third'],
106+
['lt', 1, 'first'],
107+
['lt', 2, 'second'],
108+
['sl', 0, 'fourth'],
109+
['sl', 1, 'first'],
110+
['sl', 2, 'second'],
111+
['sl', 4, 'third'],
112+
['mk', 0, 'second'],
113+
['mk', 1, 'first'],
114+
['mt', 0, 'second'],
115+
['mt', 1, 'first'],
116+
['mt', 11, 'third'],
117+
['mt', 21, 'fourth'],
118+
['lv', 0, 'first'],
119+
['lv', 1, 'second'],
120+
['lv', 2, 'third'],
121+
['pl', 0, 'third'],
122+
['pl', 1, 'first'],
123+
['pl', 2, 'second'],
124+
['cy', 0, 'fourth'],
125+
['cy', 1, 'first'],
126+
['cy', 2, 'second'],
127+
['cy', 8, 'third'],
128+
['ro', 0, 'second'],
129+
['ro', 1, 'first'],
130+
['ro', 21, 'third'],
131+
['ar', 0, 'first'],
132+
['ar', 1, 'second'],
133+
['ar', 2, 'third'],
134+
['ar', 3, 'fourth'],
135+
['ar', 12, 'fifth'],
136+
['ar', 99.1, 'sixth'],
137+
['az', 0, 'first'],
138+
['az', 1, 'first'],
139+
['random', 0, 'first'],
140+
])('translates each lang with the correct plural', (lang, number, correctMessage) => {
141+
const message = 'first|second|third|fourth|fifth|sixth';
142+
143+
expect(choose(message, number, lang)).toBe(correctMessage);
144+
});

0 commit comments

Comments
 (0)