~ubuntu-branches/ubuntu/saucy/whoopsie-daisy/saucy

« back to all changes in this revision

Viewing changes to backend/stats/static/js/yui/3.4.1/tests/highlight/tests/functional/highlight-test.js

  • Committer: Package Import Robot
  • Author(s): Evan Dandrea
  • Date: 2012-04-18 13:04:36 UTC
  • Revision ID: package-import@ubuntu.com-20120418130436-vmt93p8fds516lws
Tags: 0.1.32
Fix failing tests on powerpc and ARM.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
YUI.add('highlight-test', function (Y) {
2
 
 
3
 
var Assert = Y.Assert,
4
 
    Hi     = Y.Highlight,
5
 
 
6
 
    suite = new Y.Test.Suite('Y.Highlight');
7
 
 
8
 
suite.add(new Y.Test.Case({
9
 
    name: 'API',
10
 
 
11
 
    // -- all() ----------------------------------------------------------------
12
 
    'all() should highlight all occurrences of needles in haystack': function () {
13
 
        // Array of needles.
14
 
        Assert.areSame(
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'])
17
 
        );
18
 
 
19
 
        // Single string as needle.
20
 
        Assert.areSame(
21
 
            'f<b class="yui3-highlight">oo</b> bar baz',
22
 
            Hi.all('foo bar baz', 'oo')
23
 
        );
24
 
    },
25
 
 
26
 
    'all() should escape HTML characters': function () {
27
 
        Assert.areSame(
28
 
            '&lt;f<b class="yui3-highlight">oo</b>&gt; &amp; &lt;<b class="yui3-highlight">ba</b>r&gt;',
29
 
            Hi.all('<foo> & <bar>', ['oo', 'ba'])
30
 
        );
31
 
    },
32
 
 
33
 
    'all() should not highlight matches inside HTML entities': function () {
34
 
        Assert.areSame(
35
 
            '&amp;',
36
 
            Hi.all('&', 'amp')
37
 
        );
38
 
 
39
 
        Assert.areSame(
40
 
            '&#x2F;<b class="yui3-highlight">m</b>&amp;<b class="yui3-highlight">m</b>&#x2F;',
41
 
            Hi.all('/m&m/', ['a', 'm', 'x'])
42
 
        );
43
 
    },
44
 
 
45
 
    'all() should highlight complete HTML entities when part of a match': function () {
46
 
        Assert.areSame(
47
 
            '<b class="yui3-highlight">&amp;</b>',
48
 
            Hi.all('&', '&')
49
 
        );
50
 
 
51
 
        Assert.areSame(
52
 
            'foo <b class="yui3-highlight">&amp;</b> bar',
53
 
            Hi.all('foo & bar', '&')
54
 
        );
55
 
 
56
 
    },
57
 
 
58
 
    'all() should be case-insensitive by default': function () {
59
 
        Assert.areSame(
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'])
62
 
        );
63
 
    },
64
 
 
65
 
    'all() should support a caseSensitive option': function () {
66
 
        Assert.areSame(
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})
69
 
        );
70
 
    },
71
 
 
72
 
    'all() should support a startsWith option': function () {
73
 
        Assert.areSame(
74
 
            '<b class="yui3-highlight">fo</b>o bar baz',
75
 
            Hi.all('foo bar baz', ['fo', 'ba'], {startsWith: true})
76
 
        );
77
 
    },
78
 
 
79
 
    'all() should support caseSensitive and startsWith together': function () {
80
 
        Assert.areSame(
81
 
            'FOO bar baz',
82
 
            Hi.all('FOO bar baz', ['fo', 'ba'], {caseSensitive: true, startsWith: true})
83
 
        );
84
 
 
85
 
        Assert.areSame(
86
 
            '<b class="yui3-highlight">FO</b>O bar baz',
87
 
            Hi.all('FOO bar baz', ['FO', 'ba'], {caseSensitive: true, startsWith: true})
88
 
        );
89
 
    },
90
 
 
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&#x27;Neal", Hi.all("O'Neal", ''));
97
 
    },
98
 
 
99
 
    // -- allCase() ------------------------------------------------------------
100
 
    'allCase() should be a shortcut for case-sensitive all()': function () {
101
 
        Assert.areSame(
102
 
            'f<b class="yui3-highlight">oo</b> BAR <b class="yui3-highlight">ba</b>z',
103
 
            Hi.allCase('foo BAR baz', ['oo', 'ba'])
104
 
        );
105
 
    },
106
 
 
107
 
    // -- allFold() ------------------------------------------------------------
108
 
    'allFold() should be an accent-folding variant of all()': function () {
109
 
        Assert.areSame(
110
 
            'föo <b class="yui3-highlight">bár</b> baz',
111
 
            Hi.allFold('föo bár baz', ['bar'])
112
 
        );
113
 
 
114
 
        Assert.areSame(
115
 
            'foo <b class="yui3-highlight">bar</b> baz',
116
 
            Hi.allFold('foo bar baz', ['bár'])
117
 
        );
118
 
 
119
 
        Assert.areSame(
120
 
            '&lt;foo&gt; <b class="yui3-highlight">bar</b>',
121
 
            Hi.allFold('<foo> bar', 'bar')
122
 
        );
123
 
 
124
 
        Assert.areSame(
125
 
            '<b class="yui3-highlight">ds</b>w',
126
 
            Hi.allFold('dsw', 'ds')
127
 
        );
128
 
 
129
 
        Assert.areSame('<b class="yui3-highlight">O&#x27;Neal</b>', Hi.allFold("O'Neal", "O'Neal"));
130
 
    },
131
 
 
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&#x27;Neal", Hi.allFold("O'Neal", ''));
138
 
    },
139
 
 
140
 
    // -- start() --------------------------------------------------------------
141
 
    'start() should be a shortcut for all() with startsWith option': function () {
142
 
        Assert.areSame(
143
 
            '<b class="yui3-highlight">fo</b>o bar baz',
144
 
            Hi.start('foo bar baz', ['fo', 'ba'])
145
 
        );
146
 
    },
147
 
 
148
 
    // -- startCase() ----------------------------------------------------------
149
 
    'startCase() should be a shortcut for caseSensitive + startsWith all()': function () {
150
 
        Assert.areSame(
151
 
            'FOO bar baz',
152
 
            Hi.startCase('FOO bar baz', ['fo', 'ba'])
153
 
        );
154
 
 
155
 
        Assert.areSame(
156
 
            '<b class="yui3-highlight">FO</b>O bar baz',
157
 
            Hi.startCase('FOO bar baz', ['FO', 'ba'])
158
 
        );
159
 
    },
160
 
 
161
 
    // -- startFold() ----------------------------------------------------------
162
 
    'startFold() should be an accent-folding variant of start()': function () {
163
 
        Assert.areSame(
164
 
            'föo bár baz',
165
 
            Hi.startFold('föo bár baz', ['bar'])
166
 
        );
167
 
 
168
 
        Assert.areSame(
169
 
            '<b class="yui3-highlight">föo</b> bár baz',
170
 
            Hi.startFold('föo bár baz', ['foo'])
171
 
        );
172
 
 
173
 
        Assert.areSame(
174
 
            '<b class="yui3-highlight">foo</b> bar baz',
175
 
            Hi.startFold('foo bar baz', ['föo'])
176
 
        );
177
 
    },
178
 
 
179
 
    // -- words() --------------------------------------------------------------
180
 
    'words() should highlight complete words': function () {
181
 
        // Array of words.
182
 
        Assert.areSame(
183
 
            'foo <b class="yui3-highlight">bar</b> baz',
184
 
            Hi.words('foo bar baz', ['oo', 'ba', 'bar'])
185
 
        );
186
 
 
187
 
        // String with single word.
188
 
        Assert.areSame(
189
 
            'foo <b class="yui3-highlight">bar</b> baz',
190
 
            Hi.words('foo bar baz', 'bar')
191
 
        );
192
 
 
193
 
        // String with multiple words.
194
 
        Assert.areSame(
195
 
            '<b class="yui3-highlight">foo</b> <b class="yui3-highlight">bar</b> baz',
196
 
            Hi.words('foo bar baz', 'bar foo')
197
 
        );
198
 
 
199
 
        // Repeated word.
200
 
        Assert.areSame(
201
 
            'foo <b class="yui3-highlight">bar</b> baz <b class="yui3-highlight">bar</b>',
202
 
            Hi.words('foo bar baz bar', 'bar')
203
 
        );
204
 
    },
205
 
 
206
 
    'words() should escape HTML characters': function () {
207
 
        Assert.areSame(
208
 
            '&lt;foo&gt; &amp; &lt;<b class="yui3-highlight">bar</b>&gt;',
209
 
            Hi.words('<foo> & <bar>', 'bar')
210
 
        );
211
 
    },
212
 
 
213
 
    'words() should not highlight matches inside HTML entities': function () {
214
 
        Assert.areSame(
215
 
            '&amp;',
216
 
            Hi.words('&', 'amp')
217
 
        );
218
 
 
219
 
        Assert.areSame(
220
 
            '&#x2F;<b class="yui3-highlight">m</b>&amp;<b class="yui3-highlight">m</b>&#x2F;',
221
 
            Hi.words('/m&m/', ['a', 'm', 'x'])
222
 
        );
223
 
    },
224
 
 
225
 
    'words() should be case-insensitive by default': function () {
226
 
        Assert.areSame(
227
 
            'foo <b class="yui3-highlight">BAR</b> baz',
228
 
            Hi.words('foo BAR baz', 'bar')
229
 
        );
230
 
    },
231
 
 
232
 
    'words() should support a caseSensitive option': function () {
233
 
        Assert.areSame(
234
 
            'foo BAR baz',
235
 
            Hi.words('foo BAR baz', 'bar', {caseSensitive: true})
236
 
        );
237
 
 
238
 
        Assert.areSame(
239
 
            'foo <b class="yui3-highlight">BAR</b> baz',
240
 
            Hi.words('foo BAR baz', 'BAR', {caseSensitive: true})
241
 
        );
242
 
    },
243
 
 
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&#x27;Neal", Hi.words("O'Neal", ''));
250
 
    },
