Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Fixed bug with inspecting complex tables.
  • Loading branch information
randomeizer committed Jul 19, 2018
1 parent f63a843 commit d07506e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion extensions/inspect/init.lua
Expand Up @@ -236,7 +236,8 @@ function Inspector:putTable(t)
elseif self.level >= self.depth then
self:puts('{...}')
else
if self.tableAppearances[t] > 1 then self:puts('<', self:getId(t), '>') end
local appearances = self.tableAppearances[t] or 0
if appearances > 1 then self:puts('<', self:getId(t), '>') end

local nonSequentialKeys = getNonSequentialKeys(t)
local length = #t
Expand Down
23 changes: 23 additions & 0 deletions extensions/inspect/test_inspect.lua
@@ -0,0 +1,23 @@
hs.inspect = require("hs.inspect")

-- tests the case where a custom __init always returns a new table instance as a key/value
function testInspectAlwaysNewTableKeyValue()
local t = setmetatable({}, {
__init = function(_, key)
return {}
end,
__pairs = function(self)
local function stateless_iter(_, k)
if k ~= "a" then
return "a", "b"
end
end
-- Return an iterator function, the table, starting point
return stateless_iter, self, nil
end,
})

assertIsEqual('{a = "b"}', hs.inspect(t))

return success()
end

0 comments on commit d07506e

Please sign in to comment.