diff --git a/spec/flatdump_spec.lua b/spec/flatdump_spec.lua index ed860ef..e8b1b84 100644 --- a/spec/flatdump_spec.lua +++ b/spec/flatdump_spec.lua @@ -49,4 +49,40 @@ describe('flatdump', function() } assert.same(expected, flatdump(input)) end) + + it('handles function environments', function() + local input = setfenv(function() end, { foo = 'bar' }) + local expected = { + [1] = { + e = 't2', + }, + [2] = { + sfoo = 'sbar', + }, + } + assert.same(expected, flatdump(input)) + end) + + it('handles function environments on nested table entry', function() + local input = { + outer = { + inner = setfenv(function() end, { foo = 'bar' }), + }, + } + local expected = { + [1] = { + souter = 't2', + }, + [2] = { + sinner = 'f3', + }, + [3] = { + e = 't4', + }, + [4] = { + sfoo = 'sbar', + }, + } + assert.same(expected, flatdump(input)) + end) end)