]>
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
1 module ( "selector" , { teardown : moduleTeardown
});
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
11 ======== QUnit Reference ========
12 http://docs.jquery.com/QUnit
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
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])
31 ======== testinit.js reference ========
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">]
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"]);
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"
48 test ( "element" , function () {
51 var form
, all
, good
, i
, obj1
, lengthtest
,
52 siblingTest
, siblingNext
, iframe
, iframeDoc
, html
;
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" );
61 ok ( Sizzle ( "*" ). length
>= 30 , "Select all" );
64 for ( i
= 0 ; i
< all
. length
; i
++ ) {
65 if ( all
[ i
]. nodeType
=== 8 ) {
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" ] );
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" ] );
85 t ( "Parent Element" , "dl ol" , [ "empty" , "listWithTabIndex" ] );
86 t ( "Parent Element (non-space descendant combinator)" , "dl \t ol" , [ "empty" , "listWithTabIndex" ] );
87 obj1
= document
. getElementById ( "object1" );
88 equal ( Sizzle ( "param" , obj1
). length
, 2 , "Object/param as context" );
90 deepEqual ( Sizzle ( "select" , form
), q ( "select1" , "select2" , "select3" , "select4" , "select5" ), "Finding selects with a context." );
92 // Check for unique-ness and sort order
93 deepEqual ( Sizzle ( "p, div p" ), Sizzle ( "p" ), "Check for duplicates: p, div p" );
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" ] );
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." );
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" );
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)" );
115 iframe
= document
. getElementById ( "iframe" ),
116 iframeDoc
= iframe
. contentDocument
|| iframe
. contentWindow
. document
;
118 iframeDoc
. write ( "<body><p id='foo'>bar</p></body>" );
121 Sizzle ( "p:contains(bar)" , iframeDoc
),
122 [ iframeDoc
. getElementById ( "foo" ) ],
123 "Other document as context"
127 for ( i
= 0 ; i
< 100 ; i
++ ) {
128 html
= "<div>" + html
+ "</div>" ;
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" );
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" ] );
140 test ( "XML Document Selectors" , function () {
141 var xml
= createWithFriesXML ();
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" );
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)" );
160 test ( "broken" , function () {
164 broken = function ( name
, selector
) {
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
);
172 return e
. message
. indexOf ( "Syntax error" ) >= 0 ;
173 }, name
+ ": " + selector
);
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" );
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" );
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]]" , [] );
217 test ( "id" , function () {
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 > #台北" , [ "台北" ] );
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" ] );
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" );
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" , [] );
248 t ( "All Children of ID" , "#foo > *" , [ "sndp" , "en" , "sap" ] );
249 t ( "All Children of ID with no children" , "#firstUL > *" , [] );
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" );
257 a
= jQuery ( "<a id='backslash \\ foo'></a>" ). appendTo ( "#qunit-fixture" );
258 t ( "ID Selector contains backslash" , "#backslash \\\\ foo" , [ "backslash \\ foo" ] );
260 t ( "ID Selector on Form with an input that has a name of 'id'" , "#lengthtest" , [ "lengthtest" ] );
262 t ( "ID selector with non-existant ancestor" , "#asdfasdf #foobar" , [] ); // bug #986
264 deepEqual ( Sizzle ( "div#form" , document
. body
), [], "ID selector within the context of another element" );
266 t ( "Underscore ID" , "#types_all" , [ "types_all" ] );
267 t ( "Dash ID" , "#qunit-fixture" , [ "qunit-fixture" ] );
269 t ( "ID with weird characters in it" , "#name \\ +value" , [ "name+value" ] );
272 test ( "class" , function () {
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" ] );
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" ] );
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" ] );
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." );
299 div
. lastChild
. className
= "e" ;
301 deepEqual ( Sizzle ( ".e" , div
), [ div
. firstChild
, div
. lastChild
], "Finding a modified class." );
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" );
311 div
. lastChild
. className
+= " hasOwnProperty toString" ;
312 deepEqual ( Sizzle ( ".e.hasOwnProperty.toString" , div
), [ div
. lastChild
], "Classes match Object.prototype properties" );
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" );
318 test ( "name" , function () {
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" ] );
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" ] );
331 t ( "Name selector for grouped input" , "input[name='types[]']" , [ "types_all" , "types_anime" , "types_movie" ] );
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" );
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." );
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" ] );
346 t ( "Case-sensitivity" , "[name=tname1]" , [] );
349 test ( "multiple" , function () {
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" ] );
360 test ( "child and adjacent" , function () {
363 var siblingFirst
, en
, nothiddendiv
;
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" ] );
389 siblingFirst
= document
. getElementById ( "siblingfirst" );
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." );
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." );
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" , [] );
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)" );
409 t ( "Verify deep class selector" , "div.blah > p > a" , [] );
411 t ( "No element deep selector" , "div.foo > span > a" , [] );
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" );
418 t ( "Non-existant ancestors" , ".fototab > .thumbnails > a" , [] );
421 test ( "attributes" , function () {
424 var opt
, input
, attrbad
, div
;
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" ] );
432 t ( "Boolean attribute exists" , "#select2 option[selected]" , [ "option2d" ]);
433 t ( "Boolean attribute equals" , "#select2 option[selected='selected']" , [ "option2d" ]);
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" ] );
443 document
. getElementById ( "anchor2" ). href
= "#2" ;
444 t ( "href Attribute" , "p a[href^=#]" , [ "anchor2" ] );
445 t ( "href Attribute" , "p a[href*=#]" , [ "simon1" , "anchor2" ] );
447 t ( "for Attribute" , "form label[for]" , [ "label-for" ] );
448 t ( "for Attribute in form" , "#form [for=action]" , [ "label-for" ] );
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" ] );
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 ','" );
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" ] );
467 t ( "Attribute selector using UTF8" , "span[lang=中文]" , [ "台北" ] );
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" ] );
474 opt
= document
. getElementById ( "option1a" );
475 opt
. setAttribute ( "test" , "" );
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" );
484 t ( "Empty values" , "#select1 option[value='']" , [ "option1a" ] );
485 t ( "Empty values" , "#select1 option[value!='']" , [ "option1b" , "option1c" , "option1d" ] );
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" ] );
492 t ( "Grouped Form Elements" , "input[name='foo[bar]']" , [ "hidden2" ] );
494 input
= document
. getElementById ( "text1" );
495 input
. title
= "Don't click me" ;
497 ok ( Sizzle
. matchesSelector ( input
, "input[title= \" Don't click me \" ]" ), "Quote within attribute value does not mess up tokenizer" );
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)" );
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" );
511 // Make sure attribute value quoting works correctly. See jQuery #6093; #6428; #13894
512 // Use seeded results to bypass querySelectorAll optimizations
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']'/>" +
518 "<input type='hidden' id='attrbad_quote' data-attr='''/>" +
519 "<input type='hidden' id='attrbad_backslash' data-attr='\'/>" +
520 "<input type='hidden' id='attrbad_backslash_quote' data-attr='\''/>" +
521 "<input type='hidden' id='attrbad_backslash_backslash' data-attr='\\'/>" +
522 "<input type='hidden' id='attrbad_unicode' data-attr='一'/>"
523 ). appendTo ( "#qunit-fixture" ). get ();
525 t ( "Underscores don't need escaping" , "input[id=types_all]" , [ "types_all" ] );
527 deepEqual ( Sizzle ( "input[name=foo \\ bar]" , null , null , attrbad
), q ( "attrbad_space" ),
529 deepEqual ( Sizzle ( "input[name=foo \\ .baz]" , null , null , attrbad
), q ( "attrbad_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" );
536 deepEqual ( Sizzle ( "input[data-attr=' \\ '']" , null , null , attrbad
), q ( "attrbad_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" );
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)" );
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" ] );
563 div
= document
. createElement ( "div" );
564 div
. innerHTML
= "<div id='foo' xml:test='something'></div>" ;
566 deepEqual ( Sizzle ( "[xml \\ :test]" , div
), [ div
. firstChild
], "Finding by attribute with escaped characters." );
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" ] );
576 t ( "Value attribute is retrieved correctly" , "input[value=Test]" , [ "text1" , "text2" ] );
579 test ( "pseudo - (parent|empty)" , function () {
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" ] );
586 test ( "pseudo - (first|last|only)-(child|of-type)" , function () {
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" ] );
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" ] );
597 t ( "Only Child" , "#qunit-fixture a:only-child" , [ "simon1" , "anchor1" , "yahoo" , "anchor2" , "liveLink1" , "liveLink2" ] );
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" ] );
603 // Verify that the child position isn't being cached improperly
604 var secondChildren
= jQuery ( "p:nth-child(2)" ). before ( "<div></div>" );
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" ] );
611 test ( "pseudo - nth-child" , function () {
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" ] );
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" ] );
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" ] );
646 deepEqual ( Sizzle ( ":nth-child(n)" , null , null , [ document
. createElement ( "a" ) ]. concat ( q ( "ap" ) ) ), q ( "ap" ), "Seeded nth-child" );
649 test ( "pseudo - nth-last-child" , function () {
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" ] );
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" ] );
683 deepEqual ( Sizzle ( ":nth-last-child(n)" , null , null , [ document
. createElement ( "a" ) ]. concat ( q ( "ap" ) ) ), q ( "ap" ), "Seeded nth-last-child" );
686 test ( "pseudo - nth-of-type" , function () {
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" ] );
699 test ( "pseudo - nth-last-of-type" , function () {
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" ] );
712 test ( "pseudo - has" , function () {
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" ] );
720 test ( "pseudo - misc" , function () {
723 var select
, tmp
, input
;
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" ] );
729 ok ( Sizzle ( "#qunit-fixture :not(:has(:has(*)))" ). length
, "All not grandparents" );
731 select
= document
. getElementById ( "select1" );
732 ok ( Sizzle
. matchesSelector ( select
, ":has(option)" ), "Has Option Matches" );
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" ] );
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" ] );
744 tmp
= document
. createElement ( "div" );
745 tmp
. id
= "tmp_input" ;
746 document
. body
. appendChild ( tmp
);
748 jQuery
. each ( [ "button" , "submit" , "reset" ], function ( i
, type
) {
750 "<input id='input_%' type='%'/><button id='button_%' type='%'>test</button>"
751 . replace ( /%/ g
, type
)
754 t ( "Input Buttons :" + type
, "#tmp_input :" + type
, [ "input_" + type
, "button_" + type
] );
756 ok ( Sizzle
. matchesSelector ( els
[ 0 ], ":" + type
), "Input Matches :" + type
);
757 ok ( Sizzle
. matchesSelector ( els
[ 1 ], ":" + type
), "Button Matches :" + type
);
760 document
. body
. removeChild ( 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
);
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." );
776 t ( "tabIndex element focused" , ":focus" , [ "tmp_input" ] );
777 ok ( Sizzle
. matchesSelector ( tmp
, ":focus" ), ":focus matches tabIndex div" );
782 document
. body
. focus ();
783 ok ( ! Sizzle
. matchesSelector ( tmp
, ":focus" ), ":focus doesn't match tabIndex div" );
784 document
. body
. removeChild ( tmp
);
786 // Input focus/active
787 input
= document
. createElement ( "input" );
789 input
. id
= "focus-input" ;
791 document
. body
. appendChild ( input
);
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." );
800 t ( "Element focused" , "input:focus" , [ "focus-input" ] );
801 ok ( Sizzle
. matchesSelector ( input
, ":focus" ), ":focus matches" );
806 // When IE is out of focus, blur does not work. Force it here.
807 if ( document
. activeElement
=== input
) {
808 document
. body
. focus ();
811 ok ( ! Sizzle
. matchesSelector ( input
, ":focus" ), ":focus doesn't match" );
812 document
. body
. removeChild ( input
);
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"
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" ] );
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" ] );
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" ] );
836 t ( "Tokenization stressor" , "a[class*=blog]:not(:has(*, :contains(!)), :contains(!)), br:contains(]), p:contains(]), :not(:empty):not(:parent)" , [ "ap" , "mark" , "yahoo" , "simon" ] );
840 test ( "pseudo - :not" , function () {
843 t ( "Not" , "a.blog:not(.link)" , [ "mark" ] );
844 t ( ":not() with :first" , "#foo p:not(:first) .link" , [ "simon" ] );
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" ] );
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" ] );
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" ] );
868 t ( "No element not selector" , ".container div:not(.excluded) div" , [] );
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" ]);
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" ] );
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)" , [] );
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" ] );
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" ] );
897 test ( "pseudo - position" , function () {
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" ] );
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" ] );
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" ] );
932 t ( "Check sort order with POS and comma" , "#qunit-fixture em>em>em>em:first-child,div>em:first" , [ "siblingfirst" , "siblinggreatgrandchild" ] );
934 t ( "Isolated position" , ":last" , [ "last" ] );
936 deepEqual ( Sizzle ( "*:lt(2) + *" , null , [], Sizzle ( "#qunit-fixture > p" ) ), q ( "ap" ), "Seeded pos with trailing relative" );
939 var context
= jQuery ( "#qunit-fixture" ). append ( "<div id='jquery12526'></div>" )[ 0 ];
940 deepEqual ( Sizzle ( ":last" , context
), q ( "jquery12526" ), "Post-manipulation positional" );
943 test ( "pseudo - form" , function () {
946 var extraTexts
= jQuery ( "<input id= \" impliedText \" /><input id= \" capitalText \" type= \" TEXT \" >" ). appendTo ( "#form" );
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" ] );
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" ] );
963 test ( "pseudo - :target and :root" , function () {
968 $ link
= jQuery ( "<a/>" ). attr ({
971 }). appendTo ( "#qunit-fixture" );
973 oldHash
= window
. location
. hash
;
974 window
. location
. hash
= "new-link" ;
976 t ( ":target" , ":target" , [ "new-link" ] );
979 window
. location
. hash
= oldHash
;
982 equal ( Sizzle ( ":root" )[ 0 ], document
. documentElement
, ":root selector" );
985 test ( "pseudo - :lang" , function () {
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
) {
996 full
= lang
+ "-" + extra
;
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)" );
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)" );
1020 mixCase = function ( str
) {
1021 var ret
= str
. split ( "" ),
1025 ret
[ i
] = ret
[ i
]. toUpperCase ();
1028 return ret
. join ( "" );
1030 assertMatch = function ( text
, elem
, selector
) {
1031 ok ( Sizzle
. matchesSelector ( elem
, selector
), text
+ " match " + selector
);
1033 assertNoMatch = function ( text
, elem
, selector
) {
1034 ok ( ! Sizzle
. matchesSelector ( elem
, selector
), text
+ " fail " + selector
);
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" );
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" );
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" );
1059 Sizzle
. call ( null , "dl:lang(c++)" );
1061 return e
. message
. indexOf ( "Syntax error" ) >= 0 ;
1062 }, ":lang value must be a valid identifier" );
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" );
1076 if ( docXmlLang
== null ) {
1077 docElem
. removeAttribute ( "xml:lang" );
1079 docElem
. setAttribute ( "xml:lang" , docXmlLang
);
1081 docElem
. lang
= docLang
;
1084 test ( "caching" , function () {
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" );
1089 t ( "Deep ancestry caching in post-positional element matcher (jQuery #14657)" ,
1090 "#qunit-fixture a:lt(3):parent" ,
1091 [ "simon1" , "google" , "groups" ] );
1094 asyncTest ( "Iframe dispatch should not affect Sizzle, see jQuery #13936" , 1 , function () {
1097 iframe
= document
. getElementById ( "iframe" ),
1098 iframeDoc
= iframe
. contentDocument
|| iframe
. contentWindow
. document
;
1100 jQuery ( iframe
). on ( "load" , function () {
1104 iframeDoc
= this . contentDocument
|| this . contentWindow
. document
;
1105 form
= Sizzle ( "#navigate" , iframeDoc
)[ 0 ];
1111 strictEqual ( thrown
, false , "No error thrown from post-reload Sizzle call" );
1120 iframeDoc
. write ( "<body><form id='navigate'></form></body>" );
1124 test ( "matchesSelector" , function () {
1127 var el
= document
. getElementById ( "simon1" ),
1128 disconnected
= document
. createElement ( "div" );
1130 ok ( Sizzle
. matchesSelector ( el
, "[rel='bookmark']" ), "quoted attribute" );
1131 ok ( Sizzle
. matchesSelector ( el
, "[rel=bookmark]" ), "unquoted attribute" );
1132 ok ( Sizzle
. matchesSelector ( el
, "[ \n rel = bookmark \t ]" ), "unquoted attribute with non-semantic whitespace" );
1134 ok ( Sizzle
. matchesSelector ( disconnected
, "div" ), "disconnected element" );
1136 ok ( Sizzle
. matchesSelector ( el
, "* > *" ), "child combinator (matching)" );
1137 ok ( ! Sizzle
. matchesSelector ( disconnected
, "* > *" ), "child combinator (not matching)" );
1140 test ( "select() with pre-compiled function" , function () {
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" );