251
 
 
252
 
    // -- wordsCase() ----------------------------------------------------------
253
 
    'wordsCase() should be a shortcut for case-sensitive words()': function () {
254
 
        Assert.areSame(
255
 
            'foo BAR baz',
256
 
            Hi.wordsCase('foo BAR baz', 'bar')
257
 
        );
258
 
 
259
 
        Assert.areSame(
260
 
            'foo <b class="yui3-highlight">BAR</b> baz',
261
 
            Hi.wordsCase('foo BAR baz', 'BAR')
262
 
        );
263
 
    },
264
 
 
265
 
    // -- wordsFold() ----------------------------------------------------------
266
 
    'wordsFold() should be an accent-folding variant of words()': function () {
267
 
        Assert.areSame(
268
 
            'föo bár baz',
269
 
            Hi.wordsFold('föo bár baz', ['fo', 'ba'])
270
 
        );
271
 
 
272
 
        Assert.areSame(
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')
275
 
        );
276
 
 
277
 
        Assert.areSame(
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'])
280
 
        );
281
 
 
282
 
        Assert.areSame(
283
 
            '<b class="yui3-highlight">foo</b> <b class="yui3-highlight">bar</b> baz',
284
 
            Hi.wordsFold('foo bar baz', ['föo', 'bár'])
285
 
        );
286
 
 
287
 
        Assert.areSame(
288
 
            '&lt;foo&gt; <b class="yui3-highlight">bar</b>',
289
 
            Hi.wordsFold('<foo> bar', 'bar')
290
 
        );
291
 
 
292
 
        Assert.areSame(
293
 
            '<b class="yui3-highlight">O&#x27;Neal</b>',
294
 
            Hi.wordsFold("O'Neal", "O'Neal")
295
 
        );
296
 
    },
297
 
 
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', ['']));
303
 
    }
304
 
}));
305
 
 
306
 
Y.Test.Runner.add(suite);
307
 
 
308
 
}, '@VERSION@', {requires:['highlight', 'test']});