From 98d8e202e43977186cbee0012eeb9e25cfe6375d Mon Sep 17 00:00:00 2001 From: Peter Klijn Date: Fri, 26 Aug 2022 10:51:41 +0100 Subject: [PATCH 1/7] Fixed typo in mounted volume and set volume as default workdir --- .docker/ci.Dockerfile | 2 ++ .docker/docker-compose.ci.yaml | 2 +- Makefile | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.docker/ci.Dockerfile b/.docker/ci.Dockerfile index 3b483e1..98ab28c 100644 --- a/.docker/ci.Dockerfile +++ b/.docker/ci.Dockerfile @@ -2,3 +2,5 @@ FROM akorn/luarocks:lua5.4-alpine RUN apk add gcc musl-dev RUN luarocks install luacheck + +WORKDIR shiftit diff --git a/.docker/docker-compose.ci.yaml b/.docker/docker-compose.ci.yaml index 9c77b53..15d6728 100644 --- a/.docker/docker-compose.ci.yaml +++ b/.docker/docker-compose.ci.yaml @@ -5,4 +5,4 @@ services: context: .. dockerfile: ./.docker/ci.Dockerfile volumes: - - ..:/shifit + - ..:/shiftit diff --git a/Makefile b/Makefile index 4fc9d1f..ca28863 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,6 @@ ci-init: docker-compose -f .docker/docker-compose.ci.yaml build ci-lint: - docker-compose -f .docker/docker-compose.ci.yaml run hammerspoon-shiftit-ci luacheck --globals hs -- shifit/ + docker-compose -f .docker/docker-compose.ci.yaml run hammerspoon-shiftit-ci luacheck --globals hs -- . .PHONY: ci-init ci-lint From 380a1c8ff7a0c6d31602e247c7e86c309894f261 Mon Sep 17 00:00:00 2001 From: Peter Klijn Date: Fri, 26 Aug 2022 23:48:44 +0100 Subject: [PATCH 2/7] Add first unit tests --- .docker/ci.Dockerfile | 6 +++-- .github/workflows/ci.yaml | 3 +++ Makefile | 6 +++++ hammerspoon_mocks.lua | 22 ++++++++++++++++ init.lua | 38 +++++++++++++++------------- init_test.lua | 53 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 108 insertions(+), 20 deletions(-) create mode 100644 hammerspoon_mocks.lua create mode 100644 init_test.lua diff --git a/.docker/ci.Dockerfile b/.docker/ci.Dockerfile index 98ab28c..a8bad23 100644 --- a/.docker/ci.Dockerfile +++ b/.docker/ci.Dockerfile @@ -1,6 +1,8 @@ FROM akorn/luarocks:lua5.4-alpine -RUN apk add gcc musl-dev -RUN luarocks install luacheck +RUN apk add gcc musl-dev make + +RUN luarocks install luacheck \ + && luarocks install luaunit WORKDIR shiftit diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 45ceaaa..ffcceea 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -16,3 +16,6 @@ jobs: - name: Run linter run: make ci-lint + + - name: Run tests + run: make ci-test diff --git a/Makefile b/Makefile index ca28863..74efea2 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,13 @@ +test: + find . -name "*_test.lua" | xargs sh -c 'lua $$0 -v' + ci-init: docker-compose -f .docker/docker-compose.ci.yaml build ci-lint: docker-compose -f .docker/docker-compose.ci.yaml run hammerspoon-shiftit-ci luacheck --globals hs -- . +ci-test: + docker-compose -f .docker/docker-compose.ci.yaml run hammerspoon-shiftit-ci make test + .PHONY: ci-init ci-lint diff --git a/hammerspoon_mocks.lua b/hammerspoon_mocks.lua new file mode 100644 index 0000000..9cd9818 --- /dev/null +++ b/hammerspoon_mocks.lua @@ -0,0 +1,22 @@ +local lu = require('luaunit') + +local hotkey = { + bindings = {}, +} + +function hotkey.bind(mods, key, fn) + lu.assertNotNil(mods) + lu.assertNotNil(key) + lu.assertIsFunction(fn) + table.insert(hotkey.bindings, { mods, key, fn }) +end + +local mocks = { + hotkey = hotkey +} + +function mocks:reset() + self.hotkey.bindings = {} +end + +return mocks diff --git a/init.lua b/init.lua index 34042c7..aa31dd3 100644 --- a/init.lua +++ b/init.lua @@ -4,7 +4,9 @@ --- --- Download: https://github.com/peterklijn/hammerspoon-shiftit/raw/master/Spoons/ShiftIt.spoon.zip -local obj = {} +local obj = { + hs = hs +} obj.__index = obj -- Metadata @@ -136,7 +138,7 @@ function obj.nextScreen() hs.window.focusedWindow():moveToScreen(hs.window.focusedWindow():screen():next(), false, true, 0) end -function obj.previousScreen() +function obj.prevScreen() hs.window.focusedWindow():moveToScreen(hs.window.focusedWindow():screen():previous(), false, true, 0) end @@ -172,24 +174,24 @@ function obj:bindHotkeys(mapping) for k, v in pairs(mapping) do self.mapping[k] = v end end - hs.hotkey.bind(self.mapping.left[1], self.mapping.left[2], function() self:left() end) - hs.hotkey.bind(self.mapping.right[1], self.mapping.right[2], function() self:right() end) - hs.hotkey.bind(self.mapping.up[1], self.mapping.up[2], function() self:up() end) - hs.hotkey.bind(self.mapping.down[1], self.mapping.down[2], function() self:down() end) - hs.hotkey.bind(self.mapping.upleft[1], self.mapping.upleft[2], function() self:upleft() end) - hs.hotkey.bind(self.mapping.upright[1], self.mapping.upright[2], function() self:upright() end) - hs.hotkey.bind(self.mapping.botleft[1], self.mapping.botleft[2], function() self:botleft() end) - hs.hotkey.bind(self.mapping.botright[1], self.mapping.botright[2], function() self:botright() end) - hs.hotkey.bind(self.mapping.maximum[1], self.mapping.maximum[2], function() self:maximum() end) - hs.hotkey.bind(self.mapping.toggleFullScreen[1], self.mapping.toggleFullScreen[2], function() + self.hs.hotkey.bind(self.mapping.left[1], self.mapping.left[2], function() self:left() end) + self.hs.hotkey.bind(self.mapping.right[1], self.mapping.right[2], function() self:right() end) + self.hs.hotkey.bind(self.mapping.up[1], self.mapping.up[2], function() self:up() end) + self.hs.hotkey.bind(self.mapping.down[1], self.mapping.down[2], function() self:down() end) + self.hs.hotkey.bind(self.mapping.upleft[1], self.mapping.upleft[2], function() self:upleft() end) + self.hs.hotkey.bind(self.mapping.upright[1], self.mapping.upright[2], function() self:upright() end) + self.hs.hotkey.bind(self.mapping.botleft[1], self.mapping.botleft[2], function() self:botleft() end) + self.hs.hotkey.bind(self.mapping.botright[1], self.mapping.botright[2], function() self:botright() end) + self.hs.hotkey.bind(self.mapping.maximum[1], self.mapping.maximum[2], function() self:maximum() end) + self.hs.hotkey.bind(self.mapping.toggleFullScreen[1], self.mapping.toggleFullScreen[2], function() self:toggleFullScreen() end) - hs.hotkey.bind(self.mapping.toggleZoom[1], self.mapping.toggleZoom[2], function() self:toggleZoom() end) - hs.hotkey.bind(self.mapping.center[1], self.mapping.center[2], function() self:center() end) - hs.hotkey.bind(self.mapping.nextScreen[1], self.mapping.nextScreen[2], function() self:nextScreen() end) - hs.hotkey.bind(self.mapping.previousScreen[1], self.mapping.previousScreen[2], function() self:previousScreen() end) - hs.hotkey.bind(self.mapping.resizeOut[1], self.mapping.resizeOut[2], function() self:resizeOut() end) - hs.hotkey.bind(self.mapping.resizeIn[1], self.mapping.resizeIn[2], function() self:resizeIn() end) + self.hs.hotkey.bind(self.mapping.toggleZoom[1], self.mapping.toggleZoom[2], function() self:toggleZoom() end) + self.hs.hotkey.bind(self.mapping.center[1], self.mapping.center[2], function() self:center() end) + self.hs.hotkey.bind(self.mapping.nextScreen[1], self.mapping.nextScreen[2], function() self:nextScreen() end) + self.hs.hotkey.bind(self.mapping.previousScreen[1], self.mapping.previousScreen[2], function() self:prevScreen() end) + self.hs.hotkey.bind(self.mapping.resizeOut[1], self.mapping.resizeOut[2], function() self:resizeOut() end) + self.hs.hotkey.bind(self.mapping.resizeIn[1], self.mapping.resizeIn[2], function() self:resizeIn() end) return self end diff --git a/init_test.lua b/init_test.lua new file mode 100644 index 0000000..bb30b55 --- /dev/null +++ b/init_test.lua @@ -0,0 +1,53 @@ +local lu = require('luaunit') +local shiftit = require('init') +local hsmocks = require('hammerspoon_mocks') + +-- disable lint errors for mutating global variable TestShiftIt: +-- luacheck: ignore 112 + +TestShiftIt = {} -- luacheck: ignore 111 + +function TestShiftIt.setUp() + hsmocks:reset() +end + +function TestShiftIt.testBindDefault() + shiftit.hs = hsmocks + shiftit:bindHotkeys({}) + lu.assertEquals(#hsmocks.hotkey.bindings, 16) + + local expected = { + 'left', 'right', 'up', 'down', + '1', '2', '3', '4', 'm', + 'f', 'z', 'c', 'n', 'p', + '=', '-', + } + for i, item in pairs(expected) do + lu.assertEquals(hsmocks.hotkey.bindings[i][1], shiftit.mash) + lu.assertEquals(hsmocks.hotkey.bindings[i][2], item) + end +end + +function TestShiftIt.testBindOverrideVimKeys() + shiftit.hs = hsmocks + shiftit:bindHotkeys({ + left = { { 'ctrl', 'alt', 'cmd' }, 'h' }, + down = { { 'ctrl', 'alt', 'cmd' }, 'j' }, + up = { { 'ctrl', 'alt', 'cmd' }, 'k' }, + right = { { 'ctrl', 'alt', 'cmd' }, 'l' }, + }) + lu.assertEquals(#hsmocks.hotkey.bindings, 16) + + local expected = { + 'h', 'l', 'k', 'j', + '1', '2', '3', '4', 'm', + 'f', 'z', 'c', 'n', 'p', + '=', '-', + } + for i, item in pairs(expected) do + lu.assertEquals(hsmocks.hotkey.bindings[i][1], shiftit.mash) + lu.assertEquals(hsmocks.hotkey.bindings[i][2], item) + end +end + +os.exit(lu.LuaUnit.run()) From d29f58ebd5ed914d38f9fe17f8d47704b418fc38 Mon Sep 17 00:00:00 2001 From: Peter Klijn Date: Sun, 28 Aug 2022 10:08:01 +0100 Subject: [PATCH 3/7] Refactor all methods to use `hs` variable in object, so it can be mocked --- init.lua | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/init.lua b/init.lua index aa31dd3..7a6012f 100644 --- a/init.lua +++ b/init.lua @@ -50,11 +50,11 @@ local units = { maximum = { x = 0.00, y = 0.00, w = 1.00, h = 1.00 }, } -local function move(unit) hs.window.focusedWindow():move(unit, nil, true, 0) end +function obj:move(unit) self.hs.window.focusedWindow():move(unit, nil, true, 0) end -local function resizeWindowInSteps(increment) - local screen = hs.window.focusedWindow():screen():frame() - local window = hs.window.focusedWindow():frame() +function obj:resizeWindowInSteps(increment) + local screen = self.hs.window.focusedWindow():screen():frame() + local window = self.hs.window.focusedWindow():frame() local wStep = math.floor(screen.w / 12) local hStep = math.floor(screen.h / 12) local x, y, w, h = window.x, window.y, window.w, window.h @@ -107,44 +107,44 @@ local noChange = true h = notMinHeight and h - hStep * 2 or h end end - hs.window.focusedWindow():move({ x = x, y = y, w = w, h = h }, nil, true, 0) + self:move({ x = x, y = y, w = w, h = h }) end -function obj.left() move(units.left50, nil, true, 0) end +function obj:left() self:move(units.left50) end -function obj.right() move(units.right50, nil, true, 0) end +function obj:right() self:move(units.right50) end -function obj.up() move(units.top50, nil, true, 0) end +function obj:up() self:move(units.top50) end -function obj.down() move(units.bot50, nil, true, 0) end +function obj:down() self:move(units.bot50) end -function obj.upleft() move(units.upleft50, nil, true, 0) end +function obj:upleft() self:move(units.upleft50) end -function obj.upright() move(units.upright50, nil, true, 0) end +function obj:upright() self:move(units.upright50) end -function obj.botleft() move(units.botleft50, nil, true, 0) end +function obj:botleft() self:move(units.botleft50) end -function obj.botright() move(units.botright50, nil, true, 0) end +function obj:botright() self:move(units.botright50) end -function obj.maximum() move(units.maximum, nil, true, 0) end +function obj:maximum() self:move(units.maximum) end -function obj.toggleFullScreen() hs.window.focusedWindow():toggleFullScreen() end +function obj:toggleFullScreen() self.hs.window.focusedWindow():toggleFullScreen() end -function obj.toggleZoom() hs.window.focusedWindow():toggleZoom() end +function obj:toggleZoom() self.hs.window.focusedWindow():toggleZoom() end -function obj.center() hs.window.focusedWindow():centerOnScreen(nil, true, 0) end +function obj:center() self.hs.window.focusedWindow():centerOnScreen(nil, true, 0) end -function obj.nextScreen() - hs.window.focusedWindow():moveToScreen(hs.window.focusedWindow():screen():next(), false, true, 0) +function obj:nextScreen() + self.hs.window.focusedWindow():moveToScreen(self.hs.window.focusedWindow():screen():next(), false, true, 0) end -function obj.prevScreen() - hs.window.focusedWindow():moveToScreen(hs.window.focusedWindow():screen():previous(), false, true, 0) +function obj:prevScreen() + self.hs.window.focusedWindow():moveToScreen(self.hs.window.focusedWindow():screen():previous(), false, true, 0) end -function obj.resizeOut() resizeWindowInSteps(true) end +function obj:resizeOut() self:resizeWindowInSteps(true) end -function obj.resizeIn() resizeWindowInSteps(false) end +function obj:resizeIn() self:resizeWindowInSteps(false) end --- HammerspoonShiftIt:bindHotkeys(mapping) --- Method From f7eafb00f09a1b0b459a4555ada7baf7a2384e6a Mon Sep 17 00:00:00 2001 From: Peter Klijn Date: Sun, 28 Aug 2022 10:09:56 +0100 Subject: [PATCH 4/7] Fixed indentation --- init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 7a6012f..8f4ec36 100644 --- a/init.lua +++ b/init.lua @@ -69,7 +69,7 @@ function obj:resizeWindowInSteps(increment) w = math.min(screen.w - x + screen.x, w + wStep) h = math.min(screen.h - y + screen.y, h + hStep) else -local noChange = true + local noChange = true local notMinWidth = w > wStep * 3 local notMinHeight = h > hStep * 3 From 0aac20a4b8b85c3390b155221ca42c51218e8d4b Mon Sep 17 00:00:00 2001 From: Peter Klijn Date: Sun, 28 Aug 2022 11:44:35 +0100 Subject: [PATCH 5/7] Add some tests for increasing and decreasing windows sticking to the sides --- hammerspoon_mocks.lua | 36 ++++++++++++- init_test.lua | 119 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 152 insertions(+), 3 deletions(-) diff --git a/hammerspoon_mocks.lua b/hammerspoon_mocks.lua index 9cd9818..fe3587c 100644 --- a/hammerspoon_mocks.lua +++ b/hammerspoon_mocks.lua @@ -11,8 +11,42 @@ function hotkey.bind(mods, key, fn) table.insert(hotkey.bindings, { mods, key, fn }) end +local screen = { + rect = { x = 0, y = 0, w = 1200, h = 800 }, +} + +function screen:frame() + return self.rect +end + +local window = { + rect = { x = 0, y = 0, w = 1200, h = 800 }, + _screen = screen, +} + +function window.focusedWindow() + return window +end + +function window:frame() + return self.rect +end + +function window:screen() + return self._screen +end + +function window:move(rect, _, _, _) + lu.assertIsNumber(rect.x) + lu.assertIsNumber(rect.y) + lu.assertIsNumber(rect.w) + lu.assertIsNumber(rect.h) + self.rect = rect +end + local mocks = { - hotkey = hotkey + hotkey = hotkey, + window = window, } function mocks:reset() diff --git a/init_test.lua b/init_test.lua index bb30b55..d9be559 100644 --- a/init_test.lua +++ b/init_test.lua @@ -8,11 +8,11 @@ local hsmocks = require('hammerspoon_mocks') TestShiftIt = {} -- luacheck: ignore 111 function TestShiftIt.setUp() + shiftit.hs = hsmocks hsmocks:reset() end function TestShiftIt.testBindDefault() - shiftit.hs = hsmocks shiftit:bindHotkeys({}) lu.assertEquals(#hsmocks.hotkey.bindings, 16) @@ -29,7 +29,6 @@ function TestShiftIt.testBindDefault() end function TestShiftIt.testBindOverrideVimKeys() - shiftit.hs = hsmocks shiftit:bindHotkeys({ left = { { 'ctrl', 'alt', 'cmd' }, 'h' }, down = { { 'ctrl', 'alt', 'cmd' }, 'j' }, @@ -50,4 +49,120 @@ function TestShiftIt.testBindOverrideVimKeys() end end +function TestShiftIt.testResizeWindowInStepsStickingToSides() + local tests = { + { + desc = 'increase window sticking to left', + before = { x = 0, y = 0, w = 600, h = 800 }, + expect = { x = 0, y = 0, w = 700, h = 800 }, + increase = true, + }, + { + desc = 'decrease window sticking to left', + before = { x = 0, y = 0, w = 600, h = 800 }, + expect = { x = 0, y = 0, w = 500, h = 800 }, + increase = false, + }, + { + desc = 'increase window sticking to right', + before = { x = 600, y = 0, w = 600, h = 800 }, + expect = { x = 500, y = 0, w = 700, h = 800 }, + increase = true, + }, + { + desc = 'decrease window sticking to right', + before = { x = 600, y = 0, w = 600, h = 800 }, + expect = { x = 700, y = 0, w = 500, h = 800 }, + increase = false, + }, + { + desc = 'increase window sticking to top', + before = { x = 0, y = 0, w = 1200, h = 400 }, + expect = { x = 0, y = 0, w = 1200, h = 466 }, + increase = true, + }, + { + desc = 'decrease window sticking to top', + before = { x = 0, y = 0, w = 1200, h = 400 }, + expect = { x = 0, y = 0, w = 1200, h = 334 }, + increase = false, + }, + { + desc = 'increase window sticking to bottom', + before = { x = 0, y = 400, w = 1200, h = 400 }, + expect = { x = 0, y = 334, w = 1200, h = 466 }, + increase = true, + }, + { + desc = 'decrease window sticking to bottom', + before = { x = 0, y = 400, w = 1200, h = 400 }, + expect = { x = 0, y = 466, w = 1200, h = 334 }, + increase = false, + }, + } + for _, test in pairs(tests) do + hsmocks.window.rect = test.before + shiftit:resizeWindowInSteps(test.increase) + lu.assertEquals(hsmocks.window.rect, test.expect, test.desc) + end +end + +function TestShiftIt.testResizeWindowInStepsStickingToCorners() + local tests = { + { + desc = 'increase window sticking to left top', + before = { x = 0, y = 0, w = 600, h = 400 }, + expect = { x = 0, y = 0, w = 700, h = 466 }, + increase = true, + }, + { + desc = 'decrease window sticking to left top', + before = { x = 0, y = 0, w = 600, h = 400 }, + expect = { x = 0, y = 0, w = 500, h = 334 }, + increase = false, + }, + { + desc = 'increase window sticking to right top', + before = { x = 600, y = 0, w = 600, h = 400 }, + expect = { x = 500, y = 0, w = 700, h = 466 }, + increase = true, + }, + { + desc = 'decrease window sticking to right top', + before = { x = 600, y = 0, w = 600, h = 400 }, + expect = { x = 700, y = 0, w = 500, h = 334 }, + increase = false, + }, + { + desc = 'increase window sticking to left bottom', + before = { x = 0, y = 400, w = 600, h = 400 }, + expect = { x = 0, y = 334, w = 700, h = 466 }, + increase = true, + }, + { + desc = 'decrease window sticking to left bottom', + before = { x = 0, y = 400, w = 600, h = 400 }, + expect = { x = 0, y = 466, w = 500, h = 334 }, + increase = false, + }, + { + desc = 'increase window sticking to right bottom', + before = { x = 0, y = 400, w = 600, h = 400 }, + expect = { x = 0, y = 334, w = 700, h = 466 }, + increase = true, + }, + { + desc = 'decrease window sticking to right bottom', + before = { x = 600, y = 400, w = 600, h = 400 }, + expect = { x = 700, y = 466, w = 500, h = 334 }, + increase = false, + }, + } + for _, test in pairs(tests) do + hsmocks.window.rect = test.before + shiftit:resizeWindowInSteps(test.increase) + lu.assertEquals(hsmocks.window.rect, test.expect, test.desc) + end +end + os.exit(lu.LuaUnit.run()) From ae03cc3fe384cdd6e692a8f988593ee82fc15e6a Mon Sep 17 00:00:00 2001 From: Peter Klijn Date: Sun, 28 Aug 2022 12:20:19 +0100 Subject: [PATCH 6/7] Add some edge case tests for decreasing and increasing windows --- init_test.lua | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/init_test.lua b/init_test.lua index d9be559..1605e22 100644 --- a/init_test.lua +++ b/init_test.lua @@ -165,4 +165,50 @@ function TestShiftIt.testResizeWindowInStepsStickingToCorners() end end +function TestShiftIt.testResizeWindowInStepsEdgeCases() + local tests = { + { + desc = 'does not exceed screen width', + before = { x = 5, y = 200, w = 1190, h = 400 }, + expect = { x = 0, y = 134, w = 1200, h = 532 }, + increase = true, + }, + { + desc = 'does not exceed screen height', + before = { x = 200, y = 5, w = 800, h = 790 }, + expect = { x = 100, y = 0, w = 1000, h = 800 }, + increase = true, + }, + { + desc = 'does not exceed screen size', + before = { x = 5, y = 5, w = 1190, h = 790 }, + expect = { x = 0, y = 0, w = 1200, h = 800 }, + increase = true, + }, + { + desc = 'does not become too narrow', + before = { x = 0, y = 0, w = 300, h = 800 }, + expect = { x = 0, y = 66, w = 300, h = 668 }, + increase = false, + }, + { + desc = 'does not become too short', + before = { x = 0, y = 0, w = 1200, h = 198 }, + expect = { x = 100, y = 0, w = 1000, h = 198 }, + increase = false, + }, + { + desc = 'does not become too tiny', + before = { x = 100, y = 100, w = 300, h = 198 }, + expect = { x = 100, y = 100, w = 300, h = 198 }, + increase = false, + }, + } + for _, test in pairs(tests) do + hsmocks.window.rect = test.before + shiftit:resizeWindowInSteps(test.increase) + lu.assertEquals(hsmocks.window.rect, test.expect, test.desc) + end +end + os.exit(lu.LuaUnit.run()) From cfb3a485b4b6148707d8b260554bf90c54f66e18 Mon Sep 17 00:00:00 2001 From: Peter Klijn Date: Sun, 28 Aug 2022 12:25:08 +0100 Subject: [PATCH 7/7] Added screen and window sizes to reset function --- hammerspoon_mocks.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/hammerspoon_mocks.lua b/hammerspoon_mocks.lua index fe3587c..f6a527d 100644 --- a/hammerspoon_mocks.lua +++ b/hammerspoon_mocks.lua @@ -4,6 +4,9 @@ local hotkey = { bindings = {}, } +local defaultScreenRect = { x = 0, y = 0, w = 1200, h = 800 } +local defaultWindowRect = { x = 100, y = 100, w = 1000, h = 600 } + function hotkey.bind(mods, key, fn) lu.assertNotNil(mods) lu.assertNotNil(key) @@ -12,7 +15,7 @@ function hotkey.bind(mods, key, fn) end local screen = { - rect = { x = 0, y = 0, w = 1200, h = 800 }, + rect = defaultScreenRect, } function screen:frame() @@ -20,7 +23,7 @@ function screen:frame() end local window = { - rect = { x = 0, y = 0, w = 1200, h = 800 }, + rect = defaultWindowRect, _screen = screen, } @@ -51,6 +54,8 @@ local mocks = { function mocks:reset() self.hotkey.bindings = {} + self.window.rect = defaultWindowRect + self.window._screen.rect = defaultScreenRect end return mocks