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 eval =n . eval 9local feed =n . feed 10local api =n . api 11local testprg =n . testprg 12local retry =t . retry 13 14describe ( ':ls' , function () 15before_each ( function () 16clear () 17end ) 18 19--- @param start_running_term fun() 20--- @param start_finished_term fun() 21local function test_ls_terminal_buffer ( start_running_term , start_finished_term ) 22command ( 'edit foo' ) 23command ( 'set hidden' ) 24start_running_term () 25command ( 'vsplit' ) 26start_finished_term () 27 28retry ( nil , 5000 , function () 29local ls_output =eval ( 'execute("ls")' ) 30-- Normal buffer. 31eq ( '\n 1 h ' , string . match ( ls_output , '\n *1....' )) 32-- Terminal buffer [R]unning. 33eq ( '\n 2 #aR' , string . match ( ls_output , '\n *2....' )) 34-- Terminal buffer [F]inished. 35eq ( '\n 3 %aF' , string . match ( ls_output , '\n *3....' )) 36end ) 37 38retry ( nil , 5000 , function () 39local ls_output =eval ( 'execute("ls R")' ) 40-- Just the [R]unning terminal buffer. 41eq ( '\n 2 #aR ' , string . match ( ls_output , '^\n *2 ... ' )) 42end ) 43 44retry ( nil , 5000 , function () 45local ls_output =eval ( 'execute("ls F")' ) 46-- Just the [F]inished terminal buffer. 47eq ( '\n 3 %aF ' , string . match ( ls_output , '^\n *3 ... ' )) 48end ) 49end 50 51describe ( 'R, F for' , function () 52it ( 'terminal buffers' , function () 53api . nvim_set_option_value ( 'shell' , string . format ( '"%s" INTERACT' , testprg ( 'shell-test' )), {} ) 54test_ls_terminal_buffer ( function () 55command ( 'terminal' ) 56end , function () 57command ( 'terminal' ) 58feed ( 'iexit<cr>' ) 59end ) 60end ) 61 62it ( 'nvim_open_term() buffers' , function () 63test_ls_terminal_buffer ( function () 64command ( 'enew | call nvim_open_term(0, {})' ) 65end , function () 66command ( 'enew | call chanclose(nvim_open_term(0, {}))' ) 67end ) 68end ) 69end ) 70end )