canola.nvim/spec/trash_spec.lua
Barrett Ruth 0d3088f57e
refactor: rename oil to canola across entire codebase (#70)
Problem: the codebase still used the upstream \`oil\` naming everywhere —
URL schemes, the \`:Oil\` command, highlight groups, user events, module
paths, filetypes, buffer/window variables, LuaCATS type annotations,
vimdoc help tags, syntax groups, and internal identifiers.

Solution: mechanical rename of every reference. URL schemes now use
\`canola://\` (plus \`canola-ssh://\`, \`canola-s3://\`, \`canola-sss://\`,
\`canola-trash://\`, \`canola-test://\`). The \`:Canola\` command replaces
\`:Oil\`. All highlight groups, user events, augroups, namespaces,
filetypes, require paths, type annotations, help tags, and identifiers
follow suit. The \`upstream\` remote to \`stevearc/oil.nvim\` has been
removed and the \`vim.g.oil\` deprecation shim dropped.
2026-03-05 14:50:10 -05:00

149 lines
5 KiB
Lua

local TmpDir = require('spec.tmpdir')
local test_util = require('spec.test_util')
describe('freedesktop', function()
local tmpdir
local tmphome
local home = vim.env.XDG_DATA_HOME
before_each(function()
require('canola.config').delete_to_trash = true
tmpdir = TmpDir.new()
tmphome = TmpDir.new()
package.loaded['canola.adapters.trash'] = require('canola.adapters.trash.freedesktop')
vim.env.XDG_DATA_HOME = tmphome.path
end)
after_each(function()
vim.env.XDG_DATA_HOME = home
if tmpdir then
tmpdir:dispose()
end
if tmphome then
tmphome:dispose()
end
test_util.reset_editor()
package.loaded['canola.adapters.trash'] = nil
end)
it('files can be moved to the trash', function()
tmpdir:create({ 'a.txt', 'foo/b.txt' })
test_util.actions.open({ tmpdir.path })
test_util.actions.focus('a.txt')
vim.api.nvim_feedkeys('dd', 'x', true)
test_util.actions.open({ '--trash', tmpdir.path })
vim.api.nvim_feedkeys('p', 'x', true)
test_util.actions.save()
tmpdir:assert_not_exists('a.txt')
tmpdir:assert_exists('foo/b.txt')
test_util.actions.reload()
assert.are.same({ 'a.txt' }, test_util.parse_entries(0))
end)
it('deleting a file moves it to trash', function()
tmpdir:create({ 'a.txt', 'foo/b.txt' })
test_util.actions.open({ tmpdir.path })
test_util.actions.focus('a.txt')
vim.api.nvim_feedkeys('dd', 'x', true)
test_util.actions.save()
tmpdir:assert_not_exists('a.txt')
tmpdir:assert_exists('foo/b.txt')
test_util.actions.open({ '--trash', tmpdir.path })
assert.are.same({ 'a.txt' }, test_util.parse_entries(0))
end)
it('deleting a directory moves it to trash', function()
tmpdir:create({ 'a.txt', 'foo/b.txt' })
test_util.actions.open({ tmpdir.path })
test_util.actions.focus('foo/')
vim.api.nvim_feedkeys('dd', 'x', true)
test_util.actions.save()
tmpdir:assert_not_exists('foo')
tmpdir:assert_exists('a.txt')
test_util.actions.open({ '--trash', tmpdir.path })
assert.are.same({ 'foo/' }, test_util.parse_entries(0))
end)
it('deleting a file from trash deletes it permanently', function()
tmpdir:create({ 'a.txt' })
test_util.actions.open({ tmpdir.path })
test_util.actions.focus('a.txt')
vim.api.nvim_feedkeys('dd', 'x', true)
test_util.actions.save()
test_util.actions.open({ '--trash', tmpdir.path })
test_util.actions.focus('a.txt')
vim.api.nvim_feedkeys('dd', 'x', true)
test_util.actions.save()
test_util.actions.reload()
tmpdir:assert_not_exists('a.txt')
assert.are.same({}, test_util.parse_entries(0))
end)
it('cannot create files in the trash', function()
tmpdir:create({ 'a.txt' })
test_util.actions.open({ tmpdir.path })
test_util.actions.focus('a.txt')
vim.api.nvim_feedkeys('dd', 'x', true)
test_util.actions.save()
test_util.actions.open({ '--trash', tmpdir.path })
vim.api.nvim_feedkeys('onew_file.txt', 'x', true)
test_util.actions.save()
test_util.actions.reload()
assert.are.same({ 'a.txt' }, test_util.parse_entries(0))
end)
it('cannot rename files in the trash', function()
tmpdir:create({ 'a.txt' })
test_util.actions.open({ tmpdir.path })
test_util.actions.focus('a.txt')
vim.api.nvim_feedkeys('dd', 'x', true)
test_util.actions.save()
test_util.actions.open({ '--trash', tmpdir.path })
vim.api.nvim_feedkeys('0facwnew_name', 'x', true)
test_util.actions.save()
test_util.actions.reload()
assert.are.same({ 'a.txt' }, test_util.parse_entries(0))
end)
it('cannot copy files in the trash', function()
tmpdir:create({ 'a.txt' })
test_util.actions.open({ tmpdir.path })
test_util.actions.focus('a.txt')
vim.api.nvim_feedkeys('dd', 'x', true)
test_util.actions.save()
test_util.actions.open({ '--trash', tmpdir.path })
vim.api.nvim_feedkeys('yypp', 'x', true)
test_util.actions.save()
test_util.actions.reload()
assert.are.same({ 'a.txt' }, test_util.parse_entries(0))
end)
it('can restore files from trash', function()
tmpdir:create({ 'a.txt' })
test_util.actions.open({ tmpdir.path })
test_util.actions.focus('a.txt')
vim.api.nvim_feedkeys('dd', 'x', true)
test_util.actions.save()
test_util.actions.open({ '--trash', tmpdir.path })
vim.api.nvim_feedkeys('dd', 'x', true)
test_util.actions.open({ tmpdir.path })
vim.api.nvim_feedkeys('p', 'x', true)
test_util.actions.save()
test_util.actions.reload()
assert.are.same({ 'a.txt' }, test_util.parse_entries(0))
tmpdir:assert_fs({
['a.txt'] = 'a.txt',
})
end)
it('can have multiple files with the same name in trash', function()
tmpdir:create({ 'a.txt' })
test_util.actions.open({ tmpdir.path })
vim.api.nvim_feedkeys('dd', 'x', true)
test_util.actions.save()
tmpdir:create({ 'a.txt' })
test_util.actions.reload()
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' }, test_util.parse_entries(0))
end)
end)