]> 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
[rbdr/dotfiles] / atom / packages / ex-mode / node_modules / space-pen / node_modules / jquery / src / sizzle / test / unit / utilities.js
1 module("utilities", { teardown: moduleTeardown });
2
3 function testAttr( doc ) {
4 expect( 9 );
5
6 var el;
7 if ( doc ) {
8 // XML
9 el = doc.createElement( "input" );
10 el.setAttribute( "type", "checkbox" );
11 } else {
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];
15 }
16
17 // Set it again for good measure
18 el.setAttribute( "checked", "checked" );
19 el.setAttribute( "id", "id" );
20 el.setAttribute( "value", "on" );
21
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\"" );
37 }
38
39 test("Sizzle.attr (HTML)", function() {
40 testAttr();
41 });
42
43 test("Sizzle.attr (XML)", function() {
44 testAttr( jQuery.parseXML("<root/>") );
45 });
46
47 test("Sizzle.contains", function() {
48 expect( 16 );
49
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)" );
71 });
72
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() {
75 expect( 4 );
76
77 var svg = jQuery(
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>" +
80 "</svg>"
81 ).appendTo("#qunit-fixture")[0];
82
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)" );
87 });
88 }
89
90 test("Sizzle.uniqueSort", function() {
91 expect( 14 );
92
93 function Arrayish( arr ) {
94 var i = this.length = arr.length;
95 while ( i-- ) {
96 this[ i ] = arr[ i ];
97 }
98 }
99 Arrayish.prototype = {
100 slice: [].slice,
101 sort: [].sort,
102 splice: [].splice
103 };
104
105 var i, tests,
106 detached = [],
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") );
113
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;
118 }
119
120 tests = {
121 "Empty": {
122 input: [],
123 expected: []
124 },
125 "Single-element": {
126 input: [ fixture ],
127 expected: [ fixture ]
128 },
129 "No duplicates": {
130 input: [ fixture, body ],
131 expected: [ body, fixture ]
132 },
133 "Duplicates": {
134 input: [ body, fixture, fixture, body ],
135 expected: [ body, fixture ]
136 },
137 "Detached": {
138 input: detached.slice( 0 ),
139 expected: detached.slice( 0 )
140 },
141 "Detached children": {
142 input: [
143 detached2.childNodes[0],
144 detached2.childNodes[1],
145 detached2.childNodes[2],
146 detached2.childNodes[3]
147 ],
148 expected: [
149 detached2.childNodes[0],
150 detached2.childNodes[1],
151 detached2.childNodes[2],
152 detached2.childNodes[3]
153 ]
154 },
155 "Attached/detached mixture": {
156 input: [ detached1, fixture, detached2, document, detachedChild, body, detachedGrandchild ],
157 expected: [ document, body, fixture ],
158 length: 3
159 }
160 };
161
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)" );
166 });
167 });
168
169 testIframeWithCallback( "Sizzle.uniqueSort works cross-window (jQuery #14381)", "mixed_sort.html", deepEqual );