Debian Codegraph @

tests/qunit/resources/mediawiki.language.test.js

raw symbols SCIP
1 ( function () {
2 'use strict';
3
4 QUnit.module( 'mediawiki.language', QUnit.newMwEnvironment( {
5 beforeEach: function () {
6 this.liveLangData = mw.language.data;
7 mw.language.data = {};
8 },
9 afterEach: function () {
10 mw.language.data = this.liveLangData;
11 },
12 messages: {
13 // mw.language.listToText test
14 and: ' and',
15 'comma-separator': ', ',
16 'word-separator': ' '
17 }
18 } ) );
19
20 QUnit.test( 'mw.language getData and setData', ( assert ) => {
21 mw.language.setData( 'en', 'testkey', 'testvalue' );
22 assert.strictEqual( mw.language.getData( 'en', 'testkey' ), 'testvalue', 'Getter setter test for mw.language' );
23 assert.strictEqual( mw.language.getData( 'en', 'invalidkey' ), null, 'Getter setter test for mw.language with invalid key' );
24 assert.strictEqual( mw.language.getData( 'xx', 'invalidLang' ), undefined, 'Getter setter test for mw.language with invalid lang' );
25 mw.language.setData( 'en-us', 'testkey', 'testvalue' );
26 assert.strictEqual( mw.language.getData( 'en-US', 'testkey' ), 'testvalue', 'Case insensitive test for mw.language' );
27 } );
28
29 QUnit.test( 'mw.language.convertNumber', ( assert ) => {
30 mw.language.setData( 'en', 'digitGroupingPattern', null );
31 mw.language.setData( 'en', 'digitTransformTable', null );
32 mw.language.setData( 'en', 'separatorTransformTable', { ',': '.', '.': ',' } );
33 mw.language.setData( 'en', 'minimumGroupingDigits', 1 );
34 mw.config.set( 'wgUserLanguage', 'en' );
35 mw.config.set( 'wgTranslateNumerals', true );
36
37 assert.strictEqual( mw.language.convertNumber( 180 ), '180', 'formatting 3-digit' );
38 assert.strictEqual( mw.language.convertNumber( 1800 ), '1.800', 'formatting 4-digit' );
39 assert.strictEqual( mw.language.convertNumber( 18000 ), '18.000', 'formatting 5-digit' );
40
41 assert.strictEqual( mw.language.convertNumber( '1.800', true ), 1800, 'unformatting' );
42
43 mw.language.setData( 'en', 'minimumGroupingDigits', 2 );
44 assert.strictEqual( mw.language.convertNumber( 180 ), '180', 'formatting 3-digit with minimumGroupingDigits=2' );
45 assert.strictEqual( mw.language.convertNumber( 1800 ), '1800', 'formatting 4-digit with minimumGroupingDigits=2' );
46 assert.strictEqual( mw.language.convertNumber( 18000 ), '18.000', 'formatting 5-digit with minimumGroupingDigits=2' );
47
48 mw.language.setData( 'en', 'minimumGroupingDigits', 3 );
49 assert.strictEqual( mw.language.convertNumber( 180 ), '180', 'formatting 3-digit with minimumGroupingDigits=3' );
50 assert.strictEqual( mw.language.convertNumber( 1800 ), '1800', 'formatting 4-digit with minimumGroupingDigits=3' );
51 assert.strictEqual( mw.language.convertNumber( 18000 ), '18000', 'formatting 5-digit with minimumGroupingDigits=3' );
52 assert.strictEqual( mw.language.convertNumber( 180000 ), '180.000', 'formatting 6-digit with minimumGroupingDigits=3' );
53 } );
54
55 QUnit.test( 'mw.language.convertNumber - digitTransformTable', ( assert ) => {
56 mw.config.set( 'wgUserLanguage', 'hi' );
57 mw.config.set( 'wgTranslateNumerals', true );
58 mw.language.setData( 'hi', 'digitGroupingPattern', null );
59 mw.language.setData( 'hi', 'separatorTransformTable', { ',': '.', '.': ',' } );
60 mw.language.setData( 'hi', 'minimumGroupingDigits', null );
61
62 // Example from Hindi (MessagesHi.php)
63 mw.language.setData( 'hi', 'digitTransformTable', {
64 0: '०',
65 1: '१',
66 2: '२'
67 } );
68
69 assert.strictEqual( mw.language.convertNumber( 1200 ), '१.२००', 'format' );
70 assert.strictEqual( mw.language.convertNumber( '१.२००', true ), 1200, 'unformat from digit transform' );
71 assert.strictEqual( mw.language.convertNumber( '1.200', true ), 1200, 'unformat plain' );
72
73 mw.config.set( 'wgTranslateNumerals', false );
74
75 assert.strictEqual( mw.language.convertNumber( 1200 ), '1.200', 'format (digit transform disabled)' );
76 assert.strictEqual( mw.language.convertNumber( '१.२००', true ), 1200, 'unformat from digit transform (when disabled)' );
77 assert.strictEqual( mw.language.convertNumber( '1.200', true ), 1200, 'unformat plain (digit transform disabled)' );
78 } );
79
80 function grammarTest( langCode, test ) {
81 // The test works only if the content language is opt.language
82 // because it requires [lang].js to be loaded.
83 QUnit.test( 'Grammar test for lang=' + langCode, ( assert ) => {
84 let i;
85 for ( i = 0; i < test.length; i++ ) {
86 assert.strictEqual(
87 mw.language.convertGrammar( test[ i ].word, test[ i ].grammarForm ),
88 test[ i ].expected,
89 test[ i ].description
90 );
91 }
92 } );
93 }
94
95 // These tests run only for the current UI language.
96 const grammarTests = {
97 bs: [
98 {
99 word: 'word',
100 grammarForm: 'instrumental',
101 expected: 's word',
102 description: 'Grammar test for instrumental case'
103 },
104 {
105 word: 'word',
106 grammarForm: 'lokativ',
107 expected: 'o word',
108 description: 'Grammar test for lokativ case'
109 }
110 ],
111
112 he: [
113 {
114 word: 'ויקיפדיה',
115 grammarForm: 'prefixed',
116 expected: 'וויקיפדיה',
117 description: 'Duplicate the "Waw" if prefixed'
118 },
119 {
120 word: 'וולפגנג',
121 grammarForm: 'prefixed',
122 expected: 'וולפגנג',
123 description: 'Duplicate the "Waw" if prefixed, but not if it is already duplicated.'
124 },
125 {
126 word: 'הקובץ',
127 grammarForm: 'prefixed',
128 expected: 'קובץ',
129 description: 'Remove the "He" if prefixed'
130 },
131 {
132 word: 'Wikipedia',
133 grammarForm: 'תחילית',
134 expected: '־Wikipedia',
135 description: 'Add a hyphen (maqaf) before non-Hebrew letters'
136 },
137 {
138 word: '1995',
139 grammarForm: 'תחילית',
140 expected: '־1995',
141 description: 'Add a hyphen (maqaf) before numbers'
142 }
143 ],
144
145 hsb: [
146 {
147 word: 'word',
148 grammarForm: 'instrumental',
149 expected: 'z word',
150 description: 'Grammar test for instrumental case'
151 },
152 {
153 word: 'word',
154 grammarForm: 'lokatiw',
155 expected: 'wo word',
156 description: 'Grammar test for lokatiw case'
157 }
158 ],
159
160 dsb: [
161 {
162 word: 'word',
163 grammarForm: 'instrumental',
164 expected: 'z word',
165 description: 'Grammar test for instrumental case'
166 },
167 {
168 word: 'word',
169 grammarForm: 'lokatiw',
170 expected: 'wo word',
171 description: 'Grammar test for lokatiw case'
172 }
173 ],
174
175 hy: [
176 {
177 word: 'Մաունա',
178 grammarForm: 'genitive',
179 expected: 'Մաունայի',
180 description: 'Grammar test for genitive case'
181 },
182 {
183 word: 'հետո',
184 grammarForm: 'genitive',
185 expected: 'հետոյի',
186 description: 'Grammar test for genitive case'
187 },
188 {
189 word: 'գիրք',
190 grammarForm: 'genitive',
191 expected: 'գրքի',
192 description: 'Grammar test for genitive case'
193 },
194 {
195 word: 'ժամանակի',
196 grammarForm: 'genitive',
197 expected: 'ժամանակիի',
198 description: 'Grammar test for genitive case'
199 }
200 ],
201
202 fi: [
203 {
204 word: 'talo',
205 grammarForm: 'genitive',
206 expected: 'talon',
207 description: 'Grammar test for genitive case'
208 },
209 {
210 word: 'linux',
211 grammarForm: 'genitive',
212 expected: 'linuxin',
213 description: 'Grammar test for genitive case'
214 },
215 {
216 word: 'talo',
217 grammarForm: 'elative',
218 expected: 'talosta',
219 description: 'Grammar test for elative case'
220 },
221 {
222 word: 'pastöroitu',
223 grammarForm: 'partitive',
224 expected: 'pastöroitua',
225 description: 'Grammar test for partitive case'
226 },
227 {
228 word: 'talo',
229 grammarForm: 'partitive',
230 expected: 'taloa',
231 description: 'Grammar test for partitive case'
232 },
233 {
234 word: 'talo',
235 grammarForm: 'illative',
236 expected: 'taloon',
237 description: 'Grammar test for illative case'
238 },
239 {
240 word: 'linux',
241 grammarForm: 'inessive',
242 expected: 'linuxissa',
243 description: 'Grammar test for inessive case'
244 }
245 ],
246
247 ka: [
248 {
249 word: 'ვიკიპედია',
250 grammarForm: 'ნათესაობითი',
251 expected: 'ვიკიპედიის',
252 description: 'Grammar test for Georgian genitive case'
253 },
254 {
255 word: 'ვიქსიკონი',
256 grammarForm: 'ნათესაობითი',
257 expected: 'ვიქსიკონის',
258 description: 'Grammar test for Georgian genitive case'
259 },
260 {
261 word: 'ვიკიწიგნები',
262 grammarForm: 'ნათესაობითი',
263 expected: 'ვიკიწიგნების',
264 description: 'Grammar test for Georgian genitive case'
265 },
266 {
267 word: 'ვიკიციტატა',
268 grammarForm: 'ნათესაობითი',
269 expected: 'ვიკიციტატის',
270 description: 'Grammar test for Georgian genitive case'
271 },
272 {
273 word: 'ვიკისიახლეები',
274 grammarForm: 'ნათესაობითი',
275 expected: 'ვიკისიახლეების',
276 description: 'Grammar test for Georgian genitive case'
277 },
278 {
279 word: 'ვიკისახეობები',
280 grammarForm: 'ნათესაობითი',
281 expected: 'ვიკისახეობების',
282 description: 'Grammar test for Georgian genitive case'
283 },
284 {
285 word: 'ვიკიმონაცემები',
286 grammarForm: 'ნათესაობითი',
287 expected: 'ვიკიმონაცემების',
288 description: 'Grammar test for Georgian genitive case'
289 },
290 {
291 word: 'ვიკისაწყობი',
292 grammarForm: 'ნათესაობითი',
293 expected: 'ვიკისაწყობის',
294 description: 'Grammar test for Georgian genitive case'
295 },
296 {
297 word: 'ვიკივოიაჟი',
298 grammarForm: 'ნათესაობითი',
299 expected: 'ვიკივოიაჟის',
300 description: 'Grammar test for Georgian genitive case'
301 },
302 {
303 word: 'მეტა-ვიკი',
304 grammarForm: 'ნათესაობითი',
305 expected: 'მეტა-ვიკის',
306 description: 'Grammar test for Georgian genitive case'
307 },
308 {
309 word: 'მედიავიკი',
310 grammarForm: 'ნათესაობითი',
311 expected: 'მედიავიკის',
312 description: 'Grammar test for Georgian genitive case'
313 },
314 {
315 word: 'ვიკივერსიტეტი',
316 grammarForm: 'ნათესაობითი',
317 expected: 'ვიკივერსიტეტის',
318 description: 'Grammar test for Georgian genitive case'
319 },
320 {
321 word: 'თავისუფლება',
322 grammarForm: 'ნათესაობითი',
323 expected: 'თავისუფლების',
324 description: 'Grammar test for Georgian genitive case'
325 }
326 ],
327
328 ru: [
329 {
330 word: 'тесть',
331 grammarForm: 'genitive',
332 expected: 'тестя',
333 description: 'Grammar test for genitive case, тесть -> тестя'
334 },
335 {
336 word: 'привилегия',
337 grammarForm: 'genitive',
338 expected: 'привилегии',
339 description: 'Grammar test for genitive case, привилегия -> привилегии'
340 },
341 {
342 word: 'установка',
343 grammarForm: 'genitive',
344 expected: 'установки',
345 description: 'Grammar test for genitive case, установка -> установки'
346 },
347 {
348 word: 'похоти',
349 grammarForm: 'genitive',
350 expected: 'похотей',
351 description: 'Grammar test for genitive case, похоти -> похотей'
352 },
353 {
354 word: 'доводы',
355 grammarForm: 'genitive',
356 expected: 'доводов',
357 description: 'Grammar test for genitive case, доводы -> доводов'
358 },
359 {
360 word: 'песчаник',
361 grammarForm: 'genitive',
362 expected: 'песчаника',
363 description: 'Grammar test for genitive case, песчаник -> песчаника'
364 },
365 {
366 word: 'данные',
367 grammarForm: 'genitive',
368 expected: 'данных',
369 description: 'Grammar test for genitive case, данные -> данных'
370 },
371 {
372 word: 'тесть',
373 grammarForm: 'prepositional',
374 expected: 'тесте',
375 description: 'Grammar test for prepositional case, тесть -> тесте'
376 },
377 {
378 word: 'привилегия',
379 grammarForm: 'prepositional',
380 expected: 'привилегии',
381 description: 'Grammar test for prepositional case, привилегия -> привилегии'
382 },
383 {
384 word: 'университет',
385 grammarForm: 'prepositional',
386 expected: 'университете',
387 description: 'Grammar test for prepositional case, университет -> университете'
388 },
389 {
390 word: 'университет',
391 grammarForm: 'genitive',
392 expected: 'университета',
393 description: 'Grammar test for prepositional case, университет -> университете'
394 },
395 {
396 word: 'установка',
397 grammarForm: 'prepositional',
398 expected: 'установке',
399 description: 'Grammar test for prepositional case, установка -> установке'
400 },
401 {
402 word: 'похоти',
403 grammarForm: 'prepositional',
404 expected: 'похотях',
405 description: 'Grammar test for prepositional case, похоти -> похотях'
406 },
407 {
408 word: 'доводы',
409 grammarForm: 'prepositional',
410 expected: 'доводах',
411 description: 'Grammar test for prepositional case, доводы -> доводах'
412 },
413 {
414 word: 'Викисклад',
415 grammarForm: 'prepositional',
416 expected: 'Викискладе',
417 description: 'Grammar test for prepositional case, Викисклад -> Викискладе'
418 },
419 {
420 word: 'Викисклад',
421 grammarForm: 'genitive',
422 expected: 'Викисклада',
423 description: 'Grammar test for genitive case, Викисклад -> Викисклада'
424 },
425 {
426 word: 'Википедия',
427 grammarForm: 'accusative',
428 expected: 'Википедию',
429 description: 'Grammar test for accusative case, Википедия -> Вики'
430 },
431 {
432 word: 'Викисловарь',
433 grammarForm: 'accusative',
434 expected: 'Викисловарь',
435 description: 'Grammar test for accusative case, Викисловарь -> Викисловарь'
436 },
437 {
438 word: 'Викицитатник',
439 grammarForm: 'accusative',
440 expected: 'Викицитатник',
441 description: 'Grammar test for accusative case, Викицитатник -> Викицитатник'
442 },
443 {
444 word: 'Викиучебник',
445 grammarForm: 'accusative',
446 expected: 'Викиучебник',
447 description: 'Grammar test for accusative case, Викиучебник -> Викиучебник'
448 },
449 {
450 word: 'Викитека',
451 grammarForm: 'accusative',
452 expected: 'Викитека',
453 description: 'Grammar test for accusative case, Викитека -> Викитеку'
454 },
455 {
456 word: 'Викиновости',
457 grammarForm: 'accusative',
458 expected: 'Викиновости',
459 description: 'Grammar test for accusative case, Викиновости -> Викиновости'
460 },
461 {
462 word: 'Викиверситет',
463 grammarForm: 'accusative',
464 expected: 'Викиверситет',
465 description: 'Grammar test for accusative case, Викиверситет -> Викиверситет'
466 },
467 {
468 word: 'Викивиды',
469 grammarForm: 'accusative',
470 expected: 'Викивиды',
471 description: 'Grammar test for accusative case, Викивиды -> Викивиды'
472 },
473 {
474 word: 'Викиданные',
475 grammarForm: 'accusative',
476 expected: 'Викиданные',
477 description: 'Grammar test for accusative case, Викиданные -> Викиданные'
478 },
479 {
480 word: 'Викисклад',
481 grammarForm: 'accusative',
482 expected: 'Викисклад',
483 description: 'Grammar test for accusative case, Викисклад -> Викисклад'
484 },
485 {
486 word: 'Викигид',
487 grammarForm: 'accusative',
488 expected: 'Викигид',
489 description: 'Grammar test for accusative case, Викигид -> Викигид'
490 },
491 {
492 word: 'Мета',
493 grammarForm: 'accusative',
494 expected: 'Мету',
495 description: 'Grammar test for accusative case, Мета -> Мету'
496 },
497 {
498 word: 'Инкубатор',
499 grammarForm: 'accusative',
500 expected: 'Инкубатор',
501 description: 'Grammar test for accusative case, Инкубатор -> Инкубатор'
502 },
503 {
504 word: 'песчаник',
505 grammarForm: 'prepositional',
506 expected: 'песчанике',
507 description: 'Grammar test for prepositional case, песчаник -> песчанике'
508 },
509 {
510 word: 'данные',
511 grammarForm: 'prepositional',
512 expected: 'данных',
513 description: 'Grammar test for prepositional case, данные -> данных'
514 },
515 {
516 word: 'русский',
517 grammarForm: 'languagegen',
518 expected: 'русского',
519 description: 'Grammar test for languagegen case, русский -> русского'
520 },
521 {
522 word: 'немецкий',
523 grammarForm: 'languagegen',
524 expected: 'немецкого',
525 description: 'Grammar test for languagegen case, немецкий -> немецкого'
526 },
527 {
528 word: 'иврит',
529 grammarForm: 'languagegen',
530 expected: 'иврита',
531 description: 'Grammar test for languagegen case, иврит -> иврита'
532 },
533 {
534 word: 'эсперанто',
535 grammarForm: 'languagegen',
536 expected: 'эсперанто',
537 description: 'Grammar test for languagegen case, эсперанто -> эсперанто'
538 },
539 {
540 word: 'русский',
541 grammarForm: 'languageprep',
542 expected: 'русском',
543 description: 'Grammar test for languageprep case, русский -> русском'
544 },
545 {
546 word: 'немецкий',
547 grammarForm: 'languageprep',
548 expected: 'немецком',
549 description: 'Grammar test for languageprep case, немецкий -> немецком'
550 },
551 {
552 word: 'идиш',
553 grammarForm: 'languageprep',
554 expected: 'идише',
555 description: 'Grammar test for languageprep case, идиш -> идише'
556 },
557 {
558 word: 'эсперанто',
559 grammarForm: 'languageprep',
560 expected: 'эсперанто',
561 description: 'Grammar test for languageprep case, эсперанто -> эсперанто'
562 },
563 {
564 word: 'русский',
565 grammarForm: 'languageadverb',
566 expected: 'по-русски',
567 description: 'Grammar test for languageadverb case, русский -> по-русски'
568 },
569 {
570 word: 'немецкий',
571 grammarForm: 'languageadverb',
572 expected: 'по-немецки',
573 description: 'Grammar test for languageadverb case, немецкий -> по-немецки'
574 },
575 {
576 word: 'иврит',
577 grammarForm: 'languageadverb',
578 expected: 'на иврите',
579 description: 'Grammar test for languageadverb case, иврит -> на иврите'
580 },
581 {
582 word: 'эсперанто',
583 grammarForm: 'languageadverb',
584 expected: 'на эсперанто',
585 description: 'Grammar test for languageadverb case, эсперанто -> на эсперанто'
586 },
587 {
588 word: 'гуарани',
589 grammarForm: 'languageadverb',
590 expected: 'на языке гуарани',
591 description: 'Grammar test for languageadverb case, гуарани -> на языке гуарани'
592 }
593 ],
594
595 hu: [
596 {
597 word: 'Wikipédiá',
598 grammarForm: 'rol',
599 expected: 'Wikipédiáról',
600 description: 'Grammar test for rol case'
601 },
602 {
603 word: 'Wikipédiá',
604 grammarForm: 'ba',
605 expected: 'Wikipédiába',
606 description: 'Grammar test for ba case'
607 },
608 {
609 word: 'Wikipédiá',
610 grammarForm: 'k',
611 expected: 'Wikipédiák',
612 description: 'Grammar test for k case'
613 }
614 ],
615
616 ga: [
617 {
618 word: 'an Domhnach',
619 grammarForm: 'ainmlae',
620 expected: 'Dé Domhnaigh',
621 description: 'Grammar test for ainmlae case'
622 },
623 {
624 word: 'an Luan',
625 grammarForm: 'ainmlae',
626 expected: 'Dé Luain',
627 description: 'Grammar test for ainmlae case'
628 },
629 {
630 word: 'an Satharn',
631 grammarForm: 'ainmlae',
632 expected: 'Dé Sathairn',
633 description: 'Grammar test for ainmlae case'
634 }
635 ],
636
637 mn: [
638 {
639 word: 'Википедиа',
640 grammarForm: 'genitive',
641 expected: 'Википедиагийн',
642 description: 'Grammar test for genitive case'
643 },
644 {
645 word: 'Викитолийн',
646 grammarForm: 'genitive',
647 expected: 'Викитоль',
648 description: 'Grammar test for genitive case'
649 }
650 ],
651
652 uk: [
653 {
654 word: 'Вікіпедія',
655 grammarForm: 'genitive',
656 expected: 'Вікіпедії',
657 description: 'Grammar test for genitive case'
658 },
659 {
660 word: 'Віківиди',
661 grammarForm: 'genitive',
662 expected: 'Віківидів',
663 description: 'Grammar test for genitive case'
664 },
665 {
666 word: 'Вікіцитати',
667 grammarForm: 'genitive',
668 expected: 'Вікіцитат',
669 description: 'Grammar test for genitive case'
670 },
671 {
672 word: 'Вікіпідручник',
673 grammarForm: 'genitive',
674 expected: 'Вікіпідручника',
675 description: 'Grammar test for genitive case'
676 },
677 {
678 word: 'Вікіпедія',
679 grammarForm: 'accusative',
680 expected: 'Вікіпедію',
681 description: 'Grammar test for accusative case'
682 }
683 ],
684
685 sl: [
686 {
687 word: 'word',
688 grammarForm: 'orodnik',
689 expected: 'z word',
690 description: 'Grammar test for orodnik case'
691 },
692 {
693 word: 'word',
694 grammarForm: 'mestnik',
695 expected: 'o word',
696 description: 'Grammar test for mestnik case'
697 }
698 ],
699
700 os: [
701 {
702 word: 'бæстæ',
703 grammarForm: 'genitive',
704 expected: 'бæсты',
705 description: 'Grammar test for genitive case'
706 },
707 {
708 word: 'бæстæ',
709 grammarForm: 'allative',
710 expected: 'бæстæм',
711 description: 'Grammar test for allative case'
712 },
713 {
714 word: 'Тигр',
715 grammarForm: 'dative',
716 expected: 'Тигрæн',
717 description: 'Grammar test for dative case'
718 },
719 {
720 word: 'цъити',
721 grammarForm: 'dative',
722 expected: 'цъитийæн',
723 description: 'Grammar test for dative case'
724 },
725 {
726 word: 'лæппу',
727 grammarForm: 'genitive',
728 expected: 'лæппуйы',
729 description: 'Grammar test for genitive case'
730 },
731 {
732 word: '2011',
733 grammarForm: 'equative',
734 expected: '2011-ау',
735 description: 'Grammar test for equative case'
736 }
737 ],
738
739 la: [
740 {
741 word: 'Translatio',
742 grammarForm: 'genitive',
743 expected: 'Translationis',
744 description: 'Grammar test for genitive case'
745 },
746 {
747 word: 'Translatio',
748 grammarForm: 'accusative',
749 expected: 'Translationem',
750 description: 'Grammar test for accusative case'
751 },
752 {
753 word: 'Translatio',
754 grammarForm: 'ablative',
755 expected: 'Translatione',
756 description: 'Grammar test for ablative case'
757 }
758 ]
759 };
760
761 // eslint-disable-next-line no-jquery/no-each-util
762 $.each( grammarTests, ( langCode, test ) => {
763 if ( langCode === mw.config.get( 'wgUserLanguage' ) ) {
764 grammarTest( langCode, test );
765 }
766 } );
767
768 QUnit.test( 'List to text test', ( assert ) => {
769 assert.strictEqual( mw.language.listToText( [] ), '', 'Blank list' );
770 assert.strictEqual( mw.language.listToText( [ 'a' ] ), 'a', 'Single item' );
771 assert.strictEqual( mw.language.listToText( [ 'a', 'b' ] ), 'a and b', 'Two items' );
772 assert.strictEqual( mw.language.listToText( [ 'a', 'b', 'c' ] ), 'a, b and c', 'More than two items' );
773 } );
774
775 const bcp47Tests = [
776 // Extracted from BCP 47 (list not exhaustive)
777 // # 2.1.1
778 [ 'en-ca-x-ca', 'en-CA-x-ca' ],
779 [ 'sgn-be-fr', 'sgn-BE-FR' ],
780 [ 'az-latn-x-latn', 'az-Latn-x-latn' ],
781 // # 2.2
782 [ 'sr-Latn-RS', 'sr-Latn-RS' ],
783 [ 'az-arab-ir', 'az-Arab-IR' ],
784
785 // # 2.2.5
786 [ 'sl-nedis', 'sl-nedis' ],
787 [ 'de-ch-1996', 'de-CH-1996' ],
788
789 // # 2.2.6
790 [
791 'en-latn-gb-boont-r-extended-sequence-x-private',
792 'en-Latn-GB-boont-r-extended-sequence-x-private'
793 ],
794
795 // Examples from BCP 47 Appendix A
796 // # Simple language subtag:
797 [ 'DE', 'de' ],
798 [ 'fR', 'fr' ],
799 [ 'ja', 'ja' ],
800
801 // # Language subtag plus script subtag:
802 [ 'zh-hans', 'zh-Hans' ],
803 [ 'sr-cyrl', 'sr-Cyrl' ],
804 [ 'sr-latn', 'sr-Latn' ],
805
806 // # Extended language subtags and their primary language subtag
807 // # counterparts:
808 [ 'zh-cmn-hans-cn', 'zh-cmn-Hans-CN' ],
809 [ 'cmn-hans-cn', 'cmn-Hans-CN' ],
810 [ 'zh-yue-hk', 'zh-yue-HK' ],
811 [ 'yue-hk', 'yue-HK' ],
812
813 // # Language-Script-Region:
814 [ 'zh-hans-cn', 'zh-Hans-CN' ],
815 [ 'sr-latn-RS', 'sr-Latn-RS' ],
816
817 // # Language-Variant:
818 [ 'sl-rozaj', 'sl-rozaj' ],
819 [ 'sl-rozaj-biske', 'sl-rozaj-biske' ],
820 [ 'sl-nedis', 'sl-nedis' ],
821
822 // # Language-Region-Variant:
823 [ 'de-ch-1901', 'de-CH-1901' ],
824 [ 'sl-it-nedis', 'sl-IT-nedis' ],
825
826 // # Language-Script-Region-Variant:
827 [ 'hy-latn-it-arevela', 'hy-Latn-IT-arevela' ],
828
829 // # Language-Region:
830 [ 'de-de', 'de-DE' ],
831 [ 'en-us', 'en-US' ],
832 [ 'es-419', 'es-419' ],
833
834 // # Private use subtags:
835 [ 'de-ch-x-phonebk', 'de-CH-x-phonebk' ],
836 [ 'az-arab-x-aze-derbend', 'az-Arab-x-aze-derbend' ],
837 /**
838 * Previous test does not reflect the BCP 47 which states:
839 * az-Arab-x-AZE-derbend
840 * AZE being private, it should be lower case, hence the test above
841 * should probably be:
842 * [ 'az-arab-x-aze-derbend', 'az-Arab-x-AZE-derbend' ],
843 */
844
845 // # Private use registry values:
846 [ 'x-whatever', 'x-whatever' ],
847 [ 'qaa-qaaa-qm-x-southern', 'qaa-Qaaa-QM-x-southern' ],
848 [ 'de-qaaa', 'de-Qaaa' ],
849 [ 'sr-latn-qm', 'sr-Latn-QM' ],
850 [ 'sr-qaaa-rs', 'sr-Qaaa-RS' ],
851
852 // # Tags that use extensions
853 [ 'en-us-u-islamcal', 'en-US-u-islamcal' ],
854 [ 'zh-cn-a-myext-x-private', 'zh-CN-a-myext-x-private' ],
855 [ 'en-a-myext-b-another', 'en-a-myext-b-another' ],
856
857 // # Invalid:
858 // de-419-DE
859 // a-DE
860 // ar-a-aaa-b-bbb-a-ccc
861
862 // Non-standard and deprecated language codes used by MediaWiki
863 [ 'als', 'gsw' ],
864 [ 'bat-smg', 'sgs' ],
865 [ 'be-x-old', 'be-tarask' ],
866 [ 'fiu-vro', 'vro' ],
867 [ 'roa-rup', 'rup' ],
868 [ 'zh-classical', 'lzh' ],
869 [ 'zh-min-nan', 'nan' ],
870 [ 'zh-yue', 'yue' ],
871 [ 'cbk-zam', 'cbk' ],
872 [ 'de-formal', 'de-x-formal' ],
873 [ 'eml', 'egl' ],
874 [ 'en-rtl', 'en-x-rtl' ],
875 [ 'es-formal', 'es-x-formal' ],
876 [ 'hu-formal', 'hu-x-formal' ],
877 [ 'kk-Arab', 'kk-Arab' ],
878 [ 'kk-Cyrl', 'kk-Cyrl' ],
879 [ 'kk-Latn', 'kk-Latn' ],
880 [ 'map-bms', 'jv-x-bms' ],
881 [ 'mo', 'ro-Cyrl-MD' ],
882 [ 'nrm', 'nrf' ],
883 [ 'nl-informal', 'nl-x-informal' ],
884 [ 'roa-tara', 'nap-x-tara' ],
885 [ 'simple', 'en-simple' ],
886 [ 'sr-ec', 'sr-Cyrl' ],
887 [ 'sr-el', 'sr-Latn' ],
888 [ 'zh-cn', 'zh-Hans-CN' ],
889 [ 'zh-sg', 'zh-Hans-SG' ],
890 [ 'zh-my', 'zh-Hans-MY' ],
891 [ 'zh-tw', 'zh-Hant-TW' ],
892 [ 'zh-hk', 'zh-Hant-HK' ],
893 [ 'zh-mo', 'zh-Hant-MO' ],
894 [ 'zh-hans', 'zh-Hans' ],
895 [ 'zh-hant', 'zh-Hant' ]
896 ];
897
898 QUnit.test( 'mw.language.bcp47', function ( assert ) {
899 mw.language.data = this.liveLangData;
900 bcp47Tests.forEach( ( data ) => {
901 const input = data[ 0 ],
902 expected = data[ 1 ];
903 assert.strictEqual( mw.language.bcp47( input ), expected );
904 assert.strictEqual( mw.language.bcp47( input.toLowerCase() ), expected );
905 assert.strictEqual( mw.language.bcp47( input.toUpperCase() ), expected );
906 } );
907 } );
908 }() );