X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fcore.js;h=8cd1aee9a91b66d31f65c5ffd75709f9031f483b;hb=77bb2c505f1d2c4437f4b52866408f8bd1a5020f;hp=80e92e6bec958a4056c64087ab807f78956b3fe7;hpb=77da94552e94925e990d058ed81419d0835747ce;p=jquery.git diff --git a/test/unit/core.js b/test/unit/core.js index 80e92e6..8cd1aee 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -1398,7 +1398,7 @@ test("$.data", function() { }); test(".data()", function() { - expect(11); + expect(16); var div = $("#foo"); ok( div.data("test") == undefined, "Check for no data exists" ); div.data("test", "success"); @@ -1406,25 +1406,41 @@ test(".data()", function() { div.data("test", "overwritten"); ok( div.data("test") == "overwritten", "Check for overwritten data" ); - var hits = 0; + var hits = {test:0}, gets = {test:0}; div - .bind("set-test",function(){ hits += 1; }) - .bind("set-test.foo",function(){ hits += 2; }) + .bind("setData",function(e,key,value){ hits[key] += value; }) + .bind("setData.foo",function(e,key,value){ hits[key] += value; }) + .bind("getData",function(e,key){ gets[key] += 1; }) + .bind("getData.foo",function(e,key){ gets[key] += 3; }); - div.data("test.foo", "foodata"); + div.data("test.foo", 2); ok( div.data("test") == "overwritten", "Check for original data" ); - ok( div.data("test.foo") == "foodata", "Check for namespaced data" ); + ok( div.data("test.foo") == 2, "Check for namespaced data" ); ok( div.data("test.bar") == "overwritten", "Check for unmatched namespace" ); - ok( hits == 2, "Check triggered functions" ); + equals( hits.test, 2, "Check triggered setter functions" ); + equals( gets.test, 5, "Check triggered getter functions" ); + + hits.test = 0; + gets.test = 0; + + div.data("test", 1); + ok( div.data("test") == 1, "Check for original data" ); + ok( div.data("test.foo") == 2, "Check for namespaced data" ); + ok( div.data("test.bar") == 1, "Check for unmatched namespace" ); + equals( hits.test, 1, "Check triggered setter functions" ); + equals( gets.test, 5, "Check triggered getter functions" ); - hits = 0; + hits.test = 0; + gets.test = 0; + + div + .bind("getData",function(e,key){ return key + "root"; }) + .bind("getData.foo",function(e,key){ return key + "foo"; }); - div.data("test", "overwritten2"); - ok( div.data("test") == "overwritten2", "Check for original data" ); - ok( div.data("test.foo") == "foodata", "Check for namespaced data" ); - ok( div.data("test.bar") == "overwritten2", "Check for unmatched namespace" ); - ok( hits == 1, "Check triggered functions" ); + ok( div.data("test") == "testroot", "Check for original data" ); + ok( div.data("test.foo") == "testfoo", "Check for namespaced data" ); + ok( div.data("test.bar") == "testroot", "Check for unmatched namespace" ); }); test("$.removeData", function() { @@ -1545,3 +1561,34 @@ test("contents()", function() { equals( c.length, 1, "Check node,textnode,comment contents is just one" ); equals( c[0].nodeValue, "hi", "Check node,textnode,comment contents is just the one from span" ); }); + +test("$.makeArray", function(){ + expect(13); + + equals( $.makeArray(document.getElementsByName("PWD")).slice(0,1)[0].name, "PWD", "Pass makeArray a nodelist" ); + + equals( (function(){ return $.makeArray(arguments); })(1,2).join(""), "12", "Pass makeArray an arguments array" ); + + equals( $.makeArray([1,2,3]).join(""), "123", "Pass makeArray a real array" ); + + equals( $.makeArray().length, 0, "Pass nothing to makeArray and expect an empty array" ); + + equals( $.makeArray( 0 )[0], 0 , "Pass makeArray a number" ); + + equals( $.makeArray( "foo" )[0], "foo", "Pass makeArray a string" ); + + equals( $.makeArray( true )[0].constructor, Boolean, "Pass makeArray a boolean" ); + + equals( $.makeArray( document.createElement("div") )[0].nodeName, "DIV", "Pass makeArray a single node" ); + + equals( $.makeArray( {length:2, 0:"a", 1:"b"} ).join(""), "ab", "Pass makeArray an array like map (with length)" ); + + equals( $.makeArray( document.documentElement.childNodes ).slice(0,1)[0].nodeName, "HEAD", "Pass makeArray a childNodes array" ); + + //function, is tricky as it has length + equals( $.makeArray( function(){ return 1;} )[0](), 1, "Pass makeArray a function" ); + //window, also has length + equals( $.makeArray(window)[0], window, "Pass makeArray the window" ); + + equals( $.makeArray(/a/)[0].constructor, RegExp, "Pass makeArray a regex" ); +}); \ No newline at end of file