errorlist_spec.lua 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local clear = helpers.clear
  3. local command = helpers.command
  4. local eq = helpers.eq
  5. local exc_exec = helpers.exc_exec
  6. local get_cur_win_var = helpers.curwinmeths.get_var
  7. describe('setqflist()', function()
  8. local setqflist = helpers.funcs.setqflist
  9. before_each(clear)
  10. it('requires a list for {list}', function()
  11. eq('Vim(call):E714: List required', exc_exec('call setqflist("foo")'))
  12. eq('Vim(call):E714: List required', exc_exec('call setqflist(5)'))
  13. eq('Vim(call):E714: List required', exc_exec('call setqflist({})'))
  14. end)
  15. it('requires a string for {action}', function()
  16. eq('Vim(call):E928: String required', exc_exec('call setqflist([], 5)'))
  17. eq('Vim(call):E928: String required', exc_exec('call setqflist([], [])'))
  18. eq('Vim(call):E928: String required', exc_exec('call setqflist([], {})'))
  19. end)
  20. it('sets w:quickfix_title', function()
  21. setqflist({''}, 'r', 'foo')
  22. command('copen')
  23. eq('foo', get_cur_win_var('quickfix_title'))
  24. setqflist({}, 'r', {['title'] = 'qf_title'})
  25. eq('qf_title', get_cur_win_var('quickfix_title'))
  26. end)
  27. it('allows string {what} for backwards compatibility', function()
  28. setqflist({}, 'r', '5')
  29. command('copen')
  30. eq('5', get_cur_win_var('quickfix_title'))
  31. end)
  32. it('requires a dict for {what}', function()
  33. eq('Vim(call):E715: Dictionary required', exc_exec('call setqflist([], "r", function("function"))'))
  34. end)
  35. end)
  36. describe('setloclist()', function()
  37. local setloclist = helpers.funcs.setloclist
  38. before_each(clear)
  39. it('requires a list for {list}', function()
  40. eq('Vim(call):E714: List required', exc_exec('call setloclist(0, "foo")'))
  41. eq('Vim(call):E714: List required', exc_exec('call setloclist(0, 5)'))
  42. eq('Vim(call):E714: List required', exc_exec('call setloclist(0, {})'))
  43. end)
  44. it('requires a string for {action}', function()
  45. eq('Vim(call):E928: String required', exc_exec('call setloclist(0, [], 5)'))
  46. eq('Vim(call):E928: String required', exc_exec('call setloclist(0, [], [])'))
  47. eq('Vim(call):E928: String required', exc_exec('call setloclist(0, [], {})'))
  48. end)
  49. it('sets w:quickfix_title for the correct window', function()
  50. command('rightbelow vsplit')
  51. setloclist(1, {}, 'r', 'foo')
  52. setloclist(2, {}, 'r', 'bar')
  53. command('lopen')
  54. eq('bar', get_cur_win_var('quickfix_title'))
  55. command('lclose | wincmd w | lopen')
  56. eq('foo', get_cur_win_var('quickfix_title'))
  57. end)
  58. it("doesn't crash when when window is closed in the middle #13721", function()
  59. helpers.insert([[
  60. hello world]])
  61. command("vsplit")
  62. command("autocmd WinLeave * :call nvim_win_close(0, v:true)")
  63. command("call setloclist(0, [])")
  64. command("lopen")
  65. helpers.assert_alive()
  66. end)
  67. end)