build: replace luacheck with selene, add nix devshell and pre-commit (#20)

* build: replace luacheck with selene

Problem: luacheck is unmaintained (last release 2018) and required
suppressing four warning classes to avoid false positives. It also
lacks first-class vim/neovim awareness.

Solution: switch to selene with std='vim' for vim-aware linting.
Replace the luacheck CI job with selene, update the Makefile lint
target, and delete .luacheckrc.

* build: add nix devshell and pre-commit hooks

Problem: oil.nvim had no reproducible dev environment. The .envrc
set up a Python venv for the now-removed docgen pipeline, and there
were no pre-commit hooks for local formatting checks.

Solution: add flake.nix with stylua, selene, and prettier in the
devshell. Replace the stale Python .envrc with 'use flake'. Add
.pre-commit-config.yaml with stylua and prettier hooks matching
other plugins in the repo collection.

* fix: format with stylua

* build(selene): configure lints and add inline suppressions

Problem: selene fails on 5 errors and 3 warnings from upstream code
patterns that are intentional (mixed tables in config API, unused
callback parameters, identical if branches for readability).

Solution: globally allow mixed_table and unused_variable (high volume,
inherent to the codebase design). Add inline selene:allow directives
for the 8 remaining issues: if_same_then_else (4), mismatched_arg_count
(1), empty_if (2), global_usage (1). Remove .envrc from tracking.

* build: switch typecheck action to mrcjkb/lua-typecheck-action

Problem: oil.nvim used stevearc/nvim-typecheck-action, which required
cloning the action repo locally for the Makefile lint target. All
other plugins in the collection use mrcjkb/lua-typecheck-action.

Solution: swap to mrcjkb/lua-typecheck-action@v0 for consistency.
Remove the nvim-typecheck-action git clone from the Makefile and
.gitignore. Drop LuaLS from the local lint target since it requires
a full language server install — CI handles it.
This commit is contained in:
Barrett Ruth 2026-02-21 23:52:27 -05:00 committed by GitHub
parent df53b172a9
commit 86f553cd0a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
72 changed files with 2762 additions and 2649 deletions

View file

@ -1,157 +1,157 @@
require("plenary.async").tests.add_to_env()
local fs = require("oil.fs")
local oil = require("oil")
local test_util = require("tests.test_util")
require('plenary.async').tests.add_to_env()
local fs = require('oil.fs')
local oil = require('oil')
local test_util = require('tests.test_util')
a.describe("Alternate buffer", function()
a.describe('Alternate buffer', function()
after_each(function()
test_util.reset_editor()
end)
a.it("sets previous buffer as alternate", function()
vim.cmd.edit({ args = { "foo" } })
a.it('sets previous buffer as alternate', function()
vim.cmd.edit({ args = { 'foo' } })
oil.open()
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
vim.cmd.edit({ args = { "bar" } })
assert.equals("foo", vim.fn.expand("#"))
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
vim.cmd.edit({ args = { 'bar' } })
assert.equals('foo', vim.fn.expand('#'))
end)
a.it("sets previous buffer as alternate when editing url file", function()
vim.cmd.edit({ args = { "foo" } })
a.it('sets previous buffer as alternate when editing url file', function()
vim.cmd.edit({ args = { 'foo' } })
oil.open()
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
local readme = fs.join(vim.fn.getcwd(), "README.md")
vim.cmd.edit({ args = { "oil://" .. fs.os_to_posix_path(readme) } })
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
local readme = fs.join(vim.fn.getcwd(), 'README.md')
vim.cmd.edit({ args = { 'oil://' .. fs.os_to_posix_path(readme) } })
-- We're gonna jump around to 2 different buffers
test_util.wait_for_autocmd("BufEnter")
test_util.wait_for_autocmd("BufEnter")
test_util.wait_for_autocmd('BufEnter')
test_util.wait_for_autocmd('BufEnter')
assert.equals(readme, vim.api.nvim_buf_get_name(0))
assert.equals("foo", vim.fn.expand("#"))
assert.equals('foo', vim.fn.expand('#'))
end)
a.it("sets previous buffer as alternate when editing oil://", function()
vim.cmd.edit({ args = { "foo" } })
vim.cmd.edit({ args = { "oil://" .. fs.os_to_posix_path(vim.fn.getcwd()) } })
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
vim.cmd.edit({ args = { "bar" } })
assert.equals("foo", vim.fn.expand("#"))
a.it('sets previous buffer as alternate when editing oil://', function()
vim.cmd.edit({ args = { 'foo' } })
vim.cmd.edit({ args = { 'oil://' .. fs.os_to_posix_path(vim.fn.getcwd()) } })
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
vim.cmd.edit({ args = { 'bar' } })
assert.equals('foo', vim.fn.expand('#'))
end)
a.it("preserves alternate buffer if editing the same file", function()
vim.cmd.edit({ args = { "foo" } })
vim.cmd.edit({ args = { "bar" } })
a.it('preserves alternate buffer if editing the same file', function()
vim.cmd.edit({ args = { 'foo' } })
vim.cmd.edit({ args = { 'bar' } })
oil.open()
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
vim.cmd.edit({ args = { "bar" } })
assert.equals("foo", vim.fn.expand("#"))
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
vim.cmd.edit({ args = { 'bar' } })
assert.equals('foo', vim.fn.expand('#'))
end)
a.it("preserves alternate buffer if discarding changes", function()
vim.cmd.edit({ args = { "foo" } })
vim.cmd.edit({ args = { "bar" } })
a.it('preserves alternate buffer if discarding changes', function()
vim.cmd.edit({ args = { 'foo' } })
vim.cmd.edit({ args = { 'bar' } })
oil.open()
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
oil.close()
assert.equals("bar", vim.fn.expand("%"))
assert.equals("foo", vim.fn.expand("#"))
assert.equals('bar', vim.fn.expand('%'))
assert.equals('foo', vim.fn.expand('#'))
end)
a.it("sets previous buffer as alternate after multi-dir hops", function()
vim.cmd.edit({ args = { "foo" } })
a.it('sets previous buffer as alternate after multi-dir hops', function()
vim.cmd.edit({ args = { 'foo' } })
oil.open()
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
oil.open()
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
oil.open()
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
oil.open()
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
vim.cmd.edit({ args = { "bar" } })
assert.equals("foo", vim.fn.expand("#"))
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
vim.cmd.edit({ args = { 'bar' } })
assert.equals('foo', vim.fn.expand('#'))
end)
a.it("sets previous buffer as alternate when inside oil buffer", function()
vim.cmd.edit({ args = { "foo" } })
a.it('sets previous buffer as alternate when inside oil buffer', function()
vim.cmd.edit({ args = { 'foo' } })
oil.open()
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
assert.equals("foo", vim.fn.expand("#"))
vim.cmd.edit({ args = { "bar" } })
assert.equals("foo", vim.fn.expand("#"))
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
assert.equals('foo', vim.fn.expand('#'))
vim.cmd.edit({ args = { 'bar' } })
assert.equals('foo', vim.fn.expand('#'))
oil.open()
assert.equals("bar", vim.fn.expand("#"))
assert.equals('bar', vim.fn.expand('#'))
end)
a.it("preserves alternate when traversing oil dirs", function()
vim.cmd.edit({ args = { "foo" } })
a.it('preserves alternate when traversing oil dirs', function()
vim.cmd.edit({ args = { 'foo' } })
oil.open()
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
assert.equals("foo", vim.fn.expand("#"))
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
assert.equals('foo', vim.fn.expand('#'))
vim.wait(1000, function()
return oil.get_cursor_entry()
end, 10)
vim.api.nvim_win_set_cursor(0, { 1, 1 })
oil.select()
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
assert.equals("foo", vim.fn.expand("#"))
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
assert.equals('foo', vim.fn.expand('#'))
end)
a.it("preserves alternate when opening preview", function()
vim.cmd.edit({ args = { "foo" } })
a.it('preserves alternate when opening preview', function()
vim.cmd.edit({ args = { 'foo' } })
oil.open()
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
assert.equals("foo", vim.fn.expand("#"))
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
assert.equals('foo', vim.fn.expand('#'))
vim.wait(1000, function()
return oil.get_cursor_entry()
end, 10)
vim.api.nvim_win_set_cursor(0, { 1, 1 })
oil.open_preview()
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
assert.equals("foo", vim.fn.expand("#"))
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
assert.equals('foo', vim.fn.expand('#'))
end)
a.describe("floating window", function()
a.it("sets previous buffer as alternate", function()
vim.cmd.edit({ args = { "foo" } })
a.describe('floating window', function()
a.it('sets previous buffer as alternate', function()
vim.cmd.edit({ args = { 'foo' } })
oil.open_float()
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
-- This is lazy, but testing the actual select logic is more difficult. We can simply
-- replicate it by closing the current window and then doing the edit
vim.api.nvim_win_close(0, true)
vim.cmd.edit({ args = { "bar" } })
assert.equals("foo", vim.fn.expand("#"))
vim.cmd.edit({ args = { 'bar' } })
assert.equals('foo', vim.fn.expand('#'))
end)
a.it("preserves alternate buffer if editing the same file", function()
vim.cmd.edit({ args = { "foo" } })
vim.cmd.edit({ args = { "bar" } })
a.it('preserves alternate buffer if editing the same file', function()
vim.cmd.edit({ args = { 'foo' } })
vim.cmd.edit({ args = { 'bar' } })
oil.open_float()
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
-- This is lazy, but testing the actual select logic is more difficult. We can simply
-- replicate it by closing the current window and then doing the edit
vim.api.nvim_win_close(0, true)
vim.cmd.edit({ args = { "bar" } })
assert.equals("foo", vim.fn.expand("#"))
vim.cmd.edit({ args = { 'bar' } })
assert.equals('foo', vim.fn.expand('#'))
end)
a.it("preserves alternate buffer if discarding changes", function()
vim.cmd.edit({ args = { "foo" } })
vim.cmd.edit({ args = { "bar" } })
a.it('preserves alternate buffer if discarding changes', function()
vim.cmd.edit({ args = { 'foo' } })
vim.cmd.edit({ args = { 'bar' } })
oil.open_float()
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
oil.close()
assert.equals("foo", vim.fn.expand("#"))
assert.equals('foo', vim.fn.expand('#'))
end)
a.it("preserves alternate when traversing to a new file", function()
vim.cmd.edit({ args = { "foo" } })
a.it('preserves alternate when traversing to a new file', function()
vim.cmd.edit({ args = { 'foo' } })
oil.open_float()
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
assert.equals("foo", vim.fn.expand("#"))
test_util.feedkeys({ "/LICENSE<CR>" }, 10)
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
assert.equals('foo', vim.fn.expand('#'))
test_util.feedkeys({ '/LICENSE<CR>' }, 10)
oil.select()
test_util.wait_for_autocmd("BufEnter")
assert.equals("LICENSE", vim.fn.expand("%:."))
assert.equals("foo", vim.fn.expand("#"))
test_util.wait_for_autocmd('BufEnter')
assert.equals('LICENSE', vim.fn.expand('%:.'))
assert.equals('foo', vim.fn.expand('#'))
end)
end)
end)

View file

@ -1,8 +1,8 @@
require("plenary.async").tests.add_to_env()
local oil = require("oil")
local test_util = require("tests.test_util")
require('plenary.async').tests.add_to_env()
local oil = require('oil')
local test_util = require('tests.test_util')
a.describe("close", function()
a.describe('close', function()
a.before_each(function()
test_util.reset_editor()
end)
@ -10,36 +10,36 @@ a.describe("close", function()
test_util.reset_editor()
end)
a.it("does not close buffer from visual mode", function()
a.it('does not close buffer from visual mode', function()
oil.open()
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
assert.equals("oil", vim.bo.filetype)
test_util.feedkeys({ "V" }, 10)
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
assert.equals('oil', vim.bo.filetype)
test_util.feedkeys({ 'V' }, 10)
oil.close()
assert.equals("oil", vim.bo.filetype)
test_util.feedkeys({ "<Esc>" }, 10)
assert.equals('oil', vim.bo.filetype)
test_util.feedkeys({ '<Esc>' }, 10)
end)
a.it("does not close buffer from operator-pending mode", function()
a.it('does not close buffer from operator-pending mode', function()
oil.open()
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
assert.equals("oil", vim.bo.filetype)
vim.api.nvim_feedkeys("d", "n", false)
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
assert.equals('oil', vim.bo.filetype)
vim.api.nvim_feedkeys('d', 'n', false)
a.util.sleep(20)
local mode = vim.api.nvim_get_mode().mode
if mode:match("^no") then
if mode:match('^no') then
oil.close()
assert.equals("oil", vim.bo.filetype)
assert.equals('oil', vim.bo.filetype)
end
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes("<Esc>", true, true, true), "n", false)
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<Esc>', true, true, true), 'n', false)
a.util.sleep(20)
end)
a.it("closes buffer from normal mode", function()
a.it('closes buffer from normal mode', function()
oil.open()
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
assert.equals("oil", vim.bo.filetype)
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
assert.equals('oil', vim.bo.filetype)
oil.close()
assert.not_equals("oil", vim.bo.filetype)
assert.not_equals('oil', vim.bo.filetype)
end)
end)

View file

@ -1,25 +1,25 @@
local config = require("oil.config")
local config = require('oil.config')
describe("config", function()
describe('config', function()
after_each(function()
vim.g.oil = nil
end)
it("falls back to vim.g.oil when setup() is called with no args", function()
it('falls back to vim.g.oil when setup() is called with no args', function()
vim.g.oil = { delete_to_trash = true, cleanup_delay_ms = 5000 }
config.setup()
assert.is_true(config.delete_to_trash)
assert.equals(5000, config.cleanup_delay_ms)
end)
it("uses defaults when neither opts nor vim.g.oil is set", function()
it('uses defaults when neither opts nor vim.g.oil is set', function()
vim.g.oil = nil
config.setup()
assert.is_false(config.delete_to_trash)
assert.equals(2000, config.cleanup_delay_ms)
end)
it("prefers explicit opts over vim.g.oil", function()
it('prefers explicit opts over vim.g.oil', function()
vim.g.oil = { delete_to_trash = true }
config.setup({ delete_to_trash = false })
assert.is_false(config.delete_to_trash)

View file

@ -1,9 +1,9 @@
require("plenary.async").tests.add_to_env()
local TmpDir = require("tests.tmpdir")
local files = require("oil.adapters.files")
local test_util = require("tests.test_util")
require('plenary.async').tests.add_to_env()
local TmpDir = require('tests.tmpdir')
local files = require('oil.adapters.files')
local test_util = require('tests.test_util')
a.describe("files adapter", function()
a.describe('files adapter', function()
local tmpdir
a.before_each(function()
tmpdir = TmpDir.new()
@ -15,159 +15,159 @@ a.describe("files adapter", function()
test_util.reset_editor()
end)
a.it("tmpdir creates files and asserts they exist", function()
tmpdir:create({ "a.txt", "foo/b.txt", "foo/c.txt", "bar/" })
a.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,
['a.txt'] = 'a.txt',
['foo/b.txt'] = 'foo/b.txt',
['foo/c.txt'] = 'foo/c.txt',
['bar/'] = true,
})
end)
a.it("Creates files", function()
a.it('Creates files', function()
local err = a.wrap(files.perform_action, 2)({
url = "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") .. "a.txt",
entry_type = "file",
type = "create",
url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. 'a.txt',
entry_type = 'file',
type = 'create',
})
assert.is_nil(err)
tmpdir:assert_fs({
["a.txt"] = "",
['a.txt'] = '',
})
end)
a.it("Creates directories", function()
a.it('Creates directories', function()
local err = a.wrap(files.perform_action, 2)({
url = "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") .. "a",
entry_type = "directory",
type = "create",
url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. 'a',
entry_type = 'directory',
type = 'create',
})
assert.is_nil(err)
tmpdir:assert_fs({
["a/"] = true,
['a/'] = true,
})
end)
a.it("Deletes files", function()
tmpdir:create({ "a.txt" })
a.it('Deletes files', function()
tmpdir:create({ 'a.txt' })
a.util.scheduler()
local url = "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") .. "a.txt"
local url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. 'a.txt'
local err = a.wrap(files.perform_action, 2)({
url = url,
entry_type = "file",
type = "delete",
entry_type = 'file',
type = 'delete',
})
assert.is_nil(err)
tmpdir:assert_fs({})
end)
a.it("Deletes directories", function()
tmpdir:create({ "a/" })
local url = "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") .. "a"
a.it('Deletes directories', function()
tmpdir:create({ 'a/' })
local url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. 'a'
local err = a.wrap(files.perform_action, 2)({
url = url,
entry_type = "directory",
type = "delete",
entry_type = 'directory',
type = 'delete',
})
assert.is_nil(err)
tmpdir:assert_fs({})
end)
a.it("Moves files", function()
tmpdir:create({ "a.txt" })
a.it('Moves files', function()
tmpdir:create({ 'a.txt' })
a.util.scheduler()
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 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 = a.wrap(files.perform_action, 2)({
src_url = src_url,
dest_url = dest_url,
entry_type = "file",
type = "move",
entry_type = 'file',
type = 'move',
})
assert.is_nil(err)
tmpdir:assert_fs({
["b.txt"] = "a.txt",
['b.txt'] = 'a.txt',
})
end)
a.it("Moves directories", function()
tmpdir:create({ "a/a.txt" })
a.it('Moves directories', function()
tmpdir:create({ 'a/a.txt' })
a.util.scheduler()
local src_url = "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") .. "a"
local dest_url = "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") .. "b"
local src_url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. 'a'
local dest_url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. 'b'
local err = a.wrap(files.perform_action, 2)({
src_url = src_url,
dest_url = dest_url,
entry_type = "directory",
type = "move",
entry_type = 'directory',
type = 'move',
})
assert.is_nil(err)
tmpdir:assert_fs({
["b/a.txt"] = "a/a.txt",
["b/"] = true,
['b/a.txt'] = 'a/a.txt',
['b/'] = true,
})
end)
a.it("Copies files", function()
tmpdir:create({ "a.txt" })
a.it('Copies files', function()
tmpdir:create({ 'a.txt' })
a.util.scheduler()
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 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 = a.wrap(files.perform_action, 2)({
src_url = src_url,
dest_url = dest_url,
entry_type = "file",
type = "copy",
entry_type = 'file',
type = 'copy',
})
assert.is_nil(err)
tmpdir:assert_fs({
["a.txt"] = "a.txt",
["b.txt"] = "a.txt",
['a.txt'] = 'a.txt',
['b.txt'] = 'a.txt',
})
end)
a.it("Recursively copies directories", function()
tmpdir:create({ "a/a.txt" })
a.it('Recursively copies directories', function()
tmpdir:create({ 'a/a.txt' })
a.util.scheduler()
local src_url = "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") .. "a"
local dest_url = "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") .. "b"
local src_url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. 'a'
local dest_url = 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') .. 'b'
local err = a.wrap(files.perform_action, 2)({
src_url = src_url,
dest_url = dest_url,
entry_type = "directory",
type = "copy",
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,
['b/a.txt'] = 'a/a.txt',
['b/'] = true,
['a/a.txt'] = 'a/a.txt',
['a/'] = true,
})
end)
a.it("Editing a new oil://path/ creates an oil buffer", function()
local tmpdir_url = "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") .. "/"
a.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"
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('oil', vim.bo.filetype)
-- The normalization will add a '/'
assert.equals(new_url .. "/", vim.api.nvim_buf_get_name(0))
assert.equals(new_url .. '/', vim.api.nvim_buf_get_name(0))
end)
a.it("Editing a new oil://file.rb creates a normal buffer", function()
local tmpdir_url = "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") .. "/"
a.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"
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())
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)
end)

View file

@ -1,5 +1,5 @@
-- Manual test for minimizing/restoring progress window
local Progress = require("oil.mutator.progress")
local Progress = require('oil.mutator.progress')
local progress = Progress.new()
@ -12,9 +12,9 @@ progress:show({
for i = 1, 10, 1 do
vim.defer_fn(function()
progress:set_action({
type = "create",
url = string.format("oil:///tmp/test_%d.txt", i),
entry_type = "file",
type = 'create',
url = string.format('oil:///tmp/test_%d.txt', i),
entry_type = 'file',
}, i, 10)
end, (i - 1) * 1000)
end
@ -23,6 +23,6 @@ vim.defer_fn(function()
progress:close()
end, 10000)
vim.keymap.set("n", "R", function()
vim.keymap.set('n', 'R', function()
progress:restore()
end, {})

View file

@ -1,5 +1,5 @@
vim.opt.runtimepath:append(".")
vim.opt.runtimepath:append('.')
vim.o.swapfile = false
vim.bo.swapfile = false
require("tests.test_util").reset_editor()
require('tests.test_util').reset_editor()

View file

@ -1,59 +1,59 @@
local fs = require("oil.fs")
local test_util = require("tests.test_util")
local util = require("oil.util")
local fs = require('oil.fs')
local test_util = require('tests.test_util')
local util = require('oil.util')
describe("update_moved_buffers", function()
describe('update_moved_buffers', function()
after_each(function()
test_util.reset_editor()
end)
it("Renames moved buffers", function()
vim.cmd.edit({ args = { "oil-test:///foo/bar.txt" } })
util.update_moved_buffers("file", "oil-test:///foo/bar.txt", "oil-test:///foo/baz.txt")
assert.equals("oil-test:///foo/baz.txt", vim.api.nvim_buf_get_name(0))
it('Renames moved buffers', function()
vim.cmd.edit({ args = { 'oil-test:///foo/bar.txt' } })
util.update_moved_buffers('file', 'oil-test:///foo/bar.txt', 'oil-test:///foo/baz.txt')
assert.equals('oil-test:///foo/baz.txt', vim.api.nvim_buf_get_name(0))
end)
it("Renames moved buffers when they are normal files", function()
local tmpdir = fs.join(vim.loop.fs_realpath(vim.fn.stdpath("cache")), "oil", "test")
local testfile = fs.join(tmpdir, "foo.txt")
it('Renames moved buffers when they are normal files', function()
local tmpdir = fs.join(vim.loop.fs_realpath(vim.fn.stdpath('cache')), 'oil', 'test')
local testfile = fs.join(tmpdir, 'foo.txt')
vim.cmd.edit({ args = { testfile } })
util.update_moved_buffers(
"file",
"oil://" .. fs.os_to_posix_path(testfile),
"oil://" .. fs.os_to_posix_path(fs.join(tmpdir, "bar.txt"))
'file',
'oil://' .. fs.os_to_posix_path(testfile),
'oil://' .. fs.os_to_posix_path(fs.join(tmpdir, 'bar.txt'))
)
assert.equals(fs.join(tmpdir, "bar.txt"), vim.api.nvim_buf_get_name(0))
assert.equals(fs.join(tmpdir, 'bar.txt'), vim.api.nvim_buf_get_name(0))
end)
it("Renames directories", function()
vim.cmd.edit({ args = { "oil-test:///foo/" } })
util.update_moved_buffers("directory", "oil-test:///foo/", "oil-test:///bar/")
assert.equals("oil-test:///bar/", vim.api.nvim_buf_get_name(0))
it('Renames directories', function()
vim.cmd.edit({ args = { 'oil-test:///foo/' } })
util.update_moved_buffers('directory', 'oil-test:///foo/', 'oil-test:///bar/')
assert.equals('oil-test:///bar/', vim.api.nvim_buf_get_name(0))
end)
it("Renames subdirectories", function()
vim.cmd.edit({ args = { "oil-test:///foo/bar/" } })
util.update_moved_buffers("directory", "oil-test:///foo/", "oil-test:///baz/")
assert.equals("oil-test:///baz/bar/", vim.api.nvim_buf_get_name(0))
it('Renames subdirectories', function()
vim.cmd.edit({ args = { 'oil-test:///foo/bar/' } })
util.update_moved_buffers('directory', 'oil-test:///foo/', 'oil-test:///baz/')
assert.equals('oil-test:///baz/bar/', vim.api.nvim_buf_get_name(0))
end)
it("Renames subfiles", function()
vim.cmd.edit({ args = { "oil-test:///foo/bar.txt" } })
util.update_moved_buffers("directory", "oil-test:///foo/", "oil-test:///baz/")
assert.equals("oil-test:///baz/bar.txt", vim.api.nvim_buf_get_name(0))
it('Renames subfiles', function()
vim.cmd.edit({ args = { 'oil-test:///foo/bar.txt' } })
util.update_moved_buffers('directory', 'oil-test:///foo/', 'oil-test:///baz/')
assert.equals('oil-test:///baz/bar.txt', vim.api.nvim_buf_get_name(0))
end)
it("Renames subfiles when they are normal files", function()
local tmpdir = fs.join(vim.loop.fs_realpath(vim.fn.stdpath("cache")), "oil", "test")
local foo = fs.join(tmpdir, "foo")
local bar = fs.join(tmpdir, "bar")
local testfile = fs.join(foo, "foo.txt")
it('Renames subfiles when they are normal files', function()
local tmpdir = fs.join(vim.loop.fs_realpath(vim.fn.stdpath('cache')), 'oil', 'test')
local foo = fs.join(tmpdir, 'foo')
local bar = fs.join(tmpdir, 'bar')
local testfile = fs.join(foo, 'foo.txt')
vim.cmd.edit({ args = { testfile } })
util.update_moved_buffers(
"directory",
"oil://" .. fs.os_to_posix_path(foo),
"oil://" .. fs.os_to_posix_path(bar)
'directory',
'oil://' .. fs.os_to_posix_path(foo),
'oil://' .. fs.os_to_posix_path(bar)
)
assert.equals(fs.join(bar, "foo.txt"), vim.api.nvim_buf_get_name(0))
assert.equals(fs.join(bar, 'foo.txt'), vim.api.nvim_buf_get_name(0))
end)
end)

View file

@ -1,22 +1,22 @@
require("plenary.async").tests.add_to_env()
local cache = require("oil.cache")
local constants = require("oil.constants")
local mutator = require("oil.mutator")
local test_adapter = require("oil.adapters.test")
local test_util = require("tests.test_util")
require('plenary.async').tests.add_to_env()
local cache = require('oil.cache')
local constants = require('oil.constants')
local mutator = require('oil.mutator')
local test_adapter = require('oil.adapters.test')
local test_util = require('tests.test_util')
local FIELD_ID = constants.FIELD_ID
local FIELD_NAME = constants.FIELD_NAME
local FIELD_TYPE = constants.FIELD_TYPE
a.describe("mutator", function()
a.describe('mutator', function()
after_each(function()
test_util.reset_editor()
end)
describe("build actions", function()
it("empty diffs produce no actions", function()
vim.cmd.edit({ args = { "oil-test:///foo/" } })
describe('build actions', function()
it('empty diffs produce no actions', function()
vim.cmd.edit({ args = { 'oil-test:///foo/' } })
local bufnr = vim.api.nvim_get_current_buf()
local actions = mutator.create_actions_from_diffs({
[bufnr] = {},
@ -24,320 +24,320 @@ a.describe("mutator", function()
assert.are.same({}, actions)
end)
it("constructs CREATE actions", function()
vim.cmd.edit({ args = { "oil-test:///foo/" } })
it('constructs CREATE actions', function()
vim.cmd.edit({ args = { 'oil-test:///foo/' } })
local bufnr = vim.api.nvim_get_current_buf()
local diffs = {
{ type = "new", name = "a.txt", entry_type = "file" },
{ type = 'new', name = 'a.txt', entry_type = 'file' },
}
local actions = mutator.create_actions_from_diffs({
[bufnr] = diffs,
})
assert.are.same({
{
type = "create",
entry_type = "file",
url = "oil-test:///foo/a.txt",
type = 'create',
entry_type = 'file',
url = 'oil-test:///foo/a.txt',
},
}, actions)
end)
it("constructs DELETE actions", function()
local file = test_adapter.test_set("/foo/a.txt", "file")
vim.cmd.edit({ args = { "oil-test:///foo/" } })
it('constructs DELETE actions', function()
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 = {
{ type = "delete", name = "a.txt", id = file[FIELD_ID] },
{ type = 'delete', name = 'a.txt', id = file[FIELD_ID] },
}
local actions = mutator.create_actions_from_diffs({
[bufnr] = diffs,
})
assert.are.same({
{
type = "delete",
entry_type = "file",
url = "oil-test:///foo/a.txt",
type = 'delete',
entry_type = 'file',
url = 'oil-test:///foo/a.txt',
},
}, actions)
end)
it("constructs COPY actions", function()
local file = test_adapter.test_set("/foo/a.txt", "file")
vim.cmd.edit({ args = { "oil-test:///foo/" } })
it('constructs COPY actions', function()
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 = {
{ type = "new", name = "b.txt", entry_type = "file", id = file[FIELD_ID] },
{ type = 'new', name = 'b.txt', entry_type = 'file', id = file[FIELD_ID] },
}
local actions = mutator.create_actions_from_diffs({
[bufnr] = diffs,
})
assert.are.same({
{
type = "copy",
entry_type = "file",
src_url = "oil-test:///foo/a.txt",
dest_url = "oil-test:///foo/b.txt",
type = 'copy',
entry_type = 'file',
src_url = 'oil-test:///foo/a.txt',
dest_url = 'oil-test:///foo/b.txt',
},
}, actions)
end)
it("constructs MOVE actions", function()
local file = test_adapter.test_set("/foo/a.txt", "file")
vim.cmd.edit({ args = { "oil-test:///foo/" } })
it('constructs MOVE actions', function()
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 = {
{ type = "delete", name = "a.txt", id = file[FIELD_ID] },
{ type = "new", name = "b.txt", entry_type = "file", id = file[FIELD_ID] },
{ type = 'delete', name = 'a.txt', id = file[FIELD_ID] },
{ type = 'new', name = 'b.txt', entry_type = 'file', id = file[FIELD_ID] },
}
local actions = mutator.create_actions_from_diffs({
[bufnr] = diffs,
})
assert.are.same({
{
type = "move",
entry_type = "file",
src_url = "oil-test:///foo/a.txt",
dest_url = "oil-test:///foo/b.txt",
type = 'move',
entry_type = 'file',
src_url = 'oil-test:///foo/a.txt',
dest_url = 'oil-test:///foo/b.txt',
},
}, actions)
end)
it("correctly orders MOVE + CREATE", function()
local file = test_adapter.test_set("/a.txt", "file")
vim.cmd.edit({ args = { "oil-test:///" } })
it('correctly orders MOVE + CREATE', function()
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 = {
{ type = "delete", name = "a.txt", id = file[FIELD_ID] },
{ type = "new", name = "b.txt", entry_type = "file", id = file[FIELD_ID] },
{ type = "new", name = "a.txt", entry_type = "file" },
{ type = 'delete', name = 'a.txt', id = file[FIELD_ID] },
{ type = 'new', name = 'b.txt', entry_type = 'file', id = file[FIELD_ID] },
{ type = 'new', name = 'a.txt', entry_type = 'file' },
}
local actions = mutator.create_actions_from_diffs({
[bufnr] = diffs,
})
assert.are.same({
{
type = "move",
entry_type = "file",
src_url = "oil-test:///a.txt",
dest_url = "oil-test:///b.txt",
type = 'move',
entry_type = 'file',
src_url = 'oil-test:///a.txt',
dest_url = 'oil-test:///b.txt',
},
{
type = "create",
entry_type = "file",
url = "oil-test:///a.txt",
type = 'create',
entry_type = 'file',
url = 'oil-test:///a.txt',
},
}, actions)
end)
it("resolves MOVE loops", function()
local afile = test_adapter.test_set("/a.txt", "file")
local bfile = test_adapter.test_set("/b.txt", "file")
vim.cmd.edit({ args = { "oil-test:///" } })
it('resolves MOVE loops', function()
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 = {
{ type = "delete", name = "a.txt", id = afile[FIELD_ID] },
{ type = "new", name = "b.txt", entry_type = "file", id = afile[FIELD_ID] },
{ type = "delete", name = "b.txt", id = bfile[FIELD_ID] },
{ type = "new", name = "a.txt", entry_type = "file", id = bfile[FIELD_ID] },
{ type = 'delete', name = 'a.txt', id = afile[FIELD_ID] },
{ type = 'new', name = 'b.txt', entry_type = 'file', id = afile[FIELD_ID] },
{ type = 'delete', name = 'b.txt', id = bfile[FIELD_ID] },
{ type = 'new', name = 'a.txt', entry_type = 'file', id = bfile[FIELD_ID] },
}
math.randomseed(2983982)
local actions = mutator.create_actions_from_diffs({
[bufnr] = diffs,
})
local tmp_url = "oil-test:///a.txt__oil_tmp_510852"
local tmp_url = 'oil-test:///a.txt__oil_tmp_510852'
assert.are.same({
{
type = "move",
entry_type = "file",
src_url = "oil-test:///a.txt",
type = 'move',
entry_type = 'file',
src_url = 'oil-test:///a.txt',
dest_url = tmp_url,
},
{
type = "move",
entry_type = "file",
src_url = "oil-test:///b.txt",
dest_url = "oil-test:///a.txt",
type = 'move',
entry_type = 'file',
src_url = 'oil-test:///b.txt',
dest_url = 'oil-test:///a.txt',
},
{
type = "move",
entry_type = "file",
type = 'move',
entry_type = 'file',
src_url = tmp_url,
dest_url = "oil-test:///b.txt",
dest_url = 'oil-test:///b.txt',
},
}, actions)
end)
end)
describe("order actions", function()
it("Creates files inside dir before move", function()
describe('order actions', function()
it('Creates files inside dir before move', function()
local move = {
type = "move",
src_url = "oil-test:///a",
dest_url = "oil-test:///b",
entry_type = "directory",
type = 'move',
src_url = 'oil-test:///a',
dest_url = 'oil-test:///b',
entry_type = 'directory',
}
local create = { type = "create", url = "oil-test:///a/hi.txt", entry_type = "file" }
local create = { type = 'create', url = 'oil-test:///a/hi.txt', entry_type = 'file' }
local actions = { move, create }
local ordered_actions = mutator.enforce_action_order(actions)
assert.are.same({ create, move }, ordered_actions)
end)
it("Moves file out of parent before deleting parent", function()
it('Moves file out of parent before deleting parent', function()
local move = {
type = "move",
src_url = "oil-test:///a/b.txt",
dest_url = "oil-test:///b.txt",
entry_type = "file",
type = 'move',
src_url = 'oil-test:///a/b.txt',
dest_url = 'oil-test:///b.txt',
entry_type = 'file',
}
local delete = { type = "delete", url = "oil-test:///a", entry_type = "directory" }
local delete = { type = 'delete', url = 'oil-test:///a', entry_type = 'directory' }
local actions = { delete, move }
local ordered_actions = mutator.enforce_action_order(actions)
assert.are.same({ move, delete }, ordered_actions)
end)
it("Handles parent child move ordering", function()
it('Handles parent child move ordering', function()
-- move parent into a child and child OUT of parent
-- MOVE /a/b -> /b
-- MOVE /a -> /b/a
local move1 = {
type = "move",
src_url = "oil-test:///a/b",
dest_url = "oil-test:///b",
entry_type = "directory",
type = 'move',
src_url = 'oil-test:///a/b',
dest_url = 'oil-test:///b',
entry_type = 'directory',
}
local move2 = {
type = "move",
src_url = "oil-test:///a",
dest_url = "oil-test:///b/a",
entry_type = "directory",
type = 'move',
src_url = 'oil-test:///a',
dest_url = 'oil-test:///b/a',
entry_type = 'directory',
}
local actions = { move2, move1 }
local ordered_actions = mutator.enforce_action_order(actions)
assert.are.same({ move1, move2 }, ordered_actions)
end)
it("Handles a delete inside a moved folder", function()
it('Handles a delete inside a moved folder', function()
-- delete in directory and move directory
-- DELETE /a/b.txt
-- MOVE /a/ -> /b/
local del = {
type = "delete",
url = "oil-test:///a/b.txt",
entry_type = "file",
type = 'delete',
url = 'oil-test:///a/b.txt',
entry_type = 'file',
}
local move = {
type = "move",
src_url = "oil-test:///a",
dest_url = "oil-test:///b",
entry_type = "directory",
type = 'move',
src_url = 'oil-test:///a',
dest_url = 'oil-test:///b',
entry_type = 'directory',
}
local actions = { move, del }
local ordered_actions = mutator.enforce_action_order(actions)
assert.are.same({ del, move }, ordered_actions)
end)
it("Detects move directory loops", function()
it('Detects move directory loops', function()
local move = {
type = "move",
src_url = "oil-test:///a",
dest_url = "oil-test:///a/b",
entry_type = "directory",
type = 'move',
src_url = 'oil-test:///a',
dest_url = 'oil-test:///a/b',
entry_type = 'directory',
}
assert.has_error(function()
mutator.enforce_action_order({ move })
end)
end)
it("Detects copy directory loops", function()
it('Detects copy directory loops', function()
local move = {
type = "copy",
src_url = "oil-test:///a",
dest_url = "oil-test:///a/b",
entry_type = "directory",
type = 'copy',
src_url = 'oil-test:///a',
dest_url = 'oil-test:///a/b',
entry_type = 'directory',
}
assert.has_error(function()
mutator.enforce_action_order({ move })
end)
end)
it("Detects nested copy directory loops", function()
it('Detects nested copy directory loops', function()
local move = {
type = "copy",
src_url = "oil-test:///a",
dest_url = "oil-test:///a/b/a",
entry_type = "directory",
type = 'copy',
src_url = 'oil-test:///a',
dest_url = 'oil-test:///a/b/a',
entry_type = 'directory',
}
assert.has_error(function()
mutator.enforce_action_order({ move })
end)
end)
describe("change", function()
it("applies CHANGE after CREATE", function()
local create = { type = "create", url = "oil-test:///a/hi.txt", entry_type = "file" }
describe('change', function()
it('applies CHANGE after CREATE', function()
local create = { type = 'create', url = 'oil-test:///a/hi.txt', entry_type = 'file' }
local change = {
type = "change",
url = "oil-test:///a/hi.txt",
entry_type = "file",
column = "TEST",
value = "TEST",
type = 'change',
url = 'oil-test:///a/hi.txt',
entry_type = 'file',
column = 'TEST',
value = 'TEST',
}
local actions = { change, create }
local ordered_actions = mutator.enforce_action_order(actions)
assert.are.same({ create, change }, ordered_actions)
end)
it("applies CHANGE after COPY src", function()
it('applies CHANGE after COPY src', function()
local copy = {
type = "copy",
src_url = "oil-test:///a/hi.txt",
dest_url = "oil-test:///b.txt",
entry_type = "file",
type = 'copy',
src_url = 'oil-test:///a/hi.txt',
dest_url = 'oil-test:///b.txt',
entry_type = 'file',
}
local change = {
type = "change",
url = "oil-test:///a/hi.txt",
entry_type = "file",
column = "TEST",
value = "TEST",
type = 'change',
url = 'oil-test:///a/hi.txt',
entry_type = 'file',
column = 'TEST',
value = 'TEST',
}
local actions = { change, copy }
local ordered_actions = mutator.enforce_action_order(actions)
assert.are.same({ copy, change }, ordered_actions)
end)
it("applies CHANGE after COPY dest", function()
it('applies CHANGE after COPY dest', function()
local copy = {
type = "copy",
src_url = "oil-test:///b.txt",
dest_url = "oil-test:///a/hi.txt",
entry_type = "file",
type = 'copy',
src_url = 'oil-test:///b.txt',
dest_url = 'oil-test:///a/hi.txt',
entry_type = 'file',
}
local change = {
type = "change",
url = "oil-test:///a/hi.txt",
entry_type = "file",
column = "TEST",
value = "TEST",
type = 'change',
url = 'oil-test:///a/hi.txt',
entry_type = 'file',
column = 'TEST',
value = 'TEST',
}
local actions = { change, copy }
local ordered_actions = mutator.enforce_action_order(actions)
assert.are.same({ copy, change }, ordered_actions)
end)
it("applies CHANGE after MOVE dest", function()
it('applies CHANGE after MOVE dest', function()
local move = {
type = "move",
src_url = "oil-test:///b.txt",
dest_url = "oil-test:///a/hi.txt",
entry_type = "file",
type = 'move',
src_url = 'oil-test:///b.txt',
dest_url = 'oil-test:///a/hi.txt',
entry_type = 'file',
}
local change = {
type = "change",
url = "oil-test:///a/hi.txt",
entry_type = "file",
column = "TEST",
value = "TEST",
type = 'change',
url = 'oil-test:///a/hi.txt',
entry_type = 'file',
column = 'TEST',
value = 'TEST',
}
local actions = { change, move }
local ordered_actions = mutator.enforce_action_order(actions)
@ -346,29 +346,29 @@ a.describe("mutator", function()
end)
end)
a.describe("perform actions", function()
a.it("creates new entries", function()
a.describe('perform actions', function()
a.it('creates new entries', function()
local actions = {
{ type = "create", url = "oil-test:///a.txt", entry_type = "file" },
{ type = 'create', url = 'oil-test:///a.txt', entry_type = 'file' },
}
a.wrap(mutator.process_actions, 2)(actions)
local files = cache.list_url("oil-test:///")
local files = cache.list_url('oil-test:///')
assert.are.same({
["a.txt"] = {
['a.txt'] = {
[FIELD_ID] = 1,
[FIELD_TYPE] = "file",
[FIELD_NAME] = "a.txt",
[FIELD_TYPE] = 'file',
[FIELD_NAME] = 'a.txt',
},
}, files)
end)
a.it("deletes entries", function()
local file = test_adapter.test_set("/a.txt", "file")
a.it('deletes entries', function()
local file = test_adapter.test_set('/a.txt', 'file')
local actions = {
{ type = "delete", url = "oil-test:///a.txt", entry_type = "file" },
{ type = 'delete', url = 'oil-test:///a.txt', entry_type = 'file' },
}
a.wrap(mutator.process_actions, 2)(actions)
local files = cache.list_url("oil-test:///")
local files = cache.list_url('oil-test:///')
assert.are.same({}, files)
assert.is_nil(cache.get_entry_by_id(file[FIELD_ID]))
assert.has_error(function()
@ -376,50 +376,50 @@ a.describe("mutator", function()
end)
end)
a.it("moves entries", function()
local file = test_adapter.test_set("/a.txt", "file")
a.it('moves entries', function()
local file = test_adapter.test_set('/a.txt', 'file')
local actions = {
{
type = "move",
src_url = "oil-test:///a.txt",
dest_url = "oil-test:///b.txt",
entry_type = "file",
type = 'move',
src_url = 'oil-test:///a.txt',
dest_url = 'oil-test:///b.txt',
entry_type = 'file',
},
}
a.wrap(mutator.process_actions, 2)(actions)
local files = cache.list_url("oil-test:///")
local files = cache.list_url('oil-test:///')
local new_entry = {
[FIELD_ID] = file[FIELD_ID],
[FIELD_TYPE] = "file",
[FIELD_NAME] = "b.txt",
[FIELD_TYPE] = 'file',
[FIELD_NAME] = 'b.txt',
}
assert.are.same({
["b.txt"] = new_entry,
['b.txt'] = new_entry,
}, files)
assert.are.same(new_entry, cache.get_entry_by_id(file[FIELD_ID]))
assert.equals("oil-test:///", cache.get_parent_url(file[FIELD_ID]))
assert.equals('oil-test:///', cache.get_parent_url(file[FIELD_ID]))
end)
a.it("copies entries", function()
local file = test_adapter.test_set("/a.txt", "file")
a.it('copies entries', function()
local file = test_adapter.test_set('/a.txt', 'file')
local actions = {
{
type = "copy",
src_url = "oil-test:///a.txt",
dest_url = "oil-test:///b.txt",
entry_type = "file",
type = 'copy',
src_url = 'oil-test:///a.txt',
dest_url = 'oil-test:///b.txt',
entry_type = 'file',
},
}
a.wrap(mutator.process_actions, 2)(actions)
local files = cache.list_url("oil-test:///")
local files = cache.list_url('oil-test:///')
local new_entry = {
[FIELD_ID] = file[FIELD_ID] + 1,
[FIELD_TYPE] = "file",
[FIELD_NAME] = "b.txt",
[FIELD_TYPE] = 'file',
[FIELD_NAME] = 'b.txt',
}
assert.are.same({
["a.txt"] = file,
["b.txt"] = new_entry,
['a.txt'] = file,
['b.txt'] = new_entry,
}, files)
end)
end)

View file

@ -1,10 +1,10 @@
require("plenary.async").tests.add_to_env()
local constants = require("oil.constants")
local parser = require("oil.mutator.parser")
local test_adapter = require("oil.adapters.test")
local test_util = require("tests.test_util")
local util = require("oil.util")
local view = require("oil.view")
require('plenary.async').tests.add_to_env()
local constants = require('oil.constants')
local parser = require('oil.mutator.parser')
local test_adapter = require('oil.adapters.test')
local test_util = require('tests.test_util')
local util = require('oil.util')
local view = require('oil.view')
local FIELD_ID = constants.FIELD_ID
local FIELD_META = constants.FIELD_META
@ -14,101 +14,101 @@ local function set_lines(bufnr, lines)
vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, lines)
end
describe("parser", function()
describe('parser', function()
after_each(function()
test_util.reset_editor()
end)
it("detects new files", function()
vim.cmd.edit({ args = { "oil-test:///foo/" } })
it('detects new files', function()
vim.cmd.edit({ args = { 'oil-test:///foo/' } })
local bufnr = vim.api.nvim_get_current_buf()
set_lines(bufnr, {
"a.txt",
'a.txt',
})
local diffs = parser.parse(bufnr)
assert.are.same({ { entry_type = "file", name = "a.txt", type = "new" } }, diffs)
assert.are.same({ { entry_type = 'file', name = 'a.txt', type = 'new' } }, diffs)
end)
it("detects new directories", function()
vim.cmd.edit({ args = { "oil-test:///foo/" } })
it('detects new directories', function()
vim.cmd.edit({ args = { 'oil-test:///foo/' } })
local bufnr = vim.api.nvim_get_current_buf()
set_lines(bufnr, {
"foo/",
'foo/',
})
local diffs = parser.parse(bufnr)
assert.are.same({ { entry_type = "directory", name = "foo", type = "new" } }, diffs)
assert.are.same({ { entry_type = 'directory', name = 'foo', type = 'new' } }, diffs)
end)
it("detects new links", function()
vim.cmd.edit({ args = { "oil-test:///foo/" } })
it('detects new links', function()
vim.cmd.edit({ args = { 'oil-test:///foo/' } })
local bufnr = vim.api.nvim_get_current_buf()
set_lines(bufnr, {
"a.txt -> b.txt",
'a.txt -> b.txt',
})
local diffs = parser.parse(bufnr)
assert.are.same(
{ { entry_type = "link", name = "a.txt", type = "new", link = "b.txt" } },
{ { entry_type = 'link', name = 'a.txt', type = 'new', link = 'b.txt' } },
diffs
)
end)
it("detects deleted files", function()
local file = test_adapter.test_set("/foo/a.txt", "file")
vim.cmd.edit({ args = { "oil-test:///foo/" } })
it('detects deleted files', function()
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, {})
local diffs = parser.parse(bufnr)
assert.are.same({
{ name = "a.txt", type = "delete", id = file[FIELD_ID] },
{ name = 'a.txt', type = 'delete', id = file[FIELD_ID] },
}, diffs)
end)
it("detects deleted directories", function()
local dir = test_adapter.test_set("/foo/bar", "directory")
vim.cmd.edit({ args = { "oil-test:///foo/" } })
it('detects deleted directories', function()
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, {})
local diffs = parser.parse(bufnr)
assert.are.same({
{ name = "bar", type = "delete", id = dir[FIELD_ID] },
{ name = 'bar', type = 'delete', id = dir[FIELD_ID] },
}, diffs)
end)
it("detects deleted links", function()
local file = test_adapter.test_set("/foo/a.txt", "link")
file[FIELD_META] = { link = "b.txt" }
vim.cmd.edit({ args = { "oil-test:///foo/" } })
it('detects deleted links', function()
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()
set_lines(bufnr, {})
local diffs = parser.parse(bufnr)
assert.are.same({
{ name = "a.txt", type = "delete", id = file[FIELD_ID] },
{ name = 'a.txt', type = 'delete', id = file[FIELD_ID] },
}, diffs)
end)
it("ignores empty lines", function()
local file = test_adapter.test_set("/foo/a.txt", "file")
vim.cmd.edit({ args = { "oil-test:///foo/" } })
it('ignores empty lines', function()
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, false)
local lines = util.render_table({ cols }, {})
table.insert(lines, "")
table.insert(lines, " ")
table.insert(lines, '')
table.insert(lines, ' ')
set_lines(bufnr, lines)
local diffs = parser.parse(bufnr)
assert.are.same({}, diffs)
end)
it("errors on missing filename", function()
vim.cmd.edit({ args = { "oil-test:///foo/" } })
it('errors on missing filename', function()
vim.cmd.edit({ args = { 'oil-test:///foo/' } })
local bufnr = vim.api.nvim_get_current_buf()
set_lines(bufnr, {
"/008",
'/008',
})
local _, errors = parser.parse(bufnr)
assert.are_same({
{
message = "Malformed ID at start of line",
message = 'Malformed ID at start of line',
lnum = 0,
end_lnum = 1,
col = 0,
@ -116,16 +116,16 @@ describe("parser", function()
}, errors)
end)
it("errors on empty dirname", function()
vim.cmd.edit({ args = { "oil-test:///foo/" } })
it('errors on empty dirname', function()
vim.cmd.edit({ args = { 'oil-test:///foo/' } })
local bufnr = vim.api.nvim_get_current_buf()
set_lines(bufnr, {
"/008 /",
'/008 /',
})
local _, errors = parser.parse(bufnr)
assert.are.same({
{
message = "No filename found",
message = 'No filename found',
lnum = 0,
end_lnum = 1,
col = 0,
@ -133,17 +133,17 @@ describe("parser", function()
}, errors)
end)
it("errors on duplicate names", function()
vim.cmd.edit({ args = { "oil-test:///foo/" } })
it('errors on duplicate names', function()
vim.cmd.edit({ args = { 'oil-test:///foo/' } })
local bufnr = vim.api.nvim_get_current_buf()
set_lines(bufnr, {
"foo",
"foo/",
'foo',
'foo/',
})
local _, errors = parser.parse(bufnr)
assert.are.same({
{
message = "Duplicate filename",
message = 'Duplicate filename',
lnum = 1,
end_lnum = 2,
col = 0,
@ -151,18 +151,18 @@ describe("parser", function()
}, errors)
end)
it("errors on duplicate names for existing files", function()
local file = test_adapter.test_set("/foo/a.txt", "file")
vim.cmd.edit({ args = { "oil-test:///foo/" } })
it('errors on duplicate names for existing files', function()
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, {
"a.txt",
string.format("/%d a.txt", file[FIELD_ID]),
'a.txt',
string.format('/%d a.txt', file[FIELD_ID]),
})
local _, errors = parser.parse(bufnr)
assert.are.same({
{
message = "Duplicate filename",
message = 'Duplicate filename',
lnum = 1,
end_lnum = 2,
col = 0,
@ -170,52 +170,52 @@ describe("parser", function()
}, errors)
end)
it("ignores new dirs with empty name", function()
vim.cmd.edit({ args = { "oil-test:///foo/" } })
it('ignores new dirs with empty name', function()
vim.cmd.edit({ args = { 'oil-test:///foo/' } })
local bufnr = vim.api.nvim_get_current_buf()
set_lines(bufnr, {
"/",
'/',
})
local diffs = parser.parse(bufnr)
assert.are.same({}, diffs)
end)
it("parses a rename as a delete + new", function()
local file = test_adapter.test_set("/foo/a.txt", "file")
vim.cmd.edit({ args = { "oil-test:///foo/" } })
it('parses a rename as a delete + new', function()
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, {
string.format("/%d b.txt", file[FIELD_ID]),
string.format('/%d b.txt', file[FIELD_ID]),
})
local diffs = parser.parse(bufnr)
assert.are.same({
{ type = "new", id = file[FIELD_ID], name = "b.txt", entry_type = "file" },
{ type = "delete", id = file[FIELD_ID], name = "a.txt" },
{ type = 'new', id = file[FIELD_ID], name = 'b.txt', entry_type = 'file' },
{ type = 'delete', id = file[FIELD_ID], name = 'a.txt' },
}, diffs)
end)
it("detects a new trailing slash as a delete + create", function()
local file = test_adapter.test_set("/foo", "file")
vim.cmd.edit({ args = { "oil-test:///" } })
it('detects a new trailing slash as a delete + create', function()
local file = test_adapter.test_set('/foo', 'file')
vim.cmd.edit({ args = { 'oil-test:///' } })
local bufnr = vim.api.nvim_get_current_buf()
set_lines(bufnr, {
string.format("/%d foo/", file[FIELD_ID]),
string.format('/%d foo/', file[FIELD_ID]),
})
local diffs = parser.parse(bufnr)
assert.are.same({
{ type = "new", name = "foo", entry_type = "directory" },
{ type = "delete", id = file[FIELD_ID], name = "foo" },
{ type = 'new', name = 'foo', entry_type = 'directory' },
{ type = 'delete', id = file[FIELD_ID], name = 'foo' },
}, diffs)
end)
it("detects renamed files that conflict", function()
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/" } })
it('detects renamed files that conflict', function()
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, {
string.format("/%d a.txt", bfile[FIELD_ID]),
string.format("/%d b.txt", afile[FIELD_ID]),
string.format('/%d a.txt', bfile[FIELD_ID]),
string.format('/%d b.txt', afile[FIELD_ID]),
})
local diffs = parser.parse(bufnr)
local first_two = { diffs[1], diffs[2] }
@ -227,22 +227,22 @@ describe("parser", function()
return a.id < b.id
end)
assert.are.same({
{ name = "b.txt", type = "new", id = afile[FIELD_ID], entry_type = "file" },
{ name = "a.txt", type = "new", id = bfile[FIELD_ID], entry_type = "file" },
{ name = 'b.txt', type = 'new', id = afile[FIELD_ID], entry_type = 'file' },
{ name = 'a.txt', type = 'new', id = bfile[FIELD_ID], entry_type = 'file' },
}, first_two)
assert.are.same({
{ name = "a.txt", type = "delete", id = afile[FIELD_ID] },
{ name = "b.txt", type = "delete", id = bfile[FIELD_ID] },
{ name = 'a.txt', type = 'delete', id = afile[FIELD_ID] },
{ name = 'b.txt', type = 'delete', id = bfile[FIELD_ID] },
}, last_two)
end)
it("views link targets with trailing slashes as the same", function()
local file = test_adapter.test_set("/foo/mydir", "link")
file[FIELD_META] = { link = "dir/" }
vim.cmd.edit({ args = { "oil-test:///foo/" } })
it('views link targets with trailing slashes as the same', function()
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()
set_lines(bufnr, {
string.format("/%d mydir/ -> dir/", file[FIELD_ID]),
string.format('/%d mydir/ -> dir/', file[FIELD_ID]),
})
local diffs = parser.parse(bufnr)
assert.are.same({}, diffs)

View file

@ -1,13 +1,13 @@
local pathutil = require("oil.pathutil")
describe("pathutil", function()
it("calculates parent path", function()
local pathutil = require('oil.pathutil')
describe('pathutil', function()
it('calculates parent path', function()
local cases = {
{ "/foo/bar", "/foo/" },
{ "/foo/bar/", "/foo/" },
{ "/", "/" },
{ "", "" },
{ "foo/bar/", "foo/" },
{ "foo", "" },
{ '/foo/bar', '/foo/' },
{ '/foo/bar/', '/foo/' },
{ '/', '/' },
{ '', '' },
{ 'foo/bar/', 'foo/' },
{ 'foo', '' },
}
for _, case in ipairs(cases) do
local input, expected = unpack(case)
@ -16,12 +16,12 @@ describe("pathutil", function()
end
end)
it("calculates basename", function()
it('calculates basename', function()
local cases = {
{ "/foo/bar", "bar" },
{ "/foo/bar/", "bar" },
{ "/", nil },
{ "", nil },
{ '/foo/bar', 'bar' },
{ '/foo/bar/', 'bar' },
{ '/', nil },
{ '', nil },
}
for _, case in ipairs(cases) do
local input, expected = unpack(case)

View file

@ -1,10 +1,10 @@
require("plenary.async").tests.add_to_env()
local TmpDir = require("tests.tmpdir")
local oil = require("oil")
local test_util = require("tests.test_util")
local util = require("oil.util")
require('plenary.async').tests.add_to_env()
local TmpDir = require('tests.tmpdir')
local oil = require('oil')
local test_util = require('tests.test_util')
local util = require('oil.util')
a.describe("oil preview", function()
a.describe('oil preview', function()
local tmpdir
a.before_each(function()
tmpdir = TmpDir.new()
@ -16,8 +16,8 @@ a.describe("oil preview", function()
test_util.reset_editor()
end)
a.it("opens preview window", function()
tmpdir:create({ "a.txt" })
a.it('opens preview window', function()
tmpdir:create({ 'a.txt' })
test_util.oil_open(tmpdir.path)
a.wrap(oil.open_preview, 2)()
local preview_win = util.get_preview_win()
@ -25,17 +25,17 @@ a.describe("oil preview", function()
assert(preview_win)
local bufnr = vim.api.nvim_win_get_buf(preview_win)
local preview_lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
assert.are.same({ "a.txt" }, preview_lines)
assert.are.same({ 'a.txt' }, preview_lines)
end)
a.it("opens preview window when open(preview={})", function()
tmpdir:create({ "a.txt" })
a.it('opens preview window when open(preview={})', function()
tmpdir:create({ 'a.txt' })
test_util.oil_open(tmpdir.path, { preview = {} })
local preview_win = util.get_preview_win()
assert.not_nil(preview_win)
assert(preview_win)
local bufnr = vim.api.nvim_win_get_buf(preview_win)
local preview_lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
assert.are.same({ "a.txt" }, preview_lines)
assert.are.same({ 'a.txt' }, preview_lines)
end)
end)

View file

@ -1,11 +1,11 @@
require("plenary.async").tests.add_to_env()
local TmpDir = require("tests.tmpdir")
local actions = require("oil.actions")
local oil = require("oil")
local test_util = require("tests.test_util")
local view = require("oil.view")
require('plenary.async').tests.add_to_env()
local TmpDir = require('tests.tmpdir')
local actions = require('oil.actions')
local oil = require('oil')
local test_util = require('tests.test_util')
local view = require('oil.view')
a.describe("regression tests", function()
a.describe('regression tests', function()
local tmpdir
a.before_each(function()
tmpdir = TmpDir.new()
@ -19,37 +19,37 @@ a.describe("regression tests", function()
end)
-- see https://github.com/stevearc/oil.nvim/issues/25
a.it("can edit dirs that will be renamed to an existing buffer", function()
vim.cmd.edit({ args = { "README.md" } })
a.it('can edit dirs that will be renamed to an existing buffer', function()
vim.cmd.edit({ args = { 'README.md' } })
vim.cmd.vsplit()
vim.cmd.edit({ args = { "%:p:h" } })
assert.equals("oil", vim.bo.filetype)
vim.cmd.wincmd({ args = { "p" } })
assert.equals("markdown", vim.bo.filetype)
vim.cmd.edit({ args = { "%:p:h" } })
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
assert.equals("oil", vim.bo.filetype)
vim.cmd.edit({ args = { '%:p:h' } })
assert.equals('oil', vim.bo.filetype)
vim.cmd.wincmd({ args = { 'p' } })
assert.equals('markdown', vim.bo.filetype)
vim.cmd.edit({ args = { '%:p:h' } })
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
assert.equals('oil', vim.bo.filetype)
end)
-- https://github.com/stevearc/oil.nvim/issues/37
a.it("places the cursor on correct entry when opening on file", function()
vim.cmd.edit({ args = { "." } })
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
a.it('places the cursor on correct entry when opening on file', function()
vim.cmd.edit({ args = { '.' } })
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
local entry = oil.get_cursor_entry()
assert.not_nil(entry)
assert.not_equals("README.md", entry and entry.name)
vim.cmd.edit({ args = { "README.md" } })
assert.not_equals('README.md', entry and entry.name)
vim.cmd.edit({ args = { 'README.md' } })
view.delete_hidden_buffers()
oil.open()
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
entry = oil.get_cursor_entry()
assert.equals("README.md", entry and entry.name)
assert.equals('README.md', entry and entry.name)
end)
-- https://github.com/stevearc/oil.nvim/issues/64
a.it("doesn't close floating windows oil didn't open itself", function()
local winid = vim.api.nvim_open_win(vim.fn.bufadd("README.md"), true, {
relative = "editor",
local winid = vim.api.nvim_open_win(vim.fn.bufadd('README.md'), true, {
relative = 'editor',
row = 1,
col = 1,
width = 100,
@ -64,7 +64,7 @@ a.describe("regression tests", function()
-- https://github.com/stevearc/oil.nvim/issues/64
a.it("doesn't close splits on oil.close", function()
vim.cmd.edit({ args = { "README.md" } })
vim.cmd.edit({ args = { 'README.md' } })
vim.cmd.vsplit()
local winid = vim.api.nvim_get_current_win()
local bufnr = vim.api.nvim_get_current_buf()
@ -78,71 +78,71 @@ a.describe("regression tests", function()
end)
-- https://github.com/stevearc/oil.nvim/issues/79
a.it("Returns to empty buffer on close", function()
a.it('Returns to empty buffer on close', function()
oil.open()
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
oil.close()
assert.not_equals("oil", vim.bo.filetype)
assert.equals("", vim.api.nvim_buf_get_name(0))
assert.not_equals('oil', vim.bo.filetype)
assert.equals('', vim.api.nvim_buf_get_name(0))
end)
a.it("All buffers set nomodified after save", function()
tmpdir:create({ "a.txt" })
a.it('All buffers set nomodified after save', function()
tmpdir:create({ 'a.txt' })
a.util.scheduler()
vim.cmd.edit({ args = { "oil://" .. vim.fn.fnamemodify(tmpdir.path, ":p") } })
vim.cmd.edit({ args = { 'oil://' .. vim.fn.fnamemodify(tmpdir.path, ':p') } })
local first_dir = vim.api.nvim_get_current_buf()
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
test_util.feedkeys({ "dd", "itest/<esc>", "<CR>" }, 10)
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
test_util.feedkeys({ 'dd', 'itest/<esc>', '<CR>' }, 10)
vim.wait(1000, function()
return vim.bo.modifiable
end, 10)
test_util.feedkeys({ "p" }, 10)
test_util.feedkeys({ 'p' }, 10)
a.util.scheduler()
oil.save({ confirm = false })
vim.wait(1000, function()
return vim.bo.modifiable
end, 10)
tmpdir:assert_fs({
["test/a.txt"] = "a.txt",
['test/a.txt'] = 'a.txt',
})
-- The first oil buffer should not be modified anymore
assert.falsy(vim.bo[first_dir].modified)
end)
a.it("refreshing buffer doesn't lose track of it", function()
vim.cmd.edit({ args = { "." } })
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
vim.cmd.edit({ args = { '.' } })
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
local bufnr = vim.api.nvim_get_current_buf()
vim.cmd.edit({ bang = true })
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
assert.are.same({ bufnr }, require("oil.view").get_all_buffers())
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()
a.it('can copy a file multiple times', function()
test_util.actions.open({ tmpdir.path })
vim.api.nvim_feedkeys("ifoo.txt", "x", true)
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)
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))
assert.are.same({ 'bar.txt', 'baz.txt', 'foo.txt' }, test_util.parse_entries(0))
tmpdir:assert_fs({
["foo.txt"] = "",
["bar.txt"] = "",
["baz.txt"] = "",
['foo.txt'] = '',
['bar.txt'] = '',
['baz.txt'] = '',
})
end)
-- https://github.com/stevearc/oil.nvim/issues/355
a.it("can open files from floating window", function()
tmpdir:create({ "a.txt" })
a.it('can open files from floating window', function()
tmpdir:create({ 'a.txt' })
a.util.scheduler()
oil.open_float(tmpdir.path)
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
actions.select.callback()
vim.wait(1000, function()
return vim.fn.expand("%:t") == "a.txt"
return vim.fn.expand('%:t') == 'a.txt'
end, 10)
assert.equals("a.txt", vim.fn.expand("%:t"))
assert.equals('a.txt', vim.fn.expand('%:t'))
end)
end)

View file

@ -1,22 +1,22 @@
require("plenary.async").tests.add_to_env()
local oil = require("oil")
local test_util = require("tests.test_util")
require('plenary.async').tests.add_to_env()
local oil = require('oil')
local test_util = require('tests.test_util')
a.describe("oil select", function()
a.describe('oil select', function()
after_each(function()
test_util.reset_editor()
end)
a.it("opens file under cursor", function()
a.it('opens file under cursor', function()
test_util.oil_open()
-- Go to the bottom, so the cursor is not on a directory
vim.cmd.normal({ args = { "G" } })
vim.cmd.normal({ args = { 'G' } })
a.wrap(oil.select, 2)()
assert.equals(1, #vim.api.nvim_tabpage_list_wins(0))
assert.not_equals("oil", vim.bo.filetype)
assert.not_equals('oil', vim.bo.filetype)
end)
a.it("opens file in new tab", function()
a.it('opens file in new tab', function()
test_util.oil_open()
local tabpage = vim.api.nvim_get_current_tabpage()
a.wrap(oil.select, 2)({ tab = true })
@ -25,7 +25,7 @@ a.describe("oil select", function()
assert.not_equals(tabpage, vim.api.nvim_get_current_tabpage())
end)
a.it("opens file in new split", function()
a.it('opens file in new split', function()
test_util.oil_open()
local winid = vim.api.nvim_get_current_win()
a.wrap(oil.select, 2)({ vertical = true })
@ -34,9 +34,9 @@ a.describe("oil select", function()
assert.not_equals(winid, vim.api.nvim_get_current_win())
end)
a.it("opens multiple files in new tabs", function()
a.it('opens multiple files in new tabs', function()
test_util.oil_open()
vim.api.nvim_feedkeys("Vj", "x", true)
vim.api.nvim_feedkeys('Vj', 'x', true)
local tabpage = vim.api.nvim_get_current_tabpage()
a.wrap(oil.select, 2)({ tab = true })
assert.equals(3, #vim.api.nvim_list_tabpages())
@ -44,9 +44,9 @@ a.describe("oil select", function()
assert.not_equals(tabpage, vim.api.nvim_get_current_tabpage())
end)
a.it("opens multiple files in new splits", function()
a.it('opens multiple files in new splits', function()
test_util.oil_open()
vim.api.nvim_feedkeys("Vj", "x", true)
vim.api.nvim_feedkeys('Vj', 'x', true)
local winid = vim.api.nvim_get_current_win()
a.wrap(oil.select, 2)({ vertical = true })
assert.equals(1, #vim.api.nvim_list_tabpages())
@ -54,23 +54,23 @@ a.describe("oil select", function()
assert.not_equals(winid, vim.api.nvim_get_current_win())
end)
a.describe("close after open", function()
a.it("same window", function()
vim.cmd.edit({ args = { "foo" } })
a.describe('close after open', function()
a.it('same window', function()
vim.cmd.edit({ args = { 'foo' } })
local bufnr = vim.api.nvim_get_current_buf()
test_util.oil_open()
-- Go to the bottom, so the cursor is not on a directory
vim.cmd.normal({ args = { "G" } })
vim.cmd.normal({ args = { 'G' } })
a.wrap(oil.select, 2)({ close = true })
assert.equals(1, #vim.api.nvim_tabpage_list_wins(0))
-- This one we actually don't expect the buffer to be the same as the initial buffer, because
-- we opened a file
assert.not_equals(bufnr, vim.api.nvim_get_current_buf())
assert.not_equals("oil", vim.bo.filetype)
assert.not_equals('oil', vim.bo.filetype)
end)
a.it("split", function()
vim.cmd.edit({ args = { "foo" } })
a.it('split', function()
vim.cmd.edit({ args = { 'foo' } })
local bufnr = vim.api.nvim_get_current_buf()
local winid = vim.api.nvim_get_current_win()
test_util.oil_open()
@ -79,8 +79,8 @@ a.describe("oil select", function()
assert.equals(bufnr, vim.api.nvim_win_get_buf(winid))
end)
a.it("tab", function()
vim.cmd.edit({ args = { "foo" } })
a.it('tab', function()
vim.cmd.edit({ args = { 'foo' } })
local bufnr = vim.api.nvim_get_current_buf()
local tabpage = vim.api.nvim_get_current_tabpage()
test_util.oil_open()

View file

@ -1,14 +1,14 @@
require("plenary.async").tests.add_to_env()
local cache = require("oil.cache")
local test_adapter = require("oil.adapters.test")
local util = require("oil.util")
require('plenary.async').tests.add_to_env()
local cache = require('oil.cache')
local test_adapter = require('oil.adapters.test')
local util = require('oil.util')
local M = {}
M.reset_editor = function()
require("oil").setup({
require('oil').setup({
columms = {},
adapters = {
["oil-test://"] = "test",
['oil-test://'] = 'test',
},
prompt_save_on_select_new_entry = false,
})
@ -35,7 +35,7 @@ local function throwiferr(err, ...)
end
M.oil_open = function(...)
a.wrap(require("oil").open, 3)(...)
a.wrap(require('oil').open, 3)(...)
end
M.await = function(fn, nargs, ...)
@ -44,12 +44,12 @@ end
M.wait_for_autocmd = a.wrap(function(autocmd, cb)
local opts = {
pattern = "*",
pattern = '*',
nested = true,
once = true,
}
if type(autocmd) == "table" then
opts = vim.tbl_extend("force", opts, autocmd)
if type(autocmd) == 'table' then
opts = vim.tbl_extend('force', opts, autocmd)
autocmd = autocmd[1]
opts[1] = nil
end
@ -70,12 +70,12 @@ M.feedkeys = function(actions, timestep)
for _, action in ipairs(actions) do
a.util.sleep(timestep)
local escaped = vim.api.nvim_replace_termcodes(action, true, false, true)
vim.api.nvim_feedkeys(escaped, "m", true)
vim.api.nvim_feedkeys(escaped, 'm', true)
end
a.util.sleep(timestep)
-- process pending keys until the queue is empty.
-- Note that this will exit insert mode.
vim.api.nvim_feedkeys("", "x", true)
vim.api.nvim_feedkeys('', 'x', true)
a.util.sleep(timestep)
end
@ -87,39 +87,39 @@ M.actions = {
vim.cmd.Oil({ args = args })
-- If this buffer was already open, manually dispatch the autocmd to finish the wait
if vim.b.oil_ready then
vim.api.nvim_exec_autocmds("User", {
pattern = "OilEnter",
vim.api.nvim_exec_autocmds('User', {
pattern = 'OilEnter',
modeline = false,
data = { buf = vim.api.nvim_get_current_buf() },
})
end
end)
M.wait_for_autocmd({ "User", pattern = "OilEnter" })
M.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
end,
---Save all changes and wait for operation to complete
save = function()
vim.schedule_wrap(require("oil").save)({ confirm = false })
M.wait_for_autocmd({ "User", pattern = "OilMutationComplete" })
vim.schedule_wrap(require('oil').save)({ confirm = false })
M.wait_for_autocmd({ 'User', pattern = 'OilMutationComplete' })
end,
---@param bufnr? integer
reload = function(bufnr)
M.await(require("oil.view").render_buffer_async, 3, bufnr or 0)
M.await(require('oil.view').render_buffer_async, 3, bufnr or 0)
end,
---Move cursor to a file or directory in an oil buffer
---@param filename string
focus = function(filename)
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, true)
local search = " " .. filename .. "$"
local search = ' ' .. filename .. '$'
for i, line in ipairs(lines) do
if line:match(search) then
vim.api.nvim_win_set_cursor(0, { i, 0 })
return
end
end
error("Could not find file " .. filename)
error('Could not find file ' .. filename)
end,
}
@ -133,7 +133,7 @@ M.parse_entries = function(bufnr)
end
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, true)
return vim.tbl_map(function(line)
return line:match("^/%d+ +(.+)$")
return line:match('^/%d+ +(.+)$')
end, lines)
end

View file

@ -1,16 +1,16 @@
local fs = require("oil.fs")
local test_util = require("tests.test_util")
local fs = require('oil.fs')
local test_util = require('tests.test_util')
local await = test_util.await
---@param path string
---@param cb fun(err: nil|string)
local function touch(path, cb)
vim.loop.fs_open(path, "w", 420, function(err, fd) -- 0644
vim.loop.fs_open(path, 'w', 420, function(err, fd) -- 0644
if err then
cb(err)
else
local shortpath = path:gsub("^[^" .. fs.sep .. "]*" .. fs.sep, "")
local shortpath = path:gsub('^[^' .. fs.sep .. ']*' .. fs.sep, '')
vim.loop.fs_write(fd, shortpath, nil, function(err2)
if err2 then
cb(err2)
@ -31,7 +31,7 @@ end
local TmpDir = {}
TmpDir.new = function()
local path = await(vim.loop.fs_mkdtemp, 2, "oil_test_XXXXXXXXX")
local path = await(vim.loop.fs_mkdtemp, 2, 'oil_test_XXXXXXXXX')
a.util.scheduler()
return setmetatable({ path = path }, {
__index = TmpDir,
@ -58,7 +58,7 @@ end
---@param filepath string
---@return string?
local read_file = function(filepath)
local fd = vim.loop.fs_open(filepath, "r", 420)
local fd = vim.loop.fs_open(filepath, 'r', 420)
if not fd then
return nil
end
@ -79,7 +79,7 @@ local function walk(dir)
type = type,
root = dir,
})
if type == "directory" then
if type == 'directory' then
vim.list_extend(ret, walk(fs.join(dir, name)))
end
end
@ -90,10 +90,10 @@ end
local assert_fs = function(root, paths)
local unlisted_dirs = {}
for k in pairs(paths) do
local pieces = vim.split(k, "/")
local partial_path = ""
local pieces = vim.split(k, '/')
local partial_path = ''
for i, piece in ipairs(pieces) do
partial_path = partial_path .. piece .. "/"
partial_path = partial_path .. piece .. '/'
if i ~= #pieces then
unlisted_dirs[partial_path] = true
end
@ -107,13 +107,13 @@ local assert_fs = function(root, paths)
for _, entry in ipairs(entries) do
local fullpath = fs.join(entry.root, entry.name)
local shortpath = fullpath:sub(root:len() + 2)
if entry.type == "directory" then
shortpath = shortpath .. "/"
if entry.type == 'directory' then
shortpath = shortpath .. '/'
end
local expected_content = paths[shortpath]
paths[shortpath] = nil
assert.truthy(expected_content, string.format("Unexpected entry '%s'", shortpath))
if entry.type == "file" then
if entry.type == 'file' then
local data = read_file(fullpath)
assert.equals(
expected_content,
@ -133,7 +133,7 @@ local assert_fs = function(root, paths)
k,
string.format(
"Expected %s '%s', but it was not found",
v == true and "directory" or "file",
v == true and 'directory' or 'file',
k
)
)
@ -161,7 +161,7 @@ function TmpDir:assert_not_exists(path)
end
function TmpDir:dispose()
await(fs.recursive_delete, 3, "directory", self.path)
await(fs.recursive_delete, 3, 'directory', self.path)
a.util.scheduler()
end

View file

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

View file

@ -1,15 +1,15 @@
local oil = require("oil")
local util = require("oil.util")
describe("url", function()
it("get_url_for_path", function()
local oil = require('oil')
local util = require('oil.util')
describe('url', function()
it('get_url_for_path', function()
local cases = {
{ "", "oil://" .. util.addslash(vim.fn.getcwd()) },
{ "term://~/oil.nvim//52953:/bin/sh", "oil://" .. vim.loop.os_homedir() .. "/oil.nvim/" },
{ "/foo/bar.txt", "oil:///foo/", "bar.txt" },
{ "oil:///foo/bar.txt", "oil:///foo/", "bar.txt" },
{ "oil:///", "oil:///" },
{ "oil-ssh://user@hostname:8888//bar.txt", "oil-ssh://user@hostname:8888//", "bar.txt" },
{ "oil-ssh://user@hostname:8888//", "oil-ssh://user@hostname:8888//" },
{ '', 'oil://' .. util.addslash(vim.fn.getcwd()) },
{ 'term://~/oil.nvim//52953:/bin/sh', 'oil://' .. vim.loop.os_homedir() .. '/oil.nvim/' },
{ '/foo/bar.txt', 'oil:///foo/', 'bar.txt' },
{ 'oil:///foo/bar.txt', 'oil:///foo/', 'bar.txt' },
{ 'oil:///', 'oil:///' },
{ 'oil-ssh://user@hostname:8888//bar.txt', 'oil-ssh://user@hostname:8888//', 'bar.txt' },
{ 'oil-ssh://user@hostname:8888//', 'oil-ssh://user@hostname:8888//' },
}
for _, case in ipairs(cases) do
local input, expected, expected_basename = unpack(case)

View file

@ -1,10 +1,10 @@
local util = require("oil.util")
describe("util", function()
it("url_escape", function()
local util = require('oil.util')
describe('util', function()
it('url_escape', function()
local cases = {
{ "foobar", "foobar" },
{ "foo bar", "foo%20bar" },
{ "/foo/bar", "%2Ffoo%2Fbar" },
{ 'foobar', 'foobar' },
{ 'foo bar', 'foo%20bar' },
{ '/foo/bar', '%2Ffoo%2Fbar' },
}
for _, case in ipairs(cases) do
local input, expected = unpack(case)
@ -13,12 +13,12 @@ describe("util", function()
end
end)
it("url_unescape", function()
it('url_unescape', function()
local cases = {
{ "foobar", "foobar" },
{ "foo%20bar", "foo bar" },
{ "%2Ffoo%2Fbar", "/foo/bar" },
{ "foo%%bar", "foo%%bar" },
{ 'foobar', 'foobar' },
{ 'foo%20bar', 'foo bar' },
{ '%2Ffoo%2Fbar', '/foo/bar' },
{ 'foo%%bar', 'foo%%bar' },
}
for _, case in ipairs(cases) do
local input, expected = unpack(case)

View file

@ -1,62 +1,62 @@
require("plenary.async").tests.add_to_env()
local oil = require("oil")
local test_util = require("tests.test_util")
require('plenary.async').tests.add_to_env()
local oil = require('oil')
local test_util = require('tests.test_util')
a.describe("window options", function()
a.describe('window options', function()
after_each(function()
test_util.reset_editor()
end)
a.it("Restores window options on close", function()
vim.cmd.edit({ args = { "README.md" } })
a.it('Restores window options on close', function()
vim.cmd.edit({ args = { 'README.md' } })
test_util.oil_open()
assert.equals("no", vim.o.signcolumn)
assert.equals('no', vim.o.signcolumn)
oil.close()
assert.equals("auto", vim.o.signcolumn)
assert.equals('auto', vim.o.signcolumn)
end)
a.it("Restores window options on edit", function()
a.it('Restores window options on edit', function()
test_util.oil_open()
assert.equals("no", vim.o.signcolumn)
vim.cmd.edit({ args = { "README.md" } })
assert.equals("auto", vim.o.signcolumn)
assert.equals('no', vim.o.signcolumn)
vim.cmd.edit({ args = { 'README.md' } })
assert.equals('auto', vim.o.signcolumn)
end)
a.it("Restores window options on split <filename>", function()
a.it('Restores window options on split <filename>', function()
test_util.oil_open()
assert.equals("no", vim.o.signcolumn)
vim.cmd.split({ args = { "README.md" } })
assert.equals("auto", vim.o.signcolumn)
assert.equals('no', vim.o.signcolumn)
vim.cmd.split({ args = { 'README.md' } })
assert.equals('auto', vim.o.signcolumn)
end)
a.it("Restores window options on split", function()
a.it('Restores window options on split', function()
test_util.oil_open()
assert.equals("no", vim.o.signcolumn)
assert.equals('no', vim.o.signcolumn)
vim.cmd.split()
vim.cmd.edit({ args = { "README.md" } })
assert.equals("auto", vim.o.signcolumn)
vim.cmd.edit({ args = { 'README.md' } })
assert.equals('auto', vim.o.signcolumn)
end)
a.it("Restores window options on tabnew <filename>", function()
a.it('Restores window options on tabnew <filename>', function()
test_util.oil_open()
assert.equals("no", vim.o.signcolumn)
vim.cmd.tabnew({ args = { "README.md" } })
assert.equals("auto", vim.o.signcolumn)
assert.equals('no', vim.o.signcolumn)
vim.cmd.tabnew({ args = { 'README.md' } })
assert.equals('auto', vim.o.signcolumn)
end)
a.it("Restores window options on tabnew", function()
a.it('Restores window options on tabnew', function()
test_util.oil_open()
assert.equals("no", vim.o.signcolumn)
assert.equals('no', vim.o.signcolumn)
vim.cmd.tabnew()
vim.cmd.edit({ args = { "README.md" } })
assert.equals("auto", vim.o.signcolumn)
vim.cmd.edit({ args = { 'README.md' } })
assert.equals('auto', vim.o.signcolumn)
end)
a.it("Sets the window options when re-entering oil buffer", function()
a.it('Sets the window options when re-entering oil buffer', function()
oil.open()
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
test_util.wait_for_autocmd({ 'User', pattern = 'OilEnter' })
assert.truthy(vim.w.oil_did_enter)
vim.cmd.edit({ args = { "README.md" } })
vim.cmd.edit({ args = { 'README.md' } })
assert.falsy(vim.w.oil_did_enter)
oil.open()
assert.truthy(vim.w.oil_did_enter)