diff options
author | Catatonic Prime <catatonicprime@gmail.com> | 2014-09-12 12:56:32 -0400 |
---|---|---|
committer | Catatonic Prime <catatonicprime@gmail.com> | 2014-09-12 12:56:32 -0400 |
commit | 320c79c720443b8ad4a0cf903da372e687422d6c (patch) | |
tree | 9b9367d3c9a988e104459c73fd5bd3e826fb780b /test/json_test.js | |
parent | 3c8fe5b3d6074405b562166e318fc6438bec3f65 (diff) | |
download | sjcl-320c79c720443b8ad4a0cf903da372e687422d6c.zip sjcl-320c79c720443b8ad4a0cf903da372e687422d6c.tar.gz sjcl-320c79c720443b8ad4a0cf903da372e687422d6c.tar.bz2 |
Updates for convenience JSON decoding
- Handle booleans
- Handle negative integers
- Handle spaces between values
Updates for JSON Tests
- Needed modification because arrays are serialized to base64 strings
- Using === instead == for comparing encode(decode(str)) === str check
Diffstat (limited to 'test/json_test.js')
-rw-r--r-- | test/json_test.js | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/test/json_test.js b/test/json_test.js index b2110e2..5052143 100644 --- a/test/json_test.js +++ b/test/json_test.js @@ -40,7 +40,8 @@ new sjcl.test.TestCase("JSON Decode Test", function (cb) { } var str = ''; var i; - str = '{"int":4,"nint":-5,"str":"string","iv":[0,1,2,3],"truth":true,"lie":false}'; + str = '{"int":4,"nint":-5,"str":"string","iv":"/////wAAAAAAAAABAAAAAg==","truth":true,"lie":false}'; + try { var obj = sjcl.json.decode(str); this.require(obj.int === 4); @@ -49,11 +50,11 @@ new sjcl.test.TestCase("JSON Decode Test", function (cb) { this.require(obj.truth === true); this.require(obj.lie === false); for(i in obj.iv) { - this.require(obj.iv[i] == i); + this.require(obj.iv[i] == (i-1)); //Array in iv is [-1,0,1,2] } } catch (e) { this.fail(e); } - str = '{ "int" : 4, "nint" : -5,"str":"string", "iv": [0,1 , 2 ,3],"truth": true,"lie": false }'; + str = '{ "int" : 4, "nint" : -5,"str":"string", "iv": "/////wAAAAAAAAABAAAAAg==","truth": true,"lie": false }'; try { var obj = sjcl.json.decode(str); this.require(obj.int === 4); @@ -62,7 +63,7 @@ new sjcl.test.TestCase("JSON Decode Test", function (cb) { this.require(obj.truth === true); this.require(obj.lie === false); for(i in obj.iv) { - this.require(obj.iv[i] == i); + this.require(obj.iv[i] == (i-1)); //Array in iv is [-1,0,1,2] } } catch (e) { this.fail(e); } @@ -89,7 +90,6 @@ new sjcl.test.TestCase("JSON Commutative Test", function (cb) { obj1.iv = [ -95577995, -949876189, 1443400017, 697058741 ]; obj1.truth = true; obj1.lie = false; - obj1.udef = undefined; var str1 = ''; var str2 = ''; @@ -104,7 +104,7 @@ new sjcl.test.TestCase("JSON Commutative Test", function (cb) { } try { - this.require(str1 == str2); + this.require(str1 === str2); this.require(obj1.int == obj2.int); this.require(obj1.str == obj2.str); this.require(obj1.lie == obj2.lie); |