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