Remove Profiler::isStub()
[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;
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
46 } );
49 // These tests run only for the current UI language.
50 var grammarTests = {
51 bs: [
53 word: 'word',
54 grammarForm: 'instrumental',
55 expected: 's word',
56 description: 'Grammar test for instrumental case'
59 word: 'word',
60 grammarForm: 'lokativ',
61 expected: 'o word',
62 description: 'Grammar test for lokativ case'
66 he: [
68 word: 'ויקיפדיה',
69 grammarForm: 'prefixed',
70 expected: 'וויקיפדיה',
71 description: 'Duplicate the "Waw" if prefixed'
74 word: 'וולפגנג',
75 grammarForm: 'prefixed',
76 expected: 'וולפגנג',
77 description: 'Duplicate the "Waw" if prefixed, but not if it is already duplicated.'
80 word: 'הקובץ',
81 grammarForm: 'prefixed',
82 expected: 'קובץ',
83 description: 'Remove the "He" if prefixed'
86 word: 'Wikipedia',
87 grammarForm: 'תחילית',
88 expected: '־Wikipedia',
89 description: 'GAdd a hyphen (maqaf) before non-Hebrew letters'
92 word: '1995',
93 grammarForm: 'תחילית',
94 expected: '־1995',
95 description: 'Add a hyphen (maqaf) before numbers'
99 hsb: [
101 word: 'word',
102 grammarForm: 'instrumental',
103 expected: 'z word',
104 description: 'Grammar test for instrumental case'
107 word: 'word',
108 grammarForm: 'lokatiw',
109 expected: 'wo word',
110 description: 'Grammar test for lokatiw case'
114 dsb: [
116 word: 'word',
117 grammarForm: 'instrumental',
118 expected: 'z word',
119 description: 'Grammar test for instrumental case'
122 word: 'word',
123 grammarForm: 'lokatiw',
124 expected: 'wo word',
125 description: 'Grammar test for lokatiw case'
129 hy: [
131 word: 'Մաունա',
132 grammarForm: 'genitive',
133 expected: 'Մաունայի',
134 description: 'Grammar test for genitive case'
137 word: 'հետո',
138 grammarForm: 'genitive',
139 expected: 'հետոյի',
140 description: 'Grammar test for genitive case'
143 word: 'գիրք',
144 grammarForm: 'genitive',
145 expected: 'գրքի',
146 description: 'Grammar test for genitive case'
149 word: 'ժամանակի',
150 grammarForm: 'genitive',
151 expected: 'ժամանակիի',
152 description: 'Grammar test for genitive case'
156 fi: [
158 word: 'talo',
159 grammarForm: 'genitive',
160 expected: 'talon',
161 description: 'Grammar test for genitive case'
164 word: 'linux',
165 grammarForm: 'genitive',
166 expected: 'linuxin',
167 description: 'Grammar test for genitive case'
170 word: 'talo',
171 grammarForm: 'elative',
172 expected: 'talosta',
173 description: 'Grammar test for elative case'
176 word: 'pastöroitu',
177 grammarForm: 'partitive',
178 expected: 'pastöroitua',
179 description: 'Grammar test for partitive case'
182 word: 'talo',
183 grammarForm: 'partitive',
184 expected: 'taloa',
185 description: 'Grammar test for partitive case'
188 word: 'talo',
189 grammarForm: 'illative',
190 expected: 'taloon',
191 description: 'Grammar test for illative case'
194 word: 'linux',
195 grammarForm: 'inessive',
196 expected: 'linuxissa',
197 description: 'Grammar test for inessive case'
201 ru: [
203 word: 'тесть',
204 grammarForm: 'genitive',
205 expected: 'тестя',
206 description: 'Grammar test for genitive case, тесть -> тестя'
209 word: 'привилегия',
210 grammarForm: 'genitive',
211 expected: 'привилегии',
212 description: 'Grammar test for genitive case, привилегия -> привилегии'
215 word: 'установка',
216 grammarForm: 'genitive',
217 expected: 'установки',
218 description: 'Grammar test for genitive case, установка -> установки'
221 word: 'похоти',
222 grammarForm: 'genitive',
223 expected: 'похотей',
224 description: 'Grammar test for genitive case, похоти -> похотей'
227 word: 'доводы',
228 grammarForm: 'genitive',
229 expected: 'доводов',
230 description: 'Grammar test for genitive case, доводы -> доводов'
233 word: 'песчаник',
234 grammarForm: 'genitive',
235 expected: 'песчаника',
236 description: 'Grammar test for genitive case, песчаник -> песчаника'
239 word: 'данные',
240 grammarForm: 'genitive',
241 expected: 'данных',
242 description: 'Grammar test for genitive case, данные -> данных'
245 word: 'тесть',
246 grammarForm: 'prepositional',
247 expected: 'тесте',
248 description: 'Grammar test for prepositional case, тесть -> тесте'
251 word: 'привилегия',
252 grammarForm: 'prepositional',
253 expected: 'привилегии',
254 description: 'Grammar test for prepositional case, привилегия -> привилегии'
257 word: 'установка',
258 grammarForm: 'prepositional',
259 expected: 'установке',
260 description: 'Grammar test for prepositional case, установка -> установке'
263 word: 'похоти',
264 grammarForm: 'prepositional',
265 expected: 'похотях',
266 description: 'Grammar test for prepositional case, похоти -> похотях'
269 word: 'доводы',
270 grammarForm: 'prepositional',
271 expected: 'доводах',
272 description: 'Grammar test for prepositional case, доводы -> доводах'
275 word: 'Викисклад',
276 grammarForm: 'prepositional',
277 expected: 'Викискладе',
278 description: 'Grammar test for prepositional case, Викисклад -> Викискладе'
281 word: 'Викисклад',
282 grammarForm: 'genitive',
283 expected: 'Викисклада',
284 description: 'Grammar test for genitive case, Викисклад -> Викисклада'
287 word: 'песчаник',
288 grammarForm: 'prepositional',
289 expected: 'песчанике',
290 description: 'Grammar test for prepositional case, песчаник -> песчанике'
293 word: 'данные',
294 grammarForm: 'prepositional',
295 expected: 'данных',
296 description: 'Grammar test for prepositional case, данные -> данных'
300 hu: [
302 word: 'Wikipédiá',
303 grammarForm: 'rol',
304 expected: 'Wikipédiáról',
305 description: 'Grammar test for rol case'
308 word: 'Wikipédiá',
309 grammarForm: 'ba',
310 expected: 'Wikipédiába',
311 description: 'Grammar test for ba case'
314 word: 'Wikipédiá',
315 grammarForm: 'k',
316 expected: 'Wikipédiák',
317 description: 'Grammar test for k case'
321 ga: [
323 word: 'an Domhnach',
324 grammarForm: 'ainmlae',
325 expected: 'Dé Domhnaigh',
326 description: 'Grammar test for ainmlae case'
329 word: 'an Luan',
330 grammarForm: 'ainmlae',
331 expected: 'Dé Luain',
332 description: 'Grammar test for ainmlae case'
335 word: 'an Satharn',
336 grammarForm: 'ainmlae',
337 expected: 'Dé Sathairn',
338 description: 'Grammar test for ainmlae case'
342 uk: [
344 word: 'тесть',
345 grammarForm: 'genitive',
346 expected: 'тестя',
347 description: 'Grammar test for genitive case'
350 word: 'Вікіпедія',
351 grammarForm: 'genitive',
352 expected: 'Вікіпедії',
353 description: 'Grammar test for genitive case'
356 word: 'установка',
357 grammarForm: 'genitive',
358 expected: 'установки',
359 description: 'Grammar test for genitive case'
362 word: 'похоти',
363 grammarForm: 'genitive',
364 expected: 'похотей',
365 description: 'Grammar test for genitive case'
368 word: 'доводы',
369 grammarForm: 'genitive',
370 expected: 'доводов',
371 description: 'Grammar test for genitive case'
374 word: 'песчаник',
375 grammarForm: 'genitive',
376 expected: 'песчаника',
377 description: 'Grammar test for genitive case'
380 word: 'Вікіпедія',
381 grammarForm: 'accusative',
382 expected: 'Вікіпедію',
383 description: 'Grammar test for accusative case'
387 sl: [
389 word: 'word',
390 grammarForm: 'orodnik',
391 expected: 'z word',
392 description: 'Grammar test for orodnik case'
395 word: 'word',
396 grammarForm: 'mestnik',
397 expected: 'o word',
398 description: 'Grammar test for mestnik case'
402 os: [
404 word: 'бæстæ',
405 grammarForm: 'genitive',
406 expected: 'бæсты',
407 description: 'Grammar test for genitive case'
410 word: 'бæстæ',
411 grammarForm: 'allative',
412 expected: 'бæстæм',
413 description: 'Grammar test for allative case'
416 word: 'Тигр',
417 grammarForm: 'dative',
418 expected: 'Тигрæн',
419 description: 'Grammar test for dative case'
422 word: 'цъити',
423 grammarForm: 'dative',
424 expected: 'цъитийæн',
425 description: 'Grammar test for dative case'
428 word: 'лæппу',
429 grammarForm: 'genitive',
430 expected: 'лæппуйы',
431 description: 'Grammar test for genitive case'
434 word: '2011',
435 grammarForm: 'equative',
436 expected: '2011-ау',
437 description: 'Grammar test for equative case'
441 la: [
443 word: 'Translatio',
444 grammarForm: 'genitive',
445 expected: 'Translationis',
446 description: 'Grammar test for genitive case'
449 word: 'Translatio',
450 grammarForm: 'accusative',
451 expected: 'Translationem',
452 description: 'Grammar test for accusative case'
455 word: 'Translatio',
456 grammarForm: 'ablative',
457 expected: 'Translatione',
458 description: 'Grammar test for ablative case'
463 $.each( grammarTests, function ( langCode, test ) {
464 if ( langCode === mw.config.get( 'wgUserLanguage' ) ) {
465 grammarTest( langCode, test );
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 ) );