t; ); deepEqual( jQuery.parseJSON("[ \"string\", -4.2, 2.7180e0, 3.14E-1, {}, [], true, false, null ]"), [ "string", -4.2, 2.718, 0.314, {}, [], true, false, null ], "Array of all data types" ); deepEqual( jQuery.parseJSON( "{ \"string\": \"\", \"number\": 4.2e+1, \"object\": {}," + "\"array\": [[]], \"boolean\": [ true, false ], \"null\": null }"), { string: "", number: 42, object: {}, array: [[]], boolean: [ true, false ], "null": null }, "Dictionary of all data types" ); deepEqual( jQuery.parseJSON("\n{\"test\":1}\t"), { "test": 1 }, "Leading and trailing whitespace are ignored" ); throws(function() { jQuery.parseJSON(); }, null, "Undefined raises an error" ); throws(function() { jQuery.parseJSON( "" ); }, null, "Empty string raises an error" ); throws(function() { jQuery.parseJSON("''"); }, null, "Single-quoted string raises an error" ); /* // Broken on IE8 throws(function() { jQuery.parseJSON("\" \\a \""); }, null, "Invalid string escape raises an error" ); // Broken on IE8, Safari 5.1 Windows throws(function() { jQuery.parseJSON("\"\t\""); }, null, "Unescaped control character raises an error" ); // Broken on IE8 throws(function() { jQuery.parseJSON(".123"); }, null, "Number with no integer component raises an error" ); */ throws(function() { var result = jQuery.parseJSON("0101"); // Support: IE9+ // Ensure base-10 interpretation on browsers that erroneously accept leading-zero numbers if ( result === 101 ) { throw new Error("close enough"); } }, null, "Leading-zero number raises an error or is parsed as decimal" ); throws(function() { jQuery.parseJSON("{a:1}"); }, null, "Unquoted property raises an error" ); throws(function() { jQuery.parseJSON("{'a':1}"); }, null, "Single-quoted property raises an error" ); throws(function() { jQuery.parseJSON("[,]"); }, null, "Array element elision raises an error" ); throws(function() { jQuery.parseJSON("{},[]"); }, null, "Comma expression raises an error" ); throws(function() { jQuery.parseJSON("[]\n,{}"); }, null, "Newline-containing comma expression raises an error" ); throws(function() { jQuery.parseJSON("\"\"\n\"\""); }, null, "Automatic semicolon insertion raises an error" ); strictEqual( jQuery.parseJSON([ 0 ]), 0, "Input cast to string" ); }); test("jQuery.parseXML", 8, function(){ var xml, tmp; try { xml = jQuery.parseXML( "<p>A <b>well-formed</b> xml string</p>" ); tmp = xml.getElementsByTagName( "p" )[ 0 ]; ok( !!tmp, "<p> present in document" ); tmp = tmp.getElementsByTagName( "b" )[ 0 ]; ok( !!tmp, "<b> present in document" ); strictEqual( tmp.childNodes[ 0 ].nodeValue, "well-formed", "<b> text is as expected" ); } catch (e) { strictEqual( e, undefined, "unexpected error" ); } try { xml = jQuery.parseXML( "<p>Not a <<b>well-formed</b> xml string</p>" ); ok( false, "invalid xml not detected" ); } catch( e ) { strictEqual( e.message, "Invalid XML: <p>Not a <<b>well-formed</b> xml string</p>", "invalid xml detected" ); } try { xml = jQuery.parseXML( "" ); strictEqual( xml, null, "empty string => null document" ); xml = jQuery.parseXML(); strictEqual( xml, null, "undefined string => null document" ); xml = jQuery.parseXML( null ); strictEqual( xml, null, "null string => null document" ); xml = jQuery.parseXML( true ); strictEqual( xml, null, "non-string => null document" ); } catch( e ) { ok( false, "empty input throws exception" ); } }); test("jQuery.camelCase()", function() { var tests = { "foo-bar": "fooBar", "foo-bar-baz": "fooBarBaz", "girl-u-want": "girlUWant", "the-4th-dimension": "the4thDimension", "-o-tannenbaum": "OTannenbaum", "-moz-illa": "MozIlla", "-ms-take": "msTake" }; expect(7); jQuery.each( tests, function( key, val ) { equal( jQuery.camelCase( key ), val, "Converts: " + key + " => " + val ); }); }); testIframeWithCallback( "Conditional compilation compatibility (#13274)", "core/cc_on.html", function( cc_on, errors, $ ) { expect( 3 ); ok( true, "JScript conditional compilation " + ( cc_on ? "supported" : "not supported" ) ); deepEqual( errors, [], "No errors" ); ok( $(), "jQuery executes" ); }); // iOS7 doesn't fire the load event if the long-loading iframe gets its source reset to about:blank. // This makes this test fail but it doesn't seem to cause any real-life problems so blacklisting // this test there is preferred to complicating the hard-to-test core/ready code further. if ( !/iphone os 7_/i.test( navigator.userAgent ) ) { testIframeWithCallback( "document ready when jQuery loaded asynchronously (#13655)", "core/dynamic_ready.html", function( ready ) { expect( 1 ); equal( true, ready, "document ready correctly fired when jQuery is loaded after DOMContentLoaded" ); }); } testIframeWithCallback( "Tolerating alias-masked DOM properties (#14074)", "core/aliased.html", function( errors ) { expect( 1 ); deepEqual( errors, [], "jQuery loaded" ); } ); testIframeWithCallback( "Don't call window.onready (#14802)", "core/onready.html", function( error ) { expect( 1 ); equal( error, false, "no call to user-defined onready" ); } );