1 | var assert = require("assert"),
|
2 | CSSwhat = require("../");
|
3 |
|
4 | var tests = [
|
5 |
|
6 | [
|
7 | 'div',
|
8 | [
|
9 | [
|
10 | {
|
11 | 'type': 'tag',
|
12 | 'name': 'div'
|
13 | }
|
14 | ]
|
15 | ],
|
16 | 'simple tag'
|
17 | ],
|
18 | [
|
19 | '*',
|
20 | [
|
21 | [
|
22 | {
|
23 | 'type': 'universal'
|
24 | }
|
25 | ]
|
26 | ],
|
27 | 'universal'
|
28 | ],
|
29 |
|
30 |
|
31 | [
|
32 | 'div div',
|
33 | [
|
34 | [
|
35 | {
|
36 | 'type': 'tag',
|
37 | 'name': 'div'
|
38 | },
|
39 | {
|
40 | 'type': 'descendant'
|
41 | },
|
42 | {
|
43 | 'type': 'tag',
|
44 | 'name': 'div'
|
45 | }
|
46 | ]
|
47 | ],
|
48 | 'descendant'
|
49 | ],
|
50 | [
|
51 | 'div\t \n \tdiv',
|
52 | [
|
53 | [
|
54 | {
|
55 | 'type': 'tag',
|
56 | 'name': 'div'
|
57 | },
|
58 | {
|
59 | 'type': 'descendant'
|
60 | },
|
61 | {
|
62 | 'type': 'tag',
|
63 | 'name': 'div'
|
64 | }
|
65 | ]
|
66 | ],
|
67 | 'descendant /w whitespace'
|
68 | ],
|
69 | [
|
70 | 'div + div',
|
71 | [
|
72 | [
|
73 | {
|
74 | 'type': 'tag',
|
75 | 'name': 'div'
|
76 | },
|
77 | {
|
78 | 'type': 'adjacent'
|
79 | },
|
80 | {
|
81 | 'type': 'tag',
|
82 | 'name': 'div'
|
83 | }
|
84 | ]
|
85 | ],
|
86 | 'adjacent'
|
87 | ],
|
88 | [
|
89 | 'div ~ div',
|
90 | [
|
91 | [
|
92 | {
|
93 | 'type': 'tag',
|
94 | 'name': 'div'
|
95 | },
|
96 | {
|
97 | 'type': 'sibling'
|
98 | },
|
99 | {
|
100 | 'type': 'tag',
|
101 | 'name': 'div'
|
102 | }
|
103 | ]
|
104 | ],
|
105 | 'sibling'
|
106 | ],
|
107 | [
|
108 | 'p < div',
|
109 | [
|
110 | [
|
111 | {
|
112 | 'type': 'tag',
|
113 | 'name': 'p'
|
114 | },
|
115 | {
|
116 | 'type': 'parent'
|
117 | },
|
118 | {
|
119 | 'type': 'tag',
|
120 | 'name': 'div'
|
121 | }
|
122 | ]
|
123 | ],
|
124 | 'parent'
|
125 | ],
|
126 |
|
127 |
|
128 |
|
129 | [
|
130 | '#\\ > a ',
|
131 | [
|
132 | [
|
133 | {
|
134 | 'type': 'attribute',
|
135 | 'action': 'equals',
|
136 | 'name': 'id',
|
137 | 'value': ' ',
|
138 | 'ignoreCase': false
|
139 | },
|
140 | {
|
141 | 'type': 'child'
|
142 | },
|
143 | {
|
144 | 'type': 'tag',
|
145 | 'name': 'a'
|
146 | }
|
147 | ]
|
148 | ],
|
149 | 'Space between escaped space and combinator'
|
150 | ],
|
151 | [
|
152 | '.\\ ',
|
153 | [
|
154 | [
|
155 | {
|
156 | 'type': 'attribute',
|
157 | 'name': 'class',
|
158 | 'action': 'element',
|
159 | 'value': ' ',
|
160 | 'ignoreCase': false
|
161 | }
|
162 | ]
|
163 | ],
|
164 | 'Space after escaped space'
|
165 | ],
|
166 | [
|
167 | '\\61 ',
|
168 | [
|
169 | [
|
170 | {
|
171 | 'type': 'tag',
|
172 | 'name': 'a'
|
173 | }
|
174 | ]
|
175 | ],
|
176 | 'Numeric escape with space (BMP)'
|
177 | ],
|
178 | [
|
179 | '\\1d306\\01d306',
|
180 | [
|
181 | [
|
182 | {
|
183 | 'type': 'tag',
|
184 | 'name': '\uD834\uDF06\uD834\uDF06'
|
185 | }
|
186 | ]
|
187 | ],
|
188 | 'Numeric escape (outside BMP)'
|
189 | ],
|
190 |
|
191 |
|
192 |
|
193 | [
|
194 | '[name^=\'foo[\']',
|
195 | [
|
196 | [
|
197 | {
|
198 | 'type': 'attribute',
|
199 | 'name': 'name',
|
200 | 'action': 'start',
|
201 | 'value': 'foo[',
|
202 | 'ignoreCase': false
|
203 | }
|
204 | ]
|
205 | ],
|
206 | 'quoted attribute'
|
207 | ],
|
208 | [
|
209 | '[name^=\'foo[bar]\']',
|
210 | [
|
211 | [
|
212 | {
|
213 | 'type': 'attribute',
|
214 | 'name': 'name',
|
215 | 'action': 'start',
|
216 | 'value': 'foo[bar]',
|
217 | 'ignoreCase': false
|
218 | }
|
219 | ]
|
220 | ],
|
221 | 'quoted attribute'
|
222 | ],
|
223 | [
|
224 | '[name$=\'[bar]\']',
|
225 | [
|
226 | [
|
227 | {
|
228 | 'type': 'attribute',
|
229 | 'name': 'name',
|
230 | 'action': 'end',
|
231 | 'value': '[bar]',
|
232 | 'ignoreCase': false
|
233 | }
|
234 | ]
|
235 | ],
|
236 | 'quoted attribute'
|
237 | ],
|
238 | [
|
239 | '[href *= \'google\']',
|
240 | [
|
241 | [
|
242 | {
|
243 | 'type': 'attribute',
|
244 | 'name': 'href',
|
245 | 'action': 'any',
|
246 | 'value': 'google',
|
247 | 'ignoreCase': false
|
248 | }
|
249 | ]
|
250 | ],
|
251 | 'quoted attribute with spaces'
|
252 | ],
|
253 | [
|
254 | '[name=foo\\.baz]',
|
255 | [
|
256 | [
|
257 | {
|
258 | 'type': 'attribute',
|
259 | 'name': 'name',
|
260 | 'action': 'equals',
|
261 | 'value': 'foo.baz',
|
262 | 'ignoreCase': false
|
263 | }
|
264 | ]
|
265 | ],
|
266 | 'attribute with escaped dot'
|
267 | ],
|
268 | [
|
269 | '[name=foo\\[bar\\]]',
|
270 | [
|
271 | [
|
272 | {
|
273 | 'type': 'attribute',
|
274 | 'name': 'name',
|
275 | 'action': 'equals',
|
276 | 'value': 'foo[bar]',
|
277 | 'ignoreCase': false
|
278 | }
|
279 | ]
|
280 | ],
|
281 | 'attribute with escaped square brackets'
|
282 | ],
|
283 | [
|
284 | '[xml\\:test]',
|
285 | [
|
286 | [
|
287 | {
|
288 | 'type': 'attribute',
|
289 | 'name': 'xml:test',
|
290 | 'action': 'exists',
|
291 | 'value': '',
|
292 | 'ignoreCase': false
|
293 | }
|
294 | ]
|
295 | ],
|
296 | 'escaped attribute'
|
297 | ],
|
298 | [
|
299 | '[name="foo ~ < > , bar" i]',
|
300 | [
|
301 | [
|
302 | {
|
303 | 'type': 'attribute',
|
304 | 'name': 'name',
|
305 | 'action': 'equals',
|
306 | 'value': 'foo ~ < > , bar',
|
307 | 'ignoreCase': true
|
308 | }
|
309 | ]
|
310 | ],
|
311 | 'attribute with previously normalized characters'
|
312 | ],
|
313 |
|
314 |
|
315 |
|
316 |
|
317 | [
|
318 | ':foo',
|
319 | [
|
320 | [
|
321 | {
|
322 | 'type': 'pseudo',
|
323 | 'name': 'foo',
|
324 | 'data': null
|
325 | }
|
326 | ]
|
327 | ],
|
328 | 'pseudo selector without any data'
|
329 | ],
|
330 | [
|
331 | ':bar(baz)',
|
332 | [
|
333 | [
|
334 | {
|
335 | 'type': 'pseudo',
|
336 | 'name': 'bar',
|
337 | 'data': 'baz'
|
338 | }
|
339 | ]
|
340 | ],
|
341 | 'pseudo selector with data'
|
342 | ],
|
343 | [
|
344 | ':contains(\'(foo)\')',
|
345 | [
|
346 | [
|
347 | {
|
348 | 'type': 'pseudo',
|
349 | 'name': 'contains',
|
350 | 'data': '\'(foo)\''
|
351 | }
|
352 | ]
|
353 | ],
|
354 | 'pseudo selector with data'
|
355 | ],
|
356 |
|
357 |
|
358 | [
|
359 | 'a , b',
|
360 | [
|
361 | [
|
362 | {
|
363 | 'type': 'tag',
|
364 | 'name': 'a'
|
365 | }
|
366 | ],
|
367 | [
|
368 | {
|
369 | 'type': 'tag',
|
370 | 'name': 'b'
|
371 | }
|
372 | ]
|
373 | ],
|
374 | 'multiple selectors'
|
375 | ]
|
376 | ];
|
377 |
|
378 | tests.forEach(function(arr, i){
|
379 | arr[0] = CSSwhat(arr[0]);
|
380 | assert.deepEqual.apply(null, arr);
|
381 | console.log("\t%d: '%s' passed", i + 1, arr[2]);
|
382 | });
|
383 |
|
384 | console.log("\nCollected selectors (qwery, sizzle, nwmatcher)...");
|
385 |
|
386 | var out = require("./out.json");
|
387 |
|
388 | Object.keys(out).forEach(function(s){
|
389 | assert.deepEqual(CSSwhat(s), out[s], s);
|
390 | });
|
391 |
|
392 | console.log("Passed!"); |
\ | No newline at end of file |