fix: bug copying file multiple times

This commit is contained in:
Steven Arcangeli 2023-11-19 23:58:40 -08:00
parent 8f0bf3789f
commit 05cb8257cb
4 changed files with 47 additions and 29 deletions

View file

@ -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)