2016-04-23 16:53:11 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
2016-02-29 12:27:48 -07:00
|
|
|
local clear, source = helpers.clear, helpers.source
|
2017-04-08 14:12:26 -07:00
|
|
|
local eq, eval, command = helpers.eq, helpers.eval, helpers.command
|
2022-04-03 05:27:46 -07:00
|
|
|
local exc_exec = helpers.exc_exec
|
2016-02-28 02:32:46 -07:00
|
|
|
|
|
|
|
describe('Test for delete()', function()
|
|
|
|
before_each(clear)
|
2018-05-25 04:42:59 -07:00
|
|
|
after_each(function()
|
|
|
|
os.remove('Xfile')
|
|
|
|
end)
|
2016-02-28 02:32:46 -07:00
|
|
|
|
2022-04-03 05:27:46 -07:00
|
|
|
it('file delete', function()
|
|
|
|
command('split Xfile')
|
|
|
|
command("call setline(1, ['a', 'b'])")
|
|
|
|
command('wq')
|
|
|
|
eq(eval("['a', 'b']"), eval("readfile('Xfile')"))
|
|
|
|
eq(0, eval("delete('Xfile')"))
|
|
|
|
eq(-1, eval("delete('Xfile')"))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('directory delete', function()
|
|
|
|
command("call mkdir('Xdir1')")
|
|
|
|
eq(1, eval("isdirectory('Xdir1')"))
|
|
|
|
eq(0, eval("delete('Xdir1', 'd')"))
|
|
|
|
eq(0, eval("isdirectory('Xdir1')"))
|
|
|
|
eq(-1, eval("delete('Xdir1', 'd')"))
|
|
|
|
end)
|
|
|
|
|
2016-02-28 04:44:59 -07:00
|
|
|
it('symlink delete', function()
|
|
|
|
source([[
|
|
|
|
split Xfile
|
|
|
|
call setline(1, ['a', 'b'])
|
|
|
|
wq
|
2017-10-12 19:55:14 -07:00
|
|
|
if has('win32')
|
|
|
|
silent !mklink Xlink Xfile
|
|
|
|
else
|
|
|
|
silent !ln -s Xfile Xlink
|
|
|
|
endif
|
2016-02-28 04:44:59 -07:00
|
|
|
]])
|
2018-05-25 04:42:59 -07:00
|
|
|
if eval('v:shell_error') ~= 0 then
|
2019-10-17 19:46:30 -07:00
|
|
|
pending('Cannot create symlink')
|
2018-05-18 16:30:15 -07:00
|
|
|
end
|
2016-02-28 04:44:59 -07:00
|
|
|
-- Delete the link, not the file
|
|
|
|
eq(0, eval("delete('Xlink')"))
|
|
|
|
eq(-1, eval("delete('Xlink')"))
|
|
|
|
eq(0, eval("delete('Xfile')"))
|
|
|
|
end)
|
2021-05-11 15:44:39 -07:00
|
|
|
|
|
|
|
it('symlink directory delete', function()
|
|
|
|
command("call mkdir('Xdir1')")
|
2022-11-21 17:13:30 -07:00
|
|
|
if helpers.is_os('win') then
|
2021-05-11 15:44:39 -07:00
|
|
|
command('silent !mklink /j Xlink Xdir1')
|
|
|
|
else
|
|
|
|
command('silent !ln -s Xdir1 Xlink')
|
|
|
|
end
|
|
|
|
eq(1, eval("isdirectory('Xdir1')"))
|
|
|
|
eq(1, eval("isdirectory('Xlink')"))
|
|
|
|
-- Delete the link, not the directory
|
|
|
|
eq(0, eval("delete('Xlink')"))
|
|
|
|
eq(-1, eval("delete('Xlink')"))
|
|
|
|
eq(0, eval("delete('Xdir1', 'd')"))
|
|
|
|
end)
|
|
|
|
|
2022-04-03 05:27:46 -07:00
|
|
|
it('gives correct emsgs', function()
|
|
|
|
eq('Vim(call):E474: Invalid argument', exc_exec("call delete('')"))
|
2023-04-16 03:27:33 -07:00
|
|
|
eq('Vim(call):E15: Invalid expression: "0"', exc_exec("call delete('foo', 0)"))
|
2021-05-11 15:44:39 -07:00
|
|
|
end)
|
2016-02-28 02:32:46 -07:00
|
|
|
end)
|