]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/javascript/tests/testJSON_v1.js
LP1999823: Bump libtool library version
[OpenSRF.git] / src / javascript / tests / testJSON_v1.js
1 dojo.provide('opensrf.tests.testJSON_v1');
2
3 dojo.require('DojoSRF');
4
5 doh.register("JSONTests", [
6     function test_version() {
7         doh.assertTrue(JSON_version() == 'wrapper');
8     },
9     function test_decodeJS() {
10         doh.assertTrue(decodeJS(0) === 0);
11         doh.assertTrue(decodeJS(null) === null);
12         doh.assertTrue(decodeJS("") === "");
13     },
14     function test_encodeJS() {
15         doh.assertTrue(encodeJS(0) === 0);
16         doh.assertTrue(encodeJS(null) === null);
17         doh.assertTrue(encodeJS("") === "");
18     },
19     function test_js2JSON_strict() {
20         // Solo nulls and booleans are stringified XXX
21         doh.assertTrue(js2JSON(null) === "null");
22         doh.assertTrue(js2JSON(true) === "true");
23         doh.assertTrue(js2JSON(false) === "false");
24     },
25     function test_js2JSON_numbers() {
26         doh.assertTrue(js2JSON(0) === 0);
27         doh.assertTrue(js2JSON(1.5) === 1.5);
28         doh.assertTrue(js2JSON(.7) === .7);
29     },
30     function test_js2JSON_strings() {
31         doh.assertTrue(js2JSON("") == '""');
32         doh.assertTrue(js2JSON("foo") == '"foo"');
33         // Escape sequences
34         doh.assertTrue(js2JSON("foo\n\t\n") == '"foo\\n\\t\\n"');
35     },
36     function test_js2JSON_arrays() {
37         doh.assertTrue(js2JSON([0,"foo",null,"true",true]) === '[0,"foo",null,"true",true]');
38     },
39     function test_js2JSON_objects() {
40         doh.assertTrue(js2JSON({"foo":"bar"}) == '{"foo":"bar"}');
41         doh.assertTrue(js2JSON({"foo":true}) == '{"foo":true}');
42         doh.assertTrue(js2JSON({"foo":0}) == '{"foo":0}');
43     },
44     function test_js2JSON_objects_ordered() {
45         // Order of object attributes is not guaranteed
46         doh.assertTrue(js2JSON({"foo":{"one":[null,"two",2]}}) == '{"foo":{"one":[null,"two",2]}}');
47     },
48     function test_JSON2js_strict() {
49         // Standalone quoted nulls and booleans are converted to primitives
50         doh.assertTrue(JSON2js(null) === null);
51         doh.assertTrue(JSON2js("null") === null);
52         doh.assertTrue(JSON2js(true) === true);
53         doh.assertTrue(JSON2js("true") === true);
54         doh.assertTrue(JSON2js(false) === false);
55         doh.assertTrue(JSON2js("false") === false);
56     },
57     function test_JSON2js_numbers() {
58         // Zero is zero and only zero
59         doh.assertTrue(JSON2js(0) === 0);
60         doh.assertTrue(JSON2js(1.5) === 1.5);
61         doh.assertTrue(JSON2js(.5) === .5);
62     },
63     function test_JSON2js_strings() {
64         // Empty string
65         doh.assertTrue(JSON2js('""') === "");
66         // String
67         doh.assertTrue(JSON2js('"foo"') == "foo");
68     },
69     function test_JSON2js_arrays() {
70         // Array; access an index
71         doh.assertTrue(JSON2js('[0,1,2,3,4,5]')[1] == 1);
72     },
73     function test_JSON2js_objects() {
74         // Object; access a key
75         doh.assertTrue(JSON2js('{"foo":"bar"}').foo == "bar");
76         doh.assertTrue(JSON2js('{"foo":{"two":2,"one":null}}').foo.one === null);
77         doh.assertTrue(JSON2js('{"foo":{"two":2,"one":"null"}}').foo.one === "null");
78     }
79 ]);