Created temporary stopgap for when __index throws errors.
This commit is contained in:
parent
4d3cf18797
commit
08e659fc4a
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user