robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
fbcb7a056c
master
1local t =require ( 'test.testutil' ) 2local n =require ( 'test.functional.testnvim' )() 3local Screen =require ( 'test.functional.ui.screen' ) 4 5local describe , it , before_each =t . describe , t . it , t . before_each 6local clear =n . clear 7local command =n . command 8local eq =t . eq 9local feed =n . feed 10local fn =n . fn 11 12before_each ( clear ) 13 14-- Interactive Ex mode ([count]q:) is a keep-open |cmdwin| REPL. #40962 15describe ( 'Ex mode' , function () 16it ( 'executes commands against the caller window, auto-prints, records history' , function () 17local screen =Screen . new ( 60 , 10 ) 18command ( [[call setline(1, ['line1', 'line2', 'line3'])]] ) 19feed ( '1q:' ) 20screen : expect ( [[ 21line1 | 22{2:[No Name] [+] }| 23{1::}^ | 24{1:~ }|*5 25{3:[Ex mode] }| 26{5:-- INSERT --} | 27]] ) 28t . matches ( 'Entering Ex mode%.' , n . exec_capture ( 'messages' )) 29feed ( "put ='inserted'<CR>" ) 30feed ( 'visual<CR>' ) 31eq ( 'n' , fn . mode ( 1 )) 32eq ( { 'line1' , 'inserted' , 'line2' , 'line3' } , fn . getline ( 1 , '$' )) 33eq ( 'visual' , fn . histget ( 'cmd' , - 1 )) 34eq ( "put ='inserted'" , fn . histget ( 'cmd' , - 2 )) 35-- Ex mode can be re-entered (the "[Ex mode]" buffer name is not duplicated). 36feed ( '1q:' ) 37screen : expect ( { any =vim . pesc ( '{3:[Ex mode]' ) } ) 38feed ( 'visual<CR>' ) 39eq ( 'n' , fn . mode ( 1 )) 40-- ":exmode" (but not ":ex", which is ":edit") also enters Ex mode. 41eq ( 'ex' , fn . fullcommand ( 'ex' )) 42eq ( 'exmode' , fn . fullcommand ( 'exm' )) 43command ( 'exmode' ) 44screen : expect ( { any =vim . pesc ( '{3:[Ex mode]' ) } ) 45feed ( 'visual<CR>' ) 46eq ( 'n' , fn . mode ( 1 )) 47end ) 48 49it ( 'bare address and empty line move the cursor and auto-print' , function () 50local screen =Screen . new ( 60 , 8 ) 51command ( [[call setline(1, ['line1', 'line2'])]] ) 52feed ( '1q:' ) 53feed ( '1<CR>' ) -- Bare address: move and auto-print. 54screen : expect ( { any =vim . pesc ( '" line1' ) } ) 55feed ( '<CR>' ) -- Empty line: advance and auto-print (POSIX ex "+"). 56screen : expect ( { any =vim . pesc ( '" line2' ) } ) 57feed ( '<CR>' ) -- At end-of-file. 58screen : expect ( { any ='E501' } ) 59feed ( 'visual<CR>' ) 60eq ( 2 , fn . line ( '.' )) 61end ) 62 63it ( 'explicit :print is not doubled by auto-print' , function () 64command ( [[call setline(1, ['line1', 'line2'])]] ) 65feed ( '1q:' ) 66feed ( '1,2print<CR>' ) 67-- Transcript records each printed line once, not the cursor line again. 68eq ( { '1,2print' , '" line1' , '" line2' , '' } , n . api . nvim_buf_get_lines ( 0 , 0 , - 1 , false )) 69feed ( 'visual<CR>' ) 70end ) 71 72it ( 'substitute confirmation prompt' , function () 73local screen =Screen . new ( 60 , 8 ) 74command ( 'set inccommand=' ) 75command ( [[call setline(1, repeat(['foo foo'], 2))]] ) 76feed ( '1q:' ) 77feed ( '%s/foo/bar/gc<CR>' ) 78screen : expect ( { any =vim . pesc ( 'replace with bar? (y)es/(n)o/(a)ll' ) } ) 79feed ( 'y' ) -- Replace the first match ... 80feed ( 'q' ) -- ... then quit at the second prompt: back to the REPL. 81screen : expect ( { any =vim . pesc ( '{5:-- INSERT --}' ) } ) 82feed ( 'visual<CR>' ) 83eq ( { 'bar foo' , 'foo foo' } , fn . getline ( 1 , '$' )) 84end ) 85 86it ( 'collects multi-line commands until the block is complete' , function () 87local screen =Screen . new ( 60 , 10 ) 88feed ( '1q:' ) 89feed ( 'append<CR>' ) 90-- Continuation lines should not have ":" prefix in 'statuscolumn'. 91screen : expect ( [[ 92| 93{2:[No Name] }| 94{1::}append | 95{1: }^ | 96{1:~ }|*4 97{3:[Ex mode] }| 98{5:-- INSERT --} | 99]] ) 100feed ( 'x1<CR>x2<CR>.<CR>' ) 101-- Executing :append does not end the REPL's Insert mode (ex_append restores "State"). 102eq ( 'i' , fn . mode ( 1 )) 103-- Ending :append with "." does not auto-print the last inserted line. 104eq ( { 'append' , 'x1' , 'x2' , '.' , '' } , n . api . nvim_buf_get_lines ( 0 , 0 , - 1 , false )) 105feed ( 'let g:x = 0<CR>' ) 106feed ( 'if 1<CR>' ) 107-- Continuation lines should not have ":" prefix in 'statuscolumn'. 108screen : expect ( [[ 109x1 | 110{2:[No Name] [+] }| 111{1: }x1 | 112{1: }x2 | 113{1: }. | 114{1::}let g:x = 0 | 115{1::}if 1 | 116{1: }^ | 117{3:[Ex mode] }| 118{5:-- INSERT --} | 119]] ) 120feed ( 'let g:x = 1<CR>endif<CR>' ) 121feed ( 'function! F()<CR>return 42<CR>endfunction<CR>' ) 122feed ( 'let g:h =<lt><lt> trim EOS<CR> hey<CR>EOS<CR>' ) 123feed ( 'visual<CR>' ) 124eq ( { 'x1' , 'x2' } , fn . getline ( 1 , '$' )) 125eq ( 1 , n . eval ( 'g:x' )) 126eq ( 42 , n . eval ( 'F()' )) 127eq ( { 'hey' } , n . eval ( 'g:h' )) 128end ) 129 130it ( 'pressing Ctrl-C in :append inside a loop does not hang' , function () 131feed ( '1q:' ) 132feed ( 'for i in range(1)<CR>' ) 133feed ( 'append<CR>' ) 134-- CTRL-C cancels the cmdwin (ends Ex mode): back to the ":" cmdline, like |q:|. 135feed ( '<C-C>' ) 136eq ( '' , fn . getcmdwintype ()) 137feed ( '<Esc>' ) 138eq ( 'n' , fn . mode ( 1 )) 139eq ( { '' } , fn . getline ( 1 , '$' )) 140end ) 141end )