2015-05-15 10:03:44 -07:00
|
|
|
-- Tests for 'directory' option.
|
|
|
|
-- - ".", in same dir as file
|
|
|
|
-- - "./dir", in directory relative to file
|
|
|
|
-- - "dir", in directory relative to current dir
|
|
|
|
|
2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
2017-04-08 11:58:13 -07:00
|
|
|
|
2024-04-08 02:03:20 -07:00
|
|
|
local eq = t.eq
|
|
|
|
local neq = t.neq
|
2024-04-20 08:44:13 -07:00
|
|
|
local poke_eventloop = n.poke_eventloop
|
|
|
|
local fn = n.fn
|
|
|
|
local api = n.api
|
|
|
|
local clear = n.clear
|
|
|
|
local insert = n.insert
|
|
|
|
local command = n.command
|
2024-04-08 02:03:20 -07:00
|
|
|
local write_file = t.write_file
|
2024-04-20 08:44:13 -07:00
|
|
|
local expect_exit = n.expect_exit
|
2024-04-08 02:03:20 -07:00
|
|
|
local mkdir = t.mkdir
|
2015-05-15 10:03:44 -07:00
|
|
|
|
|
|
|
local function ls_dir_sorted(dirname)
|
|
|
|
local files = {}
|
2023-04-04 12:59:06 -07:00
|
|
|
for f in vim.fs.dir(dirname) do
|
2015-05-15 10:03:44 -07:00
|
|
|
if f ~= '.' and f ~= '..' then
|
|
|
|
table.insert(files, f)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
table.sort(files)
|
|
|
|
return files
|
|
|
|
end
|
|
|
|
|
|
|
|
describe("'directory' option", function()
|
|
|
|
setup(function()
|
|
|
|
local text = [[
|
|
|
|
start of testfile
|
|
|
|
line 2 Abcdefghij
|
|
|
|
line 3 Abcdefghij
|
|
|
|
end of testfile
|
|
|
|
]]
|
|
|
|
write_file('Xtest1', text)
|
2023-04-04 12:59:06 -07:00
|
|
|
mkdir('Xtest.je')
|
|
|
|
mkdir('Xtest2')
|
2015-05-15 10:03:44 -07:00
|
|
|
write_file('Xtest2/Xtest3', text)
|
|
|
|
clear()
|
|
|
|
end)
|
|
|
|
teardown(function()
|
2022-06-08 14:22:50 -07:00
|
|
|
expect_exit(command, 'qall!')
|
2024-04-20 08:44:13 -07:00
|
|
|
n.rmdir('Xtest.je')
|
|
|
|
n.rmdir('Xtest2')
|
2015-05-15 10:03:44 -07:00
|
|
|
os.remove('Xtest1')
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('is working', function()
|
|
|
|
insert([[
|
|
|
|
start of testfile
|
|
|
|
line 2 Abcdefghij
|
|
|
|
line 3 Abcdefghij
|
|
|
|
end of testfile]])
|
|
|
|
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_option_value('swapfile', true, {})
|
|
|
|
api.nvim_set_option_value('swapfile', true, {})
|
|
|
|
api.nvim_set_option_value('directory', '.', {})
|
2015-05-15 10:03:44 -07:00
|
|
|
|
|
|
|
-- sanity check: files should not exist yet.
|
2024-01-12 05:03:25 -07:00
|
|
|
eq(nil, vim.uv.fs_stat('.Xtest1.swp'))
|
2015-05-15 10:03:44 -07:00
|
|
|
|
2017-04-08 11:58:13 -07:00
|
|
|
command('edit! Xtest1')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2024-01-12 10:59:57 -07:00
|
|
|
eq('Xtest1', fn.buffer_name('%'))
|
2015-05-15 10:03:44 -07:00
|
|
|
-- Verify that the swapfile exists. In the legacy test this was done by
|
|
|
|
-- reading the output from :!ls.
|
2024-01-12 05:03:25 -07:00
|
|
|
neq(nil, vim.uv.fs_stat('.Xtest1.swp'))
|
2015-05-15 10:03:44 -07:00
|
|
|
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_option_value('directory', './Xtest2,.', {})
|
2017-04-08 11:58:13 -07:00
|
|
|
command('edit Xtest1')
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2015-05-15 10:03:44 -07:00
|
|
|
|
|
|
|
-- swapfile should no longer exist in CWD.
|
2024-01-12 05:03:25 -07:00
|
|
|
eq(nil, vim.uv.fs_stat('.Xtest1.swp'))
|
2015-05-15 10:03:44 -07:00
|
|
|
|
|
|
|
eq({ 'Xtest1.swp', 'Xtest3' }, ls_dir_sorted('Xtest2'))
|
|
|
|
|
2024-01-12 10:59:57 -07:00
|
|
|
api.nvim_set_option_value('directory', 'Xtest.je', {})
|
2021-08-17 20:30:58 -07:00
|
|
|
command('bdelete')
|
2017-04-08 11:58:13 -07:00
|
|
|
command('edit Xtest2/Xtest3')
|
2024-01-12 10:59:57 -07:00
|
|
|
eq(true, api.nvim_get_option_value('swapfile', {}))
|
2020-10-19 11:17:51 -07:00
|
|
|
poke_eventloop()
|
2015-05-15 10:03:44 -07:00
|
|
|
|
|
|
|
eq({ 'Xtest3' }, ls_dir_sorted('Xtest2'))
|
|
|
|
eq({ 'Xtest3.swp' }, ls_dir_sorted('Xtest.je'))
|
|
|
|
end)
|
|
|
|
end)
|