show is now element aware (#960)
[jquery.git] / test / unit / core.js
1 module("core");
2
3 test("Basic requirements", function() {
4         expect(7);
5         ok( Array.prototype.push, "Array.push()" );
6         ok( Function.prototype.apply, "Function.apply()" );
7         ok( document.getElementById, "getElementById" );
8         ok( document.getElementsByTagName, "getElementsByTagName" );
9         ok( RegExp, "RegExp" );
10         ok( jQuery, "jQuery" );
11         ok( $, "$()" );
12 });
13
14 test("$()", function() {
15         expect(4);
16         
17         var main = $("#main");
18         isSet( $("div p", main).get(), q("sndp", "en", "sap"), "Basic selector with jQuery object as context" );
19         
20 /*
21         // disabled since this test was doing nothing. i tried to fix it but i'm not sure
22         // what the expected behavior should even be. FF returns "\n" for the text node
23         // make sure this is handled
24         var crlfContainer = $('<p>\r\n</p>');
25         var x = crlfContainer.contents().get(0).nodeValue;
26         equals( x, what???, "Check for \\r and \\n in jQuery()" );
27 */
28         
29         /* // Disabled until we add this functionality in
30         var pass = true;
31         try {
32                 $("<div>Testing</div>").appendTo(document.getElementById("iframe").contentDocument.body);
33         } catch(e){
34                 pass = false;
35         }
36         ok( pass, "$('&lt;tag&gt;') needs optional document parameter to ease cross-frame DOM wrangling, see #968" );*/
37
38         var code = $("<code/>");
39         equals( code.length, 1, "Correct number of elements generated for code" );
40         var img = $("<img/>");
41         equals( img.length, 1, "Correct number of elements generated for img" );
42         var div = $("<div/><hr/><code/><b/>");
43         equals( div.length, 4, "Correct number of elements generated for div hr code b" );
44 });
45
46 test("noConflict", function() {
47         expect(6);
48         
49         var old = jQuery;
50         var newjQuery = jQuery.noConflict();
51
52         ok( newjQuery == old, "noConflict returned the jQuery object" );
53         ok( jQuery == old, "Make sure jQuery wasn't touched." );
54         ok( $ == "$", "Make sure $ was reverted." );
55
56         jQuery = $ = old;
57
58         newjQuery = jQuery.noConflict(true);
59
60         ok( newjQuery == old, "noConflict returned the jQuery object" );
61         ok( jQuery == "jQuery", "Make sure jQuery was reverted." );
62         ok( $ == "$", "Make sure $ was reverted." );
63
64         jQuery = $ = old;
65 });
66
67 test("isFunction", function() {
68         expect(21);
69
70         // Make sure that false values return false
71         ok( !jQuery.isFunction(), "No Value" );
72         ok( !jQuery.isFunction( null ), "null Value" );
73         ok( !jQuery.isFunction( undefined ), "undefined Value" );
74         ok( !jQuery.isFunction( "" ), "Empty String Value" );
75         ok( !jQuery.isFunction( 0 ), "0 Value" );
76
77         // Check built-ins
78         // Safari uses "(Internal Function)"
79         ok( jQuery.isFunction(String), "String Function" );
80         ok( jQuery.isFunction(Array), "Array Function" );
81         ok( jQuery.isFunction(Object), "Object Function" );
82         ok( jQuery.isFunction(Function), "Function Function" );
83
84         // When stringified, this could be misinterpreted
85         var mystr = "function";
86         ok( !jQuery.isFunction(mystr), "Function String" );
87
88         // When stringified, this could be misinterpreted
89         var myarr = [ "function" ];
90         ok( !jQuery.isFunction(myarr), "Function Array" );
91
92         // When stringified, this could be misinterpreted
93         var myfunction = { "function": "test" };
94         ok( !jQuery.isFunction(myfunction), "Function Object" );
95
96         // Make sure normal functions still work
97         var fn = function(){};
98         ok( jQuery.isFunction(fn), "Normal Function" );
99
100         var obj = document.createElement("object");
101
102         // Firefox says this is a function
103         ok( !jQuery.isFunction(obj), "Object Element" );
104
105         // IE says this is an object
106         ok( jQuery.isFunction(obj.getAttribute), "getAttribute Function" );
107
108         var nodes = document.body.childNodes;
109
110         // Safari says this is a function
111         ok( !jQuery.isFunction(nodes), "childNodes Property" );
112
113         var first = document.body.firstChild;
114         
115         // Normal elements are reported ok everywhere
116         ok( !jQuery.isFunction(first), "A normal DOM Element" );
117
118         var input = document.createElement("input");
119         input.type = "text";
120         document.body.appendChild( input );
121
122         // IE says this is an object
123         ok( jQuery.isFunction(input.focus), "A default function property" );
124
125         document.body.removeChild( input );
126
127         var a = document.createElement("a");
128         a.href = "some-function";
129         document.body.appendChild( a );
130
131         // This serializes with the word 'function' in it
132         ok( !jQuery.isFunction(a), "Anchor Element" );
133
134         document.body.removeChild( a );
135
136         // Recursive function calls have lengths and array-like properties
137         function callme(callback){
138                 function fn(response){
139                         callback(response);
140                 }
141
142                 ok( jQuery.isFunction(fn), "Recursive Function Call" );
143
144                 fn({ some: "data" });
145         };
146
147         callme(function(){
148                 callme(function(){});
149         });
150 });
151
152 var foo = false;
153
154 test("$('html')", function() {
155         expect(5);
156
157         reset();
158         foo = false;
159         var s = $("<script>var foo='test';</script>")[0];
160         ok( s, "Creating a script" );
161         ok( !foo, "Make sure the script wasn't executed prematurely" );
162         $("body").append(s);
163         ok( foo, "Executing a scripts contents in the right context" );
164         
165         reset();
166         ok( $("<link rel='stylesheet'/>")[0], "Creating a link" );
167         
168         reset();
169
170         var j = $("<span>hi</span> there <!-- mon ami -->");
171         ok( j.length >= 2, "Check node,textnode,comment creation (some browsers delete comments)" );
172 });
173
174 test("$('html', context)", function() {
175         expect(1);
176
177         var $div = $("<div/>");
178         var $span = $("<span/>", $div);
179         equals($span.length, 1, "Verify a span created with a div context works, #1763");
180 });
181
182 test("$(selector, xml).text(str) - Loaded via XML document", function() {
183         expect(2);
184         stop();
185         $.get('data/dashboard.xml', function(xml) { 
186                 // tests for #1419 where IE was a problem
187                 equals( $("tab:first", xml).text(), "blabla", "Verify initial text correct" );
188                 $("tab:first", xml).text("newtext");
189                 equals( $("tab:first", xml).text(), "newtext", "Verify new text correct" );
190                 start();
191         });
192 });
193
194 test("length", function() {
195         expect(1);
196         ok( $("p").length == 6, "Get Number of Elements Found" );
197 });
198
199 test("size()", function() {
200         expect(1);
201         ok( $("p").size() == 6, "Get Number of Elements Found" );
202 });
203
204 test("get()", function() {
205         expect(1);
206         isSet( $("p").get(), q("firstp","ap","sndp","en","sap","first"), "Get All Elements" );
207 });
208
209 test("get(Number)", function() {
210         expect(1);
211         ok( $("p").get(0) == document.getElementById("firstp"), "Get A Single Element" );
212 });
213
214 test("add(String|Element|Array|undefined)", function() {
215         expect(8);
216         isSet( $("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" );
217         isSet( $("#sndp").add( $("#en")[0] ).add( $("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" );
218         ok( $([]).add($("#form")[0].elements).length >= 13, "Check elements from array" );
219         
220         var x = $([]).add($("<p id='x1'>xxx</p>")).add($("<p id='x2'>xxx</p>"));
221         ok( x[0].id == "x1", "Check on-the-fly element1" );
222         ok( x[1].id == "x2", "Check on-the-fly element2" );
223         
224         var x = $([]).add("<p id='x1'>xxx</p>").add("<p id='x2'>xxx</p>");
225         ok( x[0].id == "x1", "Check on-the-fly element1" );
226         ok( x[1].id == "x2", "Check on-the-fly element2" );
227         
228         var notDefined;
229         equals( $([]).add(notDefined).length, 0, "Check that undefined adds nothing." );
230 });
231
232 test("each(Function)", function() {
233         expect(1);
234         var div = $("div");
235         div.each(function(){this.foo = 'zoo';});
236         var pass = true;
237         for ( var i = 0; i < div.size(); i++ ) {
238                 if ( div.get(i).foo != "zoo" ) pass = false;
239         }
240         ok( pass, "Execute a function, Relative" );
241 });
242
243 test("index(Object)", function() {
244         expect(8);
245         ok( $([window, document]).index(window) == 0, "Check for index of elements" );
246         ok( $([window, document]).index(document) == 1, "Check for index of elements" );
247         var inputElements = $('#radio1,#radio2,#check1,#check2');
248         ok( inputElements.index(document.getElementById('radio1')) == 0, "Check for index of elements" );
249         ok( inputElements.index(document.getElementById('radio2')) == 1, "Check for index of elements" );
250         ok( inputElements.index(document.getElementById('check1')) == 2, "Check for index of elements" );
251         ok( inputElements.index(document.getElementById('check2')) == 3, "Check for index of elements" );
252         ok( inputElements.index(window) == -1, "Check for not found index" );
253         ok( inputElements.index(document) == -1, "Check for not found index" );
254 });
255
256 test("attr(String)", function() {
257         expect(20);
258         ok( $('#text1').attr('value') == "Test", 'Check for value attribute' );
259         ok( $('#text1').attr('value', "Test2").attr('defaultValue') == "Test", 'Check for defaultValue attribute' );
260         ok( $('#text1').attr('type') == "text", 'Check for type attribute' );
261         ok( $('#radio1').attr('type') == "radio", 'Check for type attribute' );
262         ok( $('#check1').attr('type') == "checkbox", 'Check for type attribute' );
263         ok( $('#simon1').attr('rel') == "bookmark", 'Check for rel attribute' );
264         ok( $('#google').attr('title') == "Google!", 'Check for title attribute' );
265         ok( $('#mark').attr('hreflang') == "en", 'Check for hreflang attribute' );
266         ok( $('#en').attr('lang') == "en", 'Check for lang attribute' );
267         ok( $('#simon').attr('class') == "blog link", 'Check for class attribute' );
268         ok( $('#name').attr('name') == "name", 'Check for name attribute' );
269         ok( $('#text1').attr('name') == "action", 'Check for name attribute' );
270         ok( $('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
271         ok( $('#text1').attr('maxlength') == '30', 'Check for maxlength attribute' );
272         ok( $('#text1').attr('maxLength') == '30', 'Check for maxLength attribute' );
273         ok( $('#area1').attr('maxLength') == '30', 'Check for maxLength attribute' );
274         ok( $('#select2').attr('selectedIndex') == 3, 'Check for selectedIndex attribute' );
275         ok( $('#foo').attr('nodeName') == 'DIV', 'Check for nodeName attribute' );
276         ok( $('#foo').attr('tagName') == 'DIV', 'Check for tagName attribute' );
277         
278         $('<a id="tAnchor5"></a>').attr('href', '#5').appendTo('#main'); // using innerHTML in IE causes href attribute to be serialized to the full path
279         ok( $('#tAnchor5').attr('href') == "#5", 'Check for non-absolute href (an anchor)' );
280 });
281
282 if ( !isLocal ) {
283         test("attr(String) in XML Files", function() {
284                 expect(2);
285                 stop();
286                 $.get("data/dashboard.xml", function(xml) {
287                         ok( $("locations", xml).attr("class") == "foo", "Check class attribute in XML document" );
288                         ok( $("location", xml).attr("for") == "bar", "Check for attribute in XML document" );
289                         start();
290                 });
291         });
292 }
293
294 test("attr(String, Function)", function() {
295         expect(2);
296         ok( $('#text1').attr('value', function() { return this.id })[0].value == "text1", "Set value from id" );
297         ok( $('#text1').attr('title', function(i) { return i }).attr('title') == "0", "Set value with an index");
298 });
299
300 test("attr(Hash)", function() {
301         expect(1);
302         var pass = true;
303         $("div").attr({foo: 'baz', zoo: 'ping'}).each(function(){
304                 if ( this.getAttribute('foo') != "baz" && this.getAttribute('zoo') != "ping" ) pass = false;
305         });
306         ok( pass, "Set Multiple Attributes" );
307 });
308
309 test("attr(String, Object)", function() {
310         expect(17);
311         var div = $("div");
312         div.attr("foo", "bar");
313         var pass = true;
314         for ( var i = 0; i < div.size(); i++ ) {
315                 if ( div.get(i).getAttribute('foo') != "bar" ) pass = false;
316         }
317         ok( pass, "Set Attribute" );
318
319         ok( $("#foo").attr({"width": null}), "Try to set an attribute to nothing" );    
320         
321         $("#name").attr('name', 'something');
322         ok( $("#name").attr('name') == 'something', 'Set name attribute' );
323         $("#check2").attr('checked', true);
324         ok( document.getElementById('check2').checked == true, 'Set checked attribute' );
325         $("#check2").attr('checked', false);
326         ok( document.getElementById('check2').checked == false, 'Set checked attribute' );
327         $("#text1").attr('readonly', true);
328         ok( document.getElementById('text1').readOnly == true, 'Set readonly attribute' );
329         $("#text1").attr('readonly', false);
330         ok( document.getElementById('text1').readOnly == false, 'Set readonly attribute' );
331         $("#name").attr('maxlength', '5');
332         ok( document.getElementById('name').maxLength == '5', 'Set maxlength attribute' );
333         $("#name").attr('maxLength', '10');
334         ok( document.getElementById('name').maxLength == '10', 'Set maxlength attribute' );
335
336         // for #1070
337         $("#name").attr('someAttr', '0');
338         equals( $("#name").attr('someAttr'), '0', 'Set attribute to a string of "0"' );
339         $("#name").attr('someAttr', 0);
340         equals( $("#name").attr('someAttr'), 0, 'Set attribute to the number 0' );
341         $("#name").attr('someAttr', 1);
342         equals( $("#name").attr('someAttr'), 1, 'Set attribute to the number 1' );
343
344         // using contents will get comments regular, text, and comment nodes
345         var j = $("#nonnodes").contents();
346
347         j.attr("name", "attrvalue");
348         equals( j.attr("name"), "attrvalue", "Check node,textnode,comment for attr" );
349         j.removeAttr("name")
350
351         reset();
352
353         var type = $("#check2").attr('type');
354         var thrown = false;
355         try {
356                 $("#check2").attr('type','hidden');
357         } catch(e) {
358                 thrown = true;
359         }
360         ok( thrown, "Exception thrown when trying to change type property" );
361         equals( type, $("#check2").attr('type'), "Verify that you can't change the type of an input element" );
362
363         var check = document.createElement("input");
364         var thrown = true;
365         try {
366                 $(check).attr('type','checkbox');
367         } catch(e) {
368                 thrown = false;
369         }
370         ok( thrown, "Exception thrown when trying to change type property" );
371         equals( "checkbox", $(check).attr('type'), "Verify that you can change the type of an input element that isn't in the DOM" );
372 });
373
374 if ( !isLocal ) {
375         test("attr(String, Object) - Loaded via XML document", function() {
376                 expect(2);
377                 stop();
378                 $.get('data/dashboard.xml', function(xml) { 
379                         var titles = [];
380                         $('tab', xml).each(function() {
381                                 titles.push($(this).attr('title'));
382                         });
383                         equals( titles[0], 'Location', 'attr() in XML context: Check first title' );
384                         equals( titles[1], 'Users', 'attr() in XML context: Check second title' );
385                         start();
386                 });
387         });
388 }
389
390 test("css(String|Hash)", function() {
391         expect(19);
392         
393         ok( $('#main').css("display") == 'none', 'Check for css property "display"');
394         
395         ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
396         $('#foo').css({display: 'none'});
397         ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
398         $('#foo').css({display: 'block'});
399         ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
400         
401         $('#floatTest').css({styleFloat: 'right'});
402         ok( $('#floatTest').css('styleFloat') == 'right', 'Modified CSS float using "styleFloat": Assert float is right');
403         $('#floatTest').css({cssFloat: 'left'});
404         ok( $('#floatTest').css('cssFloat') == 'left', 'Modified CSS float using "cssFloat": Assert float is left');
405         $('#floatTest').css({'float': 'right'});
406         ok( $('#floatTest').css('float') == 'right', 'Modified CSS float using "float": Assert float is right');
407         $('#floatTest').css({'font-size': '30px'});
408         ok( $('#floatTest').css('font-size') == '30px', 'Modified CSS font-size: Assert font-size is 30px');
409         
410         $.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
411                 $('#foo').css({opacity: n});
412                 ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
413                 $('#foo').css({opacity: parseFloat(n)});
414                 ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
415         });     
416         $('#foo').css({opacity: ''});
417         ok( $('#foo').css('opacity') == '1', "Assert opacity is 1 when set to an empty String" );
418 });
419
420 test("css(String, Object)", function() {
421         expect(20);
422         ok( $('#foo').is(':visible'), 'Modifying CSS display: Assert element is visible');
423         $('#foo').css('display', 'none');
424         ok( !$('#foo').is(':visible'), 'Modified CSS display: Assert element is hidden');
425         $('#foo').css('display', 'block');
426         ok( $('#foo').is(':visible'), 'Modified CSS display: Assert element is visible');
427         
428         $('#floatTest').css('styleFloat', 'left');
429         ok( $('#floatTest').css('styleFloat') == 'left', 'Modified CSS float using "styleFloat": Assert float is left');
430         $('#floatTest').css('cssFloat', 'right');
431         ok( $('#floatTest').css('cssFloat') == 'right', 'Modified CSS float using "cssFloat": Assert float is right');
432         $('#floatTest').css('float', 'left');
433         ok( $('#floatTest').css('float') == 'left', 'Modified CSS float using "float": Assert float is left');
434         $('#floatTest').css('font-size', '20px');
435         ok( $('#floatTest').css('font-size') == '20px', 'Modified CSS font-size: Assert font-size is 20px');
436         
437         $.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
438                 $('#foo').css('opacity', n);
439                 ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
440                 $('#foo').css('opacity', parseFloat(n));
441                 ok( $('#foo').css('opacity') == parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
442         });
443         $('#foo').css('opacity', '');
444         ok( $('#foo').css('opacity') == '1', "Assert opacity is 1 when set to an empty String" );
445         // for #1438, IE throws JS error when filter exists but doesn't have opacity in it
446         if (jQuery.browser.msie) {
447                 $('#foo').css("filter", "progid:DXImageTransform.Microsoft.Chroma(color='red');");
448         }
449         equals( $('#foo').css('opacity'), '1', "Assert opacity is 1 when a different filter is set in IE, #1438" );
450
451         // using contents will get comments regular, text, and comment nodes
452         var j = $("#nonnodes").contents();
453         j.css("padding-left", "1px");
454         equals( j.css("padding-left"), "1px", "Check node,textnode,comment css works" );
455 });
456
457 test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function () {
458         expect(4);
459
460         var $checkedtest = $("#checkedtest");
461         // IE6 was clearing "checked" in jQuery.css(elem, "height");
462         jQuery.css($checkedtest[0], "height");
463         ok( !! $(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
464         ok( ! $(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
465         ok( !! $(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
466         ok( ! $(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
467 });
468
469 test("width()", function() {
470         expect(2);
471
472         $("#nothiddendiv").width(30);
473         equals($("#nothiddendiv").width(), 30, "Test set to 30 correctly");
474         $("#nothiddendiv").width(-1); // handle negative numbers by ignoring #1599
475         equals($("#nothiddendiv").width(), 30, "Test negative width ignored");
476 });
477
478 test("text()", function() {
479         expect(1);
480         var expected = "This link has class=\"blog\": Simon Willison's Weblog";
481         ok( $('#sap').text() == expected, 'Check for merged text of more then one element.' );
482 });
483
484 test("wrap(String|Element)", function() {
485         expect(8);
486         var defaultText = 'Try them out:'
487         var result = $('#first').wrap('<div class="red"><span></span></div>').text();
488         ok( defaultText == result, 'Check for wrapping of on-the-fly html' );
489         ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
490
491         reset();
492         var defaultText = 'Try them out:'
493         var result = $('#first').wrap(document.getElementById('empty')).parent();
494         ok( result.is('ol'), 'Check for element wrapping' );
495         ok( result.text() == defaultText, 'Check for element wrapping' );
496         
497         reset();
498         $('#check1').click(function() {         
499                 var checkbox = this;            
500                 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
501                 $(checkbox).wrap( '<div id="c1" style="display:none;"></div>' );
502                 ok( checkbox.checked, "Checkbox's state is erased after wrap() action, see #769" );
503         }).click();
504
505         // using contents will get comments regular, text, and comment nodes
506         var j = $("#nonnodes").contents();
507         j.wrap("<i></i>");
508         equals( $("#nonnodes > i").length, 3, "Check node,textnode,comment wraps ok" );
509         equals( $("#nonnodes > i").text(), j.text() + j[1].nodeValue, "Check node,textnode,comment wraps doesn't hurt text" );
510 });
511
512 test("wrapAll(String|Element)", function() {
513         expect(8);
514         var prev = $("#first")[0].previousSibling;
515         var p = $("#first")[0].parentNode;
516         var result = $('#first,#firstp').wrapAll('<div class="red"><div id="tmp"></div></div>');
517         equals( result.parent().length, 1, 'Check for wrapping of on-the-fly html' );
518         ok( $('#first').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
519         ok( $('#firstp').parent().parent().is('.red'), 'Check if wrapper has class "red"' );
520         equals( $("#first").parent().parent()[0].previousSibling, prev, "Correct Previous Sibling" );
521         equals( $("#first").parent().parent()[0].parentNode, p, "Correct Parent" );
522
523         reset();
524         var prev = $("#first")[0].previousSibling;
525         var p = $("#first")[0].parentNode;
526         var result = $('#first,#firstp').wrapAll(document.getElementById('empty'));
527         equals( $("#first").parent()[0], $("#firstp").parent()[0], "Same Parent" );
528         equals( $("#first").parent()[0].previousSibling, prev, "Correct Previous Sibling" );
529         equals( $("#first").parent()[0].parentNode, p, "Correct Parent" );
530 });
531
532 test("wrapInner(String|Element)", function() {
533         expect(6);
534         var num = $("#first").children().length;
535         var result = $('#first').wrapInner('<div class="red"><div id="tmp"></div></div>');
536         equals( $("#first").children().length, 1, "Only one child" );
537         ok( $("#first").children().is(".red"), "Verify Right Element" );
538         equals( $("#first").children().children().children().length, num, "Verify Elements Intact" );
539
540         reset();
541         var num = $("#first").children().length;
542         var result = $('#first').wrapInner(document.getElementById('empty'));
543         equals( $("#first").children().length, 1, "Only one child" );
544         ok( $("#first").children().is("#empty"), "Verify Right Element" );
545         equals( $("#first").children().children().length, num, "Verify Elements Intact" );
546 });
547
548 test("append(String|Element|Array&lt;Element&gt;|jQuery)", function() {
549         expect(21);
550         var defaultText = 'Try them out:'
551         var result = $('#first').append('<b>buga</b>');
552         ok( result.text() == defaultText + 'buga', 'Check if text appending works' );
553         ok( $('#select3').append('<option value="appendTest">Append Test</option>').find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
554         
555         reset();
556         var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
557         $('#sap').append(document.getElementById('first'));
558         ok( expected == $('#sap').text(), "Check for appending of element" );
559         
560         reset();
561         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
562         $('#sap').append([document.getElementById('first'), document.getElementById('yahoo')]);
563         ok( expected == $('#sap').text(), "Check for appending of array of elements" );
564         
565         reset();
566         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
567         $('#sap').append($("#first, #yahoo"));
568         ok( expected == $('#sap').text(), "Check for appending of jQuery object" );
569
570         reset();
571         $("#sap").append( 5 );
572         ok( $("#sap")[0].innerHTML.match( /5$/ ), "Check for appending a number" );
573
574         reset();
575         $("#sap").append( " text with spaces " );
576         ok( $("#sap")[0].innerHTML.match(/ text with spaces $/), "Check for appending text with spaces" );
577
578         reset();
579         ok( $("#sap").append([]), "Check for appending an empty array." );
580         ok( $("#sap").append(""), "Check for appending an empty string." );
581         ok( $("#sap").append(document.getElementsByTagName("foo")), "Check for appending an empty nodelist." );
582         
583         reset();
584         $("#sap").append(document.getElementById('form'));
585         ok( $("#sap>form").size() == 1, "Check for appending a form" ); // Bug #910
586
587         reset();
588         var pass = true;
589         try {
590                 $( $("#iframe")[0].contentWindow.document.body ).append("<div>test</div>");
591         } catch(e) {
592                 pass = false;
593         }
594
595         ok( pass, "Test for appending a DOM node to the contents of an IFrame" );
596         
597         reset();
598         $('<fieldset/>').appendTo('#form').append('<legend id="legend">test</legend>');
599         t( 'Append legend', '#legend', ['legend'] );
600         
601         reset();
602         $('#select1').append('<OPTION>Test</OPTION>');
603         ok( $('#select1 option:last').text() == "Test", "Appending &lt;OPTION&gt; (all caps)" );
604         
605         $('#table').append('<colgroup></colgroup>');
606         ok( $('#table colgroup').length, "Append colgroup" );
607         
608         $('#table colgroup').append('<col/>');
609         ok( $('#table colgroup col').length, "Append col" );
610         
611         reset();
612         $('#table').append('<caption></caption>');
613         ok( $('#table caption').length, "Append caption" );
614
615         reset();
616         $('form:last')
617                 .append('<select id="appendSelect1"></select>')
618                 .append('<select id="appendSelect2"><option>Test</option></select>');
619         
620         t( "Append Select", "#appendSelect1, #appendSelect2", ["appendSelect1", "appendSelect2"] );
621
622         // using contents will get comments regular, text, and comment nodes
623         var j = $("#nonnodes").contents();
624         var d = $("<div/>").appendTo("#nonnodes").append(j);
625         equals( $("#nonnodes").length, 1, "Check node,textnode,comment append moved leaving just the div" );
626         ok( d.contents().length >= 2, "Check node,textnode,comment append works" );
627         d.contents().appendTo("#nonnodes");
628         d.remove();
629         ok( $("#nonnodes").contents().length >= 2, "Check node,textnode,comment append cleanup worked" );
630 });
631
632 test("appendTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
633         expect(6);
634         var defaultText = 'Try them out:'
635         $('<b>buga</b>').appendTo('#first');
636         ok( $("#first").text() == defaultText + 'buga', 'Check if text appending works' );
637         ok( $('<option value="appendTest">Append Test</option>').appendTo('#select3').parent().find('option:last-child').attr('value') == 'appendTest', 'Appending html options to select element');
638         
639         reset();
640         var expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:";
641         $(document.getElementById('first')).appendTo('#sap');
642         ok( expected == $('#sap').text(), "Check for appending of element" );
643         
644         reset();
645         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
646         $([document.getElementById('first'), document.getElementById('yahoo')]).appendTo('#sap');
647         ok( expected == $('#sap').text(), "Check for appending of array of elements" );
648         
649         reset();
650         expected = "This link has class=\"blog\": Simon Willison's WeblogTry them out:Yahoo";
651         $("#first, #yahoo").appendTo('#sap');
652         ok( expected == $('#sap').text(), "Check for appending of jQuery object" );
653         
654         reset();
655         $('#select1').appendTo('#foo');
656         t( 'Append select', '#foo select', ['select1'] );
657 });
658
659 test("prepend(String|Element|Array&lt;Element&gt;|jQuery)", function() {
660         expect(5);
661         var defaultText = 'Try them out:'
662         var result = $('#first').prepend('<b>buga</b>');
663         ok( result.text() == 'buga' + defaultText, 'Check if text prepending works' );
664         ok( $('#select3').prepend('<option value="prependTest">Prepend Test</option>').find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
665         
666         reset();
667         var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
668         $('#sap').prepend(document.getElementById('first'));
669         ok( expected == $('#sap').text(), "Check for prepending of element" );
670
671         reset();
672         expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
673         $('#sap').prepend([document.getElementById('first'), document.getElementById('yahoo')]);
674         ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
675         
676         reset();
677         expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
678         $('#sap').prepend($("#first, #yahoo"));
679         ok( expected == $('#sap').text(), "Check for prepending of jQuery object" );
680 });
681
682 test("prependTo(String|Element|Array&lt;Element&gt;|jQuery)", function() {
683         expect(6);
684         var defaultText = 'Try them out:'
685         $('<b>buga</b>').prependTo('#first');
686         ok( $('#first').text() == 'buga' + defaultText, 'Check if text prepending works' );
687         ok( $('<option value="prependTest">Prepend Test</option>').prependTo('#select3').parent().find('option:first-child').attr('value') == 'prependTest', 'Prepending html options to select element');
688         
689         reset();
690         var expected = "Try them out:This link has class=\"blog\": Simon Willison's Weblog";
691         $(document.getElementById('first')).prependTo('#sap');
692         ok( expected == $('#sap').text(), "Check for prepending of element" );
693
694         reset();
695         expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
696         $([document.getElementById('yahoo'), document.getElementById('first')]).prependTo('#sap');
697         ok( expected == $('#sap').text(), "Check for prepending of array of elements" );
698         
699         reset();
700         expected = "Try them out:YahooThis link has class=\"blog\": Simon Willison's Weblog";
701         $("#yahoo, #first").prependTo('#sap');
702         ok( expected == $('#sap').text(), "Check for prepending of jQuery object" );
703         
704         reset();
705         $('<select id="prependSelect1"></select>').prependTo('form:last');
706         $('<select id="prependSelect2"><option>Test</option></select>').prependTo('form:last');
707         
708         t( "Prepend Select", "#prependSelect1, #prependSelect2", ["prependSelect1", "prependSelect2"] );
709 });
710
711 test("before(String|Element|Array&lt;Element&gt;|jQuery)", function() {
712         expect(4);
713         var expected = 'This is a normal link: bugaYahoo';
714         $('#yahoo').before('<b>buga</b>');
715         ok( expected == $('#en').text(), 'Insert String before' );
716         
717         reset();
718         expected = "This is a normal link: Try them out:Yahoo";
719         $('#yahoo').before(document.getElementById('first'));
720         ok( expected == $('#en').text(), "Insert element before" );
721         
722         reset();
723         expected = "This is a normal link: Try them out:diveintomarkYahoo";
724         $('#yahoo').before([document.getElementById('first'), document.getElementById('mark')]);
725         ok( expected == $('#en').text(), "Insert array of elements before" );
726         
727         reset();
728         expected = "This is a normal link: Try them out:diveintomarkYahoo";
729         $('#yahoo').before($("#first, #mark"));
730         ok( expected == $('#en').text(), "Insert jQuery before" );
731 });
732
733 test("insertBefore(String|Element|Array&lt;Element&gt;|jQuery)", function() {
734         expect(4);
735         var expected = 'This is a normal link: bugaYahoo';
736         $('<b>buga</b>').insertBefore('#yahoo');
737         ok( expected == $('#en').text(), 'Insert String before' );
738         
739         reset();
740         expected = "This is a normal link: Try them out:Yahoo";
741         $(document.getElementById('first')).insertBefore('#yahoo');
742         ok( expected == $('#en').text(), "Insert element before" );
743         
744         reset();
745         expected = "This is a normal link: Try them out:diveintomarkYahoo";
746         $([document.getElementById('first'), document.getElementById('mark')]).insertBefore('#yahoo');
747         ok( expected == $('#en').text(), "Insert array of elements before" );
748         
749         reset();
750         expected = "This is a normal link: Try them out:diveintomarkYahoo";
751         $("#first, #mark").insertBefore('#yahoo');
752         ok( expected == $('#en').text(), "Insert jQuery before" );
753 });
754
755 test("after(String|Element|Array&lt;Element&gt;|jQuery)", function() {
756         expect(4);
757         var expected = 'This is a normal link: Yahoobuga';
758         $('#yahoo').after('<b>buga</b>');
759         ok( expected == $('#en').text(), 'Insert String after' );
760         
761         reset();
762         expected = "This is a normal link: YahooTry them out:";
763         $('#yahoo').after(document.getElementById('first'));
764         ok( expected == $('#en').text(), "Insert element after" );
765
766         reset();
767         expected = "This is a normal link: YahooTry them out:diveintomark";
768         $('#yahoo').after([document.getElementById('first'), document.getElementById('mark')]);
769         ok( expected == $('#en').text(), "Insert array of elements after" );
770         
771         reset();
772         expected = "This is a normal link: YahooTry them out:diveintomark";
773         $('#yahoo').after($("#first, #mark"));
774         ok( expected == $('#en').text(), "Insert jQuery after" );
775 });
776
777 test("insertAfter(String|Element|Array&lt;Element&gt;|jQuery)", function() {
778         expect(4);
779         var expected = 'This is a normal link: Yahoobuga';
780         $('<b>buga</b>').insertAfter('#yahoo');
781         ok( expected == $('#en').text(), 'Insert String after' );
782         
783         reset();
784         expected = "This is a normal link: YahooTry them out:";
785         $(document.getElementById('first')).insertAfter('#yahoo');
786         ok( expected == $('#en').text(), "Insert element after" );
787
788         reset();
789         expected = "This is a normal link: YahooTry them out:diveintomark";
790         $([document.getElementById('mark'), document.getElementById('first')]).insertAfter('#yahoo');
791         ok( expected == $('#en').text(), "Insert array of elements after" );
792         
793         reset();
794         expected = "This is a normal link: YahooTry them out:diveintomark";
795         $("#mark, #first").insertAfter('#yahoo');
796         ok( expected == $('#en').text(), "Insert jQuery after" );
797 });
798
799 test("replaceWith(String|Element|Array&lt;Element&gt;|jQuery)", function() {
800         expect(10);
801         $('#yahoo').replaceWith('<b id="replace">buga</b>');
802         ok( $("#replace")[0], 'Replace element with string' );
803         ok( !$("#yahoo")[0], 'Verify that original element is gone, after string' );
804         
805         reset();
806         $('#yahoo').replaceWith(document.getElementById('first'));
807         ok( $("#first")[0], 'Replace element with element' );
808         ok( !$("#yahoo")[0], 'Verify that original element is gone, after element' );
809
810         reset();
811         $('#yahoo').replaceWith([document.getElementById('first'), document.getElementById('mark')]);
812         ok( $("#first")[0], 'Replace element with array of elements' );
813         ok( $("#mark")[0], 'Replace element with array of elements' );
814         ok( !$("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
815         
816         reset();
817         $('#yahoo').replaceWith($("#first, #mark"));
818         ok( $("#first")[0], 'Replace element with set of elements' );
819         ok( $("#mark")[0], 'Replace element with set of elements' );
820         ok( !$("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
821 });
822
823 test("replaceAll(String|Element|Array&lt;Element&gt;|jQuery)", function() {
824         expect(10);
825         $('<b id="replace">buga</b>').replaceAll("#yahoo");
826         ok( $("#replace")[0], 'Replace element with string' );
827         ok( !$("#yahoo")[0], 'Verify that original element is gone, after string' );
828         
829         reset();
830         $(document.getElementById('first')).replaceAll("#yahoo");
831         ok( $("#first")[0], 'Replace element with element' );
832         ok( !$("#yahoo")[0], 'Verify that original element is gone, after element' );
833
834         reset();
835         $([document.getElementById('first'), document.getElementById('mark')]).replaceAll("#yahoo");
836         ok( $("#first")[0], 'Replace element with array of elements' );
837         ok( $("#mark")[0], 'Replace element with array of elements' );
838         ok( !$("#yahoo")[0], 'Verify that original element is gone, after array of elements' );
839         
840         reset();
841         $("#first, #mark").replaceAll("#yahoo");
842         ok( $("#first")[0], 'Replace element with set of elements' );
843         ok( $("#mark")[0], 'Replace element with set of elements' );
844         ok( !$("#yahoo")[0], 'Verify that original element is gone, after set of elements' );
845 });
846
847 test("end()", function() {
848         expect(3);
849         ok( 'Yahoo' == $('#yahoo').parent().end().text(), 'Check for end' );
850         ok( $('#yahoo').end(), 'Check for end with nothing to end' );
851         
852         var x = $('#yahoo');
853         x.parent();
854         ok( 'Yahoo' == $('#yahoo').text(), 'Check for non-destructive behaviour' );
855 });
856
857 test("find(String)", function() {
858         expect(2);
859         ok( 'Yahoo' == $('#foo').find('.blogTest').text(), 'Check for find' );
860
861         // using contents will get comments regular, text, and comment nodes
862         var j = $("#nonnodes").contents();
863         equals( j.find("div").length, 0, "Check node,textnode,comment to find zero divs" );
864 });
865
866 test("clone()", function() {
867         expect(4);
868         ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Assert text for #en' );
869         var clone = $('#yahoo').clone();
870         ok( 'Try them out:Yahoo' == $('#first').append(clone).text(), 'Check for clone' );
871         ok( 'This is a normal link: Yahoo' == $('#en').text(), 'Reassert text for #en' );
872         // using contents will get comments regular, text, and comment nodes
873         var cl = $("#nonnodes").contents().clone();
874         ok( cl.length >= 2, "Check node,textnode,comment clone works (some browsers delete comments on clone)" );
875 });
876
877 test("is(String)", function() {
878         expect(26);
879         ok( $('#form').is('form'), 'Check for element: A form must be a form' );
880         ok( !$('#form').is('div'), 'Check for element: A form is not a div' );
881         ok( $('#mark').is('.blog'), 'Check for class: Expected class "blog"' );
882         ok( !$('#mark').is('.link'), 'Check for class: Did not expect class "link"' );
883         ok( $('#simon').is('.blog.link'), 'Check for multiple classes: Expected classes "blog" and "link"' );
884         ok( !$('#simon').is('.blogTest'), 'Check for multiple classes: Expected classes "blog" and "link", but not "blogTest"' );
885         ok( $('#en').is('[lang="en"]'), 'Check for attribute: Expected attribute lang to be "en"' );
886         ok( !$('#en').is('[lang="de"]'), 'Check for attribute: Expected attribute lang to be "en", not "de"' );
887         ok( $('#text1').is('[type="text"]'), 'Check for attribute: Expected attribute type to be "text"' );
888         ok( !$('#text1').is('[type="radio"]'), 'Check for attribute: Expected attribute type to be "text", not "radio"' );
889         ok( $('#text2').is(':disabled'), 'Check for pseudoclass: Expected to be disabled' );
890         ok( !$('#text1').is(':disabled'), 'Check for pseudoclass: Expected not disabled' );
891         ok( $('#radio2').is(':checked'), 'Check for pseudoclass: Expected to be checked' );
892         ok( !$('#radio1').is(':checked'), 'Check for pseudoclass: Expected not checked' );
893         ok( $('#foo').is(':has(p)'), 'Check for child: Expected a child "p" element' );
894         ok( !$('#foo').is(':has(ul)'), 'Check for child: Did not expect "ul" element' );
895         ok( $('#foo').is(':has(p):has(a):has(code)'), 'Check for childs: Expected "p", "a" and "code" child elements' );
896         ok( !$('#foo').is(':has(p):has(a):has(code):has(ol)'), 'Check for childs: Expected "p", "a" and "code" child elements, but no "ol"' );
897         ok( !$('#foo').is(0), 'Expected false for an invalid expression - 0' );
898         ok( !$('#foo').is(null), 'Expected false for an invalid expression - null' );
899         ok( !$('#foo').is(''), 'Expected false for an invalid expression - ""' );
900         ok( !$('#foo').is(undefined), 'Expected false for an invalid expression - undefined' );
901         
902         // test is() with comma-seperated expressions
903         ok( $('#en').is('[lang="en"],[lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
904         ok( $('#en').is('[lang="de"],[lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
905         ok( $('#en').is('[lang="en"] , [lang="de"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
906         ok( $('#en').is('[lang="de"] , [lang="en"]'), 'Comma-seperated; Check for lang attribute: Expect en or de' );
907 });
908
909 test("$.extend(Object, Object)", function() {
910         expect(17);
911
912         var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
913                 options = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
914                 optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
915                 merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" },
916                 deep1 = { foo: { bar: true } },
917                 deep1copy = { foo: { bar: true } },
918                 deep2 = { foo: { baz: true }, foo2: document },
919                 deep2copy = { foo: { baz: true }, foo2: document },
920                 deepmerged = { foo: { bar: true, baz: true }, foo2: document };
921
922         jQuery.extend(settings, options);
923         isObj( settings, merged, "Check if extended: settings must be extended" );
924         isObj( options, optionsCopy, "Check if not modified: options must not be modified" );
925
926         jQuery.extend(settings, null, options);
927         isObj( settings, merged, "Check if extended: settings must be extended" );
928         isObj( options, optionsCopy, "Check if not modified: options must not be modified" );
929
930         jQuery.extend(true, deep1, deep2);
931         isObj( deep1.foo, deepmerged.foo, "Check if foo: settings must be extended" );
932         isObj( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" );
933         equals( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" );
934
935         var target = {};
936         var recursive = { foo:target, bar:5 };
937         jQuery.extend(true, target, recursive);
938         isObj( target, { bar:5 }, "Check to make sure a recursive obj doesn't go never-ending loop by not copying it over" );
939
940         var ret = jQuery.extend(true, { foo: [] }, { foo: [0] } ); // 1907
941         ok( ret.foo.length == 1, "Check to make sure a value with coersion 'false' copies over when necessary to fix #1907" );
942
943         var ret = jQuery.extend(true, { foo: "1,2,3" }, { foo: [1, 2, 3] } );
944         ok( typeof ret.foo != "string", "Check to make sure values equal with coersion (but not actually equal) overwrite correctly" );
945
946         var ret = jQuery.extend(true, { foo:"bar" }, { foo:null } );
947         ok( typeof ret.foo !== 'undefined', "Make sure a null value doesn't crash with deep extend, for #1908" );
948
949         var obj = { foo:null };
950         jQuery.extend(true, obj, { foo:"notnull" } );
951         equals( obj.foo, "notnull", "Make sure a null value can be overwritten" );
952
953         function func() {}
954         jQuery.extend(func, { key: "value" } );
955         equals( func.key, "value", "Verify a function can be extended" );
956
957         var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
958                 defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
959                 options1 = { xnumber2: 1, xstring2: "x" },
960                 options1Copy = { xnumber2: 1, xstring2: "x" },
961                 options2 = { xstring2: "xx", xxx: "newstringx" },
962                 options2Copy = { xstring2: "xx", xxx: "newstringx" },
963                 merged2 = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" };
964
965         var settings = jQuery.extend({}, defaults, options1, options2);
966         isObj( settings, merged2, "Check if extended: settings must be extended" );
967         isObj( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
968         isObj( options1, options1Copy, "Check if not modified: options1 must not be modified" );
969         isObj( options2, options2Copy, "Check if not modified: options2 must not be modified" );
970 });
971
972 test("val()", function() {
973         expect(3);
974         ok( $("#text1").val() == "Test", "Check for value of input element" );
975         ok( !$("#text1").val() == "", "Check for value of input element" );
976         // ticket #1714 this caused a JS error in IE
977         ok( $("#first").val() == "", "Check a paragraph element to see if it has a value" );
978 });
979
980 test("val(String)", function() {
981         expect(4);
982         document.getElementById('text1').value = "bla";
983         ok( $("#text1").val() == "bla", "Check for modified value of input element" );
984         $("#text1").val('test');
985         ok ( document.getElementById('text1').value == "test", "Check for modified (via val(String)) value of input element" );
986         
987         $("#select1").val("3");
988         ok( $("#select1").val() == "3", "Check for modified (via val(String)) value of select element" );
989
990         // using contents will get comments regular, text, and comment nodes
991         var j = $("#nonnodes").contents();
992         j.val("asdf");
993         equals( j.val(), "asdf", "Check node,textnode,comment with val()" );
994         j.removeAttr("value");
995 });
996
997 var scriptorder = 0;
998
999 test("html(String)", function() {
1000         expect(11);
1001         var div = $("#main > div");
1002         div.html("<b>test</b>");
1003         var pass = true;
1004         for ( var i = 0; i < div.size(); i++ ) {
1005                 if ( div.get(i).childNodes.length != 1 ) pass = false;
1006         }
1007         ok( pass, "Set HTML" );
1008
1009         reset();
1010         // using contents will get comments regular, text, and comment nodes
1011         var j = $("#nonnodes").contents();
1012         j.html("<b>bold</b>");
1013         equals( j.html().toLowerCase(), "<b>bold</b>", "Check node,textnode,comment with html()" );
1014
1015         $("#main").html("<select/>");
1016         $("#main select").html("<option>O1</option><option selected='selected'>O2</option><option>O3</option>");
1017         equals( $("#main select").val(), "O2", "Selected option correct" );
1018
1019         stop();
1020
1021         $("#main").html('<script type="text/javascript">ok( true, "$().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script>');
1022
1023         $("#main").html('foo <form><script type="text/javascript">ok( true, "$().html().evalScripts() Evals Scripts Twice in Firefox, see #975" );</script></form>');
1024
1025         $("#main").html("<script>ok(scriptorder++ == 0, 'Script is executed in order');ok($('#scriptorder').length == 0,'Execute before html')<\/script><span id='scriptorder'><script>ok(scriptorder++ == 1, 'Script is executed in order');ok($('#scriptorder').length == 1,'Execute after html')<\/script></span><script>ok(scriptorder++ == 2, 'Script is executed in order');ok($('#scriptorder').length == 1,'Execute after html')<\/script>");
1026
1027         setTimeout( start, 100 );
1028 });
1029
1030 test("filter()", function() {
1031         expect(6);
1032         isSet( $("#form input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" );
1033         isSet( $("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" );
1034         isSet( $("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" );
1035         isSet( $("p").filter(function() { return !$("a", this).length }).get(), q("sndp", "first"), "filter(Function)" );
1036
1037         // using contents will get comments regular, text, and comment nodes
1038         var j = $("#nonnodes").contents();
1039         equals( j.filter("span").length, 1, "Check node,textnode,comment to filter the one span" );
1040         equals( j.filter("[name]").length, 0, "Check node,textnode,comment to filter the one span" );
1041 });
1042
1043 test("not()", function() {
1044         expect(3);
1045         ok( $("#main > p#ap > a").not("#google").length == 2, "not('selector')" );
1046         isSet( $("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" );
1047         isSet( $("p").not($("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" );
1048 });
1049
1050 test("andSelf()", function() {
1051         expect(4);
1052         isSet( $("#en").siblings().andSelf().get(), q("sndp", "sap","en"), "Check for siblings and self" );
1053         isSet( $("#foo").children().andSelf().get(), q("sndp", "en", "sap", "foo"), "Check for children and self" );
1054         isSet( $("#en, #sndp").parent().andSelf().get(), q("foo","en","sndp"), "Check for parent and self" );
1055         isSet( $("#groups").parents("p, div").andSelf().get(), q("ap", "main", "groups"), "Check for parents and self" );
1056 });
1057
1058 test("siblings([String])", function() {
1059         expect(5);
1060         isSet( $("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" );
1061         isSet( $("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" ); 
1062         isSet( $("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" );
1063         isSet( $("#foo").siblings("form, b").get(), q("form", "lengthtest", "testForm", "floatTest"), "Check for multiple filters" );
1064         isSet( $("#en, #sndp").siblings().get(), q("sndp", "sap", "en"), "Check for unique results from siblings" );
1065 });
1066
1067 test("children([String])", function() {
1068         expect(3);
1069         isSet( $("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" );
1070         isSet( $("#foo").children(":has(code)").get(), q("sndp", "sap"), "Check for filtered children" );
1071         isSet( $("#foo").children("#en, #sap").get(), q("en", "sap"), "Check for multiple filters" );
1072 });
1073
1074 test("parent([String])", function() {
1075         expect(5);
1076         ok( $("#groups").parent()[0].id == "ap", "Simple parent check" );
1077         ok( $("#groups").parent("p")[0].id == "ap", "Filtered parent check" );
1078         ok( $("#groups").parent("div").length == 0, "Filtered parent check, no match" );
1079         ok( $("#groups").parent("div, p")[0].id == "ap", "Check for multiple filters" );
1080         isSet( $("#en, #sndp").parent().get(), q("foo"), "Check for unique results from parent" );
1081 });
1082         
1083 test("parents([String])", function() {
1084         expect(5);
1085         ok( $("#groups").parents()[0].id == "ap", "Simple parents check" );
1086         ok( $("#groups").parents("p")[0].id == "ap", "Filtered parents check" );
1087         ok( $("#groups").parents("div")[0].id == "main", "Filtered parents check2" );
1088         isSet( $("#groups").parents("p, div").get(), q("ap", "main"), "Check for multiple filters" );
1089         isSet( $("#en, #sndp").parents().get(), q("foo", "main", "dl", "body", "html"), "Check for unique results from parents" );
1090 });
1091
1092 test("next([String])", function() {
1093         expect(4);
1094         ok( $("#ap").next()[0].id == "foo", "Simple next check" );
1095         ok( $("#ap").next("div")[0].id == "foo", "Filtered next check" );
1096         ok( $("#ap").next("p").length == 0, "Filtered next check, no match" );
1097         ok( $("#ap").next("div, p")[0].id == "foo", "Multiple filters" );
1098 });
1099         
1100 test("prev([String])", function() {
1101         expect(4);
1102         ok( $("#foo").prev()[0].id == "ap", "Simple prev check" );
1103         ok( $("#foo").prev("p")[0].id == "ap", "Filtered prev check" );
1104         ok( $("#foo").prev("div").length == 0, "Filtered prev check, no match" );
1105         ok( $("#foo").prev("p, div")[0].id == "ap", "Multiple filters" );
1106 });
1107
1108 test("show()", function() {
1109         expect(15);
1110         var pass = true, div = $("div");
1111         div.show().each(function(){
1112                 if ( this.style.display == "none" ) pass = false;
1113         });
1114         ok( pass, "Show" );
1115         
1116         $("#main").append('<div id="show-tests"><div><p><a href="#"></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div>');
1117         var test = {
1118                 "div"      : "block",
1119                 "p"        : "block",
1120                 "a"        : "inline",
1121                 "code"     : "inline",
1122                 "pre"      : "block",
1123                 "span"     : "inline",
1124                 "table"    : $.browser.msie ? "block" : "table",
1125                 "thead"    : $.browser.msie ? "block" : "table-header-group",
1126                 "tbody"    : $.browser.msie ? "block" : "table-row-group",
1127                 "tr"       : $.browser.msie ? "block" : "table-row",
1128                 "th"       : $.browser.msie ? "block" : "table-cell",
1129                 "td"       : $.browser.msie ? "block" : "table-cell",
1130                 "ul"       : "block",
1131                 "li"       : $.browser.msie ? "block" : "list-item"
1132         };
1133         
1134         $.each(test, function(selector, expected) {
1135                 var elem = $(selector, "#show-tests").show();
1136                 equals( elem.css("display"), expected, "Show using correct display type for " + selector );
1137         });
1138 });
1139
1140 test("addClass(String)", function() {
1141         expect(2);
1142         var div = $("div");
1143         div.addClass("test");
1144         var pass = true;
1145         for ( var i = 0; i < div.size(); i++ ) {
1146          if ( div.get(i).className.indexOf("test") == -1 ) pass = false;
1147         }
1148         ok( pass, "Add Class" );
1149
1150         // using contents will get regular, text, and comment nodes
1151         var j = $("#nonnodes").contents();
1152         j.addClass("asdf");
1153         ok( j.hasClass("asdf"), "Check node,textnode,comment for addClass" );
1154 });
1155
1156 test("removeClass(String) - simple", function() {
1157         expect(4);
1158         var div = $("div").addClass("test").removeClass("test"),
1159                 pass = true;
1160         for ( var i = 0; i < div.size(); i++ ) {
1161                 if ( div.get(i).className.indexOf("test") != -1 ) pass = false;
1162         }
1163         ok( pass, "Remove Class" );
1164         
1165         reset();
1166         var div = $("div").addClass("test").addClass("foo").addClass("bar");
1167         div.removeClass("test").removeClass("bar").removeClass("foo");
1168         var pass = true;
1169         for ( var i = 0; i < div.size(); i++ ) {
1170          if ( div.get(i).className.match(/test|bar|foo/) ) pass = false;
1171         }
1172         ok( pass, "Remove multiple classes" );
1173         
1174         reset();
1175         var div = $("div:eq(0)").addClass("test").removeClass("");
1176         ok( div.is('.test'), "Empty string passed to removeClass" );
1177         
1178         // using contents will get regular, text, and comment nodes
1179         var j = $("#nonnodes").contents();
1180         j.removeClass("asdf");
1181         ok( !j.hasClass("asdf"), "Check node,textnode,comment for removeClass" );
1182 });
1183
1184 test("toggleClass(String)", function() {
1185         expect(3);
1186         var e = $("#firstp");
1187         ok( !e.is(".test"), "Assert class not present" );
1188         e.toggleClass("test");
1189         ok( e.is(".test"), "Assert class present" ); 
1190         e.toggleClass("test");
1191         ok( !e.is(".test"), "Assert class not present" );
1192 });
1193
1194 test("removeAttr(String", function() {
1195         expect(1);
1196         ok( $('#mark').removeAttr("class")[0].className == "", "remove class" );
1197 });
1198
1199 test("text(String)", function() {
1200         expect(4);
1201         ok( $("#foo").text("<div><b>Hello</b> cruel world!</div>")[0].innerHTML == "&lt;div&gt;&lt;b&gt;Hello&lt;/b&gt; cruel world!&lt;/div&gt;", "Check escaped text" );
1202
1203         // using contents will get comments regular, text, and comment nodes
1204         var j = $("#nonnodes").contents();
1205         j.text("hi!");
1206         equals( $(j[0]).text(), "hi!", "Check node,textnode,comment with text()" );
1207         equals( j[1].nodeValue, " there ", "Check node,textnode,comment with text()" );
1208         equals( j[2].nodeType, 8, "Check node,textnode,comment with text()" );
1209 });
1210
1211 test("$.each(Object,Function)", function() {
1212         expect(8);
1213         $.each( [0,1,2], function(i, n){
1214                 ok( i == n, "Check array iteration" );
1215         });
1216         
1217         $.each( [5,6,7], function(i, n){
1218                 ok( i == n - 5, "Check array iteration" );
1219         });
1220          
1221         $.each( { name: "name", lang: "lang" }, function(i, n){
1222                 ok( i == n, "Check object iteration" );
1223         });
1224 });
1225
1226 test("$.prop", function() {
1227         expect(2);
1228         var handle = function() { return this.id };
1229         ok( $.prop($("#ap")[0], handle) == "ap", "Check with Function argument" );
1230         ok( $.prop($("#ap")[0], "value") == "value", "Check with value argument" );
1231 });
1232
1233 test("$.className", function() {
1234         expect(6);
1235         var x = $("<p>Hi</p>")[0];
1236         var c = $.className;
1237         c.add(x, "hi");
1238         ok( x.className == "hi", "Check single added class" );
1239         c.add(x, "foo bar");
1240         ok( x.className == "hi foo bar", "Check more added classes" );
1241         c.remove(x);
1242         ok( x.className == "", "Remove all classes" );
1243         c.add(x, "hi foo bar");
1244         c.remove(x, "foo");
1245         ok( x.className == "hi bar", "Check removal of one class" );
1246         ok( c.has(x, "hi"), "Check has1" );
1247         ok( c.has(x, "bar"), "Check has2" );
1248 });
1249
1250 test("remove()", function() {
1251         expect(6);
1252         $("#ap").children().remove();
1253         ok( $("#ap").text().length > 10, "Check text is not removed" );
1254         ok( $("#ap").children().length == 0, "Check remove" );
1255         
1256         reset();
1257         $("#ap").children().remove("a");
1258         ok( $("#ap").text().length > 10, "Check text is not removed" );
1259         ok( $("#ap").children().length == 1, "Check filtered remove" );
1260
1261         // using contents will get comments regular, text, and comment nodes
1262         equals( $("#nonnodes").contents().length, 3, "Check node,textnode,comment remove works" );
1263         $("#nonnodes").contents().remove();
1264         equals( $("#nonnodes").contents().length, 0, "Check node,textnode,comment remove works" );
1265 });
1266
1267 test("empty()", function() {
1268         expect(3);
1269         ok( $("#ap").children().empty().text().length == 0, "Check text is removed" );
1270         ok( $("#ap").children().length == 4, "Check elements are not removed" );
1271
1272         // using contents will get comments regular, text, and comment nodes
1273         var j = $("#nonnodes").contents();
1274         j.empty();
1275         equals( j.html(), "", "Check node,textnode,comment empty works" );
1276 });
1277
1278 test("slice()", function() {
1279         expect(5);
1280         isSet( $("#ap a").slice(1,2), q("groups"), "slice(1,2)" );
1281         isSet( $("#ap a").slice(1), q("groups", "anchor1", "mark"), "slice(1)" );
1282         isSet( $("#ap a").slice(0,3), q("google", "groups", "anchor1"), "slice(0,3)" );
1283         isSet( $("#ap a").slice(-1), q("mark"), "slice(-1)" );
1284
1285         isSet( $("#ap a").eq(1), q("groups"), "eq(1)" );
1286 });
1287
1288 test("map()", function() {
1289         expect(2);
1290
1291         isSet(
1292                 $("#ap").map(function(){
1293                         return $(this).find("a").get();
1294                 }),
1295                 q("google", "groups", "anchor1", "mark"),
1296                 "Array Map"
1297         );
1298
1299         isSet(
1300                 $("#ap > a").map(function(){
1301                         return this.parentNode;
1302                 }),
1303                 q("ap","ap","ap"),
1304                 "Single Map"
1305         );
1306 });
1307
1308 test("contents()", function() {
1309         expect(12);
1310         equals( $("#ap").contents().length, 9, "Check element contents" );
1311         ok( $("#iframe").contents()[0], "Check existance of IFrame document" );
1312         var ibody = $("#loadediframe").contents()[0].body;
1313         ok( ibody, "Check existance of IFrame body" );
1314
1315         equals( $("span", ibody).text(), "span text", "Find span in IFrame and check its text" );
1316
1317         $(ibody).append("<div>init text</div>");
1318         equals( $("div", ibody).length, 2, "Check the original div and the new div are in IFrame" );
1319
1320         equals( $("div:last", ibody).text(), "init text", "Add text to div in IFrame" );
1321
1322         $("div:last", ibody).text("div text");
1323         equals( $("div:last", ibody).text(), "div text", "Add text to div in IFrame" );
1324
1325         $("div:last", ibody).remove();
1326         equals( $("div", ibody).length, 1, "Delete the div and check only one div left in IFrame" );
1327
1328         equals( $("div", ibody).text(), "span text", "Make sure the correct div is still left after deletion in IFrame" );
1329
1330         $("<table/>", ibody).append("<tr><td>cell</td></tr>").appendTo(ibody);
1331         $("table", ibody).remove();
1332         equals( $("div", ibody).length, 1, "Check for JS error on add and delete of a table in IFrame" );
1333
1334         // using contents will get comments regular, text, and comment nodes
1335         var c = $("#nonnodes").contents().contents();
1336         equals( c.length, 1, "Check node,textnode,comment contents is just one" );
1337         equals( c[0].nodeValue, "hi", "Check node,textnode,comment contents is just the one from span" );
1338 });