X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=test%2Funit%2Fcore.js;h=590bb0c869f70e56e50bdee098d0b2564916d344;hb=d6f03aa0df4f734f6f09bf82effa5b7fcd8487fc;hp=a61f8ba0f23348ac2a45bff44b9e2267fe3bc14a;hpb=ea9e0ed841f0f2851162e01d5199052872ba7483;p=jquery.git diff --git a/test/unit/core.js b/test/unit/core.js index a61f8ba..590bb0c 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -25,7 +25,7 @@ test("jQuery()", function() { equals( jQuery(obj).selector, "div", "jQuery(jQueryObj) == jQueryObj" ); // can actually yield more than one, when iframes are included, the window is an array as well - equals( 1, jQuery(window).length, "Correct number of elements generated for jQuery(window)" ); + equals( jQuery(window).length, 1, "Correct number of elements generated for jQuery(window)" ); var main = jQuery("#main"); @@ -201,14 +201,20 @@ test("noConflict", function() { }); test("trim", function() { - expect(4); + expect(9); - var nbsp = String.fromCharCode(160); + var nbsp = String.fromCharCode(160); - equals( jQuery.trim("hello "), "hello", "trailing space" ); - equals( jQuery.trim(" hello"), "hello", "leading space" ); - equals( jQuery.trim(" hello "), "hello", "space on both sides" ); - equals( jQuery.trim(" " + nbsp + "hello " + nbsp + " "), "hello", " " ); + equals( jQuery.trim("hello "), "hello", "trailing space" ); + equals( jQuery.trim(" hello"), "hello", "leading space" ); + equals( jQuery.trim(" hello "), "hello", "space on both sides" ); + equals( jQuery.trim(" " + nbsp + "hello " + nbsp + " "), "hello", " " ); + + equals( jQuery.trim(), "", "Nothing in." ); + equals( jQuery.trim( undefined ), "", "Undefined" ); + equals( jQuery.trim( null ), "", "Null" ); + equals( jQuery.trim( 5 ), "5", "Number" ); + equals( jQuery.trim( false ), "false", "Boolean" ); }); test("isPlainObject", function() { @@ -265,7 +271,7 @@ test("isPlainObject", function() { var doc = iframe.contentDocument || iframe.contentWindow.document; doc.open(); - doc.write(""); + doc.write(""); doc.close(); }); @@ -805,3 +811,30 @@ test("jQuery.proxy", function(){ // Use the string shortcut jQuery.proxy( thisObject, "method" )(); }); + +test("jQuery.parseJSON", function(){ + expect(8); + + equals( jQuery.parseJSON(), null, "Nothing in, null out." ); + equals( jQuery.parseJSON( null ), null, "Nothing in, null out." ); + equals( jQuery.parseJSON( "" ), null, "Nothing in, null out." ); + + same( jQuery.parseJSON("{}"), {}, "Plain object parsing." ); + same( jQuery.parseJSON('{"test":1}'), {"test":1}, "Plain object parsing." ); + + same( jQuery.parseJSON('\n{"test":1}'), {"test":1}, "Make sure leading whitespaces are handled." ); + + try { + jQuery.parseJSON("{a:1}"); + ok( false, "Test malformed JSON string." ); + } catch( e ) { + ok( true, "Test malformed JSON string." ); + } + + try { + jQuery.parseJSON("{'a':1}"); + ok( false, "Test malformed JSON string." ); + } catch( e ) { + ok( true, "Test malformed JSON string." ); + } +});