diff --git a/lua/zettelkasten/action_spec.lua b/lua/test/action_spec.lua similarity index 79% rename from lua/zettelkasten/action_spec.lua rename to lua/test/action_spec.lua index 1d2cec6..d720f4c 100644 --- a/lua/zettelkasten/action_spec.lua +++ b/lua/test/action_spec.lua @@ -34,18 +34,17 @@ describe("open_selected", function() before_each(function() vim.api = { nvim_command = mock(function() end), - nvim_get_current_line = function(sure) + nvim_get_current_line = function(_) return "Hello, this is a line and [mylink](1910271456_link-to-my-file.md) whereas another [link](2030101158 another-link-now.md)" end, - nvim_win_get_cursor = function(winnum) return {0, 0} end + nvim_win_get_cursor = function(_) return {0, 0} end } end) describe("when looking under cursor", function() it("should open link", function() vim.g['zettel_link_following'] = 'cursor' - vim.api.nvim_win_get_cursor = - function(winnum) return {0, 30} end + vim.api.nvim_win_get_cursor = function(_) return {0, 30} end action.open_selected() assert.spy(vim.api.nvim_command).was_called_with( "edit 1910271456_link-to-my-file.md") @@ -53,13 +52,11 @@ describe("open_selected", function() it("should detect correct position for link start", function() vim.g['zettel_link_following'] = 'cursor' - vim.api.nvim_win_get_cursor = - function(winnum) return {0, 25} end + vim.api.nvim_win_get_cursor = function(_) return {0, 25} end action.open_selected() assert.spy(vim.api.nvim_command).was_not_called() - vim.api.nvim_win_get_cursor = - function(winnum) return {0, 26} end + vim.api.nvim_win_get_cursor = function(_) return {0, 26} end action.open_selected() assert.spy(vim.api.nvim_command).was_called_with( "edit 1910271456_link-to-my-file.md") @@ -67,13 +64,11 @@ describe("open_selected", function() it("should detect correct position for link end", function() vim.g['zettel_link_following'] = 'cursor' - vim.api.nvim_win_get_cursor = - function(winnum) return {0, 65} end + vim.api.nvim_win_get_cursor = function(_) return {0, 65} end action.open_selected() assert.spy(vim.api.nvim_command).was_not_called() - vim.api.nvim_win_get_cursor = - function(winnum) return {0, 64} end + vim.api.nvim_win_get_cursor = function(_) return {0, 64} end action.open_selected() assert.spy(vim.api.nvim_command).was_called_with( "edit 1910271456_link-to-my-file.md") @@ -97,8 +92,7 @@ describe("open_selected", function() end) it("should ignore links before cursor position", function() vim.g['zettel_link_following'] = 'line' - vim.api.nvim_win_get_cursor = - function(winnum) return {0, 65} end + vim.api.nvim_win_get_cursor = function(_) return {0, 65} end action.open_selected() assert.spy(vim.api.nvim_command).was_called_with( "edit 2030101158 another-link-now.md") @@ -108,12 +102,15 @@ end) describe("create_link", function() it("substitutes the argument text with a link", function() - -- vim.fn = { - -- getpos = function() return {0, 0, 0, 0} end, - -- getline = function() return "testline" end - -- } pending() - vim.cmd = function() end - action.create_link("my selection", 1, 1, 37) + vim.fn = {getpos = function() return {1, 2, 3} end} + vim.api = { + nvim_buf_get_lines = function() return {"hi", 1, 2} end, + nvim_win_get_cursor = function() return {1, 1, 2} end, + nvim_get_current_line = function() + return "hi i am a line" + end + } + action.make_link() end) end) diff --git a/lua/zettelkasten/anchor_spec.lua b/lua/test/anchor_spec.lua similarity index 100% rename from lua/zettelkasten/anchor_spec.lua rename to lua/test/anchor_spec.lua diff --git a/lua/zettelkasten/files_spec.lua b/lua/test/files_spec.lua similarity index 100% rename from lua/zettelkasten/files_spec.lua rename to lua/test/files_spec.lua diff --git a/lua/zettelkasten/init_spec.lua b/lua/test/init_spec.lua similarity index 100% rename from lua/zettelkasten/init_spec.lua rename to lua/test/init_spec.lua diff --git a/lua/zettelkasten/link_spec.lua b/lua/test/link_spec.lua similarity index 100% rename from lua/zettelkasten/link_spec.lua rename to lua/test/link_spec.lua diff --git a/lua/zettelkasten/options_spec.lua b/lua/test/options_spec.lua similarity index 100% rename from lua/zettelkasten/options_spec.lua rename to lua/test/options_spec.lua diff --git a/lua/zettelkasten/text_spec.lua b/lua/test/text_spec.lua similarity index 100% rename from lua/zettelkasten/text_spec.lua rename to lua/test/text_spec.lua diff --git a/lua/zettelkasten/action.lua b/lua/zettelkasten/action.lua index 9edc778..1a21a0e 100644 --- a/lua/zettelkasten/action.lua +++ b/lua/zettelkasten/action.lua @@ -22,7 +22,7 @@ function A.open_selected(style) style = style or o.link().following local curpos = vim.api.nvim_win_get_cursor(0)[2] - local links = l.extract_all(vim.api.nvim_get_current_line()) + local links = l.extract_all(t.get_line()) local ln if style == 'line' then