Merge 0.10->trunk
authorMatthew Wild <mwild1@gmail.com>
Fri, 4 Mar 2016 22:28:15 +0000 (22:28 +0000)
committerMatthew Wild <mwild1@gmail.com>
Fri, 4 Mar 2016 22:28:15 +0000 (22:28 +0000)
Makefile
tests/test.lua
tests/test_util_json.lua [new file with mode: 0644]
util/json.lua

index 4e4a407daf5fc03e056162d08e0b2bf0a3d5d974..a5cdbb37d303c131bf4a2e6c1b58c45bc48b116e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -53,7 +53,7 @@ clean:
        $(MAKE) clean -C util-src
 
 test:
-       cd tests && $(RUNWITH) test.lua
+       cd tests && $(RUNWITH) test.lua 0
 
 util/%.so:
        $(MAKE) install -C util-src
index 0fcc49073983eb96c96411ccee835ee9d4128d68..4172b36346b18809ff0bd974216393e2948bbbe3 100644 (file)
@@ -18,6 +18,7 @@ function run_all_tests()
        dotest "core.s2smanager"
        dotest "core.configmanager"
        dotest "util.ip"
+       dotest "util.json"
        dotest "util.stanza"
        dotest "util.sasl.scram"
        dotest "util.cache"
diff --git a/tests/test_util_json.lua b/tests/test_util_json.lua
new file mode 100644 (file)
index 0000000..2c1a9ce
--- /dev/null
@@ -0,0 +1,21 @@
+
+function encode(encode, json)
+       local function test(f, j, e)
+               if e then
+                       assert_equal(f(j), e);
+               end
+               assert_equal(f(j), f(json.decode(f(j))));
+       end
+       test(encode, json.null, "null")
+       test(encode, {}, "{}")
+       test(encode, {a=1});
+       test(encode, {a={1,2,3}});
+       test(encode, {1}, "[1]");
+end
+
+function decode(decode)
+       local empty_array = decode("[]");
+       assert_equal(type(empty_array), "table");
+       assert_equal(#empty_array, 0);
+       assert_equal(next(empty_array), nil);
+end
index becd295d55590e4757736c8a9cc1b4c16e7d834f..2c598446bab233d05825b7926bd21a7bd29d7b19 100644 (file)
@@ -145,7 +145,9 @@ end
 
 function simplesave(o, buffer)
        local t = type(o);
-       if t == "number" then
+       if o == null then
+               t_insert(buffer, "null");
+       elseif t == "number" then
                t_insert(buffer, tostring(o));
        elseif t == "string" then
                stringsave(o, buffer);