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