follow up to r94807 : more test cases incl. hebrew RTL and Japanese, the test cases...
[lhc/web/wiklou.git] / tests / qunit / suites / resources / jquery / jquery.highlightText.test.js
1 module( 'jquery.highlightText' );
2
3 test( '-- Initial check', function() {
4 expect(1);
5 ok( $.fn.highlightText, 'jQuery.fn.highlightText defined' );
6 } );
7
8 test( 'Check', function() {
9 var cases = [
10 {
11 desc: 'Test 001',
12 text: 'Blue Öyster Cult',
13 highlight: 'Blue',
14 expected: '<span class="highlight">Blue</span> Öyster Cult'
15 },
16 {
17 desc: 'Test 002',
18 text: 'Blue Öyster Cult',
19 highlight: 'Blue ',
20 expected: '<span class="highlight">Blue</span> Öyster Cult'
21 },
22 {
23 desc: 'Test 003',
24 text: 'Blue Öyster Cult',
25 highlight: 'Blue Ö',
26 expected: '<span class="highlight">Blue</span> <span class="highlight">Ö</span>yster Cult'
27 },
28 {
29 desc: 'Test 004',
30 text: 'Blue Öyster Cult',
31 highlight: 'Blue Öy',
32 expected: '<span class="highlight">Blue</span> <span class="highlight">Öy</span>ster Cult'
33 },
34 {
35 desc: 'Test 005',
36 text: 'Blue Öyster Cult',
37 highlight: ' Blue',
38 expected: '<span class="highlight">Blue</span> Öyster Cult'
39 },
40 {
41 desc: 'Test 006',
42 text: 'Blue Öyster Cult',
43 highlight: ' Blue ',
44 expected: '<span class="highlight">Blue</span> Öyster Cult'
45 },
46 {
47 desc: 'Test 007',
48 text: 'Blue Öyster Cult',
49 highlight: ' Blue Ö',
50 expected: '<span class="highlight">Blue</span> <span class="highlight">Ö</span>yster Cult'
51 },
52 {
53 desc: 'Test 008',
54 text: 'Blue Öyster Cult',
55 highlight: ' Blue Öy',
56 expected: '<span class="highlight">Blue</span> <span class="highlight">Öy</span>ster Cult'
57 },
58 {
59 desc: 'Test 009: Highlighter broken on starting Umlaut?',
60 text: 'Österreich',
61 highlight: 'Österreich',
62 expected: '<span class="highlight">Österreich</span>'
63 },
64 {
65 desc: 'Test 010: Highlighter broken on starting Umlaut?',
66 text: 'Österreich',
67 highlight: 'Ö',
68 expected: '<span class="highlight">Ö</span>sterreich'
69 },
70 {
71 desc: 'Test 011: Highlighter broken on starting Umlaut?',
72 text: 'Österreich',
73 highlight: 'Öst',
74 expected: '<span class="highlight">Öst</span>erreich'
75 },
76 {
77 desc: 'Test 012: Highlighter broken on starting Umlaut?',
78 text: 'Österreich',
79 highlight: 'Oe',
80 expected: 'Österreich'
81 },
82 {
83 desc: 'Test 013: Highlighter broken on punctuation mark?',
84 text: 'So good. To be there',
85 highlight: 'good',
86 expected: 'So <span class="highlight">good</span>. To be there'
87 },
88 {
89 desc: 'Test 014: Highlighter broken on space?',
90 text: 'So good. To be there',
91 highlight: 'be',
92 expected: 'So good. To <span class="highlight">be</span> there'
93 },
94 {
95 desc: 'Test 015: Highlighter broken on space?',
96 text: 'So good. To be there',
97 highlight: ' be',
98 expected: 'So good. To <span class="highlight">be</span> there'
99 },
100 {
101 desc: 'Test 016: Highlighter broken on space?',
102 text: 'So good. To be there',
103 highlight: 'be ',
104 expected: 'So good. To <span class="highlight">be</span> there'
105 },
106 {
107 desc: 'Test 017: Highlighter broken on space?',
108 text: 'So good. To be there',
109 highlight: ' be ',
110 expected: 'So good. To <span class="highlight">be</span> there'
111 },
112 {
113 desc: 'Test 018: Highlighter broken on special character at the end?',
114 text: 'So good. xbß',
115 highlight: 'xbß',
116 expected: 'So good. <span class="highlight">xbß</span>'
117 },
118 {
119 desc: 'Test 019: Highlighter broken on special character at the end?',
120 text: 'So good. xbß.',
121 highlight: 'xbß.',
122 expected: 'So good. <span class="highlight">xbß.</span>'
123 },
124 {
125 desc: 'Test 020: Hebrew',
126 text: 'חסיד אומות העולם',
127 highlight: 'חסיד אומות העולם',
128 expected: '<span class="highlight">חסיד</span> <span class="highlight">אומות</span> <span class="highlight">העולם</span>'
129 },
130 {
131 desc: 'Test 021: Hebrew',
132 text: 'חסיד אומות העולם',
133 highlight: 'חסי',
134 expected: '<span class="highlight">חסי</span>ד אומות העולם'
135 },
136 {
137 desc: 'Test 022: Japanese',
138 text: '諸国民の中の正義の人',
139 highlight: '諸国民の中の正義の人',
140 expected: '<span class="highlight">諸国民の中の正義の人</span>'
141 },
142 {
143 desc: 'Test 023: Japanese',
144 text: '諸国民の中の正義の人',
145 highlight: '諸国',
146 expected: '<span class="highlight">諸国</span>民の中の正義の人'
147 },
148 {
149 desc: 'Test 100: TESTCASE FOR QUNIT FAILS: a wrong expected string was not detected in Firefox 6.0 and Chrome',
150 text: 'Österreich',
151 highlight: 'Ö',
152 expected: '<span class="highlight">Ö</span>sterreich</span this wrong tag is not detected as test failure in Firefox 6.0 or Chrome>'
153 },
154 {
155 desc: 'Test 101: TESTCASE FOR QUNIT FAILS: a wrong expected string was not detected in Firefox 6.0 or Chrome',
156 text: 'Oesterreich',
157 highlight: 'Oe',
158 expected: '<span class="highlight">Oe</span>sterreich</span this wrong tag is not detected as test failure in Firefox 6.0 or Chrome>'
159 }
160 ];
161 expect(cases.length);
162 var $fixture;
163
164 $.each(cases, function( i, item ) {
165 $fixture = $( '<p></p>' ).text( item.text );
166 $fixture.highlightText( item.highlight );
167 equals(
168 $fixture.html(),
169 $('<p>' + item.expected + '</p>').html(), // re-parse to normalize!
170 item.desc || undefined
171 );
172 } );
173 } );