test: refactor tests to use new helper methods
This commit is contained in:
parent
57528bf9c5
commit
2f6ed70161
5 changed files with 22 additions and 33 deletions
|
|
@ -150,10 +150,10 @@ a.describe("files adapter", function()
|
|||
a.it("Editing a new oil://path/ creates an oil buffer", function()
|
||||
local tmpdir_url = "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") .. "/"
|
||||
vim.cmd.edit({ args = { tmpdir_url } })
|
||||
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
|
||||
test_util.wait_oil_ready()
|
||||
local new_url = "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") .. "newdir"
|
||||
vim.cmd.edit({ args = { new_url } })
|
||||
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
|
||||
test_util.wait_oil_ready()
|
||||
assert.equals("oil", vim.bo.filetype)
|
||||
-- The normalization will add a '/'
|
||||
assert.equals(new_url .. "/", vim.api.nvim_buf_get_name(0))
|
||||
|
|
|
|||
|
|
@ -18,8 +18,7 @@ a.describe("oil preview", function()
|
|||
|
||||
a.it("opens preview window", function()
|
||||
tmpdir:create({ "a.txt" })
|
||||
oil.open(tmpdir.path)
|
||||
test_util.wait_oil_ready()
|
||||
test_util.oil_open(tmpdir.path)
|
||||
a.wrap(oil.open_preview, 2)()
|
||||
local preview_win = util.get_preview_win()
|
||||
assert.not_nil(preview_win)
|
||||
|
|
@ -31,7 +30,7 @@ a.describe("oil preview", function()
|
|||
|
||||
a.it("opens preview window when open(preview={})", function()
|
||||
tmpdir:create({ "a.txt" })
|
||||
a.wrap(oil.open, 3)(tmpdir.path, { preview = {} })
|
||||
test_util.oil_open(tmpdir.path, { preview = {} })
|
||||
local preview_win = util.get_preview_win()
|
||||
assert.not_nil(preview_win)
|
||||
assert(preview_win)
|
||||
|
|
|
|||
|
|
@ -8,8 +8,7 @@ a.describe("oil select", function()
|
|||
end)
|
||||
|
||||
a.it("opens file under cursor", function()
|
||||
oil.open()
|
||||
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
|
||||
test_util.oil_open()
|
||||
-- Go to the bottom, so the cursor is not on a directory
|
||||
vim.cmd.normal({ args = { "G" } })
|
||||
a.wrap(oil.select, 2)()
|
||||
|
|
@ -18,8 +17,7 @@ a.describe("oil select", function()
|
|||
end)
|
||||
|
||||
a.it("opens file in new tab", function()
|
||||
oil.open()
|
||||
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
|
||||
test_util.oil_open()
|
||||
local tabpage = vim.api.nvim_get_current_tabpage()
|
||||
a.wrap(oil.select, 2)({ tab = true })
|
||||
assert.equals(2, #vim.api.nvim_list_tabpages())
|
||||
|
|
@ -28,8 +26,7 @@ a.describe("oil select", function()
|
|||
end)
|
||||
|
||||
a.it("opens file in new split", function()
|
||||
oil.open()
|
||||
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
|
||||
test_util.oil_open()
|
||||
local winid = vim.api.nvim_get_current_win()
|
||||
a.wrap(oil.select, 2)({ vertical = true })
|
||||
assert.equals(1, #vim.api.nvim_list_tabpages())
|
||||
|
|
@ -38,8 +35,7 @@ a.describe("oil select", function()
|
|||
end)
|
||||
|
||||
a.it("opens multiple files in new tabs", function()
|
||||
oil.open()
|
||||
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
|
||||
test_util.oil_open()
|
||||
vim.api.nvim_feedkeys("Vj", "x", true)
|
||||
local tabpage = vim.api.nvim_get_current_tabpage()
|
||||
a.wrap(oil.select, 2)({ tab = true })
|
||||
|
|
@ -49,8 +45,7 @@ a.describe("oil select", function()
|
|||
end)
|
||||
|
||||
a.it("opens multiple files in new splits", function()
|
||||
oil.open()
|
||||
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
|
||||
test_util.oil_open()
|
||||
vim.api.nvim_feedkeys("Vj", "x", true)
|
||||
local winid = vim.api.nvim_get_current_win()
|
||||
a.wrap(oil.select, 2)({ vertical = true })
|
||||
|
|
@ -63,8 +58,7 @@ a.describe("oil select", 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" })
|
||||
test_util.oil_open()
|
||||
-- Go to the bottom, so the cursor is not on a directory
|
||||
vim.cmd.normal({ args = { "G" } })
|
||||
a.wrap(oil.select, 2)({ close = true })
|
||||
|
|
@ -79,8 +73,7 @@ a.describe("oil select", 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" })
|
||||
test_util.oil_open()
|
||||
a.wrap(oil.select, 2)({ vertical = true, close = true })
|
||||
assert.equals(2, #vim.api.nvim_tabpage_list_wins(0))
|
||||
assert.equals(bufnr, vim.api.nvim_win_get_buf(winid))
|
||||
|
|
@ -90,8 +83,7 @@ a.describe("oil select", 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" })
|
||||
test_util.oil_open()
|
||||
a.wrap(oil.select, 2)({ tab = true, close = true })
|
||||
assert.equals(1, #vim.api.nvim_tabpage_list_wins(0))
|
||||
assert.equals(2, #vim.api.nvim_list_tabpages())
|
||||
|
|
|
|||
|
|
@ -34,6 +34,10 @@ local function throwiferr(err, ...)
|
|||
end
|
||||
end
|
||||
|
||||
M.oil_open = function(...)
|
||||
a.wrap(require("oil").open, 3)(...)
|
||||
end
|
||||
|
||||
M.await = function(fn, nargs, ...)
|
||||
return throwiferr(a.wrap(fn, nargs)(...))
|
||||
end
|
||||
|
|
|
|||
|
|
@ -9,32 +9,28 @@ a.describe("window options", function()
|
|||
|
||||
a.it("Restores window options on close", function()
|
||||
vim.cmd.edit({ args = { "README.md" } })
|
||||
oil.open()
|
||||
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
|
||||
test_util.oil_open()
|
||||
assert.equals("no", vim.o.signcolumn)
|
||||
oil.close()
|
||||
assert.equals("auto", vim.o.signcolumn)
|
||||
end)
|
||||
|
||||
a.it("Restores window options on edit", function()
|
||||
oil.open()
|
||||
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
|
||||
test_util.oil_open()
|
||||
assert.equals("no", vim.o.signcolumn)
|
||||
vim.cmd.edit({ args = { "README.md" } })
|
||||
assert.equals("auto", vim.o.signcolumn)
|
||||
end)
|
||||
|
||||
a.it("Restores window options on split <filename>", function()
|
||||
oil.open()
|
||||
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
|
||||
test_util.oil_open()
|
||||
assert.equals("no", vim.o.signcolumn)
|
||||
vim.cmd.split({ args = { "README.md" } })
|
||||
assert.equals("auto", vim.o.signcolumn)
|
||||
end)
|
||||
|
||||
a.it("Restores window options on split", function()
|
||||
oil.open()
|
||||
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
|
||||
test_util.oil_open()
|
||||
assert.equals("no", vim.o.signcolumn)
|
||||
vim.cmd.split()
|
||||
vim.cmd.edit({ args = { "README.md" } })
|
||||
|
|
@ -42,16 +38,14 @@ a.describe("window options", function()
|
|||
end)
|
||||
|
||||
a.it("Restores window options on tabnew <filename>", function()
|
||||
oil.open()
|
||||
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
|
||||
test_util.oil_open()
|
||||
assert.equals("no", vim.o.signcolumn)
|
||||
vim.cmd.tabnew({ args = { "README.md" } })
|
||||
assert.equals("auto", vim.o.signcolumn)
|
||||
end)
|
||||
|
||||
a.it("Restores window options on tabnew", function()
|
||||
oil.open()
|
||||
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
|
||||
test_util.oil_open()
|
||||
assert.equals("no", vim.o.signcolumn)
|
||||
vim.cmd.tabnew()
|
||||
vim.cmd.edit({ args = { "README.md" } })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue