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 , after_each =t . describe , t . it , t . before_each , t . after_each 5local eq =t . eq 6local pcall_err =t . pcall_err 7local neq =t . neq 8local command =n . command 9local exec_capture =n . exec_capture 10local write_file =t . write_file 11local api =n . api 12local clear =n . clear 13local dedent =t . dedent 14local missing_provider =n . missing_provider 15 16local tmpfile ='X_ex_cmds_script' 17 18before_each ( clear ) 19 20local function source ( code ) 21write_file ( tmpfile , code ) 22command ( 'source ' .. tmpfile ) 23end 24 25describe ( 'script_get-based command' , function () 26local garbage =')}{+*({}]*[;(+}{&[]}{*])(' 27 28after_each ( function () 29os . remove ( tmpfile ) 30end ) 31 32local function test_garbage_exec ( cmd , check_neq ) 33describe ( cmd , function () 34it ( 'works correctly when skipping oneline variant' , function () 35eq ( 36true , 37pcall ( 38source , 39( dedent ( [[ 40if 0 41%s %s 42endif 43]] )): format ( cmd , garbage ) 44) 45) 46eq ( '' , exec_capture ( 'messages' )) 47if check_neq then 48neq ( 490 , 50pcall_err ( 51command , 52dedent ( [[ 53%s %s 54]] ) 55): format ( cmd , garbage ) 56) 57end 58end ) 59it ( 'works correctly when skipping HEREdoc variant' , function () 60eq ( 61true , 62pcall ( 63source , 64( dedent ( [[ 65if 0 66%s << EOF 67%s 68EOF 69endif 70]] )): format ( cmd , garbage ) 71) 72) 73eq ( '' , exec_capture ( 'messages' )) 74if check_neq then 75eq ( 76true , 77pcall ( 78source , 79( dedent ( [[ 80let g:exc = 0 81try 82%s << EOF 83%s 84EOF 85catch 86let g:exc = v:exception 87endtry 88]] )): format ( cmd , garbage ) 89) 90) 91neq ( 0 , api . nvim_get_var ( 'exc' )) 92end 93end ) 94end ) 95end 96 97clear () 98 99-- Built-in scripts 100test_garbage_exec ( 'lua' , true ) 101 102-- Provider-based scripts 103test_garbage_exec ( 'ruby' , not missing_provider ( 'ruby' )) 104test_garbage_exec ( 'python3' , not missing_provider ( 'python' )) 105 106-- Missing scripts 107test_garbage_exec ( 'python' , false ) 108test_garbage_exec ( 'tcl' , false ) 109test_garbage_exec ( 'mzscheme' , false ) 110test_garbage_exec ( 'perl' , false ) 111 112-- Not really a script 113test_garbage_exec ( 'xxxinvalidlanguagexxx' , true ) 114end )