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 , clear , eval , feed , api , retry =t . eq , n . clear , n . eval , n . feed , n . api , t . retry 6 7describe ( 'K' , function () 8local test_file ='K_spec_out' 9before_each ( function () 10clear () 11os . remove ( test_file ) 12end ) 13after_each ( function () 14os . remove ( test_file ) 15end ) 16 17it ( "invokes colon-prefixed 'keywordprg' as Vim command" , function () 18n . source ( [[ 19let @a='fnord' 20set keywordprg=:put]] ) 21 22-- K on the text "a" resolves to `:put a`. 23feed ( 'ia<ESC>K' ) 24n . expect ( [[ 25a 26fnord]] ) 27end ) 28 29it ( "invokes non-prefixed 'keywordprg' as shell command" , function () 30n . source ( [[ 31let @a='fnord' 32set keywordprg=echo\ fnord>>]] ) 33 34-- K on the text "K_spec_out" resolves to `!echo fnord >> K_spec_out`. 35feed ( 'i' .. test_file .. '<ESC>K' ) 36retry ( nil , nil , function () 37eq ( 1 , eval ( 'filereadable("' .. test_file .. '")' )) 38end ) 39eq ( { 'fnord' } , eval ( "readfile('" .. test_file .. "')" )) 40-- Confirm that Neovim is still in terminal mode after K is pressed (#16692). 41vim . uv . sleep ( 500 ) 42eq ( 't' , eval ( 'mode()' )) 43feed ( '<space>' ) -- Any key, not just <space>, can be used here to escape. 44eq ( 'n' , eval ( 'mode()' )) 45end ) 46 47it ( "<esc> kills the buffer for a running 'keywordprg' command" , function () 48n . source ( 'set keywordprg=less' ) 49eval ( 'writefile(["hello", "world"], "' .. test_file .. '")' ) 50feed ( 'i' .. test_file .. '<esc>K' ) 51eq ( 't' , eval ( 'mode()' )) 52-- Confirm that an arbitrary keypress doesn't escape (i.e., the process is 53-- still running). If the process were no longer running, an arbitrary 54-- keypress would escape. 55vim . uv . sleep ( 500 ) 56feed ( '<space>' ) 57eq ( 't' , eval ( 'mode()' )) 58-- Confirm that <esc> kills the buffer for the running command. 59local bufnr =eval ( 'bufnr()' ) 60feed ( '<esc>' ) 61eq ( 'n' , eval ( 'mode()' )) 62t . neq ( bufnr , eval ( 'bufnr()' )) 63end ) 64 65it ( 'empty string falls back to :help #19298' , function () 66api . nvim_set_option_value ( 'keywordprg' , '' , {} ) 67api . nvim_buf_set_lines ( 0 , 0 , - 1 , true , { 'doesnotexist' } ) 68feed ( 'K' ) 69eq ( 'E149: No help for doesnotexist' , api . nvim_get_vvar ( 'errmsg' )) 70end ) 71end )