feat: oil.select can close oil buffer afterwards (#121)

This commit is contained in:
Steven Arcangeli 2023-06-21 08:36:51 -07:00
parent a82503cd79
commit a465123659
2 changed files with 55 additions and 0 deletions

View file

@ -58,4 +58,45 @@ a.describe("oil select", function()
assert.equals(3, #vim.api.nvim_tabpage_list_wins(0))
assert.not_equals(winid, vim.api.nvim_get_current_win())
end)
a.describe("close after open", function()
a.it("same window", function()
vim.cmd.edit({ args = { "foo" } })
local bufnr = vim.api.nvim_get_current_buf()
oil.open()
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
-- Go to the bottom, so the cursor is not on a directory
vim.cmd.normal({ args = { "G" } })
oil.select({ close = true })
assert.equals(1, #vim.api.nvim_tabpage_list_wins(0))
-- This one we actually don't expect the buffer to be the same as the initial buffer, because
-- we opened a file
assert.not_equals(bufnr, vim.api.nvim_get_current_buf())
assert.not_equals("oil", vim.bo.filetype)
end)
a.it("split", function()
vim.cmd.edit({ args = { "foo" } })
local bufnr = vim.api.nvim_get_current_buf()
local winid = vim.api.nvim_get_current_win()
oil.open()
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
oil.select({ vertical = true, close = true })
assert.equals(2, #vim.api.nvim_tabpage_list_wins(0))
assert.equals(bufnr, vim.api.nvim_win_get_buf(winid))
end)
a.it("tab", function()
vim.cmd.edit({ args = { "foo" } })
local bufnr = vim.api.nvim_get_current_buf()
local tabpage = vim.api.nvim_get_current_tabpage()
oil.open()
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
oil.select({ tab = true, close = true })
assert.equals(1, #vim.api.nvim_tabpage_list_wins(0))
assert.equals(2, #vim.api.nvim_list_tabpages())
vim.api.nvim_set_current_tabpage(tabpage)
assert.equals(bufnr, vim.api.nvim_get_current_buf())
end)
end)
end)