canola.nvim/tests/files_spec.lua
Steven Arcangeli 6175bd6462
feat: trash support for linux and mac (#165)
* wip: skeleton code for trash adapter

* refactor: split trash implementation for mac and linux

* fix: ensure we create the .Trash/$uid dir

* feat: code complete linux trash implementation

* doc: write up trash features

* feat: code complete mac trash implementation

* cleanup: remove previous, terrible, undocumented trash feature

* fix: always disabled trash

* feat: show original path of trashed files

* doc: add a note about calling actions directly

* fix: bugs in trash implementation

* fix: schedule_wrap in mac trash

* doc: fix typo and line wrapping

* fix: parsing of arguments to :Oil command

* doc: small documentation tweaks

* doc: fix awkward wording in the toggle_trash action

* fix: warning on Windows when delete_to_trash = true

* feat: :Oil --trash can open specific trash directories

* fix: show all trash files in device root

* fix: trash mtime should be sortable

* fix: shorten_path handles optional trailing slash

* refactor: overhaul the UI

* fix: keep trash original path vtext from stacking

* refactor: replace disable_changes with an error filter

* fix: shorten path names in home directory relative to root

* doc: small README format changes

* cleanup: remove unnecessary preserve_undo logic

* test: add a functional test for the freedesktop trash adapter

* test: more functional tests for trash

* fix: schedule a callback to avoid main loop error

* refactor: clean up mutator logic

* doc: some comments and type annotations
2023-11-05 12:40:58 -08:00

172 lines
5.1 KiB
Lua

require("plenary.async").tests.add_to_env()
local TmpDir = require("tests.tmpdir")
local files = require("oil.adapters.files")
local test_util = require("tests.test_util")
a.describe("files adapter", function()
local tmpdir
a.before_each(function()
tmpdir = TmpDir.new()
end)
a.after_each(function()
if tmpdir then
tmpdir:dispose()
end
test_util.reset_editor()
end)
a.it("tmpdir creates files and asserts they exist", function()
tmpdir:create({ "a.txt", "foo/b.txt", "foo/c.txt", "bar/" })
tmpdir:assert_fs({
["a.txt"] = "a.txt",
["foo/b.txt"] = "foo/b.txt",
["foo/c.txt"] = "foo/c.txt",
["bar/"] = true,
})
end)
a.it("Creates files", function()
local err = a.wrap(files.perform_action, 2)({
url = "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") .. "a.txt",
entry_type = "file",
type = "create",
})
assert.is_nil(err)
tmpdir:assert_fs({
["a.txt"] = "",
})
end)
a.it("Creates directories", function()
local err = a.wrap(files.perform_action, 2)({
url = "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") .. "a",
entry_type = "directory",
type = "create",
})
assert.is_nil(err)
tmpdir:assert_fs({
["a/"] = true,
})
end)
a.it("Deletes files", function()
tmpdir:create({ "a.txt" })
a.util.scheduler()
local url = "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") .. "a.txt"
local err = a.wrap(files.perform_action, 2)({
url = url,
entry_type = "file",
type = "delete",
})
assert.is_nil(err)
tmpdir:assert_fs({})
end)
a.it("Deletes directories", function()
tmpdir:create({ "a/" })
local url = "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") .. "a"
local err = a.wrap(files.perform_action, 2)({
url = url,
entry_type = "directory",
type = "delete",
})
assert.is_nil(err)
tmpdir:assert_fs({})
end)
a.it("Moves files", function()
tmpdir:create({ "a.txt" })
a.util.scheduler()
local src_url = "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") .. "a.txt"
local dest_url = "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") .. "b.txt"
local err = a.wrap(files.perform_action, 2)({
src_url = src_url,
dest_url = dest_url,
entry_type = "file",
type = "move",
})
assert.is_nil(err)
tmpdir:assert_fs({
["b.txt"] = "a.txt",
})
end)
a.it("Moves directories", function()
tmpdir:create({ "a/a.txt" })
a.util.scheduler()
local src_url = "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") .. "a"
local dest_url = "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") .. "b"
local err = a.wrap(files.perform_action, 2)({
src_url = src_url,
dest_url = dest_url,
entry_type = "directory",
type = "move",
})
assert.is_nil(err)
tmpdir:assert_fs({
["b/a.txt"] = "a/a.txt",
["b/"] = true,
})
end)
a.it("Copies files", function()
tmpdir:create({ "a.txt" })
a.util.scheduler()
local src_url = "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") .. "a.txt"
local dest_url = "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") .. "b.txt"
local err = a.wrap(files.perform_action, 2)({
src_url = src_url,
dest_url = dest_url,
entry_type = "file",
type = "copy",
})
assert.is_nil(err)
tmpdir:assert_fs({
["a.txt"] = "a.txt",
["b.txt"] = "a.txt",
})
end)
a.it("Recursively copies directories", function()
tmpdir:create({ "a/a.txt" })
a.util.scheduler()
local src_url = "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") .. "a"
local dest_url = "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") .. "b"
local err = a.wrap(files.perform_action, 2)({
src_url = src_url,
dest_url = dest_url,
entry_type = "directory",
type = "copy",
})
assert.is_nil(err)
tmpdir:assert_fs({
["b/a.txt"] = "a/a.txt",
["b/"] = true,
["a/a.txt"] = "a/a.txt",
["a/"] = true,
})
end)
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" })
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" })
assert.equals("oil", vim.bo.filetype)
-- The normalization will add a '/'
assert.equals(new_url .. "/", vim.api.nvim_buf_get_name(0))
end)
a.it("Editing a new oil://file.rb creates a normal buffer", function()
local tmpdir_url = "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") .. "/"
vim.cmd.edit({ args = { tmpdir_url } })
test_util.wait_for_autocmd("BufReadPost")
local new_url = "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") .. "file.rb"
vim.cmd.edit({ args = { new_url } })
test_util.wait_for_autocmd("BufReadPost")
assert.equals("ruby", vim.bo.filetype)
assert.equals(vim.fn.fnamemodify(tmpdir.path, ":p") .. "file.rb", vim.api.nvim_buf_get_name(0))
end)
end)