aboutsummaryrefslogtreecommitdiffstats
path: root/test/unit/deprecated.js
diff options
context:
space:
mode:
authorMichał Gołębiowski <m.goleb@gmail.com>2016-02-24 23:47:19 +0100
committerMichał Gołębiowski <m.goleb@gmail.com>2016-03-02 13:12:35 +0100
commit93a8fa6bfc1c8a469e188630b61e736dfb69e128 (patch)
tree47494be97e64818ae3f627c97530240f8f0d10a7 /test/unit/deprecated.js
parent8a91f8442f4d31bdd4b43035ee88d40fbb116f64 (diff)
downloadjquery-93a8fa6bfc1c8a469e188630b61e736dfb69e128.tar.gz
jquery-93a8fa6bfc1c8a469e188630b61e736dfb69e128.zip
Core: Deprecate jQuery.parseJSON
Fixes gh-2800 Closes gh-2948
Diffstat (limited to 'test/unit/deprecated.js')
-rw-r--r--test/unit/deprecated.js72
1 files changed, 71 insertions, 1 deletions
diff --git a/test/unit/deprecated.js b/test/unit/deprecated.js
index 797290f3b..baf4562b1 100644
--- a/test/unit/deprecated.js
+++ b/test/unit/deprecated.js
@@ -39,4 +39,74 @@ QUnit.test( "delegate/undelegate", function( assert ) {
.end()
.undelegate( "b", "click" )
.remove();
-} ); \ No newline at end of file
+} );
+
+QUnit.test( "jQuery.parseJSON", function( assert ) {
+ assert.expect( 20 );
+
+ assert.strictEqual( jQuery.parseJSON( null ), null, "primitive null" );
+ assert.strictEqual( jQuery.parseJSON( "0.88" ), 0.88, "Number" );
+ assert.strictEqual(
+ jQuery.parseJSON( "\" \\\" \\\\ \\/ \\b \\f \\n \\r \\t \\u007E \\u263a \"" ),
+ " \" \\ / \b \f \n \r \t ~ \u263A ",
+ "String escapes"
+ );
+ assert.deepEqual( jQuery.parseJSON( "{}" ), {}, "Empty object" );
+ assert.deepEqual( jQuery.parseJSON( "{\"test\":1}" ), { "test": 1 }, "Plain object" );
+ assert.deepEqual( jQuery.parseJSON( "[0]" ), [ 0 ], "Simple array" );
+
+ assert.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"
+ );
+ assert.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"
+ );
+
+ assert.deepEqual( jQuery.parseJSON( "\n{\"test\":1}\t" ), { "test": 1 },
+ "Leading and trailing whitespace are ignored" );
+
+ assert.throws( function() {
+ jQuery.parseJSON();
+ }, null, "Undefined raises an error" );
+ assert.throws( function() {
+ jQuery.parseJSON( "" );
+ }, null, "Empty string raises an error" );
+ assert.throws( function() {
+ jQuery.parseJSON( "''" );
+ }, null, "Single-quoted string raises an error" );
+
+ assert.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" );
+ assert.throws( function() {
+ jQuery.parseJSON( "{a:1}" );
+ }, null, "Unquoted property raises an error" );
+ assert.throws( function() {
+ jQuery.parseJSON( "{'a':1}" );
+ }, null, "Single-quoted property raises an error" );
+ assert.throws( function() {
+ jQuery.parseJSON( "[,]" );
+ }, null, "Array element elision raises an error" );
+ assert.throws( function() {
+ jQuery.parseJSON( "{},[]" );
+ }, null, "Comma expression raises an error" );
+ assert.throws( function() {
+ jQuery.parseJSON( "[]\n,{}" );
+ }, null, "Newline-containing comma expression raises an error" );
+ assert.throws( function() {
+ jQuery.parseJSON( "\"\"\n\"\"" );
+ }, null, "Automatic semicolon insertion raises an error" );
+
+ assert.strictEqual( jQuery.parseJSON( [ 0 ] ), 0, "Input cast to string" );
+} );