Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1909 hs.inspect table bug #1910

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 35 additions & 0 deletions Hammerspoon Tests/HSinspect.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// HSinspect.m
// Hammerspoon
//
// Created by David Peterson on 18-Oct-2018.
// Copyright © 2016 Hammerspoon. All rights reserved.
//

#import "HSTestCase.h"

@interface HSinspect : HSTestCase

@end

@implementation HSinspect

- (void)setUp {
[super setUpWithRequire:@"test_inspect"];
// Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}

- (void)testEncode {
RUN_LUA_TEST()
}

- (void)testDecode {
RUN_LUA_TEST()
}

@end
3 changes: 2 additions & 1 deletion extensions/inspect/init.lua
Original file line number Diff line number Diff line change
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
24 changes: 24 additions & 0 deletions extensions/inspect/test_inspect.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
-- hs.inspect tests
hs.inspect = require("hs.inspect")

-- tests the case where a custom __init always returns a new table instance as a key/value
function testInspectAlwaysNewTableKeyValue()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(W111) setting non-standard global variable 'testInspectAlwaysNewTableKeyValue'

local t = setmetatable({}, {
__init = function(_, _)
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