refactor: remove cache side effects from adapter.list

This commit is contained in:
Steven Arcangeli 2023-08-20 20:56:54 +00:00
parent ffb89bf416
commit f4819d8b43
8 changed files with 86 additions and 53 deletions

View file

@ -22,6 +22,7 @@ a.describe("mutator", function()
for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do
vim.api.nvim_buf_delete(bufnr, { force = true })
end
test_adapter.test_clear()
cache.clear_everything()
end)
@ -60,7 +61,7 @@ a.describe("mutator", function()
end)
it("detects deleted files", function()
local file = cache.create_and_store_entry("oil-test:///foo/", "a.txt", "file")
local file = test_adapter.test_set("/foo/a.txt", "file")
vim.cmd.edit({ args = { "oil-test:///foo/" } })
local bufnr = vim.api.nvim_get_current_buf()
set_lines(bufnr, {})
@ -71,7 +72,7 @@ a.describe("mutator", function()
end)
it("detects deleted directories", function()
local dir = cache.create_and_store_entry("oil-test:///foo/", "bar", "directory")
local dir = test_adapter.test_set("/foo/bar", "directory")
vim.cmd.edit({ args = { "oil-test:///foo/" } })
local bufnr = vim.api.nvim_get_current_buf()
set_lines(bufnr, {})
@ -82,7 +83,7 @@ a.describe("mutator", function()
end)
it("detects deleted links", function()
local file = cache.create_and_store_entry("oil-test:///foo/", "a.txt", "link")
local file = test_adapter.test_set("/foo/a.txt", "link")
file[FIELD_META] = { link = "b.txt" }
vim.cmd.edit({ args = { "oil-test:///foo/" } })
local bufnr = vim.api.nvim_get_current_buf()
@ -94,7 +95,7 @@ a.describe("mutator", function()
end)
it("ignores empty lines", function()
local file = cache.create_and_store_entry("oil-test:///foo/", "a.txt", "file")
local file = test_adapter.test_set("/foo/a.txt", "file")
vim.cmd.edit({ args = { "oil-test:///foo/" } })
local bufnr = vim.api.nvim_get_current_buf()
local cols = view.format_entry_cols(file, {}, {}, test_adapter)
@ -156,7 +157,7 @@ a.describe("mutator", function()
end)
it("errors on duplicate names for existing files", function()
local file = cache.create_and_store_entry("oil-test:///foo/", "a.txt", "file")
local file = test_adapter.test_set("/foo/a.txt", "file")
vim.cmd.edit({ args = { "oil-test:///foo/" } })
local bufnr = vim.api.nvim_get_current_buf()
set_lines(bufnr, {
@ -184,7 +185,7 @@ a.describe("mutator", function()
end)
it("parses a rename as a delete + new", function()
local file = cache.create_and_store_entry("oil-test:///foo/", "a.txt", "file")
local file = test_adapter.test_set("/foo/a.txt", "file")
vim.cmd.edit({ args = { "oil-test:///foo/" } })
local bufnr = vim.api.nvim_get_current_buf()
set_lines(bufnr, {
@ -198,8 +199,8 @@ a.describe("mutator", function()
end)
it("detects renamed files that conflict", function()
local afile = cache.create_and_store_entry("oil-test:///foo/", "a.txt", "file")
local bfile = cache.create_and_store_entry("oil-test:///foo/", "b.txt", "file")
local afile = test_adapter.test_set("/foo/a.txt", "file")
local bfile = test_adapter.test_set("/foo/b.txt", "file")
vim.cmd.edit({ args = { "oil-test:///foo/" } })
local bufnr = vim.api.nvim_get_current_buf()
set_lines(bufnr, {
@ -226,7 +227,7 @@ a.describe("mutator", function()
end)
it("views link targets with trailing slashes as the same", function()
local file = cache.create_and_store_entry("oil-test:///foo/", "mydir", "link")
local file = test_adapter.test_set("/foo/mydir", "link")
file[FIELD_META] = { link = "dir/" }
vim.cmd.edit({ args = { "oil-test:///foo/" } })
local bufnr = vim.api.nvim_get_current_buf()
@ -267,7 +268,7 @@ a.describe("mutator", function()
end)
it("constructs DELETE actions", function()
local file = cache.create_and_store_entry("oil-test:///foo/", "a.txt", "file")
local file = test_adapter.test_set("/foo/a.txt", "file")
vim.cmd.edit({ args = { "oil-test:///foo/" } })
local bufnr = vim.api.nvim_get_current_buf()
local diffs = {
@ -286,7 +287,7 @@ a.describe("mutator", function()
end)
it("constructs COPY actions", function()
local file = cache.create_and_store_entry("oil-test:///foo/", "a.txt", "file")
local file = test_adapter.test_set("/foo/a.txt", "file")
vim.cmd.edit({ args = { "oil-test:///foo/" } })
local bufnr = vim.api.nvim_get_current_buf()
local diffs = {
@ -306,7 +307,7 @@ a.describe("mutator", function()
end)
it("constructs MOVE actions", function()
local file = cache.create_and_store_entry("oil-test:///foo/", "a.txt", "file")
local file = test_adapter.test_set("/foo/a.txt", "file")
vim.cmd.edit({ args = { "oil-test:///foo/" } })
local bufnr = vim.api.nvim_get_current_buf()
local diffs = {
@ -327,7 +328,7 @@ a.describe("mutator", function()
end)
it("correctly orders MOVE + CREATE", function()
local file = cache.create_and_store_entry("oil-test:///", "a.txt", "file")
local file = test_adapter.test_set("/a.txt", "file")
vim.cmd.edit({ args = { "oil-test:///" } })
local bufnr = vim.api.nvim_get_current_buf()
local diffs = {
@ -354,8 +355,8 @@ a.describe("mutator", function()
end)
it("resolves MOVE loops", function()
local afile = cache.create_and_store_entry("oil-test:///", "a.txt", "file")
local bfile = cache.create_and_store_entry("oil-test:///", "b.txt", "file")
local afile = test_adapter.test_set("/a.txt", "file")
local bfile = test_adapter.test_set("/b.txt", "file")
vim.cmd.edit({ args = { "oil-test:///" } })
local bufnr = vim.api.nvim_get_current_buf()
local diffs = {
@ -554,7 +555,7 @@ a.describe("mutator", function()
end)
a.it("deletes entries", function()
local file = cache.create_and_store_entry("oil-test:///", "a.txt", "file")
local file = test_adapter.test_set("/a.txt", "file")
local actions = {
{ type = "delete", url = "oil-test:///a.txt", entry_type = "file" },
}
@ -568,7 +569,7 @@ a.describe("mutator", function()
end)
a.it("moves entries", function()
local file = cache.create_and_store_entry("oil-test:///", "a.txt", "file")
local file = test_adapter.test_set("/a.txt", "file")
local actions = {
{
type = "move",
@ -592,7 +593,7 @@ a.describe("mutator", function()
end)
a.it("copies entries", function()
local file = cache.create_and_store_entry("oil-test:///", "a.txt", "file")
local file = test_adapter.test_set("/a.txt", "file")
local actions = {
{
type = "copy",