delete_spec.lua 1.9 KB

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