From 50a063b8ea319cb4c340e69824bb4725300b35f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= Date: Wed, 17 Jul 2019 22:01:46 +0000 Subject: tests: readme: show differences in first table layer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Asbjørn Sloth Tønnesen --- test/readme.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'test') diff --git a/test/readme.lua b/test/readme.lua index 7581dc5..79e165a 100644 --- a/test/readme.lua +++ b/test/readme.lua @@ -73,6 +73,14 @@ local function run_example(name, code) return run(name, format('return %s', code)) end +local function table2str(t) + local nt = {} + for i=1,#t do + nt[i] = tostring(t[i]) + end + return '{ ' .. concat(nt, ', ') .. ' }' +end + local function pack2str(t) local new = {} local n = t.n @@ -81,6 +89,9 @@ local function pack2str(t) local vt = type(v) if vt == 'nil' then new[i] = 'nil' + elseif vt == 'table' then + local tostr = rawget(getmetatable(v) or {}, "__tostring") or table2str + new[i] = tostr(v) else new[i] = format('%s "%s"', vt, v) end -- cgit v1.2.1