]> git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/ex-mode/node_modules/space-pen/node_modules/jquery/src/sizzle/test/unit/selector.js
db5ca7f02249a0fb5f5b47ce9530743cf43e785d
[rbdr/dotfiles] / atom / packages / ex-mode / node_modules / space-pen / node_modules / jquery / src / sizzle / test / unit / selector.js
1 module("selector", { teardown: moduleTeardown });
2
3 // #### NOTE: ####
4 // jQuery should not be used in this module
5 // except for DOM manipulation
6 // If jQuery is mandatory for the selection, move the test to jquery/test/unit/selector.js
7 // Use t() or Sizzle()
8 // ###############
9
10 /*
11 ======== QUnit Reference ========
12 http://docs.jquery.com/QUnit
13
14 Test methods:
15 expect(numAssertions)
16 stop()
17 start()
18 note: QUnit's eventual addition of an argument to stop/start is ignored in this test suite
19 so that start and stop can be passed as callbacks without worrying about
20 their parameters
21 Test assertions:
22 ok(value, [message])
23 equal(actual, expected, [message])
24 notEqual(actual, expected, [message])
25 deepEqual(actual, expected, [message])
26 notDeepEqual(actual, expected, [message])
27 strictEqual(actual, expected, [message])
28 notStrictEqual(actual, expected, [message])
29 raises(block, [expected], [message])
30
31 ======== testinit.js reference ========
32 See data/testinit.js
33
34 q(...);
35 Returns an array of elements with the given IDs
36 @example q("main", "foo", "bar") => [<div id="main">, <span id="foo">, <input id="bar">]
37
38 t( testName, selector, [ "array", "of", "ids" ] );
39 Asserts that a select matches the given IDs
40 @example t("Check for something", "//[a]", ["foo", "baar"]);
41
42 url( "some/url.php" );
43 Add random number to url to stop caching
44 @example url("data/test.html") => "data/test.html?10538358428943"
45 @example url("data/test.php?foo=bar") => "data/test.php?foo=bar&10538358345554"
46 */
47
48 test("element", function() {
49 expect( 39 );
50
51 var form, all, good, i, obj1, lengthtest,
52 siblingTest, siblingNext, iframe, iframeDoc, html;
53
54 equal( Sizzle("").length, 0, "Empty selector returns an empty array" );
55 deepEqual( Sizzle("div", document.createTextNode("")), [], "Text element as context fails silently" );
56 form = document.getElementById("form");
57 ok( !Sizzle.matchesSelector( form, "" ), "Empty string passed to matchesSelector does not match" );
58 equal( Sizzle(" ").length, 0, "Empty selector returns an empty array" );
59 equal( Sizzle("\t").length, 0, "Empty selector returns an empty array" );
60
61 ok( Sizzle("*").length >= 30, "Select all" );
62 all = Sizzle("*");
63 good = true;
64 for ( i = 0; i < all.length; i++ ) {
65 if ( all[i].nodeType === 8 ) {
66 good = false;
67 }
68 }
69 ok( good, "Select all elements, no comment nodes" );
70 t( "Element Selector", "html", ["html"] );
71 t( "Element Selector", "body", ["body"] );
72 t( "Element Selector", "#qunit-fixture p", ["firstp","ap","sndp","en","sap","first"] );
73
74 t( "Leading space", " #qunit-fixture p", ["firstp","ap","sndp","en","sap","first"] );
75 t( "Leading tab", "\t#qunit-fixture p", ["firstp","ap","sndp","en","sap","first"] );
76 t( "Leading carriage return", "\r#qunit-fixture p", ["firstp","ap","sndp","en","sap","first"] );
77 t( "Leading line feed", "\n#qunit-fixture p", ["firstp","ap","sndp","en","sap","first"] );
78 t( "Leading form feed", "\f#qunit-fixture p", ["firstp","ap","sndp","en","sap","first"] );
79 t( "Trailing space", "#qunit-fixture p ", ["firstp","ap","sndp","en","sap","first"] );
80 t( "Trailing tab", "#qunit-fixture p\t", ["firstp","ap","sndp","en","sap","first"] );
81 t( "Trailing carriage return", "#qunit-fixture p\r", ["firstp","ap","sndp","en","sap","first"] );
82 t( "Trailing line feed", "#qunit-fixture p\n", ["firstp","ap","sndp","en","sap","first"] );
83 t( "Trailing form feed", "#qunit-fixture p\f", ["firstp","ap","sndp","en","sap","first"] );
84
85 t( "Parent Element", "dl ol", ["empty", "listWithTabIndex"] );
86 t( "Parent Element (non-space descendant combinator)", "dl\tol", ["empty", "listWithTabIndex"] );
87 obj1 = document.getElementById("object1");
88 equal( Sizzle("param", obj1).length, 2, "Object/param as context" );
89
90 deepEqual( Sizzle("select", form), q("select1","select2","select3","select4","select5"), "Finding selects with a context." );
91
92 // Check for unique-ness and sort order
93 deepEqual( Sizzle("p, div p"), Sizzle("p"), "Check for duplicates: p, div p" );
94
95 t( "Checking sort order", "h2, h1", ["qunit-header", "qunit-banner", "qunit-userAgent"] );
96 t( "Checking sort order", "h2:first, h1:first", ["qunit-header", "qunit-banner"] );
97 t( "Checking sort order", "#qunit-fixture p, #qunit-fixture p a", ["firstp", "simon1", "ap", "google", "groups", "anchor1", "mark", "sndp", "en", "yahoo", "sap", "anchor2", "simon", "first"] );
98
99 // Test Conflict ID
100 lengthtest = document.getElementById("lengthtest");
101 deepEqual( Sizzle("#idTest", lengthtest), q("idTest"), "Finding element with id of ID." );
102 deepEqual( Sizzle("[name='id']", lengthtest), q("idTest"), "Finding element with id of ID." );
103 deepEqual( Sizzle("input[id='idTest']", lengthtest), q("idTest"), "Finding elements with id of ID." );
104
105 siblingTest = document.getElementById("siblingTest");
106 deepEqual( Sizzle("div em", siblingTest), [], "Element-rooted QSA does not select based on document context" );
107 deepEqual( Sizzle("div em, div em, div em:not(div em)", siblingTest), [], "Element-rooted QSA does not select based on document context" );
108 deepEqual( Sizzle("div em, em\\,", siblingTest), [], "Escaped commas do not get treated with an id in element-rooted QSA" );
109
110 siblingNext = document.getElementById("siblingnext");
111 document.createDocumentFragment().appendChild( siblingTest );
112 deepEqual( Sizzle( "em + :not(:has(*)):not(:empty), foo", siblingTest ), [ siblingNext ],
113 "Non-qSA path correctly sets detached context for sibling selectors (jQuery #14351)" );
114
115 iframe = document.getElementById("iframe"),
116 iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
117 iframeDoc.open();
118 iframeDoc.write("<body><p id='foo'>bar</p></body>");
119 iframeDoc.close();
120 deepEqual(
121 Sizzle( "p:contains(bar)", iframeDoc ),
122 [ iframeDoc.getElementById("foo") ],
123 "Other document as context"
124 );
125
126 html = "";
127 for ( i = 0; i < 100; i++ ) {
128 html = "<div>" + html + "</div>";
129 }
130 html = jQuery( html ).appendTo( document.body );
131 ok( !!Sizzle("body div div div").length, "No stack or performance problems with large amounts of descendents" );
132 ok( !!Sizzle("body>div div div").length, "No stack or performance problems with large amounts of descendents" );
133 html.remove();
134
135 // Real use case would be using .watch in browsers with window.watch (see Issue #157)
136 q("qunit-fixture")[0].appendChild( document.createElement("toString") ).id = "toString";
137 t( "Element name matches Object.prototype property", "toString#toString", ["toString"] );
138 });
139
140 test("XML Document Selectors", function() {
141 var xml = createWithFriesXML();
142 expect( 11 );
143
144 equal( Sizzle("foo_bar", xml).length, 1, "Element Selector with underscore" );
145 equal( Sizzle(".component", xml).length, 1, "Class selector" );
146 equal( Sizzle("[class*=component]", xml).length, 1, "Attribute selector for class" );
147 equal( Sizzle("property[name=prop2]", xml).length, 1, "Attribute selector with name" );
148 equal( Sizzle("[name=prop2]", xml).length, 1, "Attribute selector with name" );
149 equal( Sizzle("#seite1", xml).length, 1, "Attribute selector with ID" );
150 equal( Sizzle("component#seite1", xml).length, 1, "Attribute selector with ID" );
151 equal( Sizzle.matches( "#seite1", Sizzle("component", xml) ).length, 1, "Attribute selector filter with ID" );
152 equal( Sizzle("meta property thing", xml).length, 2, "Descendent selector and dir caching" );
153 ok( Sizzle.matchesSelector( xml.lastChild, "soap\\:Envelope" ), "Check for namespaced element" );
154
155 xml = jQuery.parseXML("<?xml version='1.0' encoding='UTF-8'?><root><elem id='1'/></root>");
156 equal( Sizzle( "elem:not(:has(*))", xml ).length, 1,
157 "Non-qSA path correctly handles numeric ids (jQuery #14142)" );
158 });
159
160 test("broken", function() {
161 expect( 26 );
162
163 var attrbad,
164 broken = function( name, selector ) {
165 throws(function() {
166 // Setting context to null here somehow avoids QUnit's window.error handling
167 // making the e & e.message correct
168 // For whatever reason, without this,
169 // Sizzle.error will be called but no error will be seen in oldIE
170 Sizzle.call( null, selector );
171 }, function( e ) {
172 return e.message.indexOf("Syntax error") >= 0;
173 }, name + ": " + selector );
174 };
175
176 broken( "Broken Selector", "[" );
177 broken( "Broken Selector", "(" );
178 broken( "Broken Selector", "{" );
179 broken( "Broken Selector", "<" );
180 broken( "Broken Selector", "()" );
181 broken( "Broken Selector", "<>" );
182 broken( "Broken Selector", "{}" );
183 broken( "Broken Selector", "," );
184 broken( "Broken Selector", ",a" );
185 broken( "Broken Selector", "a," );
186 // Hangs on IE 9 if regular expression is inefficient
187 broken( "Broken Selector", "[id=012345678901234567890123456789");
188 broken( "Doesn't exist", ":visble" );
189 broken( "Nth-child", ":nth-child" );
190 // Sigh again. IE 9 thinks this is also a real selector
191 // not super critical that we fix this case
192 //broken( "Nth-child", ":nth-child(-)" );
193 // Sigh. WebKit thinks this is a real selector in qSA
194 // They've already fixed this and it'll be coming into
195 // current browsers soon. Currently, Safari 5.0 still has this problem
196 // broken( "Nth-child", ":nth-child(asdf)", [] );
197 broken( "Nth-child", ":nth-child(2n+-0)" );
198 broken( "Nth-child", ":nth-child(2+0)" );
199 broken( "Nth-child", ":nth-child(- 1n)" );
200 broken( "Nth-child", ":nth-child(-1 n)" );
201 broken( "First-child", ":first-child(n)" );
202 broken( "Last-child", ":last-child(n)" );
203 broken( "Only-child", ":only-child(n)" );
204 broken( "Nth-last-last-child", ":nth-last-last-child(1)" );
205 broken( "First-last-child", ":first-last-child" );
206 broken( "Last-last-child", ":last-last-child" );
207 broken( "Only-last-child", ":only-last-child" );
208
209 // Make sure attribute value quoting works correctly. See: #6093
210 attrbad = jQuery("<input type='hidden' value='2' name='foo.baz' id='attrbad1'/><input type='hidden' value='2' name='foo[baz]' id='attrbad2'/>").appendTo("#qunit-fixture");
211
212 broken( "Attribute not escaped", "input[name=foo.baz]", [] );
213 // Shouldn't be matching those inner brackets
214 broken( "Attribute not escaped", "input[name=foo[baz]]", [] );
215 });
216
217 test("id", function() {
218 expect( 34 );
219
220 var fiddle, a;
221
222 t( "ID Selector", "#body", ["body"] );
223 t( "ID Selector w/ Element", "body#body", ["body"] );
224 t( "ID Selector w/ Element", "ul#first", [] );
225 t( "ID selector with existing ID descendant", "#firstp #simon1", ["simon1"] );
226 t( "ID selector with non-existant descendant", "#firstp #foobar", [] );
227 t( "ID selector using UTF8", "#台北Táiběi", ["台北Táiběi"] );
228 t( "Multiple ID selectors using UTF8", "#台北Táiběi, #台北", ["台北Táiběi","台北"] );
229 t( "Descendant ID selector using UTF8", "div #台北", ["台北"] );
230 t( "Child ID selector using UTF8", "form > #台北", ["台北"] );
231
232 t( "Escaped ID", "#foo\\:bar", ["foo:bar"] );
233 t( "Escaped ID with descendent", "#foo\\:bar span:not(:input)", ["foo_descendent"] );
234 t( "Escaped ID", "#test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
235 t( "Descendant escaped ID", "div #foo\\:bar", ["foo:bar"] );
236 t( "Descendant escaped ID", "div #test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
237 t( "Child escaped ID", "form > #foo\\:bar", ["foo:bar"] );
238 t( "Child escaped ID", "form > #test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
239
240 fiddle = jQuery("<div id='fiddle\\Foo'><span id='fiddleSpan'></span></div>").appendTo("#qunit-fixture");
241 deepEqual( Sizzle( "> span", Sizzle("#fiddle\\\\Foo")[0] ), q([ "fiddleSpan" ]), "Escaped ID as context" );
242 fiddle.remove();
243
244 t( "ID Selector, child ID present", "#form > #radio1", ["radio1"] ); // bug #267
245 t( "ID Selector, not an ancestor ID", "#form #first", [] );
246 t( "ID Selector, not a child ID", "#form > #option1a", [] );
247
248 t( "All Children of ID", "#foo > *", ["sndp", "en", "sap"] );
249 t( "All Children of ID with no children", "#firstUL > *", [] );
250
251 equal( Sizzle("#tName1")[0].id, "tName1", "ID selector with same value for a name attribute" );
252 t( "ID selector non-existing but name attribute on an A tag", "#tName2", [] );
253 t( "Leading ID selector non-existing but name attribute on an A tag", "#tName2 span", [] );
254 t( "Leading ID selector existing, retrieving the child", "#tName1 span", ["tName1-span"] );
255 equal( Sizzle("div > div #tName1")[0].id, Sizzle("#tName1-span")[0].parentNode.id, "Ending with ID" );
256
257 a = jQuery("<a id='backslash\\foo'></a>").appendTo("#qunit-fixture");
258 t( "ID Selector contains backslash", "#backslash\\\\foo", ["backslash\\foo"] );
259
260 t( "ID Selector on Form with an input that has a name of 'id'", "#lengthtest", ["lengthtest"] );
261
262 t( "ID selector with non-existant ancestor", "#asdfasdf #foobar", [] ); // bug #986
263
264 deepEqual( Sizzle("div#form", document.body), [], "ID selector within the context of another element" );
265
266 t( "Underscore ID", "#types_all", ["types_all"] );
267 t( "Dash ID", "#qunit-fixture", ["qunit-fixture"] );
268
269 t( "ID with weird characters in it", "#name\\+value", ["name+value"] );
270 });
271
272 test("class", function() {
273 expect( 26 );
274
275 t( "Class Selector", ".blog", ["mark","simon"] );
276 t( "Class Selector", ".GROUPS", ["groups"] );
277 t( "Class Selector", ".blog.link", ["simon"] );
278 t( "Class Selector w/ Element", "a.blog", ["mark","simon"] );
279 t( "Parent Class Selector", "p .blog", ["mark","simon"] );
280
281 t( "Class selector using UTF8", ".台北Táiběi", ["utf8class1"] );
282 //t( "Class selector using UTF8", ".台北", ["utf8class1","utf8class2"] );
283 t( "Class selector using UTF8", ".台北Táiběi.台北", ["utf8class1"] );
284 t( "Class selector using UTF8", ".台北Táiběi, .台北", ["utf8class1","utf8class2"] );
285 t( "Descendant class selector using UTF8", "div .台北Táiběi", ["utf8class1"] );
286 t( "Child class selector using UTF8", "form > .台北Táiběi", ["utf8class1"] );
287
288 t( "Escaped Class", ".foo\\:bar", ["foo:bar"] );
289 t( "Escaped Class", ".test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
290 t( "Descendant escaped Class", "div .foo\\:bar", ["foo:bar"] );
291 t( "Descendant escaped Class", "div .test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
292 t( "Child escaped Class", "form > .foo\\:bar", ["foo:bar"] );
293 t( "Child escaped Class", "form > .test\\.foo\\[5\\]bar", ["test.foo[5]bar"] );
294
295 var div = document.createElement("div");
296 div.innerHTML = "<div class='test e'></div><div class='test'></div>";
297 deepEqual( Sizzle(".e", div), [ div.firstChild ], "Finding a second class." );
298
299 div.lastChild.className = "e";
300
301 deepEqual( Sizzle(".e", div), [ div.firstChild, div.lastChild ], "Finding a modified class." );
302
303 ok( !Sizzle.matchesSelector( div, ".null"), ".null does not match an element with no class" );
304 ok( !Sizzle.matchesSelector( div.firstChild, ".null div"), ".null does not match an element with no class" );
305 div.className = "null";
306 ok( Sizzle.matchesSelector( div, ".null"), ".null matches element with class 'null'" );
307 ok( Sizzle.matchesSelector( div.firstChild, ".null div"), "caching system respects DOM changes" );
308 ok( !Sizzle.matchesSelector( document, ".foo" ), "testing class on document doesn't error" );
309 ok( !Sizzle.matchesSelector( window, ".foo" ), "testing class on window doesn't error" );
310
311 div.lastChild.className += " hasOwnProperty toString";
312 deepEqual( Sizzle(".e.hasOwnProperty.toString", div), [ div.lastChild ], "Classes match Object.prototype properties" );
313
314 div = jQuery("<div><svg width='200' height='250' version='1.1' xmlns='http://www.w3.org/2000/svg'><rect x='10' y='10' width='30' height='30' class='foo'></rect></svg></div>")[0];
315 equal( Sizzle(".foo", div).length, 1, "Class selector against SVG" );
316 });
317
318 test("name", function() {
319 expect( 14 );
320
321 var form;
322
323 t( "Name selector", "input[name=action]", ["text1"] );
324 t( "Name selector with single quotes", "input[name='action']", ["text1"] );
325 t( "Name selector with double quotes", "input[name=\"action\"]", ["text1"] );
326
327 t( "Name selector non-input", "[name=example]", ["name-is-example"] );
328 t( "Name selector non-input", "[name=div]", ["name-is-div"] );
329 t( "Name selector non-input", "*[name=iframe]", ["iframe"] );
330
331 t( "Name selector for grouped input", "input[name='types[]']", ["types_all", "types_anime", "types_movie"] );
332
333 form = document.getElementById("form");
334 deepEqual( Sizzle("input[name=action]", form), q("text1"), "Name selector within the context of another element" );
335 deepEqual( Sizzle("input[name='foo[bar]']", form), q("hidden2"), "Name selector for grouped form element within the context of another element" );
336
337 form = jQuery("<form><input name='id'/></form>").appendTo("body");
338 equal( Sizzle("input", form[0]).length, 1, "Make sure that rooted queries on forms (with possible expandos) work." );
339
340 form.remove();
341
342 t( "Find elements that have similar IDs", "[name=tName1]", ["tName1ID"] );
343 t( "Find elements that have similar IDs", "[name=tName2]", ["tName2ID"] );
344 t( "Find elements that have similar IDs", "#tName2ID", ["tName2ID"] );
345
346 t( "Case-sensitivity", "[name=tname1]", [] );
347 });
348
349 test("multiple", function() {
350 expect(6);
351
352 t( "Comma Support", "h2, #qunit-fixture p", ["qunit-banner","qunit-userAgent","firstp","ap","sndp","en","sap","first"] );
353 t( "Comma Support", "h2 , #qunit-fixture p", ["qunit-banner","qunit-userAgent","firstp","ap","sndp","en","sap","first"] );
354 t( "Comma Support", "h2 , #qunit-fixture p", ["qunit-banner","qunit-userAgent","firstp","ap","sndp","en","sap","first"] );
355 t( "Comma Support", "h2,#qunit-fixture p", ["qunit-banner","qunit-userAgent","firstp","ap","sndp","en","sap","first"] );
356 t( "Comma Support", "h2,#qunit-fixture p ", ["qunit-banner","qunit-userAgent","firstp","ap","sndp","en","sap","first"] );
357 t( "Comma Support", "h2\t,\r#qunit-fixture p\n", ["qunit-banner","qunit-userAgent","firstp","ap","sndp","en","sap","first"] );
358 });
359
360 test("child and adjacent", function() {
361 expect( 42 );
362
363 var siblingFirst, en, nothiddendiv;
364
365 t( "Child", "p > a", ["simon1","google","groups","mark","yahoo","simon"] );
366 t( "Child", "p> a", ["simon1","google","groups","mark","yahoo","simon"] );
367 t( "Child", "p >a", ["simon1","google","groups","mark","yahoo","simon"] );
368 t( "Child", "p>a", ["simon1","google","groups","mark","yahoo","simon"] );
369 t( "Child w/ Class", "p > a.blog", ["mark","simon"] );
370 t( "All Children", "code > *", ["anchor1","anchor2"] );
371 t( "All Grandchildren", "p > * > *", ["anchor1","anchor2"] );
372 t( "Adjacent", "#qunit-fixture a + a", ["groups", "tName2ID"] );
373 t( "Adjacent", "#qunit-fixture a +a", ["groups", "tName2ID"] );
374 t( "Adjacent", "#qunit-fixture a+ a", ["groups", "tName2ID"] );
375 t( "Adjacent", "#qunit-fixture a+a", ["groups", "tName2ID"] );
376 t( "Adjacent", "p + p", ["ap","en","sap"] );
377 t( "Adjacent", "p#firstp + p", ["ap"] );
378 t( "Adjacent", "p[lang=en] + p", ["sap"] );
379 t( "Adjacent", "a.GROUPS + code + a", ["mark"] );
380 t( "Comma, Child, and Adjacent", "#qunit-fixture a + a, code > a", ["groups","anchor1","anchor2","tName2ID"] );
381 t( "Element Preceded By", "#qunit-fixture p ~ div", ["foo", "nothiddendiv", "moretests","tabindex-tests", "liveHandlerOrder", "siblingTest"] );
382 t( "Element Preceded By", "#first ~ div", ["moretests","tabindex-tests", "liveHandlerOrder", "siblingTest"] );
383 t( "Element Preceded By", "#groups ~ a", ["mark"] );
384 t( "Element Preceded By", "#length ~ input", ["idTest"] );
385 t( "Element Preceded By", "#siblingfirst ~ em", ["siblingnext", "siblingthird"] );
386 t( "Element Preceded By (multiple)", "#siblingTest em ~ em ~ em ~ span", ["siblingspan"] );
387 t( "Element Preceded By, Containing", "#liveHandlerOrder ~ div em:contains('1')", ["siblingfirst"] );
388
389 siblingFirst = document.getElementById("siblingfirst");
390
391 deepEqual( Sizzle("~ em", siblingFirst), q("siblingnext", "siblingthird"), "Element Preceded By with a context." );
392 deepEqual( Sizzle("+ em", siblingFirst), q("siblingnext"), "Element Directly Preceded By with a context." );
393 deepEqual( Sizzle("~ em:first", siblingFirst), q("siblingnext"), "Element Preceded By positional with a context." );
394
395 en = document.getElementById("en");
396 deepEqual( Sizzle("+ p, a", en), q("yahoo", "sap"), "Compound selector with context, beginning with sibling test." );
397 deepEqual( Sizzle("a, + p", en), q("yahoo", "sap"), "Compound selector with context, containing sibling test." );
398
399 t( "Multiple combinators selects all levels", "#siblingTest em *", ["siblingchild", "siblinggrandchild", "siblinggreatgrandchild"] );
400 t( "Multiple combinators selects all levels", "#siblingTest > em *", ["siblingchild", "siblinggrandchild", "siblinggreatgrandchild"] );
401 t( "Multiple sibling combinators doesn't miss general siblings", "#siblingTest > em:first-child + em ~ span", ["siblingspan"] );
402 t( "Combinators are not skipped when mixing general and specific", "#siblingTest > em:contains('x') + em ~ span", [] );
403
404 equal( Sizzle("#listWithTabIndex").length, 1, "Parent div for next test is found via ID (#8310)" );
405 equal( Sizzle("#listWithTabIndex li:eq(2) ~ li").length, 1, "Find by general sibling combinator (#8310)" );
406 equal( Sizzle("#__sizzle__").length, 0, "Make sure the temporary id assigned by sizzle is cleared out (#8310)" );
407 equal( Sizzle("#listWithTabIndex").length, 1, "Parent div for previous test is still found via ID (#8310)" );
408
409 t( "Verify deep class selector", "div.blah > p > a", [] );
410
411 t( "No element deep selector", "div.foo > span > a", [] );
412
413 nothiddendiv = document.getElementById("nothiddendiv");
414 deepEqual( Sizzle("> :first", nothiddendiv), q("nothiddendivchild"), "Verify child context positional selector" );
415 deepEqual( Sizzle("> :eq(0)", nothiddendiv), q("nothiddendivchild"), "Verify child context positional selector" );
416 deepEqual( Sizzle("> *:first", nothiddendiv), q("nothiddendivchild"), "Verify child context positional selector" );
417
418 t( "Non-existant ancestors", ".fototab > .thumbnails > a", [] );
419 });
420
421 test("attributes", function() {
422 expect( 76 );
423
424 var opt, input, attrbad, div;
425
426 t( "Attribute Exists", "#qunit-fixture a[title]", ["google"] );
427 t( "Attribute Exists (case-insensitive)", "#qunit-fixture a[TITLE]", ["google"] );
428 t( "Attribute Exists", "#qunit-fixture *[title]", ["google"] );
429 t( "Attribute Exists", "#qunit-fixture [title]", ["google"] );
430 t( "Attribute Exists", "#qunit-fixture a[ title ]", ["google"] );
431
432 t( "Boolean attribute exists", "#select2 option[selected]", ["option2d"]);
433 t( "Boolean attribute equals", "#select2 option[selected='selected']", ["option2d"]);
434
435 t( "Attribute Equals", "#qunit-fixture a[rel='bookmark']", ["simon1"] );
436 t( "Attribute Equals", "#qunit-fixture a[rel='bookmark']", ["simon1"] );
437 t( "Attribute Equals", "#qunit-fixture a[rel=bookmark]", ["simon1"] );
438 t( "Attribute Equals", "#qunit-fixture a[href='http://www.google.com/']", ["google"] );
439 t( "Attribute Equals", "#qunit-fixture a[ rel = 'bookmark' ]", ["simon1"] );
440 t( "Attribute Equals Number", "#qunit-fixture option[value=1]", ["option1b","option2b","option3b","option4b","option5c"] );
441 t( "Attribute Equals Number", "#qunit-fixture li[tabIndex=-1]", ["foodWithNegativeTabIndex"] );
442
443 document.getElementById("anchor2").href = "#2";
444 t( "href Attribute", "p a[href^=#]", ["anchor2"] );
445 t( "href Attribute", "p a[href*=#]", ["simon1", "anchor2"] );
446
447 t( "for Attribute", "form label[for]", ["label-for"] );
448 t( "for Attribute in form", "#form [for=action]", ["label-for"] );
449
450 t( "Attribute containing []", "input[name^='foo[']", ["hidden2"] );
451 t( "Attribute containing []", "input[name^='foo[bar]']", ["hidden2"] );
452 t( "Attribute containing []", "input[name*='[bar]']", ["hidden2"] );
453 t( "Attribute containing []", "input[name$='bar]']", ["hidden2"] );
454 t( "Attribute containing []", "input[name$='[bar]']", ["hidden2"] );
455 t( "Attribute containing []", "input[name$='foo[bar]']", ["hidden2"] );
456 t( "Attribute containing []", "input[name*='foo[bar]']", ["hidden2"] );
457
458 deepEqual( Sizzle( "input[data-comma='0,1']" ), [ document.getElementById("el12087") ], "Without context, single-quoted attribute containing ','" );
459 deepEqual( Sizzle( "input[data-comma=\"0,1\"]" ), [ document.getElementById("el12087") ], "Without context, double-quoted attribute containing ','" );
460 deepEqual( Sizzle( "input[data-comma='0,1']", document.getElementById("t12087") ), [ document.getElementById("el12087") ], "With context, single-quoted attribute containing ','" );
461 deepEqual( Sizzle( "input[data-comma=\"0,1\"]", document.getElementById("t12087") ), [ document.getElementById("el12087") ], "With context, double-quoted attribute containing ','" );
462
463 t( "Multiple Attribute Equals", "#form input[type='radio'], #form input[type='hidden']", ["radio1", "radio2", "hidden1"] );
464 t( "Multiple Attribute Equals", "#form input[type='radio'], #form input[type=\"hidden\"]", ["radio1", "radio2", "hidden1"] );
465 t( "Multiple Attribute Equals", "#form input[type='radio'], #form input[type=hidden]", ["radio1", "radio2", "hidden1"] );
466
467 t( "Attribute selector using UTF8", "span[lang=中文]", ["台北"] );
468
469 t( "Attribute Begins With", "a[href ^= 'http://www']", ["google","yahoo"] );
470 t( "Attribute Ends With", "a[href $= 'org/']", ["mark"] );
471 t( "Attribute Contains", "a[href *= 'google']", ["google","groups"] );
472 t( "Attribute Is Not Equal", "#ap a[hreflang!='en']", ["google","groups","anchor1"] );
473
474 opt = document.getElementById("option1a");
475 opt.setAttribute( "test", "" );
476
477 ok( Sizzle.matchesSelector( opt, "[id*=option1][type!=checkbox]" ), "Attribute Is Not Equal Matches" );
478 ok( Sizzle.matchesSelector( opt, "[id*=option1]" ), "Attribute With No Quotes Contains Matches" );
479 ok( Sizzle.matchesSelector( opt, "[test=]" ), "Attribute With No Quotes No Content Matches" );
480 ok( !Sizzle.matchesSelector( opt, "[test^='']" ), "Attribute with empty string value does not match startsWith selector (^=)" );
481 ok( Sizzle.matchesSelector( opt, "[id=option1a]" ), "Attribute With No Quotes Equals Matches" );
482 ok( Sizzle.matchesSelector( document.getElementById("simon1"), "a[href*=#]" ), "Attribute With No Quotes Href Contains Matches" );
483
484 t( "Empty values", "#select1 option[value='']", ["option1a"] );
485 t( "Empty values", "#select1 option[value!='']", ["option1b","option1c","option1d"] );
486
487 t( "Select options via :selected", "#select1 option:selected", ["option1a"] );
488 t( "Select options via :selected", "#select2 option:selected", ["option2d"] );
489 t( "Select options via :selected", "#select3 option:selected", ["option3b", "option3c"] );
490 t( "Select options via :selected", "select[name='select2'] option:selected", ["option2d"] );
491
492 t( "Grouped Form Elements", "input[name='foo[bar]']", ["hidden2"] );
493
494 input = document.getElementById("text1");
495 input.title = "Don't click me";
496
497 ok( Sizzle.matchesSelector( input, "input[title=\"Don't click me\"]" ), "Quote within attribute value does not mess up tokenizer" );
498
499 // Uncomment if the boolHook is removed
500 // var check2 = document.getElementById("check2");
501 // check2.checked = true;
502 // ok( !Sizzle.matches("[checked]", [ check2 ] ), "Dynamic boolean attributes match when they should with Sizzle.matches (#11115)" );
503
504 // jQuery #12303
505 input.setAttribute( "data-pos", ":first" );
506 ok( Sizzle.matchesSelector( input, "input[data-pos=\\:first]"), "POS within attribute value is treated as an attribute value" );
507 ok( Sizzle.matchesSelector( input, "input[data-pos=':first']"), "POS within attribute value is treated as an attribute value" );
508 ok( Sizzle.matchesSelector( input, ":input[data-pos=':first']"), "POS within attribute value after pseudo is treated as an attribute value" );
509 input.removeAttribute("data-pos");
510
511 // Make sure attribute value quoting works correctly. See jQuery #6093; #6428; #13894
512 // Use seeded results to bypass querySelectorAll optimizations
513 attrbad = jQuery(
514 "<input type='hidden' id='attrbad_space' name='foo bar'/>" +
515 "<input type='hidden' id='attrbad_dot' value='2' name='foo.baz'/>" +
516 "<input type='hidden' id='attrbad_brackets' value='2' name='foo[baz]'/>" +
517 "<input type='hidden' id='attrbad_injection' data-attr='foo_baz&#39;]'/>" +
518 "<input type='hidden' id='attrbad_quote' data-attr='&#39;'/>" +
519 "<input type='hidden' id='attrbad_backslash' data-attr='&#92;'/>" +
520 "<input type='hidden' id='attrbad_backslash_quote' data-attr='&#92;&#39;'/>" +
521 "<input type='hidden' id='attrbad_backslash_backslash' data-attr='&#92;&#92;'/>" +
522 "<input type='hidden' id='attrbad_unicode' data-attr='&#x4e00;'/>"
523 ).appendTo("#qunit-fixture").get();
524
525 t( "Underscores don't need escaping", "input[id=types_all]", ["types_all"] );
526
527 deepEqual( Sizzle( "input[name=foo\\ bar]", null, null, attrbad ), q("attrbad_space"),
528 "Escaped space" );
529 deepEqual( Sizzle( "input[name=foo\\.baz]", null, null, attrbad ), q("attrbad_dot"),
530 "Escaped dot" );
531 deepEqual( Sizzle( "input[name=foo\\[baz\\]]", null, null, attrbad ), q("attrbad_brackets"),
532 "Escaped brackets" );
533 deepEqual( Sizzle( "input[data-attr='foo_baz\\']']", null, null, attrbad ), q("attrbad_injection"),
534 "Escaped quote + right bracket" );
535
536 deepEqual( Sizzle( "input[data-attr='\\'']", null, null, attrbad ), q("attrbad_quote"),
537 "Quoted quote" );
538 deepEqual( Sizzle( "input[data-attr='\\\\']", null, null, attrbad ), q("attrbad_backslash"),
539 "Quoted backslash" );
540 deepEqual( Sizzle( "input[data-attr='\\\\\\'']", null, null, attrbad ), q("attrbad_backslash_quote"),
541 "Quoted backslash quote" );
542 deepEqual( Sizzle( "input[data-attr='\\\\\\\\']", null, null, attrbad ), q("attrbad_backslash_backslash"),
543 "Quoted backslash backslash" );
544
545 deepEqual( Sizzle( "input[data-attr='\\5C\\\\']", null, null, attrbad ), q("attrbad_backslash_backslash"),
546 "Quoted backslash backslash (numeric escape)" );
547 deepEqual( Sizzle( "input[data-attr='\\5C \\\\']", null, null, attrbad ), q("attrbad_backslash_backslash"),
548 "Quoted backslash backslash (numeric escape with trailing space)" );
549 deepEqual( Sizzle( "input[data-attr='\\5C\t\\\\']", null, null, attrbad ), q("attrbad_backslash_backslash"),
550 "Quoted backslash backslash (numeric escape with trailing tab)" );
551 deepEqual( Sizzle( "input[data-attr='\\04e00']", null, null, attrbad ), q("attrbad_unicode"),
552 "Long numeric escape (BMP)" );
553 document.getElementById("attrbad_unicode").setAttribute( "data-attr", "\uD834\uDF06A" );
554 // It was too much code to fix Safari 5.x Supplemental Plane crashes (see ba5f09fa404379a87370ec905ffa47f8ac40aaa3)
555 // deepEqual( Sizzle( "input[data-attr='\\01D306A']", null, null, attrbad ), q("attrbad_unicode"),
556 // "Long numeric escape (non-BMP)" );
557
558 t( "input[type=text]", "#form input[type=text]", ["text1", "text2", "hidden2", "name"] );
559 t( "input[type=search]", "#form input[type=search]", ["search"] );
560 t( "script[src] (jQuery #13777)", "#moretests script[src]", ["script-src"] );
561
562 // #3279
563 div = document.createElement("div");
564 div.innerHTML = "<div id='foo' xml:test='something'></div>";
565
566 deepEqual( Sizzle( "[xml\\:test]", div ), [ div.firstChild ], "Finding by attribute with escaped characters." );
567
568 div = document.getElementById("foo");
569 t( "Object.prototype property \"constructor\" (negative)", "[constructor]", [] );
570 t( "Gecko Object.prototype property \"watch\" (negative)", "[watch]", [] );
571 div.setAttribute( "constructor", "foo" );
572 div.setAttribute( "watch", "bar" );
573 t( "Object.prototype property \"constructor\"", "[constructor='foo']", ["foo"] );
574 t( "Gecko Object.prototype property \"watch\"", "[watch='bar']", ["foo"] );
575
576 t( "Value attribute is retrieved correctly", "input[value=Test]", ["text1", "text2"] );
577 });
578
579 test("pseudo - (parent|empty)", function() {
580 expect( 3 );
581 t( "Empty", "ul:empty", ["firstUL"] );
582 t( "Empty with comment node", "ol:empty", ["empty"] );
583 t( "Is A Parent", "#qunit-fixture p:parent", ["firstp","ap","sndp","en","sap","first"] );
584 });
585
586 test("pseudo - (first|last|only)-(child|of-type)", function() {
587 expect( 12 );
588
589 t( "First Child", "p:first-child", ["firstp","sndp"] );
590 t( "First Child (leading id)", "#qunit-fixture p:first-child", ["firstp","sndp"] );
591 t( "First Child (leading class)", ".nothiddendiv div:first-child", ["nothiddendivchild"] );
592 t( "First Child (case-insensitive)", "#qunit-fixture p:FIRST-CHILD", ["firstp","sndp"] );
593
594 t( "Last Child", "p:last-child", ["sap"] );
595 t( "Last Child (leading id)", "#qunit-fixture a:last-child", ["simon1","anchor1","mark","yahoo","anchor2","simon","liveLink1","liveLink2"] );
596
597 t( "Only Child", "#qunit-fixture a:only-child", ["simon1","anchor1","yahoo","anchor2","liveLink1","liveLink2"] );
598
599 t( "First-of-type", "#qunit-fixture > p:first-of-type", ["firstp"] );
600 t( "Last-of-type", "#qunit-fixture > p:last-of-type", ["first"] );
601 t( "Only-of-type", "#qunit-fixture > :only-of-type", ["name+value", "firstUL", "empty", "floatTest", "iframe", "table"] );
602
603 // Verify that the child position isn't being cached improperly
604 var secondChildren = jQuery("p:nth-child(2)").before("<div></div>");
605
606 t( "No longer second child", "p:nth-child(2)", [] );
607 secondChildren.prev().remove();
608 t( "Restored second child", "p:nth-child(2)", ["ap","en"] );
609 });
610
611 test("pseudo - nth-child", function() {
612 expect( 30 );
613
614 t( "Nth-child", "p:nth-child(1)", ["firstp","sndp"] );
615 t( "Nth-child (with whitespace)", "p:nth-child( 1 )", ["firstp","sndp"] );
616 t( "Nth-child (case-insensitive)", "#form select:first option:NTH-child(3)", ["option1c"] );
617 t( "Not nth-child", "#qunit-fixture p:not(:nth-child(1))", ["ap","en","sap","first"] );
618
619 t( "Nth-child(2)", "#qunit-fixture form#form > *:nth-child(2)", ["text1"] );
620 t( "Nth-child(2)", "#qunit-fixture form#form > :nth-child(2)", ["text1"] );
621
622 t( "Nth-child(-1)", "#form select:first option:nth-child(-1)", [] );
623 t( "Nth-child(3)", "#form select:first option:nth-child(3)", ["option1c"] );
624 t( "Nth-child(0n+3)", "#form select:first option:nth-child(0n+3)", ["option1c"] );
625 t( "Nth-child(1n+0)", "#form select:first option:nth-child(1n+0)", ["option1a", "option1b", "option1c", "option1d"] );
626 t( "Nth-child(1n)", "#form select:first option:nth-child(1n)", ["option1a", "option1b", "option1c", "option1d"] );
627 t( "Nth-child(n)", "#form select:first option:nth-child(n)", ["option1a", "option1b", "option1c", "option1d"] );
628 t( "Nth-child(even)", "#form select:first option:nth-child(even)", ["option1b", "option1d"] );
629 t( "Nth-child(odd)", "#form select:first option:nth-child(odd)", ["option1a", "option1c"] );
630 t( "Nth-child(2n)", "#form select:first option:nth-child(2n)", ["option1b", "option1d"] );
631 t( "Nth-child(2n+1)", "#form select:first option:nth-child(2n+1)", ["option1a", "option1c"] );
632 t( "Nth-child(2n + 1)", "#form select:first option:nth-child(2n + 1)", ["option1a", "option1c"] );
633 t( "Nth-child(+2n + 1)", "#form select:first option:nth-child(+2n + 1)", ["option1a", "option1c"] );
634 t( "Nth-child(3n)", "#form select:first option:nth-child(3n)", ["option1c"] );
635 t( "Nth-child(3n+1)", "#form select:first option:nth-child(3n+1)", ["option1a", "option1d"] );
636 t( "Nth-child(3n+2)", "#form select:first option:nth-child(3n+2)", ["option1b"] );
637 t( "Nth-child(3n+3)", "#form select:first option:nth-child(3n+3)", ["option1c"] );
638 t( "Nth-child(3n-1)", "#form select:first option:nth-child(3n-1)", ["option1b"] );
639 t( "Nth-child(3n-2)", "#form select:first option:nth-child(3n-2)", ["option1a", "option1d"] );
640 t( "Nth-child(3n-3)", "#form select:first option:nth-child(3n-3)", ["option1c"] );
641 t( "Nth-child(3n+0)", "#form select:first option:nth-child(3n+0)", ["option1c"] );
642 t( "Nth-child(-1n+3)", "#form select:first option:nth-child(-1n+3)", ["option1a", "option1b", "option1c"] );
643 t( "Nth-child(-n+3)", "#form select:first option:nth-child(-n+3)", ["option1a", "option1b", "option1c"] );
644 t( "Nth-child(-1n + 3)", "#form select:first option:nth-child(-1n + 3)", ["option1a", "option1b", "option1c"] );
645
646 deepEqual( Sizzle( ":nth-child(n)", null, null, [ document.createElement("a") ].concat( q("ap") ) ), q("ap"), "Seeded nth-child" );
647 });
648
649 test("pseudo - nth-last-child", function() {
650 expect( 30 );
651
652 t( "Nth-last-child", "form:nth-last-child(5)", ["testForm"] );
653 t( "Nth-last-child (with whitespace)", "form:nth-last-child( 5 )", ["testForm"] );
654 t( "Nth-last-child (case-insensitive)", "#form select:first option:NTH-last-child(3)", ["option1b"] );
655 t( "Not nth-last-child", "#qunit-fixture p:not(:nth-last-child(1))", ["firstp", "ap", "sndp", "en", "first"] );
656
657 t( "Nth-last-child(-1)", "#form select:first option:nth-last-child(-1)", [] );
658 t( "Nth-last-child(3)", "#form select:first :nth-last-child(3)", ["option1b"] );
659 t( "Nth-last-child(3)", "#form select:first *:nth-last-child(3)", ["option1b"] );
660 t( "Nth-last-child(3)", "#form select:first option:nth-last-child(3)", ["option1b"] );
661 t( "Nth-last-child(0n+3)", "#form select:first option:nth-last-child(0n+3)", ["option1b"] );
662 t( "Nth-last-child(1n+0)", "#form select:first option:nth-last-child(1n+0)", ["option1a", "option1b", "option1c", "option1d"] );
663 t( "Nth-last-child(1n)", "#form select:first option:nth-last-child(1n)", ["option1a", "option1b", "option1c", "option1d"] );
664 t( "Nth-last-child(n)", "#form select:first option:nth-last-child(n)", ["option1a", "option1b", "option1c", "option1d"] );
665 t( "Nth-last-child(even)", "#form select:first option:nth-last-child(even)", ["option1a", "option1c"] );
666 t( "Nth-last-child(odd)", "#form select:first option:nth-last-child(odd)", ["option1b", "option1d"] );
667 t( "Nth-last-child(2n)", "#form select:first option:nth-last-child(2n)", ["option1a", "option1c"] );
668 t( "Nth-last-child(2n+1)", "#form select:first option:nth-last-child(2n+1)", ["option1b", "option1d"] );
669 t( "Nth-last-child(2n + 1)", "#form select:first option:nth-last-child(2n + 1)", ["option1b", "option1d"] );
670 t( "Nth-last-child(+2n + 1)", "#form select:first option:nth-last-child(+2n + 1)", ["option1b", "option1d"] );
671 t( "Nth-last-child(3n)", "#form select:first option:nth-last-child(3n)", ["option1b"] );
672 t( "Nth-last-child(3n+1)", "#form select:first option:nth-last-child(3n+1)", ["option1a", "option1d"] );
673 t( "Nth-last-child(3n+2)", "#form select:first option:nth-last-child(3n+2)", ["option1c"] );
674 t( "Nth-last-child(3n+3)", "#form select:first option:nth-last-child(3n+3)", ["option1b"] );
675 t( "Nth-last-child(3n-1)", "#form select:first option:nth-last-child(3n-1)", ["option1c"] );
676 t( "Nth-last-child(3n-2)", "#form select:first option:nth-last-child(3n-2)", ["option1a", "option1d"] );
677 t( "Nth-last-child(3n-3)", "#form select:first option:nth-last-child(3n-3)", ["option1b"] );
678 t( "Nth-last-child(3n+0)", "#form select:first option:nth-last-child(3n+0)", ["option1b"] );
679 t( "Nth-last-child(-1n+3)", "#form select:first option:nth-last-child(-1n+3)", ["option1b", "option1c", "option1d"] );
680 t( "Nth-last-child(-n+3)", "#form select:first option:nth-last-child(-n+3)", ["option1b", "option1c", "option1d"] );
681 t( "Nth-last-child(-1n + 3)", "#form select:first option:nth-last-child(-1n + 3)", ["option1b", "option1c", "option1d"] );
682
683 deepEqual( Sizzle( ":nth-last-child(n)", null, null, [ document.createElement("a") ].concat( q("ap") ) ), q("ap"), "Seeded nth-last-child" );
684 });
685
686 test("pseudo - nth-of-type", function() {
687 expect( 9 );
688 t( "Nth-of-type(-1)", ":nth-of-type(-1)", [] );
689 t( "Nth-of-type(3)", "#ap :nth-of-type(3)", ["mark"] );
690 t( "Nth-of-type(n)", "#ap :nth-of-type(n)", ["google", "groups", "code1", "anchor1", "mark"] );
691 t( "Nth-of-type(0n+3)", "#ap :nth-of-type(0n+3)", ["mark"] );
692 t( "Nth-of-type(2n)", "#ap :nth-of-type(2n)", ["groups"] );
693 t( "Nth-of-type(even)", "#ap :nth-of-type(even)", ["groups"] );
694 t( "Nth-of-type(2n+1)", "#ap :nth-of-type(2n+1)", ["google", "code1", "anchor1", "mark"] );
695 t( "Nth-of-type(odd)", "#ap :nth-of-type(odd)", ["google", "code1", "anchor1", "mark"] );
696 t( "Nth-of-type(-n+2)", "#qunit-fixture > :nth-of-type(-n+2)", ["firstp", "ap", "foo", "nothiddendiv", "name+value", "firstUL", "empty", "form", "floatTest", "iframe", "lengthtest", "table"] );
697 });
698
699 test("pseudo - nth-last-of-type", function() {
700 expect( 9 );
701 t( "Nth-last-of-type(-1)", ":nth-last-of-type(-1)", [] );
702 t( "Nth-last-of-type(3)", "#ap :nth-last-of-type(3)", ["google"] );
703 t( "Nth-last-of-type(n)", "#ap :nth-last-of-type(n)", ["google", "groups", "code1", "anchor1", "mark"] );
704 t( "Nth-last-of-type(0n+3)", "#ap :nth-last-of-type(0n+3)", ["google"] );
705 t( "Nth-last-of-type(2n)", "#ap :nth-last-of-type(2n)", ["groups"] );
706 t( "Nth-last-of-type(even)", "#ap :nth-last-of-type(even)", ["groups"] );
707 t( "Nth-last-of-type(2n+1)", "#ap :nth-last-of-type(2n+1)", ["google", "code1", "anchor1", "mark"] );
708 t( "Nth-last-of-type(odd)", "#ap :nth-last-of-type(odd)", ["google", "code1", "anchor1", "mark"] );
709 t( "Nth-last-of-type(-n+2)", "#qunit-fixture > :nth-last-of-type(-n+2)", ["ap", "name+value", "first", "firstUL", "empty", "floatTest", "iframe", "table", "name-tests", "testForm", "liveHandlerOrder", "siblingTest"] );
710 });
711
712 test("pseudo - has", function() {
713 expect( 3 );
714
715 t( "Basic test", "p:has(a)", ["firstp","ap","en","sap"] );
716 t( "Basic test (irrelevant whitespace)", "p:has( a )", ["firstp","ap","en","sap"] );
717 t( "Nested with overlapping candidates", "#qunit-fixture div:has(div:has(div:not([id])))", [ "moretests", "t2037" ] );
718 });
719
720 test("pseudo - misc", function() {
721 expect( 39 );
722
723 var select, tmp, input;
724
725 t( "Headers", ":header", ["qunit-header", "qunit-banner", "qunit-userAgent"] );
726 t( "Headers(case-insensitive)", ":Header", ["qunit-header", "qunit-banner", "qunit-userAgent"] );
727 t( "Multiple matches with the same context (cache check)", "#form select:has(option:first-child:contains('o'))", ["select1", "select2", "select3", "select4"] );
728
729 ok( Sizzle("#qunit-fixture :not(:has(:has(*)))").length, "All not grandparents" );
730
731 select = document.getElementById("select1");
732 ok( Sizzle.matchesSelector( select, ":has(option)" ), "Has Option Matches" );
733
734 ok( Sizzle("a:contains('')").length, "Empty string contains" );
735 t( "Text Contains", "a:contains(Google)", ["google","groups"] );
736 t( "Text Contains", "a:contains(Google Groups)", ["groups"] );
737
738 t( "Text Contains", "a:contains('Google Groups (Link)')", ["groups"] );
739 t( "Text Contains", "a:contains(\"(Link)\")", ["groups"] );
740 t( "Text Contains", "a:contains(Google Groups (Link))", ["groups"] );
741 t( "Text Contains", "a:contains((Link))", ["groups"] );
742
743
744 tmp = document.createElement("div");
745 tmp.id = "tmp_input";
746 document.body.appendChild( tmp );
747
748 jQuery.each( [ "button", "submit", "reset" ], function( i, type ) {
749 var els = jQuery(
750 "<input id='input_%' type='%'/><button id='button_%' type='%'>test</button>"
751 .replace( /%/g, type )
752 ).appendTo( tmp );
753
754 t( "Input Buttons :" + type, "#tmp_input :" + type, [ "input_" + type, "button_" + type ] );
755
756 ok( Sizzle.matchesSelector( els[0], ":" + type ), "Input Matches :" + type );
757 ok( Sizzle.matchesSelector( els[1], ":" + type ), "Button Matches :" + type );
758 });
759
760 document.body.removeChild( tmp );
761
762 // Recreate tmp
763 tmp = document.createElement("div");
764 tmp.id = "tmp_input";
765 tmp.innerHTML = "<span>Hello I am focusable.</span>";
766 // Setting tabIndex should make the element focusable
767 // http://dev.w3.org/html5/spec/single-page.html#focus-management
768 document.body.appendChild( tmp );
769 tmp.tabIndex = 0;
770 tmp.focus();
771 if ( document.activeElement !== tmp || (document.hasFocus && !document.hasFocus()) ||
772 (document.querySelectorAll && !document.querySelectorAll("div:focus").length) ) {
773 ok( true, "The div was not focused. Skip checking the :focus match." );
774 ok( true, "The div was not focused. Skip checking the :focus match." );
775 } else {
776 t( "tabIndex element focused", ":focus", [ "tmp_input" ] );
777 ok( Sizzle.matchesSelector( tmp, ":focus" ), ":focus matches tabIndex div" );
778 }
779
780 // Blur tmp
781 tmp.blur();
782 document.body.focus();
783 ok( !Sizzle.matchesSelector( tmp, ":focus" ), ":focus doesn't match tabIndex div" );
784 document.body.removeChild( tmp );
785
786 // Input focus/active
787 input = document.createElement("input");
788 input.type = "text";
789 input.id = "focus-input";
790
791 document.body.appendChild( input );
792 input.focus();
793
794 // Inputs can't be focused unless the document has focus
795 if ( document.activeElement !== input || (document.hasFocus && !document.hasFocus()) ||
796 (document.querySelectorAll && !document.querySelectorAll("input:focus").length) ) {
797 ok( true, "The input was not focused. Skip checking the :focus match." );
798 ok( true, "The input was not focused. Skip checking the :focus match." );
799 } else {
800 t( "Element focused", "input:focus", [ "focus-input" ] );
801 ok( Sizzle.matchesSelector( input, ":focus" ), ":focus matches" );
802 }
803
804 input.blur();
805
806 // When IE is out of focus, blur does not work. Force it here.
807 if ( document.activeElement === input ) {
808 document.body.focus();
809 }
810
811 ok( !Sizzle.matchesSelector( input, ":focus" ), ":focus doesn't match" );
812 document.body.removeChild( input );
813
814
815
816 deepEqual(
817 Sizzle( "[id='select1'] *:not(:last-child), [id='select2'] *:not(:last-child)", q("qunit-fixture")[0] ),
818 q( "option1a", "option1b", "option1c", "option2a", "option2b", "option2c" ),
819 "caching system tolerates recursive selection"
820 );
821
822 // Tokenization edge cases
823 t( "Sequential pseudos", "#qunit-fixture p:has(:contains(mark)):has(code)", ["ap"] );
824 t( "Sequential pseudos", "#qunit-fixture p:has(:contains(mark)):has(code):contains(This link)", ["ap"] );
825
826 t( "Pseudo argument containing ')'", "p:has(>a.GROUPS[src!=')'])", ["ap"] );
827 t( "Pseudo argument containing ')'", "p:has(>a.GROUPS[src!=')'])", ["ap"] );
828 t( "Pseudo followed by token containing ')'", "p:contains(id=\"foo\")[id!=\\)]", ["sndp"] );
829 t( "Pseudo followed by token containing ')'", "p:contains(id=\"foo\")[id!=')']", ["sndp"] );
830
831 t( "Multi-pseudo", "#ap:has(*), #ap:has(*)", ["ap"] );
832 t( "Multi-positional", "#ap:gt(0), #ap:lt(1)", ["ap"] );
833 t( "Multi-pseudo with leading nonexistent id", "#nonexistent:has(*), #ap:has(*)", ["ap"] );
834 t( "Multi-positional with leading nonexistent id", "#nonexistent:gt(0), #ap:lt(1)", ["ap"] );
835
836 t( "Tokenization stressor", "a[class*=blog]:not(:has(*, :contains(!)), :contains(!)), br:contains(]), p:contains(]), :not(:empty):not(:parent)", ["ap", "mark","yahoo","simon"] );
837 });
838
839
840 test("pseudo - :not", function() {
841 expect( 43 );
842
843 t( "Not", "a.blog:not(.link)", ["mark"] );
844 t( ":not() with :first", "#foo p:not(:first) .link", ["simon"] );
845
846 t( "Not - multiple", "#form option:not(:contains(Nothing),#option1b,:selected)", ["option1c", "option1d", "option2b", "option2c", "option3d", "option3e", "option4e", "option5b", "option5c"] );
847 t( "Not - recursive", "#form option:not(:not(:selected))[id^='option3']", [ "option3b", "option3c"] );
848
849 t( ":not() failing interior", "#qunit-fixture p:not(.foo)", ["firstp","ap","sndp","en","sap","first"] );
850 t( ":not() failing interior", "#qunit-fixture p:not(div.foo)", ["firstp","ap","sndp","en","sap","first"] );
851 t( ":not() failing interior", "#qunit-fixture p:not(p.foo)", ["firstp","ap","sndp","en","sap","first"] );
852 t( ":not() failing interior", "#qunit-fixture p:not(#blargh)", ["firstp","ap","sndp","en","sap","first"] );
853 t( ":not() failing interior", "#qunit-fixture p:not(div#blargh)", ["firstp","ap","sndp","en","sap","first"] );
854 t( ":not() failing interior", "#qunit-fixture p:not(p#blargh)", ["firstp","ap","sndp","en","sap","first"] );
855
856 t( ":not Multiple", "#qunit-fixture p:not(a)", ["firstp","ap","sndp","en","sap","first"] );
857 t( ":not Multiple", "#qunit-fixture p:not( a )", ["firstp","ap","sndp","en","sap","first"] );
858 t( ":not Multiple", "#qunit-fixture p:not( p )", [] );
859 t( ":not Multiple", "#qunit-fixture p:not(a, b)", ["firstp","ap","sndp","en","sap","first"] );
860 t( ":not Multiple", "#qunit-fixture p:not(a, b, div)", ["firstp","ap","sndp","en","sap","first"] );
861 t( ":not Multiple", "p:not(p)", [] );
862 t( ":not Multiple", "p:not(a,p)", [] );
863 t( ":not Multiple", "p:not(p,a)", [] );
864 t( ":not Multiple", "p:not(a,p,b)", [] );
865 t( ":not Multiple", ":input:not(:image,:input,:submit)", [] );
866 t( ":not Multiple", "#qunit-fixture p:not(:has(a), :nth-child(1))", ["first"] );
867
868 t( "No element not selector", ".container div:not(.excluded) div", [] );
869
870 t( ":not() Existing attribute", "#form select:not([multiple])", ["select1", "select2", "select5"]);
871 t( ":not() Equals attribute", "#form select:not([name=select1])", ["select2", "select3", "select4","select5"]);
872 t( ":not() Equals quoted attribute", "#form select:not([name='select1'])", ["select2", "select3", "select4", "select5"]);
873
874 t( ":not() Multiple Class", "#foo a:not(.blog)", ["yahoo", "anchor2"] );
875 t( ":not() Multiple Class", "#foo a:not(.link)", ["yahoo", "anchor2"] );
876 t( ":not() Multiple Class", "#foo a:not(.blog.link)", ["yahoo", "anchor2"] );
877
878 t( ":not chaining (compound)", "#qunit-fixture div[id]:not(:has(div, span)):not(:has(*))", ["nothiddendivchild", "divWithNoTabIndex"] );
879 t( ":not chaining (with attribute)", "#qunit-fixture form[id]:not([action$='formaction']):not(:button)", ["lengthtest", "name-tests", "testForm"] );
880 t( ":not chaining (colon in attribute)", "#qunit-fixture form[id]:not([action='form:action']):not(:button)", ["form", "lengthtest", "name-tests", "testForm"] );
881 t( ":not chaining (colon in attribute and nested chaining)", "#qunit-fixture form[id]:not([action='form:action']:button):not(:input)", ["form", "lengthtest", "name-tests", "testForm"] );
882 t( ":not chaining", "#form select:not(.select1):contains(Nothing) > option:not(option)", [] );
883
884 t( "positional :not()", "#foo p:not(:last)", ["sndp", "en"] );
885 t( "positional :not() prefix", "#foo p:not(:last) a", ["yahoo"] );
886 t( "compound positional :not()", "#foo p:not(:first, :last)", ["en"] );
887 t( "compound positional :not()", "#foo p:not(:first, :even)", ["en"] );
888 t( "compound positional :not()", "#foo p:not(:first, :odd)", ["sap"] );
889 t( "reordered compound positional :not()", "#foo p:not(:odd, :first)", ["sap"] );
890
891 t( "positional :not() with pre-filter", "#foo p:not([id]:first)", ["en", "sap"] );
892 t( "positional :not() with post-filter", "#foo p:not(:first[id])", ["en", "sap"] );
893 t( "positional :not() with pre-filter", "#foo p:not([lang]:first)", ["sndp", "sap"] );
894 t( "positional :not() with post-filter", "#foo p:not(:first[lang])", ["sndp", "en", "sap"] );
895 });
896
897 test("pseudo - position", function() {
898 expect( 33 );
899
900 t( "First element", "div:first", ["qunit"] );
901 t( "First element(case-insensitive)", "div:fiRst", ["qunit"] );
902 t( "nth Element", "#qunit-fixture p:nth(1)", ["ap"] );
903 t( "First Element", "#qunit-fixture p:first", ["firstp"] );
904 t( "Last Element", "p:last", ["first"] );
905 t( "Even Elements", "#qunit-fixture p:even", ["firstp","sndp","sap"] );
906 t( "Odd Elements", "#qunit-fixture p:odd", ["ap","en","first"] );
907 t( "Position Equals", "#qunit-fixture p:eq(1)", ["ap"] );
908 t( "Position Equals (negative)", "#qunit-fixture p:eq(-1)", ["first"] );
909 t( "Position Greater Than", "#qunit-fixture p:gt(0)", ["ap","sndp","en","sap","first"] );
910 t( "Position Less Than", "#qunit-fixture p:lt(3)", ["firstp","ap","sndp"] );
911
912 t( "Check position filtering", "div#nothiddendiv:eq(0)", ["nothiddendiv"] );
913 t( "Check position filtering", "div#nothiddendiv:last", ["nothiddendiv"] );
914 t( "Check position filtering", "div#nothiddendiv:not(:gt(0))", ["nothiddendiv"] );
915 t( "Check position filtering", "#foo > :not(:first)", ["en", "sap"] );
916 t( "Check position filtering", "#qunit-fixture select > :not(:gt(2))", ["option1a", "option1b", "option1c"] );
917 t( "Check position filtering", "#qunit-fixture select:lt(2) :not(:first)", ["option1b", "option1c", "option1d", "option2a", "option2b", "option2c", "option2d"] );
918 t( "Check position filtering", "div.nothiddendiv:eq(0)", ["nothiddendiv"] );
919 t( "Check position filtering", "div.nothiddendiv:last", ["nothiddendiv"] );
920 t( "Check position filtering", "div.nothiddendiv:not(:lt(0))", ["nothiddendiv"] );
921
922 t( "Check element position", "#qunit-fixture div div:eq(0)", ["nothiddendivchild"] );
923 t( "Check element position", "#select1 option:eq(3)", ["option1d"] );
924 t( "Check element position", "#qunit-fixture div div:eq(10)", ["names-group"] );
925 t( "Check element position", "#qunit-fixture div div:first", ["nothiddendivchild"] );
926 t( "Check element position", "#qunit-fixture div > div:first", ["nothiddendivchild"] );
927 t( "Check element position", "#dl div:first div:first", ["foo"] );
928 t( "Check element position", "#dl div:first > div:first", ["foo"] );
929 t( "Check element position", "div#nothiddendiv:first > div:first", ["nothiddendivchild"] );
930 t( "Chained pseudo after a pos pseudo", "#listWithTabIndex li:eq(0):contains(Rice)", ["foodWithNegativeTabIndex"] );
931
932 t( "Check sort order with POS and comma", "#qunit-fixture em>em>em>em:first-child,div>em:first", ["siblingfirst", "siblinggreatgrandchild"] );
933
934 t( "Isolated position", ":last", ["last"] );
935
936 deepEqual( Sizzle( "*:lt(2) + *", null, [], Sizzle("#qunit-fixture > p") ), q("ap"), "Seeded pos with trailing relative" );
937
938 // jQuery #12526
939 var context = jQuery("#qunit-fixture").append("<div id='jquery12526'></div>")[0];
940 deepEqual( Sizzle( ":last", context ), q("jquery12526"), "Post-manipulation positional" );
941 });
942
943 test("pseudo - form", function() {
944 expect( 10 );
945
946 var extraTexts = jQuery("<input id=\"impliedText\"/><input id=\"capitalText\" type=\"TEXT\">").appendTo("#form");
947
948 t( "Form element :input", "#form :input", ["text1", "text2", "radio1", "radio2", "check1", "check2", "hidden1", "hidden2", "name", "search", "button", "area1", "select1", "select2", "select3", "select4", "select5", "impliedText", "capitalText"] );
949 t( "Form element :radio", "#form :radio", ["radio1", "radio2"] );
950 t( "Form element :checkbox", "#form :checkbox", ["check1", "check2"] );
951 t( "Form element :text", "#form :text", ["text1", "text2", "hidden2", "name", "impliedText", "capitalText"] );
952 t( "Form element :radio:checked", "#form :radio:checked", ["radio2"] );
953 t( "Form element :checkbox:checked", "#form :checkbox:checked", ["check1"] );
954 t( "Form element :radio:checked, :checkbox:checked", "#form :radio:checked, #form :checkbox:checked", ["radio2", "check1"] );
955
956 t( "Selected Option Element", "#form option:selected", ["option1a","option2d","option3b","option3c","option4b","option4c","option4d","option5a"] );
957 t( "Selected Option Element are also :checked", "#form option:checked", ["option1a","option2d","option3b","option3c","option4b","option4c","option4d","option5a"] );
958 t( "Hidden inputs should be treated as enabled. See QSA test.", "#hidden1:enabled", ["hidden1"] );
959
960 extraTexts.remove();
961 });
962
963 test("pseudo - :target and :root", function() {
964 expect( 2 );
965
966 // Target
967 var oldHash,
968 $link = jQuery("<a/>").attr({
969 href: "#",
970 id: "new-link"
971 }).appendTo("#qunit-fixture");
972
973 oldHash = window.location.hash;
974 window.location.hash = "new-link";
975
976 t( ":target", ":target", ["new-link"] );
977
978 $link.remove();
979 window.location.hash = oldHash;
980
981 // Root
982 equal( Sizzle(":root")[0], document.documentElement, ":root selector" );
983 });
984
985 test("pseudo - :lang", function() {
986 expect( 105 );
987
988 var docElem = document.documentElement,
989 docXmlLang = docElem.getAttribute("xml:lang"),
990 docLang = docElem.lang,
991 foo = document.getElementById("foo"),
992 anchor = document.getElementById("anchor2"),
993 xml = createWithFriesXML(),
994 testLang = function( text, elem, container, lang, extra ) {
995 var message,
996 full = lang + "-" + extra;
997
998 message = "lang=" + lang + " " + text;
999 container.setAttribute( container.ownerDocument.documentElement.nodeName === "HTML" ? "lang" : "xml:lang", lang );
1000 assertMatch( message, elem, ":lang(" + lang + ")" );
1001 assertMatch( message, elem, ":lang(" + mixCase(lang) + ")" );
1002 assertNoMatch( message, elem, ":lang(" + full + ")" );
1003 assertNoMatch( message, elem, ":lang(" + mixCase(full) + ")" );
1004 assertNoMatch( message, elem, ":lang(" + lang + "-)" );
1005 assertNoMatch( message, elem, ":lang(" + full + "-)" );
1006 assertNoMatch( message, elem, ":lang(" + lang + "glish)" );
1007 assertNoMatch( message, elem, ":lang(" + full + "glish)" );
1008
1009 message = "lang=" + full + " " + text;
1010 container.setAttribute( container.ownerDocument.documentElement.nodeName === "HTML" ? "lang" : "xml:lang", full );
1011 assertMatch( message, elem, ":lang(" + lang + ")" );
1012 assertMatch( message, elem, ":lang(" + mixCase(lang) + ")" );
1013 assertMatch( message, elem, ":lang(" + full + ")" );
1014 assertMatch( message, elem, ":lang(" + mixCase(full) + ")" );
1015 assertNoMatch( message, elem, ":lang(" + lang + "-)" );
1016 assertNoMatch( message, elem, ":lang(" + full + "-)" );
1017 assertNoMatch( message, elem, ":lang(" + lang + "glish)" );
1018 assertNoMatch( message, elem, ":lang(" + full + "glish)" );
1019 },
1020 mixCase = function( str ) {
1021 var ret = str.split(""),
1022 i = ret.length;
1023 while ( i-- ) {
1024 if ( i & 1 ) {
1025 ret[i] = ret[i].toUpperCase();
1026 }
1027 }
1028 return ret.join("");
1029 },
1030 assertMatch = function( text, elem, selector ) {
1031 ok( Sizzle.matchesSelector( elem, selector ), text + " match " + selector );
1032 },
1033 assertNoMatch = function( text, elem, selector ) {
1034 ok( !Sizzle.matchesSelector( elem, selector ), text + " fail " + selector );
1035 };
1036
1037 // Prefixing and inheritance
1038 ok( Sizzle.matchesSelector( docElem, ":lang(" + docElem.lang + ")" ), "starting :lang" );
1039 testLang( "document", anchor, docElem, "en", "us" );
1040 testLang( "grandparent", anchor, anchor.parentNode.parentNode, "yue", "hk" );
1041 ok( !Sizzle.matchesSelector( anchor, ":lang(en), :lang(en-us)" ),
1042 ":lang does not look above an ancestor with specified lang" );
1043 testLang( "self", anchor, anchor, "es", "419" );
1044 ok( !Sizzle.matchesSelector( anchor, ":lang(en), :lang(en-us), :lang(yue), :lang(yue-hk)" ),
1045 ":lang does not look above self with specified lang" );
1046
1047 // Searching by language tag
1048 anchor.parentNode.parentNode.lang = "arab";
1049 anchor.parentNode.lang = anchor.parentNode.id = "ara-sa";
1050 anchor.lang = "ara";
1051 deepEqual( Sizzle( ":lang(ara)", foo ), [ anchor.parentNode, anchor ], "Find by :lang" );
1052
1053 // Selector validity
1054 anchor.parentNode.lang = "ara";
1055 anchor.lang = "ara\\b";
1056 deepEqual( Sizzle( ":lang(ara\\b)", foo ), [], ":lang respects backslashes" );
1057 deepEqual( Sizzle( ":lang(ara\\\\b)", foo ), [ anchor ], ":lang respects escaped backslashes" );
1058 throws(function() {
1059 Sizzle.call( null, "dl:lang(c++)" );
1060 }, function( e ) {
1061 return e.message.indexOf("Syntax error") >= 0;
1062 }, ":lang value must be a valid identifier" );
1063
1064 // XML
1065 foo = jQuery( "response", xml )[0];
1066 anchor = jQuery( "#seite1", xml )[0];
1067 testLang( "XML document", anchor, xml.documentElement, "en", "us" );
1068 testLang( "XML grandparent", anchor, foo, "yue", "hk" );
1069 ok( !Sizzle.matchesSelector( anchor, ":lang(en), :lang(en-us)" ),
1070 "XML :lang does not look above an ancestor with specified lang" );
1071 testLang( "XML self", anchor, anchor, "es", "419" );
1072 ok( !Sizzle.matchesSelector( anchor, ":lang(en), :lang(en-us), :lang(yue), :lang(yue-hk)" ),
1073 "XML :lang does not look above self with specified lang" );
1074
1075 // Cleanup
1076 if ( docXmlLang == null ) {
1077 docElem.removeAttribute("xml:lang");
1078 } else {
1079 docElem.setAttribute( "xml:lang", docXmlLang );
1080 }
1081 docElem.lang = docLang;
1082 });
1083
1084 test("caching", function() {
1085 expect( 2 );
1086 Sizzle( ":not(code)", document.getElementById("ap") );
1087 deepEqual( Sizzle( ":not(code)", document.getElementById("foo") ), q("sndp", "en", "yahoo", "sap", "anchor2", "simon"), "Reusing selector with new context" );
1088
1089 t( "Deep ancestry caching in post-positional element matcher (jQuery #14657)",
1090 "#qunit-fixture a:lt(3):parent",
1091 [ "simon1", "google", "groups" ] );
1092 });
1093
1094 asyncTest( "Iframe dispatch should not affect Sizzle, see jQuery #13936", 1, function() {
1095 var loaded = false,
1096 thrown = false,
1097 iframe = document.getElementById("iframe"),
1098 iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
1099
1100 jQuery( iframe ).on( "load", function() {
1101 var form;
1102
1103 try {
1104 iframeDoc = this.contentDocument || this.contentWindow.document;
1105 form = Sizzle( "#navigate", iframeDoc )[ 0 ];
1106 } catch ( e ) {
1107 thrown = e;
1108 }
1109
1110 if ( loaded ) {
1111 strictEqual( thrown, false, "No error thrown from post-reload Sizzle call" );
1112 start();
1113 } else {
1114 loaded = true;
1115 form.submit();
1116 }
1117 });
1118
1119 iframeDoc.open();
1120 iframeDoc.write("<body><form id='navigate'></form></body>");
1121 iframeDoc.close();
1122 });
1123
1124 test("matchesSelector", function() {
1125 expect( 6 );
1126
1127 var el = document.getElementById("simon1"),
1128 disconnected = document.createElement("div");
1129
1130 ok( Sizzle.matchesSelector( el, "[rel='bookmark']" ), "quoted attribute" );
1131 ok( Sizzle.matchesSelector( el, "[rel=bookmark]" ), "unquoted attribute" );
1132 ok( Sizzle.matchesSelector( el, "[\nrel = bookmark\t]" ), "unquoted attribute with non-semantic whitespace" );
1133
1134 ok( Sizzle.matchesSelector( disconnected, "div" ), "disconnected element" );
1135
1136 ok( Sizzle.matchesSelector( el, "* > *" ), "child combinator (matching)" );
1137 ok( !Sizzle.matchesSelector( disconnected, "* > *" ), "child combinator (not matching)" );
1138 });
1139
1140 test("select() with pre-compiled function", function() {
1141 expect( 6 );
1142
1143 jQuery.each([ "#qunit-fixture #first", "ol#listWithTabIndex > li[tabindex]", "#liveSpan1" ],
1144 function( i, selector ) {
1145 var compiled = Sizzle.compile( selector );
1146 equal( Sizzle.select( compiled, document ).length, 1, "Should match using a compiled selector function" );
1147 equal( Sizzle.select( compiled, Sizzle( "#first")[0] ).length, 0, "Should not match with different context" );
1148 });
1149 });