robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
2.0 KiB72 linesraw
1local t = require('test.testutil')
2local describe, it, before_each, after_each, pending =
3  t.describe, t.it, t.before_each, t.after_each, t.pending
4local pcall_err = t.pcall_err
5local n = require('test.functional.testnvim')()
6
7local clear, source = n.clear, n.source
8local eq, eval, command = t.eq, n.eval, n.command
9
10describe('Test for delete()', function()
11  before_each(clear)
12  after_each(function()
13    os.remove('Xfile')
14  end)
15
16  it('file delete', function()
17    command('split Xfile')
18    command("call setline(1, ['a', 'b'])")
19    command('wq')
20    eq(eval("['a', 'b']"), eval("readfile('Xfile')"))
21    eq(0, eval("delete('Xfile')"))
22    eq(-1, eval("delete('Xfile')"))
23  end)
24
25  it('directory delete', function()
26    command("call mkdir('Xdir1')")
27    eq(1, eval("isdirectory('Xdir1')"))
28    eq(0, eval("delete('Xdir1', 'd')"))
29    eq(0, eval("isdirectory('Xdir1')"))
30    eq(-1, eval("delete('Xdir1', 'd')"))
31  end)
32
33  it('symlink delete', function()
34    source([[
35      split Xfile
36      call setline(1, ['a', 'b'])
37      wq
38      if has('win32')
39        silent !mklink Xlink Xfile
40      else
41        silent !ln -s Xfile Xlink
42      endif
43    ]])
44    if eval('v:shell_error') ~= 0 then
45      pending('Cannot create symlink')
46    end
47    -- Delete the link, not the file
48    eq(0, eval("delete('Xlink')"))
49    eq(-1, eval("delete('Xlink')"))
50    eq(0, eval("delete('Xfile')"))
51  end)
52
53  it('symlink directory delete', function()
54    command("call mkdir('Xdir1')")
55    if t.is_os('win') then
56      command('silent !mklink /j Xlink Xdir1')
57    else
58      command('silent !ln -s Xdir1 Xlink')
59    end
60    eq(1, eval("isdirectory('Xdir1')"))
61    eq(1, eval("isdirectory('Xlink')"))
62    -- Delete the link, not the directory
63    eq(0, eval("delete('Xlink')"))
64    eq(-1, eval("delete('Xlink')"))
65    eq(0, eval("delete('Xdir1', 'd')"))
66  end)
67
68  it('gives correct emsgs', function()
69    eq('Vim(call):E474: Invalid argument', pcall_err(command, "call delete('')"))
70    eq('Vim(call):E15: Invalid expression: "0"', pcall_err(command, "call delete('foo', 0)"))
71  end)
72end)