Mercurial > prosody-hg
comparison spec/util_serialization_spec.lua @ 9567:dbfa286cfa88
util.serialization: Add option for allowing multiple references to the same table (but not cycles)
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sat, 27 Oct 2018 12:43:03 +0200 |
| parents | dad29508d0f2 |
| children |
comparison
equal
deleted
inserted
replaced
| 9566:dad29508d0f2 | 9567:dbfa286cfa88 |
|---|---|
| 23 assert.has_error(function () | 23 assert.has_error(function () |
| 24 local t = {} | 24 local t = {} |
| 25 t[t] = { t }; | 25 t[t] = { t }; |
| 26 serialization.serialize(t) | 26 serialization.serialize(t) |
| 27 end); | 27 end); |
| 28 -- also with multirefs allowed | |
| 29 assert.has_error(function () | |
| 30 local t = {} | |
| 31 t[t] = { t }; | |
| 32 serialization.serialize(t, { multirefs = true }) | |
| 33 end); | |
| 28 end); | 34 end); |
| 29 | 35 |
| 30 it("rejects multiple references to same table", function () | 36 it("rejects multiple references to same table", function () |
| 31 assert.has_error(function () | 37 assert.has_error(function () |
| 32 local t1 = {}; | 38 local t1 = {}; |
| 33 local t2 = { t1, t1 }; | 39 local t2 = { t1, t1 }; |
| 34 serialization.serialize(t2); | 40 serialization.serialize(t2, { multirefs = false }); |
| 41 end); | |
| 42 end); | |
| 43 | |
| 44 it("optionally allows multiple references to same table", function () | |
| 45 assert.has_error(function () | |
| 46 local t1 = {}; | |
| 47 local t2 = { t1, t1 }; | |
| 48 serialization.serialize(t2, { multirefs = true }); | |
| 35 end); | 49 end); |
| 36 end); | 50 end); |
| 37 | 51 |
| 38 it("roundtrips", function () | 52 it("roundtrips", function () |
| 39 local function test(data) | 53 local function test(data) |
