more test cases for highlighter; all pass the test of course
[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 text: 'Blue Öyster Cult',
12 highlight: 'Blue',
13 expected: '<span class="highlight">Blue</span> Öyster Cult'
14 },
15 {
16 text: 'Blue Öyster Cult',
17 highlight: 'Blue ',
18 expected: '<span class="highlight">Blue</span> Öyster Cult'
19 },
20 {
21 text: 'Blue Öyster Cult',
22 highlight: 'Blue Ö',
23 expected: '<span class="highlight">Blue</span> <span class="highlight">Ö</span>yster Cult'
24 },
25 {
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 text: 'Blue Öyster Cult',
32 highlight: ' Blue',
33 expected: '<span class="highlight">Blue</span> Öyster Cult'
34 },
35 {
36 text: 'Blue Öyster Cult',
37 highlight: ' Blue ',
38 expected: '<span class="highlight">Blue</span> Öyster Cult'
39 },
40 {
41 text: 'Blue Öyster Cult',
42 highlight: ' Blue Ö',
43 expected: '<span class="highlight">Blue</span> <span class="highlight">Ö</span>yster Cult'
44 },
45 {
46 text: 'Blue Öyster Cult',
47 highlight: ' Blue Öy',
48 expected: '<span class="highlight">Blue</span> <span class="highlight">Öy</span>ster Cult'
49 },
50 {
51 desc: 'Highlighter broken on starting Umlaut?',
52 text: 'Österreich',
53 highlight: 'Österreich',
54 expected: '<span class="highlight">Österreich</span>'
55 },
56 {
57 desc: 'Highlighter broken on starting Umlaut?',
58 text: 'Österreich',
59 highlight: 'Ö',
60 expected: '<span class="highlight">Ö</span>sterreich</span>'
61 },
62 {
63 desc: 'Highlighter broken on starting Umlaut?',
64 text: 'Österreich',
65 highlight: 'Öst',
66 expected: '<span class="highlight">Öst</span>erreich'
67 },
68 {
69 desc: 'Highlighter broken on starting Umlaut?',
70 text: 'Österreich',
71 highlight: 'Oe',
72 expected: 'Österreich'
73 },
74 {
75 desc: 'Highlighter broken on punctuation mark?',
76 text: 'So good. To be there',
77 highlight: 'good',
78 expected: 'So <span class="highlight">good</span>. To be there'
79 },
80 {
81 desc: 'Highlighter broken on space?',
82 text: 'So good. To be there',
83 highlight: 'be',
84 expected: 'So good. To <span class="highlight">be</span> there'
85 },
86 {
87 desc: 'Highlighter broken on space?',
88 text: 'So good. To be there',
89 highlight: ' be',
90 expected: 'So good. To <span class="highlight">be</span> there'
91 },
92 {
93 desc: 'Highlighter broken on space?',
94 text: 'So good. To be there',
95 highlight: 'be ',
96 expected: 'So good. To <span class="highlight">be</span> there'
97 },
98 {
99 desc: 'Highlighter broken on space?',
100 text: 'So good. To be there',
101 highlight: ' be ',
102 expected: 'So good. To <span class="highlight">be</span> there'
103 },
104 {
105 desc: 'Highlighter broken on special character at the end?',
106 text: 'So good. xbß',
107 highlight: 'xbß',
108 expected: 'So good. <span class="highlight">xbß</span>'
109 },
110 {
111 desc: 'Highlighter broken on special character at the end?',
112 text: 'So good. xbß.',
113 highlight: 'xbß.',
114 expected: 'So good. <span class="highlight">xbß.</span>'
115 }
116 ];
117 expect(cases.length);
118 var $fixture;
119
120 $.each(cases, function( i, item ) {
121 $fixture = $( '<p></p>' ).text( item.text );
122 $fixture.highlightText( item.highlight );
123 equals(
124 $fixture.html(),
125 $('<p>' + item.expected + '</p>').html(), // re-parse to normalize!
126 item.desc || undefined
127 );
128 } );
129 } );