fix: bug copying file multiple times
This commit is contained in:
parent
8f0bf3789f
commit
05cb8257cb
4 changed files with 47 additions and 29 deletions
|
|
@ -12,7 +12,6 @@ a.describe("regression tests", function()
|
|||
a.after_each(function()
|
||||
if tmpdir then
|
||||
tmpdir:dispose()
|
||||
a.util.scheduler()
|
||||
tmpdir = nil
|
||||
end
|
||||
test_util.reset_editor()
|
||||
|
|
@ -117,4 +116,19 @@ a.describe("regression tests", function()
|
|||
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
|
||||
assert.are.same({ bufnr }, require("oil.view").get_all_buffers())
|
||||
end)
|
||||
|
||||
a.it("can copy a file multiple times", function()
|
||||
test_util.actions.open({ tmpdir.path })
|
||||
vim.api.nvim_feedkeys("ifoo.txt", "x", true)
|
||||
test_util.actions.save()
|
||||
vim.api.nvim_feedkeys("yyp$ciWbar.txt", "x", true)
|
||||
vim.api.nvim_feedkeys("yyp$ciWbaz.txt", "x", true)
|
||||
test_util.actions.save()
|
||||
assert.are.same({ "bar.txt", "baz.txt", "foo.txt" }, test_util.parse_entries(0))
|
||||
tmpdir:assert_fs({
|
||||
["foo.txt"] = "",
|
||||
["bar.txt"] = "",
|
||||
["baz.txt"] = "",
|
||||
})
|
||||
end)
|
||||
end)
|
||||
|
|
|
|||
|
|
@ -114,4 +114,18 @@ M.actions = {
|
|||
end,
|
||||
}
|
||||
|
||||
---Get the raw list of filenames from an unmodified oil buffer
|
||||
---@param bufnr? integer
|
||||
---@return string[]
|
||||
M.parse_entries = function(bufnr)
|
||||
bufnr = bufnr or 0
|
||||
if vim.bo[bufnr].modified then
|
||||
error("parse_entries doesn't work on a modified oil buffer")
|
||||
end
|
||||
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, true)
|
||||
return vim.tbl_map(function(line)
|
||||
return line:match("^/%d+ +(.+)$")
|
||||
end, lines)
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
|||
|
|
@ -2,20 +2,6 @@ require("plenary.async").tests.add_to_env()
|
|||
local TmpDir = require("tests.tmpdir")
|
||||
local test_util = require("tests.test_util")
|
||||
|
||||
---Get the raw list of filenames from an unmodified oil buffer
|
||||
---@param bufnr? integer
|
||||
---@return string[]
|
||||
local function parse_entries(bufnr)
|
||||
bufnr = bufnr or 0
|
||||
if vim.bo[bufnr].modified then
|
||||
error("parse_entries doesn't work on a modified oil buffer")
|
||||
end
|
||||
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, true)
|
||||
return vim.tbl_map(function(line)
|
||||
return line:match("^/%d+ +(.+)$")
|
||||
end, lines)
|
||||
end
|
||||
|
||||
a.describe("freedesktop", function()
|
||||
local tmpdir
|
||||
local tmphome
|
||||
|
|
@ -50,7 +36,7 @@ a.describe("freedesktop", function()
|
|||
tmpdir:assert_not_exists("a.txt")
|
||||
tmpdir:assert_exists("foo/b.txt")
|
||||
test_util.actions.reload()
|
||||
assert.are.same({ "a.txt" }, parse_entries(0))
|
||||
assert.are.same({ "a.txt" }, test_util.parse_entries(0))
|
||||
end)
|
||||
|
||||
a.it("deleting a file moves it to trash", function()
|
||||
|
|
@ -62,7 +48,7 @@ a.describe("freedesktop", function()
|
|||
tmpdir:assert_not_exists("a.txt")
|
||||
tmpdir:assert_exists("foo/b.txt")
|
||||
test_util.actions.open({ "--trash", tmpdir.path })
|
||||
assert.are.same({ "a.txt" }, parse_entries(0))
|
||||
assert.are.same({ "a.txt" }, test_util.parse_entries(0))
|
||||
end)
|
||||
|
||||
a.it("deleting a directory moves it to trash", function()
|
||||
|
|
@ -74,7 +60,7 @@ a.describe("freedesktop", function()
|
|||
tmpdir:assert_not_exists("foo")
|
||||
tmpdir:assert_exists("a.txt")
|
||||
test_util.actions.open({ "--trash", tmpdir.path })
|
||||
assert.are.same({ "foo/" }, parse_entries(0))
|
||||
assert.are.same({ "foo/" }, test_util.parse_entries(0))
|
||||
end)
|
||||
|
||||
a.it("deleting a file from trash deletes it permanently", function()
|
||||
|
|
@ -89,7 +75,7 @@ a.describe("freedesktop", function()
|
|||
test_util.actions.save()
|
||||
test_util.actions.reload()
|
||||
tmpdir:assert_not_exists("a.txt")
|
||||
assert.are.same({}, parse_entries(0))
|
||||
assert.are.same({}, test_util.parse_entries(0))
|
||||
end)
|
||||
|
||||
a.it("cannot create files in the trash", function()
|
||||
|
|
@ -102,7 +88,7 @@ a.describe("freedesktop", function()
|
|||
vim.api.nvim_feedkeys("onew_file.txt", "x", true)
|
||||
test_util.actions.save()
|
||||
test_util.actions.reload()
|
||||
assert.are.same({ "a.txt" }, parse_entries(0))
|
||||
assert.are.same({ "a.txt" }, test_util.parse_entries(0))
|
||||
end)
|
||||
|
||||
a.it("cannot rename files in the trash", function()
|
||||
|
|
@ -115,7 +101,7 @@ a.describe("freedesktop", function()
|
|||
vim.api.nvim_feedkeys("0facwnew_name", "x", true)
|
||||
test_util.actions.save()
|
||||
test_util.actions.reload()
|
||||
assert.are.same({ "a.txt" }, parse_entries(0))
|
||||
assert.are.same({ "a.txt" }, test_util.parse_entries(0))
|
||||
end)
|
||||
|
||||
a.it("cannot copy files in the trash", function()
|
||||
|
|
@ -128,7 +114,7 @@ a.describe("freedesktop", function()
|
|||
vim.api.nvim_feedkeys("yypp", "x", true)
|
||||
test_util.actions.save()
|
||||
test_util.actions.reload()
|
||||
assert.are.same({ "a.txt" }, parse_entries(0))
|
||||
assert.are.same({ "a.txt" }, test_util.parse_entries(0))
|
||||
end)
|
||||
|
||||
a.it("can restore files from trash", function()
|
||||
|
|
@ -143,7 +129,7 @@ a.describe("freedesktop", function()
|
|||
vim.api.nvim_feedkeys("p", "x", true)
|
||||
test_util.actions.save()
|
||||
test_util.actions.reload()
|
||||
assert.are.same({ "a.txt" }, parse_entries(0))
|
||||
assert.are.same({ "a.txt" }, test_util.parse_entries(0))
|
||||
tmpdir:assert_fs({
|
||||
["a.txt"] = "a.txt",
|
||||
})
|
||||
|
|
@ -159,6 +145,6 @@ a.describe("freedesktop", function()
|
|||
vim.api.nvim_feedkeys("dd", "x", true)
|
||||
test_util.actions.save()
|
||||
test_util.actions.open({ "--trash", tmpdir.path })
|
||||
assert.are.same({ "a.txt", "a.txt" }, parse_entries(0))
|
||||
assert.are.same({ "a.txt", "a.txt" }, test_util.parse_entries(0))
|
||||
end)
|
||||
end)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue