From d07506eecca657a916dc7a5789dbc29884a2bced Mon Sep 17 00:00:00 2001 From: David Peterson Date: Thu, 19 Jul 2018 23:40:47 +1000 Subject: [PATCH 1/3] #1909 * Fixed bug with inspecting complex tables. --- extensions/inspect/init.lua | 3 ++- extensions/inspect/test_inspect.lua | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 extensions/inspect/test_inspect.lua diff --git a/extensions/inspect/init.lua b/extensions/inspect/init.lua index d653e2fb7..5d0b9eee8 100644 --- a/extensions/inspect/init.lua +++ b/extensions/inspect/init.lua @@ -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 diff --git a/extensions/inspect/test_inspect.lua b/extensions/inspect/test_inspect.lua new file mode 100644 index 000000000..bb12ae456 --- /dev/null +++ b/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 From 8089b4d577eab446035d3868a572c9577d8a89a4 Mon Sep 17 00:00:00 2001 From: David Peterson Date: Thu, 19 Jul 2018 23:44:53 +1000 Subject: [PATCH 2/3] #1909 * Fixed stickler issue --- extensions/inspect/test_inspect.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/extensions/inspect/test_inspect.lua b/extensions/inspect/test_inspect.lua index bb12ae456..70aa23f62 100644 --- a/extensions/inspect/test_inspect.lua +++ b/extensions/inspect/test_inspect.lua @@ -1,9 +1,10 @@ +-- 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() local t = setmetatable({}, { - __init = function(_, key) + __init = function(_, _) return {} end, __pairs = function(self) From 0c700aa07e29b342e00325c30949c18abe9aa818 Mon Sep 17 00:00:00 2001 From: David Peterson Date: Thu, 18 Oct 2018 13:43:07 +1000 Subject: [PATCH 3/3] Added HSinspect to trigger hs.inspect test cases. --- Hammerspoon Tests/HSinspect.m | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Hammerspoon Tests/HSinspect.m diff --git a/Hammerspoon Tests/HSinspect.m b/Hammerspoon Tests/HSinspect.m new file mode 100644 index 000000000..a94f6d1d7 --- /dev/null +++ b/Hammerspoon Tests/HSinspect.m @@ -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 \ No newline at end of file