aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2018-09-23 16:30:35 +0200
committerKim Alvefur <zash@zash.se>2018-09-23 16:30:35 +0200
commit31cf61bea4426c73199f505c6ccec03c155c4c27 (patch)
treee72ac48058090cdbe9d0f5a99aedaa4392f6e212 /spec
parented7c24bd0d2c888b1fc19107a8840971cb8d1468 (diff)
downloadprosody-31cf61bea4426c73199f505c6ccec03c155c4c27.tar.gz
prosody-31cf61bea4426c73199f505c6ccec03c155c4c27.zip
util.serialization: Add brief initial tests
Diffstat (limited to 'spec')
-rw-r--r--spec/util_serialization_spec.lua33
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/util_serialization_spec.lua b/spec/util_serialization_spec.lua
new file mode 100644
index 00000000..18e6ca68
--- /dev/null
+++ b/spec/util_serialization_spec.lua
@@ -0,0 +1,33 @@
+local serialization = require "util.serialization";
+local envload = require "util.envload";
+
+describe("util.serialization", function ()
+ describe("serialize", function ()
+ it("makes a string", function ()
+ assert.is_string(serialization.serialize({}));
+ assert.is_string(serialization.serialize(nil));
+ assert.is_string(serialization.serialize(1));
+ assert.is_string(serialization.serialize(true));
+ assert.is_string(serialization.serialize(function () end));
+ end);
+
+ it("roundtrips", function ()
+ local function test(data)
+ local serialized = serialization.serialize(data);
+ assert.is_string(serialized);
+ local chunk, err = envload.envload("return ("..serialized..");");
+ assert.is_function(chunk, err);
+ assert.same(data, chunk());
+ end
+
+ test({});
+ test({hello="world"});
+ test("foobar")
+ test("\0\1\2\3");
+ test("nödåtgärd");
+ test({1,2,3,4});
+ test({foo={[100]={{"bar"},{baz=1}}}});
+ end);
+ end);
+end);
+