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 Screen =require ( 'test.functional.ui.screen' ) 5 6local describe , it , before_each =t . describe , t . it , t . before_each 7local testprg =n . testprg 8local command =n . command 9local fn =n . fn 10local api =n . api 11local clear =n . clear 12local eq =t . eq 13local matches =t . matches 14local pesc =vim . pesc 15 16describe ( ':edit term://*' , function () 17before_each ( function () 18clear () 19api . nvim_set_option_value ( 'shell' , testprg ( 'shell-test' ), {} ) 20api . nvim_set_option_value ( 'shellcmdflag' , 'EXE' , {} ) 21end ) 22 23it ( 'runs TermOpen event' , function () 24api . nvim_set_var ( 'termopen_runs' , {} ) 25command ( 'autocmd TermOpen * :call add(g:termopen_runs, expand("<amatch>"))' ) 26command ( 'edit term://' ) 27local termopen_runs =api . nvim_get_var ( 'termopen_runs' ) 28eq ( 1 , # termopen_runs ) 29local cwd =fn . fnamemodify ( '.' , ':p:~' ): gsub ( [[/*$]] , '' ) 30matches ( '^term://' .. pesc ( cwd ) .. '//%d+:$' , termopen_runs [ 1 ]) 31end ) 32 33it ( "runs TermOpen early enough to set buffer-local 'scrollback'" , function () 34local columns , lines =20 , 4 35local scr =Screen . new ( columns , lines , { rgb =false } ) 36local rep =97 37api . nvim_set_option_value ( 'shellcmdflag' , 'REP ' .. rep , {} ) 38command ( 'set shellxquote=' ) -- win: avoid extra quotes 39local sb =10 40command ( 41'autocmd TermOpen * :setlocal scrollback=' .. tostring ( sb ) .. '|call feedkeys("G", "n")' 42) 43command ( 'edit term://foobar' ) 44 45local bufcontents ={} 46local winheight =api . nvim_win_get_height ( 0 ) 47local buf_cont_start =rep - sb - winheight + 1 48for i =buf_cont_start , ( rep - 1 ) do 49bufcontents [ # bufcontents + 1 ] =( '%d: foobar' ): format ( i ) 50end 51bufcontents [ # bufcontents + 1 ] ='' 52 53local exp_screen ='\n' 54for i =1 , ( winheight - 1 ) do 55local line =bufcontents [ # bufcontents - winheight + i ] 56exp_screen =( exp_screen .. line .. ( ' ' ): rep ( columns - # line ) .. '|\n' ) 57end 58exp_screen =exp_screen .. '^[Process exited 0] |\n' 59 60exp_screen =exp_screen .. ( ' ' ): rep ( columns ) .. '|\n' 61scr : expect ( exp_screen ) 62eq ( bufcontents , api . nvim_buf_get_lines ( 0 , 0 , - 1 , true )) 63end ) 64end )