Software /
code /
prosody
Comparison
spec/util_serialization_spec.lua @ 9343:e767da06399d
util.serialization: Use deserialize instead of envload directly
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 23 Sep 2018 17:02:54 +0200 |
parent | 9342:83e4596c2824 |
child | 9480:006a71a83e6a |
comparison
equal
deleted
inserted
replaced
9342:83e4596c2824 | 9343:e767da06399d |
---|---|
1 local serialization = require "util.serialization"; | 1 local serialization = require "util.serialization"; |
2 local envload = require "util.envload"; | |
3 | 2 |
4 describe("util.serialization", function () | 3 describe("util.serialization", function () |
5 describe("serialize", function () | 4 describe("serialize", function () |
6 it("makes a string", function () | 5 it("makes a string", function () |
7 assert.is_string(serialization.serialize({})); | 6 assert.is_string(serialization.serialize({})); |
13 | 12 |
14 it("roundtrips", function () | 13 it("roundtrips", function () |
15 local function test(data) | 14 local function test(data) |
16 local serialized = serialization.serialize(data); | 15 local serialized = serialization.serialize(data); |
17 assert.is_string(serialized); | 16 assert.is_string(serialized); |
18 local chunk, err = envload.envload("return ("..serialized..");"); | 17 local deserialized, err = serialization.deserialize(serialized); |
19 assert.is_function(chunk, err); | 18 assert.same(data, deserialized, err); |
20 assert.same(data, chunk()); | |
21 end | 19 end |
22 | 20 |
23 test({}); | 21 test({}); |
24 test({hello="world"}); | 22 test({hello="world"}); |
25 test("foobar") | 23 test("foobar") |