From 8e2bcbbb95962fc3808b52004641ffbda9fed050 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 23 Sep 2018 16:30:35 +0200 Subject: util.serialization: Add brief initial tests --- spec/util_serialization_spec.lua | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 spec/util_serialization_spec.lua (limited to 'spec/util_serialization_spec.lua') 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); + -- cgit v1.2.3