errorlist_spec.lua 2.7 KB

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