robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
3b00ddb601
master
1local t =require ( 'test.testutil' ) 2local Screen =require ( 'test.functional.ui.screen' ) 3local n =require ( 'test.functional.testnvim' )() 4 5local describe , it , before_each =t . describe , t . it , t . before_each 6local eq =t . eq 7local eval =n . eval 8local feed =n . feed 9local clear =n . clear 10local expect =n . expect 11local command =n . command 12local fn =n . fn 13local api =n . api 14local insert =n . insert 15 16describe ( 'macro recording with requeued key' , function () 17before_each ( function () 18clear ( { args_rm ={ '--cmd' } } ) 19end ) 20 21it ( 'mapped key does not corrupt the recording' , function () 22-- Typing over a Select-mode selection puts the key back for Insert mode (requeue_key()). 23-- A key produced by a mapping is not "typed", so ungetchars() must not touch the recording. 24command ( 'snoremap Z Y' ) 25insert ( 'abc' ) 26feed ( 'qq0ghZ<Esc>q' ) 27-- "Y" replaced the selected "a". 28expect ( 'Ybc' ) 29-- The recording holds the typed keys: the "Y" mapping must not have eaten the recorded "Z". 30eq ( '0ghZ\27' , eval ( '@q' )) 31end ) 32 33it ( 'at hit-enter prompt records the key ONCE' , function () 34-- A non-prompt key typed at the hit-enter prompt is put back to execute 35-- as a normal command: it is consumed twice, but must be recorded once. 36local screen =Screen . new ( 40 , 6 ) 37insert ( 'abc' ) 38feed ( 'qq0' ) 39feed ( ':echo "one\\ntwo"<CR>' ) 40-- The prompt must actually engage (needs an attached UI). 41screen : expect ( { any ='Press ENTER' } ) 42feed ( 'x' ) 43feed ( 'q' ) 44expect ( 'bc' ) 45eq ( '0:echo "one\\ntwo"\rx' , eval ( '@q' )) 46-- Replaying executes "x" once, not twice. 47feed ( '@q' ) 48expect ( 'c' ) 49end ) 50end ) 51 52describe ( 'macros with default mappings' , function () 53before_each ( function () 54clear ( { args_rm ={ '--cmd' } } ) 55end ) 56 57it ( 'can be recorded and replayed' , function () 58feed ( 'qiahello<esc>q' ) 59expect ( 'hello' ) 60eq ( 'ahello' , eval ( '@i' )) 61feed ( '@i' ) 62expect ( 'hellohello' ) 63eq ( 'ahello' , eval ( '@i' )) 64end ) 65 66it ( 'applies maps' , function () 67command ( 'imap x l' ) 68command ( 'nmap l a' ) 69feed ( 'qilxxx<esc>q' ) 70expect ( 'lll' ) 71eq ( 'lxxx' , eval ( '@i' )) 72feed ( '@i' ) 73expect ( 'llllll' ) 74eq ( 'lxxx' , eval ( '@i' )) 75end ) 76 77it ( 'can be replayed with @@' , function () 78insert [[ 79hello 80hello 81hello]] 82feed [[gg]] 83 84feed [[qqAFOO<esc>q]] 85expect [[ 86helloFOO 87hello 88hello]] 89 90feed [[@q]] 91expect [[ 92helloFOOFOO 93hello 94hello]] 95 96feed [[G3@@]] 97expect [[ 98helloFOOFOO 99hello 100helloFOOFOOFOO]] 101 102feed [[ggV2j@@]] 103expect [[ 104helloFOOFOOFOO 105helloFOO 106helloFOOFOOFOOFOO]] 107end ) 108 109it ( 'can be replayed with @ in linewise Visual mode' , function () 110insert [[ 111hello 112hello 113hello]] 114feed [[gg]] 115 116feed [[qqAFOO<esc>qu]] 117expect [[ 118hello 119hello 120hello]] 121 122feed [[qwA123<esc>qu]] 123expect [[ 124hello 125hello 126hello]] 127 128feed [[V3j@q]] 129expect [[ 130helloFOO 131helloFOO 132helloFOO]] 133 134feed [[ggVj@w]] 135expect [[ 136helloFOO123 137helloFOO123 138helloFOO]] 139end ) 140 141it ( 'can be replayed with @ in blockwise Visual mode' , function () 142insert [[ 143hello 144hello 145hello]] 146feed [[gg]] 147 148feed [[qqAFOO<esc>qu]] 149expect [[ 150hello 151hello 152hello]] 153 154feed [[qwA123<esc>qu]] 155expect [[ 156hello 157hello 158hello]] 159 160feed [[0<C-v>3jl@q]] 161expect [[ 162heFOOllo 163heFOOllo 164heFOOllo]] 165 166feed [[gg0<C-v>j@w]] 167expect [[ 168h123eFOOllo 169h123eFOOllo 170heFOOllo]] 171end ) 172end ) 173 174describe ( 'immediately after a macro has finished executing,' , function () 175before_each ( function () 176clear () 177command ( [[let @a = 'gg0']] ) 178end ) 179 180describe ( 'reg_executing() from RPC returns an empty string' , function () 181it ( 'if the macro does not end with a <Nop> mapping' , function () 182feed ( '@a' ) 183eq ( '' , fn . reg_executing ()) 184end ) 185 186it ( 'if the macro ends with a <Nop> mapping' , function () 187command ( 'nnoremap 0 <Nop>' ) 188feed ( '@a' ) 189eq ( '' , fn . reg_executing ()) 190end ) 191end ) 192 193describe ( 'characters from a mapping are not treated as a part of the macro #18015' , function () 194before_each ( function () 195command ( 'nnoremap s qa' ) 196end ) 197 198it ( 'if the macro does not end with a <Nop> mapping' , function () 199feed ( '@asq' ) -- "q" from "s" mapping should start recording a macro instead of being no-op 200eq ( { mode ='n' , blocking =false } , api . nvim_get_mode ()) 201expect ( '' ) 202eq ( '' , eval ( '@a' )) 203end ) 204 205it ( 'if the macro ends with a <Nop> mapping' , function () 206command ( 'nnoremap 0 <Nop>' ) 207feed ( '@asq' ) -- "q" from "s" mapping should start recording a macro instead of being no-op 208eq ( { mode ='n' , blocking =false } , api . nvim_get_mode ()) 209expect ( '' ) 210eq ( '' , eval ( '@a' )) 211end ) 212end ) 213end ) 214 215describe ( 'reg_recorded()' , function () 216before_each ( clear ) 217it ( 'returns the correct value' , function () 218feed [[qqyyq]] 219eq ( 'q' , eval ( 'reg_recorded()' )) 220end ) 221end )