Some checks are pending
quality / changes (push) Waiting to run
quality / Lua Format Check (push) Blocked by required conditions
quality / Lua Lint Check (push) Blocked by required conditions
quality / Lua Type Check (push) Blocked by required conditions
quality / Markdown Format Check (push) Blocked by required conditions
test / Test (Neovim nightly) (push) Waiting to run
test / Test (Neovim stable) (push) Waiting to run
* refactor: revert module namespace from canola back to oil
Problem: the canola rename creates unnecessary friction for users
migrating from stevearc/oil.nvim — every `require('oil')` call and
config reference must change.
Solution: revert all module paths, URL schemes, autocmd groups,
highlight groups, and filetype names back to `oil`. The repo stays
`canola.nvim` for identity; the code is a drop-in replacement.
* refactor: remove `vim.g.oil` declarative config
Problem: the `vim.g.oil` configuration path was added prematurely.
It adds a second config entrypoint before the plugin has stabilized
enough to justify it.
Solution: remove `vim.g.oil` support from `plugin/oil.lua`,
`config.setup()`, docs, and tests. Users configure via
`require("oil").setup({})`.
209 lines
6.6 KiB
Lua
209 lines
6.6 KiB
Lua
local TmpDir = require('spec.tmpdir')
|
|
local files = require('oil.adapters.files')
|
|
local test_util = require('spec.test_util')
|
|
|
|
describe('files adapter', function()
|
|
local tmpdir
|
|
before_each(function()
|
|
tmpdir = TmpDir.new()
|
|
end)
|
|
after_each(function()
|
|
if tmpdir then
|
|
tmpdir:dispose()
|
|
end
|
|
test_util.reset_editor()
|
|
end)
|
|
|
|
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)
|
|
|
|
it('Creates files', function()
|
|
local err = test_util.await(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)
|
|
|
|
it('Creates directories', function()
|
|
local err = test_util.await(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)
|
|
|
|
it('Deletes files', function()
|
|
tmpdir:create({ 'a.txt' })
|
|
local url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. 'a.txt'
|
|
local err = test_util.await(files.perform_action, 2, {
|
|
url = url,
|
|
entry_type = 'file',
|
|
type = 'delete',
|
|
})
|
|
assert.is_nil(err)
|
|
tmpdir:assert_fs({})
|
|
end)
|
|
|
|
it('Deletes directories', function()
|
|
tmpdir:create({ 'a/' })
|
|
local url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. 'a'
|
|
local err = test_util.await(files.perform_action, 2, {
|
|
url = url,
|
|
entry_type = 'directory',
|
|
type = 'delete',
|
|
})
|
|
assert.is_nil(err)
|
|
tmpdir:assert_fs({})
|
|
end)
|
|
|
|
it('Moves files', function()
|
|
tmpdir:create({ 'a.txt' })
|
|
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 = test_util.await(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)
|
|
|
|
it('Moves directories', function()
|
|
tmpdir:create({ 'a/a.txt' })
|
|
local src_url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. 'a'
|
|
local dest_url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. 'b'
|
|
local err = test_util.await(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)
|
|
|
|
it('Copies files', function()
|
|
tmpdir:create({ 'a.txt' })
|
|
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 = test_util.await(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)
|
|
|
|
it('Recursively copies directories', function()
|
|
tmpdir:create({ 'a/a.txt' })
|
|
local src_url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. 'a'
|
|
local dest_url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. 'b'
|
|
local err = test_util.await(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)
|
|
|
|
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_oil_ready()
|
|
local new_url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. 'newdir'
|
|
vim.cmd.edit({ args = { new_url } })
|
|
test_util.wait_oil_ready()
|
|
assert.equals('oil', vim.bo.filetype)
|
|
assert.equals(new_url .. '/', vim.api.nvim_buf_get_name(0))
|
|
end)
|
|
|
|
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))
|
|
assert.equals(tmpdir.path .. '/file.rb', vim.fn.bufname())
|
|
end)
|
|
|
|
describe('cleanup_buffers_on_delete', function()
|
|
local cache = require('oil.cache')
|
|
local config = require('oil.config')
|
|
local mutator = require('oil.mutator')
|
|
|
|
before_each(function()
|
|
config.cleanup_buffers_on_delete = true
|
|
end)
|
|
|
|
after_each(function()
|
|
config.cleanup_buffers_on_delete = false
|
|
end)
|
|
|
|
it('wipes the buffer for a deleted file', function()
|
|
tmpdir:create({ 'a.txt' })
|
|
local dirurl = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p')
|
|
local filepath = vim.fn.fnamemodify(tmpdir.path, ':p') .. 'a.txt'
|
|
cache.create_and_store_entry(dirurl, 'a.txt', 'file')
|
|
vim.cmd.edit({ args = { filepath } })
|
|
local bufnr = vim.api.nvim_get_current_buf()
|
|
local url = 'oil://' .. filepath
|
|
test_util.await(mutator.process_actions, 2, {
|
|
{ type = 'delete', url = url, entry_type = 'file' },
|
|
})
|
|
assert.is_false(vim.api.nvim_buf_is_valid(bufnr))
|
|
end)
|
|
|
|
it('does not wipe the buffer when disabled', function()
|
|
config.cleanup_buffers_on_delete = false
|
|
tmpdir:create({ 'b.txt' })
|
|
local dirurl = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p')
|
|
local filepath = vim.fn.fnamemodify(tmpdir.path, ':p') .. 'b.txt'
|
|
cache.create_and_store_entry(dirurl, 'b.txt', 'file')
|
|
vim.cmd.edit({ args = { filepath } })
|
|
local bufnr = vim.api.nvim_get_current_buf()
|
|
local url = 'oil://' .. filepath
|
|
test_util.await(mutator.process_actions, 2, {
|
|
{ type = 'delete', url = url, entry_type = 'file' },
|
|
})
|
|
assert.is_true(vim.api.nvim_buf_is_valid(bufnr))
|
|
end)
|
|
end)
|
|
end)
|