]>
git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/ex-mode/node_modules/space-pen/node_modules/jquery/src/sizzle/test/unit/utilities.js
d51888dd021d59ff285b8d8b8bac5fc491d0e6b3
1 module("utilities", { teardown: moduleTeardown
});
3 function testAttr( doc
) {
9 el
= doc
.createElement( "input" );
10 el
.setAttribute( "type", "checkbox" );
12 // Set checked on creation by creating with a fragment
13 // See http://jsfiddle.net/8sVgA/1/show/light in oldIE
14 el
= jQuery( "<input type='checkbox' checked='checked' />" )[0];
17 // Set it again for good measure
18 el
.setAttribute( "checked", "checked" );
19 el
.setAttribute( "id", "id" );
20 el
.setAttribute( "value", "on" );
22 strictEqual( Sizzle
.attr( el
, "nonexistent" ), null, "nonexistent" );
23 strictEqual( Sizzle
.attr( el
, "id" ), "id", "existent" );
24 strictEqual( Sizzle
.attr( el
, "value" ), "on", "value" );
25 strictEqual( Sizzle
.attr( el
, "checked" ), "checked", "boolean" );
26 strictEqual( Sizzle
.attr( el
, "href" ), null, "interpolation risk" );
27 strictEqual( Sizzle
.attr( el
, "constructor" ), null,
28 "Object.prototype property \"constructor\" (negative)" );
29 strictEqual( Sizzle
.attr( el
, "watch" ), null,
30 "Gecko Object.prototype property \"watch\" (negative)" );
31 el
.setAttribute( "constructor", "foo" );
32 el
.setAttribute( "watch", "bar" );
33 strictEqual( Sizzle
.attr( el
, "constructor" ), "foo",
34 "Object.prototype property \"constructor\"" );
35 strictEqual( Sizzle
.attr( el
, "watch" ), "bar",
36 "Gecko Object.prototype property \"watch\"" );
39 test("Sizzle.attr (HTML)", function() {
43 test("Sizzle.attr (XML)", function() {
44 testAttr( jQuery
.parseXML("<root/>") );
47 test("Sizzle.contains", function() {
50 var container
= document
.getElementById("nonnodes"),
51 element
= container
.firstChild
,
52 text
= element
.nextSibling
,
53 nonContained
= container
.nextSibling
,
54 detached
= document
.createElement("a");
55 ok( element
&& element
.nodeType
=== 1, "preliminary: found element" );
56 ok( text
&& text
.nodeType
=== 3, "preliminary: found text" );
57 ok( nonContained
, "preliminary: found non-descendant" );
58 ok( Sizzle
.contains(container
, element
), "child" );
59 ok( Sizzle
.contains(container
.parentNode
, element
), "grandchild" );
60 ok( Sizzle
.contains(container
, text
), "text child" );
61 ok( Sizzle
.contains(container
.parentNode
, text
), "text grandchild" );
62 ok( !Sizzle
.contains(container
, container
), "self" );
63 ok( !Sizzle
.contains(element
, container
), "parent" );
64 ok( !Sizzle
.contains(container
, nonContained
), "non-descendant" );
65 ok( !Sizzle
.contains(container
, document
), "document" );
66 ok( !Sizzle
.contains(container
, document
.documentElement
), "documentElement (negative)" );
67 ok( !Sizzle
.contains(container
, null), "Passing null does not throw an error" );
68 ok( Sizzle
.contains(document
, document
.documentElement
), "documentElement (positive)" );
69 ok( Sizzle
.contains(document
, element
), "document container (positive)" );
70 ok( !Sizzle
.contains(document
, detached
), "document container (negative)" );
73 if ( jQuery("<svg xmlns='http://www.w3.org/2000/svg' version='1.1' height='1' width='1'><g/></svg>")[0].firstChild
) {
74 test("Sizzle.contains in SVG (jQuery #10832)", function() {
78 "<svg xmlns='http://www.w3.org/2000/svg' version='1.1' height='1' width='1'>" +
79 "<g><circle cx='1' cy='1' r='1' /></g>" +
81 ).appendTo("#qunit-fixture")[0];
83 ok( Sizzle
.contains( svg
, svg
.firstChild
), "root child" );
84 ok( Sizzle
.contains( svg
.firstChild
, svg
.firstChild
.firstChild
), "element child" );
85 ok( Sizzle
.contains( svg
, svg
.firstChild
.firstChild
), "root granchild" );
86 ok( !Sizzle
.contains( svg
.firstChild
.firstChild
, svg
.firstChild
), "parent (negative)" );
90 test("Sizzle.uniqueSort", function() {
93 function Arrayish( arr
) {
94 var i
= this.length
= arr
.length
;
99 Arrayish
.prototype = {
107 body
= document
.body
,
108 fixture
= document
.getElementById("qunit-fixture"),
109 detached1
= document
.createElement("p"),
110 detached2
= document
.createElement("ul"),
111 detachedChild
= detached1
.appendChild( document
.createElement("a") ),
112 detachedGrandchild
= detachedChild
.appendChild( document
.createElement("b") );
114 for ( i
= 0; i
< 12; i
++ ) {
115 detached
.push( document
.createElement("li") );
116 detached
[i
].id
= "detached" + i
;
117 detached2
.appendChild( document
.createElement("li") ).id
= "detachedChild" + i
;
127 expected: [ fixture
]
130 input: [ fixture
, body
],
131 expected: [ body
, fixture
]
134 input: [ body
, fixture
, fixture
, body
],
135 expected: [ body
, fixture
]
138 input: detached
.slice( 0 ),
139 expected: detached
.slice( 0 )
141 "Detached children": {
143 detached2
.childNodes
[0],
144 detached2
.childNodes
[1],
145 detached2
.childNodes
[2],
146 detached2
.childNodes
[3]
149 detached2
.childNodes
[0],
150 detached2
.childNodes
[1],
151 detached2
.childNodes
[2],
152 detached2
.childNodes
[3]
155 "Attached/detached mixture": {
156 input: [ detached1
, fixture
, detached2
, document
, detachedChild
, body
, detachedGrandchild
],
157 expected: [ document
, body
, fixture
],
162 jQuery
.each( tests
, function( label
, test
) {
163 var length
= test
.length
|| test
.input
.length
;
164 deepEqual( Sizzle
.uniqueSort( test
.input
).slice( 0, length
), test
.expected
, label
+ " (array)" );
165 deepEqual( Sizzle
.uniqueSort( new Arrayish(test
.input
) ).slice( 0, length
), test
.expected
, label
+ " (quasi-array)" );
169 testIframeWithCallback( "Sizzle.uniqueSort works cross-window (jQuery #14381)", "mixed_sort.html", deepEqual
);