test: add tests for oil.select
This commit is contained in:
parent
0215ed3b0b
commit
a82503cd79
2 changed files with 71 additions and 3 deletions
61
tests/select_spec.lua
Normal file
61
tests/select_spec.lua
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
require("plenary.async").tests.add_to_env()
|
||||
local oil = require("oil")
|
||||
local test_util = require("tests.test_util")
|
||||
|
||||
a.describe("oil select", function()
|
||||
after_each(function()
|
||||
test_util.reset_editor()
|
||||
end)
|
||||
|
||||
a.it("opens file under cursor", function()
|
||||
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()
|
||||
assert.equals(1, #vim.api.nvim_tabpage_list_wins(0))
|
||||
assert.not_equals("oil", vim.bo.filetype)
|
||||
end)
|
||||
|
||||
a.it("opens file in new tab", function()
|
||||
oil.open()
|
||||
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
|
||||
local tabpage = vim.api.nvim_get_current_tabpage()
|
||||
oil.select({ tab = true })
|
||||
assert.equals(2, #vim.api.nvim_list_tabpages())
|
||||
assert.equals(1, #vim.api.nvim_tabpage_list_wins(0))
|
||||
assert.not_equals(tabpage, vim.api.nvim_get_current_tabpage())
|
||||
end)
|
||||
|
||||
a.it("opens file in new split", function()
|
||||
oil.open()
|
||||
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
|
||||
local winid = vim.api.nvim_get_current_win()
|
||||
oil.select({ vertical = true })
|
||||
assert.equals(1, #vim.api.nvim_list_tabpages())
|
||||
assert.equals(2, #vim.api.nvim_tabpage_list_wins(0))
|
||||
assert.not_equals(winid, vim.api.nvim_get_current_win())
|
||||
end)
|
||||
|
||||
a.it("opens multiple files in new tabs", function()
|
||||
oil.open()
|
||||
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
|
||||
vim.api.nvim_feedkeys("Vj", "x", true)
|
||||
local tabpage = vim.api.nvim_get_current_tabpage()
|
||||
oil.select({ tab = true })
|
||||
assert.equals(3, #vim.api.nvim_list_tabpages())
|
||||
assert.equals(1, #vim.api.nvim_tabpage_list_wins(0))
|
||||
assert.not_equals(tabpage, vim.api.nvim_get_current_tabpage())
|
||||
end)
|
||||
|
||||
a.it("opens multiple files in new splits", function()
|
||||
oil.open()
|
||||
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
|
||||
vim.api.nvim_feedkeys("Vj", "x", true)
|
||||
local winid = vim.api.nvim_get_current_win()
|
||||
oil.select({ vertical = true })
|
||||
assert.equals(1, #vim.api.nvim_list_tabpages())
|
||||
assert.equals(3, #vim.api.nvim_tabpage_list_wins(0))
|
||||
assert.not_equals(winid, vim.api.nvim_get_current_win())
|
||||
end)
|
||||
end)
|
||||
|
|
@ -24,12 +24,19 @@ M.reset_editor = function()
|
|||
end
|
||||
|
||||
M.wait_for_autocmd = a.wrap(function(autocmd, cb)
|
||||
vim.api.nvim_create_autocmd(autocmd, {
|
||||
local opts = {
|
||||
pattern = "*",
|
||||
nested = true,
|
||||
once = true,
|
||||
callback = vim.schedule_wrap(cb),
|
||||
})
|
||||
}
|
||||
if type(autocmd) == "table" then
|
||||
opts = vim.tbl_extend("force", opts, autocmd)
|
||||
autocmd = autocmd[1]
|
||||
opts[1] = nil
|
||||
end
|
||||
opts.callback = vim.schedule_wrap(cb)
|
||||
|
||||
vim.api.nvim_create_autocmd(autocmd, opts)
|
||||
end, 2)
|
||||
|
||||
---@param actions string[]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue