feat: builtin support for editing files over ssh (#27)
This commit is contained in:
parent
75b710e311
commit
ca4da68aae
18 changed files with 593 additions and 291 deletions
|
|
@ -1,56 +1,67 @@
|
|||
require("plenary.async").tests.add_to_env()
|
||||
local oil = require("oil")
|
||||
local test_util = require("tests.test_util")
|
||||
local fs = require("oil.fs")
|
||||
|
||||
describe("Alternate buffer", function()
|
||||
a.describe("Alternate buffer", function()
|
||||
after_each(function()
|
||||
test_util.reset_editor()
|
||||
end)
|
||||
|
||||
it("sets previous buffer as alternate", function()
|
||||
a.it("sets previous buffer as alternate", function()
|
||||
vim.cmd.edit({ args = { "foo" } })
|
||||
oil.open()
|
||||
test_util.wait_for_autocmd("BufReadPost")
|
||||
vim.cmd.edit({ args = { "bar" } })
|
||||
assert.equals("foo", vim.fn.expand("#"))
|
||||
end)
|
||||
|
||||
it("sets previous buffer as alternate when editing oil://", function()
|
||||
a.it("sets previous buffer as alternate when editing oil://", function()
|
||||
vim.cmd.edit({ args = { "foo" } })
|
||||
vim.cmd.edit({ args = { "oil://" .. fs.os_to_posix_path(vim.fn.getcwd()) } })
|
||||
test_util.wait_for_autocmd("BufReadPost")
|
||||
vim.cmd.edit({ args = { "bar" } })
|
||||
assert.equals("foo", vim.fn.expand("#"))
|
||||
end)
|
||||
|
||||
it("preserves alternate buffer if editing the same file", function()
|
||||
a.it("preserves alternate buffer if editing the same file", function()
|
||||
vim.cmd.edit({ args = { "foo" } })
|
||||
vim.cmd.edit({ args = { "bar" } })
|
||||
oil.open()
|
||||
test_util.wait_for_autocmd("BufReadPost")
|
||||
vim.cmd.edit({ args = { "bar" } })
|
||||
assert.equals("foo", vim.fn.expand("#"))
|
||||
end)
|
||||
|
||||
it("preserves alternate buffer if discarding changes", function()
|
||||
a.it("preserves alternate buffer if discarding changes", function()
|
||||
vim.cmd.edit({ args = { "foo" } })
|
||||
vim.cmd.edit({ args = { "bar" } })
|
||||
oil.open()
|
||||
test_util.wait_for_autocmd("BufReadPost")
|
||||
oil.close()
|
||||
assert.equals("bar", vim.fn.expand("%"))
|
||||
assert.equals("foo", vim.fn.expand("#"))
|
||||
end)
|
||||
|
||||
it("sets previous buffer as alternate after multi-dir hops", function()
|
||||
a.it("sets previous buffer as alternate after multi-dir hops", function()
|
||||
vim.cmd.edit({ args = { "foo" } })
|
||||
oil.open()
|
||||
test_util.wait_for_autocmd("BufReadPost")
|
||||
oil.open()
|
||||
test_util.wait_for_autocmd("BufReadPost")
|
||||
oil.open()
|
||||
test_util.wait_for_autocmd("BufReadPost")
|
||||
oil.open()
|
||||
test_util.wait_for_autocmd("BufReadPost")
|
||||
vim.cmd.edit({ args = { "bar" } })
|
||||
assert.equals("foo", vim.fn.expand("#"))
|
||||
end)
|
||||
|
||||
describe("floating window", function()
|
||||
it("sets previous buffer as alternate", function()
|
||||
a.describe("floating window", function()
|
||||
a.it("sets previous buffer as alternate", function()
|
||||
vim.cmd.edit({ args = { "foo" } })
|
||||
oil.open_float()
|
||||
test_util.wait_for_autocmd("BufReadPost")
|
||||
-- This is lazy, but testing the actual select logic is more difficult. We can simply
|
||||
-- replicated it by closing the current window and then doing the edit
|
||||
vim.api.nvim_win_close(0, true)
|
||||
|
|
@ -58,10 +69,11 @@ describe("Alternate buffer", function()
|
|||
assert.equals("foo", vim.fn.expand("#"))
|
||||
end)
|
||||
|
||||
it("preserves alternate buffer if editing the same file", function()
|
||||
a.it("preserves alternate buffer if editing the same file", function()
|
||||
vim.cmd.edit({ args = { "foo" } })
|
||||
vim.cmd.edit({ args = { "bar" } })
|
||||
oil.open_float()
|
||||
test_util.wait_for_autocmd("BufReadPost")
|
||||
-- This is lazy, but testing the actual select logic is more difficult. We can simply
|
||||
-- replicated it by closing the current window and then doing the edit
|
||||
vim.api.nvim_win_close(0, true)
|
||||
|
|
@ -69,10 +81,11 @@ describe("Alternate buffer", function()
|
|||
assert.equals("foo", vim.fn.expand("#"))
|
||||
end)
|
||||
|
||||
it("preserves alternate buffer if discarding changes", function()
|
||||
a.it("preserves alternate buffer if discarding changes", function()
|
||||
vim.cmd.edit({ args = { "foo" } })
|
||||
vim.cmd.edit({ args = { "bar" } })
|
||||
oil.open_float()
|
||||
test_util.wait_for_autocmd("BufReadPost")
|
||||
oil.close()
|
||||
assert.equals("foo", vim.fn.expand("#"))
|
||||
end)
|
||||
|
|
|
|||
59
tests/move_rename_spec.lua
Normal file
59
tests/move_rename_spec.lua
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
local fs = require("oil.fs")
|
||||
local test_util = require("tests.test_util")
|
||||
local util = require("oil.util")
|
||||
|
||||
describe("update_moved_buffers", function()
|
||||
after_each(function()
|
||||
test_util.reset_editor()
|
||||
end)
|
||||
|
||||
it("Renames moved buffers", function()
|
||||
vim.cmd.edit({ args = { "oil-test:///foo/bar.txt" } })
|
||||
util.update_moved_buffers("file", "oil-test:///foo/bar.txt", "oil-test:///foo/baz.txt")
|
||||
assert.equals("oil-test:///foo/baz.txt", vim.api.nvim_buf_get_name(0))
|
||||
end)
|
||||
|
||||
it("Renames moved buffers when they are normal files", function()
|
||||
local tmpdir = fs.join(vim.loop.fs_realpath(vim.fn.stdpath("cache")), "oil", "test")
|
||||
local testfile = fs.join(tmpdir, "foo.txt")
|
||||
vim.cmd.edit({ args = { testfile } })
|
||||
util.update_moved_buffers(
|
||||
"file",
|
||||
"oil://" .. fs.os_to_posix_path(testfile),
|
||||
"oil://" .. fs.os_to_posix_path(fs.join(tmpdir, "bar.txt"))
|
||||
)
|
||||
assert.equals(fs.join(tmpdir, "bar.txt"), vim.api.nvim_buf_get_name(0))
|
||||
end)
|
||||
|
||||
it("Renames directories", function()
|
||||
vim.cmd.edit({ args = { "oil-test:///foo/" } })
|
||||
util.update_moved_buffers("directory", "oil-test:///foo/", "oil-test:///bar/")
|
||||
assert.equals("oil-test:///bar/", vim.api.nvim_buf_get_name(0))
|
||||
end)
|
||||
|
||||
it("Renames subdirectories", function()
|
||||
vim.cmd.edit({ args = { "oil-test:///foo/bar/" } })
|
||||
util.update_moved_buffers("directory", "oil-test:///foo/", "oil-test:///baz/")
|
||||
assert.equals("oil-test:///baz/bar/", vim.api.nvim_buf_get_name(0))
|
||||
end)
|
||||
|
||||
it("Renames subfiles", function()
|
||||
vim.cmd.edit({ args = { "oil-test:///foo/bar.txt" } })
|
||||
util.update_moved_buffers("directory", "oil-test:///foo/", "oil-test:///baz/")
|
||||
assert.equals("oil-test:///baz/bar.txt", vim.api.nvim_buf_get_name(0))
|
||||
end)
|
||||
|
||||
it("Renames subfiles when they are normal files", function()
|
||||
local tmpdir = fs.join(vim.loop.fs_realpath(vim.fn.stdpath("cache")), "oil", "test")
|
||||
local foo = fs.join(tmpdir, "foo")
|
||||
local bar = fs.join(tmpdir, "bar")
|
||||
local testfile = fs.join(foo, "foo.txt")
|
||||
vim.cmd.edit({ args = { testfile } })
|
||||
util.update_moved_buffers(
|
||||
"directory",
|
||||
"oil://" .. fs.os_to_posix_path(foo),
|
||||
"oil://" .. fs.os_to_posix_path(bar)
|
||||
)
|
||||
assert.equals(fs.join(bar, "foo.txt"), vim.api.nvim_buf_get_name(0))
|
||||
end)
|
||||
end)
|
||||
|
|
@ -15,14 +15,14 @@ a.describe("regression tests", function()
|
|||
vim.cmd.wincmd({ args = { "p" } })
|
||||
assert.equals("markdown", vim.bo.filetype)
|
||||
vim.cmd.edit({ args = { "%:p:h" } })
|
||||
a.util.sleep(10)
|
||||
test_util.wait_for_autocmd("BufReadPost")
|
||||
assert.equals("oil", vim.bo.filetype)
|
||||
end)
|
||||
|
||||
-- https://github.com/stevearc/oil.nvim/issues/37
|
||||
a.it("places the cursor on correct entry when opening on file", function()
|
||||
vim.cmd.edit({ args = { "." } })
|
||||
a.util.sleep(10)
|
||||
test_util.wait_for_autocmd("BufReadPost")
|
||||
local entry = oil.get_cursor_entry()
|
||||
assert.not_equals("README.md", entry and entry.name)
|
||||
vim.cmd.edit({ args = { "README.md" } })
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
require("plenary.async").tests.add_to_env()
|
||||
local M = {}
|
||||
|
||||
M.reset_editor = function()
|
||||
|
|
@ -16,4 +17,13 @@ M.reset_editor = function()
|
|||
end
|
||||
end
|
||||
|
||||
M.wait_for_autocmd = a.wrap(function(autocmd, cb)
|
||||
vim.api.nvim_create_autocmd(autocmd, {
|
||||
pattern = "*",
|
||||
nested = true,
|
||||
once = true,
|
||||
callback = vim.schedule_wrap(cb),
|
||||
})
|
||||
end, 2)
|
||||
|
||||
return M
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ describe("url", function()
|
|||
{ "/foo/bar.txt", "oil:///foo/", "bar.txt" },
|
||||
{ "oil:///foo/bar.txt", "oil:///foo/", "bar.txt" },
|
||||
{ "oil:///", "oil:///" },
|
||||
{ "scp://user@hostname:8888//bar.txt", "oil-ssh://user@hostname:8888//", "bar.txt" },
|
||||
{ "oil-ssh://user@hostname:8888//", "oil-ssh://user@hostname:8888//" },
|
||||
{ "scp://user@hostname:8888//bar.txt", "scp://user@hostname:8888//", "bar.txt" },
|
||||
{ "scp://user@hostname:8888//", "scp://user@hostname:8888//" },
|
||||
}
|
||||
for _, case in ipairs(cases) do
|
||||
local input, expected, expected_basename = unpack(case)
|
||||
|
|
|
|||
|
|
@ -1,35 +1,40 @@
|
|||
require("plenary.async").tests.add_to_env()
|
||||
local oil = require("oil")
|
||||
local test_util = require("tests.test_util")
|
||||
|
||||
describe("window options", function()
|
||||
a.describe("window options", function()
|
||||
after_each(function()
|
||||
test_util.reset_editor()
|
||||
end)
|
||||
|
||||
it("Restores window options on close", function()
|
||||
a.it("Restores window options on close", function()
|
||||
vim.cmd.edit({ args = { "README.md" } })
|
||||
oil.open()
|
||||
test_util.wait_for_autocmd("BufReadPost")
|
||||
assert.equals("no", vim.o.signcolumn)
|
||||
oil.close()
|
||||
assert.equals("auto", vim.o.signcolumn)
|
||||
end)
|
||||
|
||||
it("Restores window options on edit", function()
|
||||
a.it("Restores window options on edit", function()
|
||||
oil.open()
|
||||
test_util.wait_for_autocmd("BufReadPost")
|
||||
assert.equals("no", vim.o.signcolumn)
|
||||
vim.cmd.edit({ args = { "README.md" } })
|
||||
assert.equals("auto", vim.o.signcolumn)
|
||||
end)
|
||||
|
||||
it("Restores window options on split <filename>", function()
|
||||
a.it("Restores window options on split <filename>", function()
|
||||
oil.open()
|
||||
test_util.wait_for_autocmd("BufReadPost")
|
||||
assert.equals("no", vim.o.signcolumn)
|
||||
vim.cmd.split({ args = { "README.md" } })
|
||||
assert.equals("auto", vim.o.signcolumn)
|
||||
end)
|
||||
|
||||
it("Restores window options on split", function()
|
||||
a.it("Restores window options on split", function()
|
||||
oil.open()
|
||||
test_util.wait_for_autocmd("BufReadPost")
|
||||
assert.equals("no", vim.o.signcolumn)
|
||||
vim.cmd.split()
|
||||
vim.cmd.edit({ args = { "README.md" } })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue