From 81c9b1e993e25207554293858732ba2d04a4f4ca Mon Sep 17 00:00:00 2001 From: Mika Vilpas Date: Sun, 13 Oct 2024 18:39:59 +0300 Subject: [PATCH] chore: remove unused vimfn.lua (#513) --- lua/yazi/vimfn.lua | 10 ------ spec/yazi/no_open_dir_spec.lua | 22 -------------- spec/yazi/open_dir_with_defaults_spec.lua | 37 ++++++++++++++--------- 3 files changed, 22 insertions(+), 47 deletions(-) delete mode 100644 lua/yazi/vimfn.lua delete mode 100644 spec/yazi/no_open_dir_spec.lua diff --git a/lua/yazi/vimfn.lua b/lua/yazi/vimfn.lua deleted file mode 100644 index 7fd6f08f..00000000 --- a/lua/yazi/vimfn.lua +++ /dev/null @@ -1,10 +0,0 @@ --- This file exists so that I can mock vim.fn functions in tests --- https://github.com/nvim-lua/plenary.nvim/issues/166 - -local M = {} - -function M.termopen(cmd, opts) - return vim.fn.termopen(cmd, opts) -end - -return M diff --git a/spec/yazi/no_open_dir_spec.lua b/spec/yazi/no_open_dir_spec.lua deleted file mode 100644 index 88b3ea00..00000000 --- a/spec/yazi/no_open_dir_spec.lua +++ /dev/null @@ -1,22 +0,0 @@ -local assert = require("luassert") -local mock = require("luassert.mock") - -local api_mock = mock(require("yazi.vimfn")) - -local plugin = require("yazi") - -describe("when the user set open_for_directories = false", function() - after_each(function() - mock.clear(api_mock) - end) - - before_each(function() - ---@diagnostic disable-next-line: missing-fields - plugin.setup({ open_for_directories = false }) - end) - - it("does not show yazi when a directory is opened", function() - vim.api.nvim_command("edit /") - assert.stub(api_mock.termopen).was_not_called() - end) -end) diff --git a/spec/yazi/open_dir_with_defaults_spec.lua b/spec/yazi/open_dir_with_defaults_spec.lua index 3a363ed8..5133f90e 100644 --- a/spec/yazi/open_dir_with_defaults_spec.lua +++ b/spec/yazi/open_dir_with_defaults_spec.lua @@ -1,25 +1,32 @@ local assert = require("luassert") local mock = require("luassert.mock") -local api_mock = mock(require("yazi.vimfn")) - local plugin = require("yazi") -describe( - "when the user has not set open_for_directories and uses the defaults", - function() - after_each(function() - mock.clear(api_mock) - end) +describe("open_for_directories", function() + local hijack_netrw = mock(require("yazi.hijack_netrw"), true) + before_each(function() + mock.clear(hijack_netrw) + end) + + it("sets up hijack_netrw when `open_for_directories` has been set", function() + plugin.setup({ open_for_directories = true }) + + -- instead of netrw opening, yazi should open + vim.api.nvim_command("edit /") + + assert.spy(hijack_netrw.hijack_netrw).was_called(1) + end) - it("does not show yazi when a directory is opened", function() - ---@diagnostic disable-next-line: missing-fields - plugin.setup() + it( + "does not set up hijack_netrw when `open_for_directories` is falsy", + function() + plugin.setup({ open_for_directories = false }) -- instead of netrw opening, yazi should open vim.api.nvim_command("edit /") - assert.stub(api_mock.termopen).was_not_called() - end) - end -) + assert.spy(hijack_netrw.hijack_netrw).was_not_called() + end + ) +end)