Implement extension registration from an extension.json file
[mediawiki.git] / tests / qunit / suites / resources / jquery / jquery.highlightText.test.js
blobe1fb96dcebc3f0872d7e590b2031592ed7e5cb86
1 ( function ( $ ) {
2         QUnit.module( 'jquery.highlightText', QUnit.newMwEnvironment() );
4         QUnit.test( 'Check', function ( assert ) {
5                 var $fixture, cases = [
6                         {
7                                 desc: 'Test 001',
8                                 text: 'Blue Öyster Cult',
9                                 highlight: 'Blue',
10                                 expected: '<span class="highlight">Blue</span> Öyster Cult'
11                         },
12                         {
13                                 desc: 'Test 002',
14                                 text: 'Blue Öyster Cult',
15                                 highlight: 'Blue ',
16                                 expected: '<span class="highlight">Blue</span> Öyster Cult'
17                         },
18                         {
19                                 desc: 'Test 003',
20                                 text: 'Blue Öyster Cult',
21                                 highlight: 'Blue Ö',
22                                 expected: '<span class="highlight">Blue</span> <span class="highlight">Ö</span>yster Cult'
23                         },
24                         {
25                                 desc: 'Test 004',
26                                 text: 'Blue Öyster Cult',
27                                 highlight: 'Blue Öy',
28                                 expected: '<span class="highlight">Blue</span> <span class="highlight">Öy</span>ster Cult'
29                         },
30                         {
31                                 desc: 'Test 005',
32                                 text: 'Blue Öyster Cult',
33                                 highlight: ' Blue',
34                                 expected: '<span class="highlight">Blue</span> Öyster Cult'
35                         },
36                         {
37                                 desc: 'Test 006',
38                                 text: 'Blue Öyster Cult',
39                                 highlight: ' Blue ',
40                                 expected: '<span class="highlight">Blue</span> Öyster Cult'
41                         },
42                         {
43                                 desc: 'Test 007',
44                                 text: 'Blue Öyster Cult',
45                                 highlight: ' Blue Ö',
46                                 expected: '<span class="highlight">Blue</span> <span class="highlight">Ö</span>yster Cult'
47                         },
48                         {
49                                 desc: 'Test 008',
50                                 text: 'Blue Öyster Cult',
51                                 highlight: ' Blue Öy',
52                                 expected: '<span class="highlight">Blue</span> <span class="highlight">Öy</span>ster Cult'
53                         },
54                         {
55                                 desc: 'Test 009: Highlighter broken on starting Umlaut?',
56                                 text: 'Österreich',
57                                 highlight: 'Österreich',
58                                 expected: '<span class="highlight">Österreich</span>'
59                         },
60                         {
61                                 desc: 'Test 010: Highlighter broken on starting Umlaut?',
62                                 text: 'Österreich',
63                                 highlight: 'Ö',
64                                 expected: '<span class="highlight">Ö</span>sterreich'
65                         },
66                         {
67                                 desc: 'Test 011: Highlighter broken on starting Umlaut?',
68                                 text: 'Österreich',
69                                 highlight: 'Öst',
70                                 expected: '<span class="highlight">Öst</span>erreich'
71                         },
72                         {
73                                 desc: 'Test 012: Highlighter broken on starting Umlaut?',
74                                 text: 'Österreich',
75                                 highlight: 'Oe',
76                                 expected: 'Österreich'
77                         },
78                         {
79                                 desc: 'Test 013: Highlighter broken on punctuation mark?',
80                                 text: 'So good. To be there',
81                                 highlight: 'good',
82                                 expected: 'So <span class="highlight">good</span>. To be there'
83                         },
84                         {
85                                 desc: 'Test 014: Highlighter broken on space?',
86                                 text: 'So good. To be there',
87                                 highlight: 'be',
88                                 expected: 'So good. To <span class="highlight">be</span> there'
89                         },
90                         {
91                                 desc: 'Test 015: Highlighter broken on space?',
92                                 text: 'So good. To be there',
93                                 highlight: ' be',
94                                 expected: 'So good. To <span class="highlight">be</span> there'
95                         },
96                         {
97                                 desc: 'Test 016: Highlighter broken on space?',
98                                 text: 'So good. To be there',
99                                 highlight: 'be ',
100                                 expected: 'So good. To <span class="highlight">be</span> there'
101                         },
102                         {
103                                 desc: 'Test 017: Highlighter broken on space?',
104                                 text: 'So good. To be there',
105                                 highlight: ' be ',
106                                 expected: 'So good. To <span class="highlight">be</span> there'
107                         },
108                         {
109                                 desc: 'Test 018: en de Highlighter broken on special character at the end?',
110                                 text: 'So good. xbß',
111                                 highlight: 'xbß',
112                                 expected: 'So good. <span class="highlight">xbß</span>'
113                         },
114                         {
115                                 desc: 'Test 019: en de Highlighter broken on special character at the end?',
116                                 text: 'So good. xbß.',
117                                 highlight: 'xbß.',
118                                 expected: 'So good. <span class="highlight">xbß.</span>'
119                         },
120                         {
121                                 desc: 'Test 020: RTL he Hebrew',
122                                 text: 'חסיד אומות העולם',
123                                 highlight: 'חסיד אומות העולם',
124                                 expected: '<span class="highlight">חסיד</span> <span class="highlight">אומות</span> <span class="highlight">העולם</span>'
125                         },
126                         {
127                                 desc: 'Test 021: RTL he Hebrew',
128                                 text: 'חסיד אומות העולם',
129                                 highlight: 'חסי',
130                                 expected: '<span class="highlight">חסי</span>ד אומות העולם'
131                         },
132                         {
133                                 desc: 'Test 022: ja Japanese',
134                                 text: '諸国民の中の正義の人',
135                                 highlight: '諸国民の中の正義の人',
136                                 expected: '<span class="highlight">諸国民の中の正義の人</span>'
137                         },
138                         {
139                                 desc: 'Test 023: ja Japanese',
140                                 text: '諸国民の中の正義の人',
141                                 highlight: '諸国',
142                                 expected: '<span class="highlight">諸国</span>民の中の正義の人'
143                         },
144                         {
145                                 desc: 'Test 024: fr French text and « french quotes » (guillemets)',
146                                 text: '« L\'oiseau est sur l’île »',
147                                 highlight: '« L\'oiseau est sur l’île »',
148                                 expected: '<span class="highlight">«</span> <span class="highlight">L\'oiseau</span> <span class="highlight">est</span> <span class="highlight">sur</span> <span class="highlight">l’île</span> <span class="highlight">»</span>'
149                         },
150                         {
151                                 desc: 'Test 025: fr French text and « french quotes » (guillemets)',
152                                 text: '« L\'oiseau est sur l’île »',
153                                 highlight: '« L\'oise',
154                                 expected: '<span class="highlight">«</span> <span class="highlight">L\'oise</span>au est sur l’île »'
155                         },
156                         {
157                                 desc: 'Test 025a: fr French text and « french quotes » (guillemets) - does it match the single strings "«" and "L" separately?',
158                                 text: '« L\'oiseau est sur l’île »',
159                                 highlight: '« L',
160                                 expected: '<span class="highlight">«</span> <span class="highlight">L</span>\'oiseau est sur <span class="highlight">l</span>’île »'
161                         },
162                         {
163                                 desc: 'Test 026: ru Russian',
164                                 text: 'Праведники мира',
165                                 highlight: 'Праведники мира',
166                                 expected: '<span class="highlight">Праведники</span> <span class="highlight">мира</span>'
167                         },
168                         {
169                                 desc: 'Test 027: ru Russian',
170                                 text: 'Праведники мира',
171                                 highlight: 'Праве',
172                                 expected: '<span class="highlight">Праве</span>дники мира'
173                         },
174                         {
175                                 desc: 'Test 028 ka Georgian',
176                                 text: 'მთავარი გვერდი',
177                                 highlight: 'მთავარი გვერდი',
178                                 expected: '<span class="highlight">მთავარი</span> <span class="highlight">გვერდი</span>'
179                         },
180                         {
181                                 desc: 'Test 029 ka Georgian',
182                                 text: 'მთავარი გვერდი',
183                                 highlight: 'მთა',
184                                 expected: '<span class="highlight">მთა</span>ვარი გვერდი'
185                         },
186                         {
187                                 desc: 'Test 030 hy Armenian',
188                                 text: 'Նոնա Գափրինդաշվիլի',
189                                 highlight: 'Նոնա Գափրինդաշվիլի',
190                                 expected: '<span class="highlight">Նոնա</span> <span class="highlight">Գափրինդաշվիլի</span>'
191                         },
192                         {
193                                 desc: 'Test 031 hy Armenian',
194                                 text: 'Նոնա Գափրինդաշվիլի',
195                                 highlight: 'Նոն',
196                                 expected: '<span class="highlight">Նոն</span>ա Գափրինդաշվիլի'
197                         },
198                         {
199                                 desc: 'Test 032: th Thai',
200                                 text: 'พอล แอร์ดิช',
201                                 highlight: 'พอล แอร์ดิช',
202                                 expected: '<span class="highlight">พอล</span> <span class="highlight">แอร์ดิช</span>'
203                         },
204                         {
205                                 desc: 'Test 033: th Thai',
206                                 text: 'พอล แอร์ดิช',
207                                 highlight: 'พอ',
208                                 expected: '<span class="highlight">พอ</span>ล แอร์ดิช'
209                         },
210                         {
211                                 desc: 'Test 034: RTL ar Arabic',
212                                 text: 'بول إيردوس',
213                                 highlight: 'بول إيردوس',
214                                 expected: '<span class="highlight">بول</span> <span class="highlight">إيردوس</span>'
215                         },
216                         {
217                                 desc: 'Test 035: RTL ar Arabic',
218                                 text: 'بول إيردوس',
219                                 highlight: 'بو',
220                                 expected: '<span class="highlight">بو</span>ل إيردوس'
221                         }
222                 ];
223                 QUnit.expect( cases.length );
225                 $.each( cases, function ( i, item ) {
226                         $fixture = $( '<p>' ).text( item.text ).highlightText( item.highlight );
227                         assert.equal(
228                                 $fixture.html(),
229                                 // Re-parse to normalize
230                                 $( '<p>' ).html( item.expected ).html(),
231                                 item.desc || undefined
232                         );
233                 } );
234         } );
235 }( jQuery ) );