From 743e525076053f5e407385ba29c45c21b9241971 Mon Sep 17 00:00:00 2001 From: dbs Date: Tue, 29 Mar 2011 02:09:16 +0000 Subject: [PATCH] A few more tests for JSON_v1.js We're not really touching the interesting parts of encodeJS/decodeJS yet, but at least we get to open the door a crack. git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@2219 9efc2488-bf62-4759-914b-345cdb29e865 --- src/javascript/tests/testJSON_v1.js | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/javascript/tests/testJSON_v1.js b/src/javascript/tests/testJSON_v1.js index d6d3b07..1cd7d10 100644 --- a/src/javascript/tests/testJSON_v1.js +++ b/src/javascript/tests/testJSON_v1.js @@ -6,6 +6,16 @@ doh.register("JSONTests", [ function test_version() { doh.assertTrue(JSON_version() == 'wrapper'); }, + function test_decodeJS() { + doh.assertTrue(decodeJS(0) === 0); + doh.assertTrue(decodeJS(null) === null); + doh.assertTrue(decodeJS("") === ""); + }, + function test_encodeJS() { + doh.assertTrue(encodeJS(0) === 0); + doh.assertTrue(encodeJS(null) === null); + doh.assertTrue(encodeJS("") === ""); + }, function test_js2JSON() { // Solo nulls and booleans are stringified XXX doh.assertTrue(js2JSON(null) === "null"); @@ -44,6 +54,27 @@ doh.register("JSONTests", [ // Order of object attributes is not guaranteed doh.assertTrue(js2JSONRaw({"foo":{"one":null,"two":2}}) == '{"foo":{"two":2,"one":null}}'); }, + function test_JSON2jsRaw() { + // Standalone quoted nulls and booleans are converted to primitives + doh.assertTrue(JSON2jsRaw(null) === null); + doh.assertTrue(JSON2jsRaw("null") === null); + doh.assertTrue(JSON2jsRaw(true) === true); + doh.assertTrue(JSON2jsRaw("true") === true); + doh.assertTrue(JSON2jsRaw(false) === false); + doh.assertTrue(JSON2jsRaw("false") === false); + // Zero is zero and only zero + doh.assertTrue(JSON2jsRaw(0) === 0); + // Empty string + doh.assertTrue(JSON2jsRaw('""') === ""); + // String + doh.assertTrue(JSON2jsRaw('"foo"') == "foo"); + // Array; access an index + doh.assertTrue(JSON2jsRaw('[0,1,2,3,4,5]')[1] == 1); + // Object; access a key + doh.assertTrue(JSON2jsRaw('{"foo":"bar"}').foo == "bar"); + doh.assertTrue(JSON2jsRaw('{"foo":{"two":2,"one":null}}').foo.one === null); + doh.assertTrue(JSON2jsRaw('{"foo":{"two":2,"one":"null"}}').foo.one === "null"); + }, function test_JSON2js() { // Standalone quoted nulls and booleans are converted to primitives doh.assertTrue(JSON2js(null) === null); -- 2.43.2