Software /
code /
prosody
Comparison
spec/util_serialization_spec.lua @ 9342:83e4596c2824
util.serialization: Add brief initial tests
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 23 Sep 2018 16:30:35 +0200 |
child | 9343:e767da06399d |
comparison
equal
deleted
inserted
replaced
9341:009dad867e52 | 9342:83e4596c2824 |
---|---|
1 local serialization = require "util.serialization"; | |
2 local envload = require "util.envload"; | |
3 | |
4 describe("util.serialization", function () | |
5 describe("serialize", function () | |
6 it("makes a string", function () | |
7 assert.is_string(serialization.serialize({})); | |
8 assert.is_string(serialization.serialize(nil)); | |
9 assert.is_string(serialization.serialize(1)); | |
10 assert.is_string(serialization.serialize(true)); | |
11 assert.is_string(serialization.serialize(function () end)); | |
12 end); | |
13 | |
14 it("roundtrips", function () | |
15 local function test(data) | |
16 local serialized = serialization.serialize(data); | |
17 assert.is_string(serialized); | |
18 local chunk, err = envload.envload("return ("..serialized..");"); | |
19 assert.is_function(chunk, err); | |
20 assert.same(data, chunk()); | |
21 end | |
22 | |
23 test({}); | |
24 test({hello="world"}); | |
25 test("foobar") | |
26 test("\0\1\2\3"); | |
27 test("nödåtgärd"); | |
28 test({1,2,3,4}); | |
29 test({foo={[100]={{"bar"},{baz=1}}}}); | |
30 end); | |
31 end); | |
32 end); | |
33 |