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