[Opensrf-commits] r2224 - branches/rel_2_0/src/javascript/tests (dbs)

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Mar 29 09:58:10 EDT 2011


Author: dbs
Date: 2011-03-29 09:58:08 -0400 (Tue, 29 Mar 2011)
New Revision: 2224

Modified:
   branches/rel_2_0/src/javascript/tests/testJSON_v1.js
Log:
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.


Modified: branches/rel_2_0/src/javascript/tests/testJSON_v1.js
===================================================================
--- branches/rel_2_0/src/javascript/tests/testJSON_v1.js	2011-03-29 13:57:51 UTC (rev 2223)
+++ branches/rel_2_0/src/javascript/tests/testJSON_v1.js	2011-03-29 13:58:08 UTC (rev 2224)
@@ -6,6 +6,16 @@
     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 @@
         // 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);



More information about the opensrf-commits mailing list