Implement extension registration from an extension.json file
[mediawiki.git] / tests / qunit / suites / resources / mediawiki / mediawiki.language.test.js
blob16f90df8cfa34c92725cef94ab7c140462a84da5
1 ( function ( mw, $ ) {
2         'use strict';
4         QUnit.module( 'mediawiki.language', QUnit.newMwEnvironment( {
5                 setup: function () {
6                         this.liveLangData = mw.language.data.values;
7                         mw.language.data.values = $.extend( true, {}, this.liveLangData );
8                 },
9                 teardown: function () {
10                         mw.language.data.values = this.liveLangData;
11                 }
12         } ) );
14         QUnit.test( 'mw.language getData and setData', 2, function ( assert ) {
15                 mw.language.setData( 'en', 'testkey', 'testvalue' );
16                 assert.equal( mw.language.getData( 'en', 'testkey' ), 'testvalue', 'Getter setter test for mw.language' );
17                 assert.equal( mw.language.getData( 'en', 'invalidkey' ), undefined, 'Getter setter test for mw.language with invalid key' );
18         } );
20         QUnit.test( 'mw.language.commafy test', 9, function ( assert ) {
21                 // Number grouping patterns are as per http://cldr.unicode.org/translation/number-patterns
22                 assert.equal( mw.language.commafy( 1234.567, '###0.#####' ), '1234.567', 'Pattern with no digit grouping separator defined' );
23                 assert.equal( mw.language.commafy( 123456789.567, '###0.#####' ), '123456789.567', 'Pattern with no digit grouping seperator defined, bigger decimal part' );
24                 assert.equal( mw.language.commafy( 0.567, '###0.#####' ), '0.567', 'Decimal part 0' );
25                 assert.equal( mw.language.commafy( '.567', '###0.#####' ), '0.567', 'Decimal part missing. replace with zero' );
26                 assert.equal( mw.language.commafy( 1234, '##,#0.#####' ), '12,34', 'Pattern with no fractional part' );
27                 assert.equal( mw.language.commafy( -1234.567, '###0.#####' ), '-1234.567', 'Negative number' );
28                 assert.equal( mw.language.commafy( -1234.567, '#,###.00' ), '-1,234.56', 'Fractional part bigger than pattern.' );
29                 assert.equal( mw.language.commafy( 123456789.567, '###,##0.00' ), '123,456,789.56', 'Decimal part as group of 3' );
30                 assert.equal( mw.language.commafy( 123456789.567, '###,###,#0.00' ), '1,234,567,89.56', 'Decimal part as group of 3 and last one 2' );
31         } );
33         function grammarTest( langCode, test ) {
34                 // The test works only if the content language is opt.language
35                 // because it requires [lang].js to be loaded.
36                 QUnit.test( 'Grammar test for lang=' + langCode, function ( assert ) {
37                         QUnit.expect( test.length );
39                         for ( var i = 0; i < test.length; i++ ) {
40                                 assert.equal(
41                                         mw.language.convertGrammar( test[i].word, test[i].grammarForm ),
42                                         test[i].expected,
43                                         test[i].description
44                                 );
45                         }
46                 } );
47         }
49         // These tests run only for the current UI language.
50         var grammarTests = {
51                 bs: [
52                         {
53                                 word: 'word',
54                                 grammarForm: 'instrumental',
55                                 expected: 's word',
56                                 description: 'Grammar test for instrumental case'
57                         },
58                         {
59                                 word: 'word',
60                                 grammarForm: 'lokativ',
61                                 expected: 'o word',
62                                 description: 'Grammar test for lokativ case'
63                         }
64                 ],
66                 he: [
67                         {
68                                 word: 'ויקיפדיה',
69                                 grammarForm: 'prefixed',
70                                 expected: 'וויקיפדיה',
71                                 description: 'Duplicate the "Waw" if prefixed'
72                         },
73                         {
74                                 word: 'וולפגנג',
75                                 grammarForm: 'prefixed',
76                                 expected: 'וולפגנג',
77                                 description: 'Duplicate the "Waw" if prefixed, but not if it is already duplicated.'
78                         },
79                         {
80                                 word: 'הקובץ',
81                                 grammarForm: 'prefixed',
82                                 expected: 'קובץ',
83                                 description: 'Remove the "He" if prefixed'
84                         },
85                         {
86                                 word: 'Wikipedia',
87                                 grammarForm: 'תחילית',
88                                 expected: '־Wikipedia',
89                                 description: 'GAdd a hyphen (maqaf) before non-Hebrew letters'
90                         },
91                         {
92                                 word: '1995',
93                                 grammarForm: 'תחילית',
94                                 expected: '־1995',
95                                 description: 'Add a hyphen (maqaf) before numbers'
96                         }
97                 ],
99                 hsb: [
100                         {
101                                 word: 'word',
102                                 grammarForm: 'instrumental',
103                                 expected: 'z word',
104                                 description: 'Grammar test for instrumental case'
105                         },
106                         {
107                                 word: 'word',
108                                 grammarForm: 'lokatiw',
109                                 expected: 'wo word',
110                                 description: 'Grammar test for lokatiw case'
111                         }
112                 ],
114                 dsb: [
115                         {
116                                 word: 'word',
117                                 grammarForm: 'instrumental',
118                                 expected: 'z word',
119                                 description: 'Grammar test for instrumental case'
120                         },
121                         {
122                                 word: 'word',
123                                 grammarForm: 'lokatiw',
124                                 expected: 'wo word',
125                                 description: 'Grammar test for lokatiw case'
126                         }
127                 ],
129                 hy: [
130                         {
131                                 word: 'Մաունա',
132                                 grammarForm: 'genitive',
133                                 expected: 'Մաունայի',
134                                 description: 'Grammar test for genitive case'
135                         },
136                         {
137                                 word: 'հետո',
138                                 grammarForm: 'genitive',
139                                 expected: 'հետոյի',
140                                 description: 'Grammar test for genitive case'
141                         },
142                         {
143                                 word: 'գիրք',
144                                 grammarForm: 'genitive',
145                                 expected: 'գրքի',
146                                 description: 'Grammar test for genitive case'
147                         },
148                         {
149                                 word: 'ժամանակի',
150                                 grammarForm: 'genitive',
151                                 expected: 'ժամանակիի',
152                                 description: 'Grammar test for genitive case'
153                         }
154                 ],
156                 fi: [
157                         {
158                                 word: 'talo',
159                                 grammarForm: 'genitive',
160                                 expected: 'talon',
161                                 description: 'Grammar test for genitive case'
162                         },
163                         {
164                                 word: 'linux',
165                                 grammarForm: 'genitive',
166                                 expected: 'linuxin',
167                                 description: 'Grammar test for genitive case'
168                         },
169                         {
170                                 word: 'talo',
171                                 grammarForm: 'elative',
172                                 expected: 'talosta',
173                                 description: 'Grammar test for elative case'
174                         },
175                         {
176                                 word: 'pastöroitu',
177                                 grammarForm: 'partitive',
178                                 expected: 'pastöroitua',
179                                 description: 'Grammar test for partitive case'
180                         },
181                         {
182                                 word: 'talo',
183                                 grammarForm: 'partitive',
184                                 expected: 'taloa',
185                                 description: 'Grammar test for partitive case'
186                         },
187                         {
188                                 word: 'talo',
189                                 grammarForm: 'illative',
190                                 expected: 'taloon',
191                                 description: 'Grammar test for illative case'
192                         },
193                         {
194                                 word: 'linux',
195                                 grammarForm: 'inessive',
196                                 expected: 'linuxissa',
197                                 description: 'Grammar test for inessive case'
198                         }
199                 ],
201                 ru: [
202                         {
203                                 word: 'тесть',
204                                 grammarForm: 'genitive',
205                                 expected: 'тестя',
206                                 description: 'Grammar test for genitive case, тесть -> тестя'
207                         },
208                         {
209                                 word: 'привилегия',
210                                 grammarForm: 'genitive',
211                                 expected: 'привилегии',
212                                 description: 'Grammar test for genitive case, привилегия -> привилегии'
213                         },
214                         {
215                                 word: 'установка',
216                                 grammarForm: 'genitive',
217                                 expected: 'установки',
218                                 description: 'Grammar test for genitive case, установка -> установки'
219                         },
220                         {
221                                 word: 'похоти',
222                                 grammarForm: 'genitive',
223                                 expected: 'похотей',
224                                 description: 'Grammar test for genitive case, похоти -> похотей'
225                         },
226                         {
227                                 word: 'доводы',
228                                 grammarForm: 'genitive',
229                                 expected: 'доводов',
230                                 description: 'Grammar test for genitive case, доводы -> доводов'
231                         },
232                         {
233                                 word: 'песчаник',
234                                 grammarForm: 'genitive',
235                                 expected: 'песчаника',
236                                 description: 'Grammar test for genitive case, песчаник -> песчаника'
237                         },
238                         {
239                                 word: 'данные',
240                                 grammarForm: 'genitive',
241                                 expected: 'данных',
242                                 description: 'Grammar test for genitive case, данные -> данных'
243                         },
244                         {
245                                 word: 'тесть',
246                                 grammarForm: 'prepositional',
247                                 expected: 'тесте',
248                                 description: 'Grammar test for prepositional case, тесть -> тесте'
249                         },
250                         {
251                                 word: 'привилегия',
252                                 grammarForm: 'prepositional',
253                                 expected: 'привилегии',
254                                 description: 'Grammar test for prepositional case, привилегия -> привилегии'
255                         },
256                         {
257                                 word: 'установка',
258                                 grammarForm: 'prepositional',
259                                 expected: 'установке',
260                                 description: 'Grammar test for prepositional case, установка -> установке'
261                         },
262                         {
263                                 word: 'похоти',
264                                 grammarForm: 'prepositional',
265                                 expected: 'похотях',
266                                 description: 'Grammar test for prepositional case, похоти -> похотях'
267                         },
268                         {
269                                 word: 'доводы',
270                                 grammarForm: 'prepositional',
271                                 expected: 'доводах',
272                                 description: 'Grammar test for prepositional case, доводы -> доводах'
273                         },
274                         {
275                                 word: 'Викисклад',
276                                 grammarForm: 'prepositional',
277                                 expected: 'Викискладе',
278                                 description: 'Grammar test for prepositional case, Викисклад -> Викискладе'
279                         },
280                         {
281                                 word: 'Викисклад',
282                                 grammarForm: 'genitive',
283                                 expected: 'Викисклада',
284                                 description: 'Grammar test for genitive case, Викисклад -> Викисклада'
285                         },
286                         {
287                                 word: 'песчаник',
288                                 grammarForm: 'prepositional',
289                                 expected: 'песчанике',
290                                 description: 'Grammar test for prepositional case, песчаник -> песчанике'
291                         },
292                         {
293                                 word: 'данные',
294                                 grammarForm: 'prepositional',
295                                 expected: 'данных',
296                                 description: 'Grammar test for prepositional case, данные -> данных'
297                         }
298                 ],
300                 hu: [
301                         {
302                                 word: 'Wikipédiá',
303                                 grammarForm: 'rol',
304                                 expected: 'Wikipédiáról',
305                                 description: 'Grammar test for rol case'
306                         },
307                         {
308                                 word: 'Wikipédiá',
309                                 grammarForm: 'ba',
310                                 expected: 'Wikipédiába',
311                                 description: 'Grammar test for ba case'
312                         },
313                         {
314                                 word: 'Wikipédiá',
315                                 grammarForm: 'k',
316                                 expected: 'Wikipédiák',
317                                 description: 'Grammar test for k case'
318                         }
319                 ],
321                 ga: [
322                         {
323                                 word: 'an Domhnach',
324                                 grammarForm: 'ainmlae',
325                                 expected: 'Dé Domhnaigh',
326                                 description: 'Grammar test for ainmlae case'
327                         },
328                         {
329                                 word: 'an Luan',
330                                 grammarForm: 'ainmlae',
331                                 expected: 'Dé Luain',
332                                 description: 'Grammar test for ainmlae case'
333                         },
334                         {
335                                 word: 'an Satharn',
336                                 grammarForm: 'ainmlae',
337                                 expected: 'Dé Sathairn',
338                                 description: 'Grammar test for ainmlae case'
339                         }
340                 ],
342                 uk: [
343                         {
344                                 word: 'тесть',
345                                 grammarForm: 'genitive',
346                                 expected: 'тестя',
347                                 description: 'Grammar test for genitive case'
348                         },
349                         {
350                                 word: 'Вікіпедія',
351                                 grammarForm: 'genitive',
352                                 expected: 'Вікіпедії',
353                                 description: 'Grammar test for genitive case'
354                         },
355                         {
356                                 word: 'установка',
357                                 grammarForm: 'genitive',
358                                 expected: 'установки',
359                                 description: 'Grammar test for genitive case'
360                         },
361                         {
362                                 word: 'похоти',
363                                 grammarForm: 'genitive',
364                                 expected: 'похотей',
365                                 description: 'Grammar test for genitive case'
366                         },
367                         {
368                                 word: 'доводы',
369                                 grammarForm: 'genitive',
370                                 expected: 'доводов',
371                                 description: 'Grammar test for genitive case'
372                         },
373                         {
374                                 word: 'песчаник',
375                                 grammarForm: 'genitive',
376                                 expected: 'песчаника',
377                                 description: 'Grammar test for genitive case'
378                         },
379                         {
380                                 word: 'Вікіпедія',
381                                 grammarForm: 'accusative',
382                                 expected: 'Вікіпедію',
383                                 description: 'Grammar test for accusative case'
384                         }
385                 ],
387                 sl: [
388                         {
389                                 word: 'word',
390                                 grammarForm: 'orodnik',
391                                 expected: 'z word',
392                                 description: 'Grammar test for orodnik case'
393                         },
394                         {
395                                 word: 'word',
396                                 grammarForm: 'mestnik',
397                                 expected: 'o word',
398                                 description: 'Grammar test for mestnik case'
399                         }
400                 ],
402                 os: [
403                         {
404                                 word: 'бæстæ',
405                                 grammarForm: 'genitive',
406                                 expected: 'бæсты',
407                                 description: 'Grammar test for genitive case'
408                         },
409                         {
410                                 word: 'бæстæ',
411                                 grammarForm: 'allative',
412                                 expected: 'бæстæм',
413                                 description: 'Grammar test for allative case'
414                         },
415                         {
416                                 word: 'Тигр',
417                                 grammarForm: 'dative',
418                                 expected: 'Тигрæн',
419                                 description: 'Grammar test for dative case'
420                         },
421                         {
422                                 word: 'цъити',
423                                 grammarForm: 'dative',
424                                 expected: 'цъитийæн',
425                                 description: 'Grammar test for dative case'
426                         },
427                         {
428                                 word: 'лæппу',
429                                 grammarForm: 'genitive',
430                                 expected: 'лæппуйы',
431                                 description: 'Grammar test for genitive case'
432                         },
433                         {
434                                 word: '2011',
435                                 grammarForm: 'equative',
436                                 expected: '2011-ау',
437                                 description: 'Grammar test for equative case'
438                         }
439                 ],
441                 la: [
442                         {
443                                 word: 'Translatio',
444                                 grammarForm: 'genitive',
445                                 expected: 'Translationis',
446                                 description: 'Grammar test for genitive case'
447                         },
448                         {
449                                 word: 'Translatio',
450                                 grammarForm: 'accusative',
451                                 expected: 'Translationem',
452                                 description: 'Grammar test for accusative case'
453                         },
454                         {
455                                 word: 'Translatio',
456                                 grammarForm: 'ablative',
457                                 expected: 'Translatione',
458                                 description: 'Grammar test for ablative case'
459                         }
460                 ]
461         };
463         $.each( grammarTests, function ( langCode, test ) {
464                 if ( langCode === mw.config.get( 'wgUserLanguage' ) ) {
465                         grammarTest( langCode, test );
466                 }
467         } );
469         QUnit.test( 'List to text test', 4, function ( assert ) {
470                 assert.equal( mw.language.listToText( [] ), '', 'Blank list' );
471                 assert.equal( mw.language.listToText( ['a'] ), 'a', 'Single item' );
472                 assert.equal( mw.language.listToText( ['a', 'b'] ), 'a and b', 'Two items' );
473                 assert.equal( mw.language.listToText( ['a', 'b', 'c'] ), 'a, b and c', 'More than two items' );
474         } );
475 }( mediaWiki, jQuery ) );