[Opensrf-commits] r2225 - 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:40 EDT 2011


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

Modified:
   branches/rel_2_0/src/javascript/tests/testJSON_v1.js
Log:
Make javascript unit tests more granular to ease tracking down errors

Noticed a failure when running with Rhino 1.7RC2 that wasn't happening
with version of Rhino packaged in shrinksafe.jar, and it was a bit
tedious narrowing down which test was actually failing. Breaking up
the tests into smaller sets will make this process easier and might invite
the submission of other tests to target areas that are not yet covered.


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:58:08 UTC (rev 2224)
+++ branches/rel_2_0/src/javascript/tests/testJSON_v1.js	2011-03-29 13:58:38 UTC (rev 2225)
@@ -16,45 +16,65 @@
         doh.assertTrue(encodeJS(null) === null);
         doh.assertTrue(encodeJS("") === "");
     },
-    function test_js2JSON() {
+    function test_js2JSON_strict() {
         // Solo nulls and booleans are stringified XXX
         doh.assertTrue(js2JSON(null) === "null");
         doh.assertTrue(js2JSON(true) === "true");
         doh.assertTrue(js2JSON(false) === "false");
+    },
+    function test_js2JSON_numbers() {
         doh.assertTrue(js2JSON(0) === 0);
         doh.assertTrue(js2JSON(1.5) === 1.5);
         doh.assertTrue(js2JSON(.7) === .7);
+    },
+    function test_js2JSON_strings() {
         doh.assertTrue(js2JSON("") == '""');
         doh.assertTrue(js2JSON("foo") == '"foo"');
         // Escape sequences
         doh.assertTrue(js2JSON("foo\n\t\n") == '"foo\\n\\t\\n"');
+    },
+    function test_js2JSON_arrays() {
+        doh.assertTrue(js2JSON([0,"foo",null,"true",true]) === '[0,"foo",null,"true",true]');
+    },
+    function test_js2JSON_objects() {
         doh.assertTrue(js2JSON({"foo":"bar"}) == '{"foo":"bar"}');
         doh.assertTrue(js2JSON({"foo":true}) == '{"foo":true}');
         doh.assertTrue(js2JSON({"foo":0}) == '{"foo":0}');
-        doh.assertTrue(js2JSON([0,"foo",null,"true",true]) === '[0,"foo",null,"true",true]');
+    },
+    function test_js2JSON_objects_ordered() {
         // Order of object attributes is not guaranteed
-        doh.assertTrue(js2JSON({"foo":{"one":null,"two":2}}) == '{"foo":{"two":2,"one":null}}');
+        doh.assertTrue(js2JSON({"foo":{"one":null,"two":2}}) == '{"foo":{"one":null,"two":2}}');
     },
-    function test_js2JSONRaw() {
+    function test_js2JSONRaw_strict() {
         // Solo nulls and booleans are stringified XXX
         doh.assertTrue(js2JSONRaw(null) === "null");
         doh.assertTrue(js2JSONRaw(true) === "true");
         doh.assertTrue(js2JSONRaw(false) === "false");
+    },
+    function test_js2JSONRaw_numbers() {
         doh.assertTrue(js2JSONRaw(0) === 0);
         doh.assertTrue(js2JSONRaw(1.5) === 1.5);
         doh.assertTrue(js2JSONRaw(.7) === .7);
+    },
+    function test_js2JSONRaw_strings() {
         doh.assertTrue(js2JSONRaw("") == '""');
         doh.assertTrue(js2JSONRaw("foo") == '"foo"');
         // Escape sequences
         doh.assertTrue(js2JSONRaw("foo\n\t\n") == '"foo\\n\\t\\n"');
+    },
+    function test_js2JSONRaw_arrays() {
+        doh.assertTrue(js2JSONRaw([0,"foo",null,"true",true]) === '[0,"foo",null,"true",true]');
+    },
+    function test_js2JSONRaw_objects() {
         doh.assertTrue(js2JSONRaw({"foo":"bar"}) == '{"foo":"bar"}');
         doh.assertTrue(js2JSONRaw({"foo":true}) == '{"foo":true}');
         doh.assertTrue(js2JSONRaw({"foo":0}) == '{"foo":0}');
-        doh.assertTrue(js2JSONRaw([0,"foo",null,"true",true]) === '[0,"foo",null,"true",true]');
+    },
+    function test_js2JSONRaw_objects_ordered() {
         // Order of object attributes is not guaranteed
-        doh.assertTrue(js2JSONRaw({"foo":{"one":null,"two":2}}) == '{"foo":{"two":2,"one":null}}');
+        doh.assertTrue(js2JSONRaw({"foo":{"one":null,"two":2}}) == '{"foo":{"one":null,"two":2}}');
     },
-    function test_JSON2jsRaw() {
+    function test_JSON2jsRaw_strict() {
         // Standalone quoted nulls and booleans are converted to primitives
         doh.assertTrue(JSON2jsRaw(null) === null);
         doh.assertTrue(JSON2jsRaw("null") === null);
@@ -62,20 +82,30 @@
         doh.assertTrue(JSON2jsRaw("true") === true);
         doh.assertTrue(JSON2jsRaw(false) === false);
         doh.assertTrue(JSON2jsRaw("false") === false);
+    },
+    function test_JSON2jsRaw_numbers() {
         // Zero is zero and only zero
         doh.assertTrue(JSON2jsRaw(0) === 0);
+        doh.assertTrue(JSON2jsRaw(1.5) === 1.5);
+        doh.assertTrue(JSON2jsRaw(.5) === .5);
+    },
+    function test_JSON2jsRaw_strings() {
         // Empty string
         doh.assertTrue(JSON2jsRaw('""') === "");
         // String
         doh.assertTrue(JSON2jsRaw('"foo"') == "foo");
+    },
+    function test_JSON2jsRaw_arrays() {
         // Array; access an index
         doh.assertTrue(JSON2jsRaw('[0,1,2,3,4,5]')[1] == 1);
+    },
+    function test_JSON2jsRaw_objects() {
         // 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() {
+    function test_JSON2js_strict() {
         // Standalone quoted nulls and booleans are converted to primitives
         doh.assertTrue(JSON2js(null) === null);
         doh.assertTrue(JSON2js("null") === null);
@@ -83,14 +113,24 @@
         doh.assertTrue(JSON2js("true") === true);
         doh.assertTrue(JSON2js(false) === false);
         doh.assertTrue(JSON2js("false") === false);
+    },
+    function test_JSON2js_numbers() {
         // Zero is zero and only zero
         doh.assertTrue(JSON2js(0) === 0);
+        doh.assertTrue(JSON2js(1.5) === 1.5);
+        doh.assertTrue(JSON2js(.5) === .5);
+    },
+    function test_JSON2js_strings() {
         // Empty string
         doh.assertTrue(JSON2js('""') === "");
         // String
         doh.assertTrue(JSON2js('"foo"') == "foo");
+    },
+    function test_JSON2js_arrays() {
         // Array; access an index
         doh.assertTrue(JSON2js('[0,1,2,3,4,5]')[1] == 1);
+    },
+    function test_JSON2js_objects() {
         // Object; access a key
         doh.assertTrue(JSON2js('{"foo":"bar"}').foo == "bar");
         doh.assertTrue(JSON2js('{"foo":{"two":2,"one":null}}').foo.one === null);



More information about the opensrf-commits mailing list