1
0

Created temporary stopgap for when __index throws errors.

This commit is contained in:
Jon Michael Aanes 2017-06-09 15:49:15 +02:00
parent 4d3cf18797
commit 08e659fc4a
2 changed files with 25 additions and 0 deletions

View File

@ -93,6 +93,14 @@ local function nr_elements_in_table (t)
end
local function nr_elements_in_seq (t)
assert(type(t) == 'table')
if getmetatable(t) and getmetatable(t).__index then
return 0, false -- FIXME: Temporary stopgap for when __index throws an
-- error. I think we need to clone the numbers part of the table, to
-- fix this.
end
local i, last_elem_i, nr_elems, has_holes = 0, 0, 0, false
while i <= last_elem_i + 2 do
i = i + 1

View File

@ -172,6 +172,23 @@ SUITE:addTest('Recursive Numeration, Through Keys', function ()
assert(info[input].marker == 1)
end)
--------------------------------------------------------------------------------
-- Metatable shennanigens.
SUITE:addTest('Wont crash, even though metatable.__index throws errors', function ()
local input = setmetatable({ 'hi', 'hello' }, {__index = function (_, k) error('Undefined access on key: '..k) end})
local info = analyze_structure(input)
assert(true)
end)
SUITE:addTest('Can count elements, even though metatable.__index throws errors', function ()
local input = setmetatable({ 'hi', 'hello' }, {__index = function (_, k) error('Undefined access on key: '..k) end})
local info = analyze_structure(input)
assert_equal(info[input].seq_elems, 2)
end)
--------------------------------------------------------------------------------
-- API stuff