1
YUI.add('highlight-test', function (Y) {
6
suite = new Y.Test.Suite('Y.Highlight');
8
suite.add(new Y.Test.Case({
11
// -- all() ----------------------------------------------------------------
12
'all() should highlight all occurrences of needles in haystack': function () {
15
'f<b class="yui3-highlight">oo</b> <b class="yui3-highlight">ba</b>r <b class="yui3-highlight">ba</b>z',
16
Hi.all('foo bar baz', ['oo', 'ba'])
19
// Single string as needle.
21
'f<b class="yui3-highlight">oo</b> bar baz',
22
Hi.all('foo bar baz', 'oo')
26
'all() should escape HTML characters': function () {
28
'<f<b class="yui3-highlight">oo</b>> & <<b class="yui3-highlight">ba</b>r>',
29
Hi.all('<foo> & <bar>', ['oo', 'ba'])
33
'all() should not highlight matches inside HTML entities': function () {
40
'/<b class="yui3-highlight">m</b>&<b class="yui3-highlight">m</b>/',
41
Hi.all('/m&m/', ['a', 'm', 'x'])
45
'all() should highlight complete HTML entities when part of a match': function () {
47
'<b class="yui3-highlight">&</b>',
52
'foo <b class="yui3-highlight">&</b> bar',
53
Hi.all('foo & bar', '&')
58
'all() should be case-insensitive by default': function () {
60
'f<b class="yui3-highlight">oo</b> <b class="yui3-highlight">BA</b>R <b class="yui3-highlight">ba</b>z',
61
Hi.all('foo BAR baz', ['oo', 'ba'])
65
'all() should support a caseSensitive option': function () {
67
'f<b class="yui3-highlight">oo</b> BAR <b class="yui3-highlight">ba</b>z',
68
Hi.all('foo BAR baz', ['oo', 'ba'], {caseSensitive: true})
72
'all() should support a startsWith option': function () {
74
'<b class="yui3-highlight">fo</b>o bar baz',
75
Hi.all('foo bar baz', ['fo', 'ba'], {startsWith: true})
79
'all() should support caseSensitive and startsWith together': function () {
82
Hi.all('FOO bar baz', ['fo', 'ba'], {caseSensitive: true, startsWith: true})
86
'<b class="yui3-highlight">FO</b>O bar baz',
87
Hi.all('FOO bar baz', ['FO', 'ba'], {caseSensitive: true, startsWith: true})
91
// bug #2529945: http://yuilibrary.com/projects/yui3/ticket/2529945
92
'all() should not attempt to highlight empty needles': function () {
93
Assert.areSame('foo', Hi.all('foo', []));
94
Assert.areSame('foo', Hi.all('foo', ['']));
95
Assert.areSame('foo', Hi.all('foo', ''));
96
Assert.areSame("O'Neal", Hi.all("O'Neal", ''));
99
// -- allCase() ------------------------------------------------------------
100
'allCase() should be a shortcut for case-sensitive all()': function () {
102
'f<b class="yui3-highlight">oo</b> BAR <b class="yui3-highlight">ba</b>z',
103
Hi.allCase('foo BAR baz', ['oo', 'ba'])
107
// -- allFold() ------------------------------------------------------------
108
'allFold() should be an accent-folding variant of all()': function () {
110
'föo <b class="yui3-highlight">bár</b> baz',
111
Hi.allFold('föo bár baz', ['bar'])
115
'foo <b class="yui3-highlight">bar</b> baz',
116
Hi.allFold('foo bar baz', ['bár'])
120
'<foo> <b class="yui3-highlight">bar</b>',
121
Hi.allFold('<foo> bar', 'bar')
125
'<b class="yui3-highlight">ds</b>w',
126
Hi.allFold('dsw', 'ds')
129
Assert.areSame('<b class="yui3-highlight">O'Neal</b>', Hi.allFold("O'Neal", "O'Neal"));
132
// bug #2529945: http://yuilibrary.com/projects/yui3/ticket/2529945
133
'allFold() should not attempt to highlight empty needles': function () {
134
Assert.areSame('foo', Hi.allFold('foo', []));
135
Assert.areSame('foo', Hi.allFold('foo', ['']));
136
Assert.areSame('foo', Hi.allFold('foo', ''));
137
Assert.areSame("O'Neal", Hi.allFold("O'Neal", ''));
140
// -- start() --------------------------------------------------------------
141
'start() should be a shortcut for all() with startsWith option': function () {
143
'<b class="yui3-highlight">fo</b>o bar baz',
144
Hi.start('foo bar baz', ['fo', 'ba'])
148
// -- startCase() ----------------------------------------------------------
149
'startCase() should be a shortcut for caseSensitive + startsWith all()': function () {
152
Hi.startCase('FOO bar baz', ['fo', 'ba'])
156
'<b class="yui3-highlight">FO</b>O bar baz',
157
Hi.startCase('FOO bar baz', ['FO', 'ba'])
161
// -- startFold() ----------------------------------------------------------
162
'startFold() should be an accent-folding variant of start()': function () {
165
Hi.startFold('föo bár baz', ['bar'])
169
'<b class="yui3-highlight">föo</b> bár baz',
170
Hi.startFold('föo bár baz', ['foo'])
174
'<b class="yui3-highlight">foo</b> bar baz',
175
Hi.startFold('foo bar baz', ['föo'])
179
// -- words() --------------------------------------------------------------
180
'words() should highlight complete words': function () {
183
'foo <b class="yui3-highlight">bar</b> baz',
184
Hi.words('foo bar baz', ['oo', 'ba', 'bar'])
187
// String with single word.
189
'foo <b class="yui3-highlight">bar</b> baz',
190
Hi.words('foo bar baz', 'bar')
193
// String with multiple words.
195
'<b class="yui3-highlight">foo</b> <b class="yui3-highlight">bar</b> baz',
196
Hi.words('foo bar baz', 'bar foo')
201
'foo <b class="yui3-highlight">bar</b> baz <b class="yui3-highlight">bar</b>',
202
Hi.words('foo bar baz bar', 'bar')
206
'words() should escape HTML characters': function () {
208
'<foo> & <<b class="yui3-highlight">bar</b>>',
209
Hi.words('<foo> & <bar>', 'bar')
213
'words() should not highlight matches inside HTML entities': function () {
220
'/<b class="yui3-highlight">m</b>&<b class="yui3-highlight">m</b>/',
221
Hi.words('/m&m/', ['a', 'm', 'x'])
225
'words() should be case-insensitive by default': function () {
227
'foo <b class="yui3-highlight">BAR</b> baz',
228
Hi.words('foo BAR baz', 'bar')
232
'words() should support a caseSensitive option': function () {
235
Hi.words('foo BAR baz', 'bar', {caseSensitive: true})
239
'foo <b class="yui3-highlight">BAR</b> baz',
240
Hi.words('foo BAR baz', 'BAR', {caseSensitive: true})
244
// bug #2529945: http://yuilibrary.com/projects/yui3/ticket/2529945
245
'words() should not attempt to highlight empty needles': function () {
246
Assert.areSame('foo bar', Hi.words('foo bar', ''));
247
Assert.areSame('foo bar', Hi.words('foo bar', []));
248
Assert.areSame('foo bar', Hi.words('foo bar', ['']));
249
Assert.areSame("O'Neal", Hi.words("O'Neal", ''));
252
// -- wordsCase() ----------------------------------------------------------
253
'wordsCase() should be a shortcut for case-sensitive words()': function () {
256
Hi.wordsCase('foo BAR baz', 'bar')
260
'foo <b class="yui3-highlight">BAR</b> baz',
261
Hi.wordsCase('foo BAR baz', 'BAR')
265
// -- wordsFold() ----------------------------------------------------------
266
'wordsFold() should be an accent-folding variant of words()': function () {
269
Hi.wordsFold('föo bár baz', ['fo', 'ba'])
273
'<b class="yui3-highlight">föo</b> <b class="yui3-highlight">bár</b> baz',
274
Hi.wordsFold('föo bár baz', 'foo bar')
278
'<b class="yui3-highlight">föo</b> <b class="yui3-highlight">bár</b> baz',
279
Hi.wordsFold('föo bár baz', ['foo', 'bar'])
283
'<b class="yui3-highlight">foo</b> <b class="yui3-highlight">bar</b> baz',
284
Hi.wordsFold('foo bar baz', ['föo', 'bár'])
288
'<foo> <b class="yui3-highlight">bar</b>',
289
Hi.wordsFold('<foo> bar', 'bar')
293
'<b class="yui3-highlight">O'Neal</b>',
294
Hi.wordsFold("O'Neal", "O'Neal")
298
// bug #2529945: http://yuilibrary.com/projects/yui3/ticket/2529945
299
'wordsFold() should not attempt to highlight empty needles': function () {
300
Assert.areSame('foo bar', Hi.wordsFold('foo bar', ''));
301
Assert.areSame('foo bar', Hi.wordsFold('foo bar', []));
302
Assert.areSame('foo bar', Hi.wordsFold('foo bar', ['']));
306
Y.Test.Runner.add(suite);
308
}, '@VERSION@', {requires:['highlight', 'test']});