X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;f=test%2Funit%2Fcore.js;h=b2cf8f137e8a1cf97373e1359b92e635c06ade81;hb=c39bd07cc9f408d5680ba565e2a2fe71bbdc64b9;hp=835dde61efafbc099594914c20535fa847a502c9;hpb=948753842bd5aeda6ad6e27c269d706675f488d1;p=jquery.git diff --git a/test/unit/core.js b/test/unit/core.js index 835dde6..b2cf8f1 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -43,6 +43,42 @@ test("$()", function() { equals( div.length, 4, "Correct number of elements generated for div hr code b" ); }); +test("browser", function() { + expect(13); + var browsers = { + //Internet Explorer + "Mozilla/5.0 (Windows; U; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)": "6.0", + "Mozilla/4.0 (compatible; MSIE 7.0b; Windows NT 5.1; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727)": "7.0", + /** Failing #1876 + * "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1) ; .NET CLR 2.0.50727; .NET CLR 1.1.4322; .NET CLR 3.0.04506.30)": "7.0", + */ + //Browsers with Gecko engine + //Mozilla + "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915" : "1.7.12", + //Firefox + "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3": "1.8.1.3", + //Netscape + "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.5) Gecko/20070321 Netscape/8.1.3" : "1.7.5", + //Flock + "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.11) Gecko/20070321 Firefox/1.5.0.11 Flock/0.7.12" : "1.8.0.11", + //Opera browser + "Opera/9.20 (X11; Linux x86_64; U; en)": "9.20", + "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; en) Opera 9.20" : "9.20", + "Mozilla/5.0 (Windows NT 5.1; U; pl; rv:1.8.0) Gecko/20060728 Firefox/1.5.0 Opera 9.20": "9.20", + //WebKit engine + "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; sv-se) AppleWebKit/418.9 (KHTML, like Gecko) Safari/419.3": "418.9", + "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/418.8 (KHTML, like Gecko) Safari/419.3" : "418.8", + "Mozilla/5.0 (Macintosh; U; PPC Mac OS X; sv-se) AppleWebKit/312.8 (KHTML, like Gecko) Safari/312.5": "312.8", + //Other user agent string + "Other browser's user agent 1.0":null + }; + for (var i in browsers) { + var v = i.toLowerCase().match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ); // RegEx from Core jQuery.browser.version check + version = v ? v[1] : null; + equals( version, browsers[i], "Checking UA string" ); + } +}); + test("noConflict", function() { expect(6); @@ -1278,7 +1314,7 @@ test("text(String)", function() { }); test("$.each(Object,Function)", function() { - expect(8); + expect(12); $.each( [0,1,2], function(i, n){ ok( i == n, "Check array iteration" ); }); @@ -1290,6 +1326,19 @@ test("$.each(Object,Function)", function() { $.each( { name: "name", lang: "lang" }, function(i, n){ ok( i == n, "Check object iteration" ); }); + + var total = 0; + jQuery.each([1,2,3], function(i,v){ total += v; }); + ok( total == 6, "Looping over an array" ); + total = 0; + jQuery.each([1,2,3], function(i,v){ total += v; if ( i == 1 ) return false; }); + ok( total == 3, "Looping over an array, with break" ); + total = 0; + jQuery.each({"a":1,"b":2,"c":3}, function(i,v){ total += v; }); + ok( total == 6, "Looping over an object" ); + total = 0; + jQuery.each({"a":3,"b":3,"c":3}, function(i,v){ total += v; return false; }); + ok( total == 3, "Looping over an object, with break" ); }); test("$.prop", function() {