robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
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 , after_each =t . describe , t . it , t . before_each , t . after_each 6local clear =n . clear 7local feed , next_msg , eq =n . feed , n . next_msg , t . eq 8local command =n . command 9local expect =n . expect 10local curbuf_contents =n . curbuf_contents 11local api =n . api 12local exec_lua =n . exec_lua 13local write_file =t . write_file 14local fn =n . fn 15local eval =n . eval 16 17before_each ( clear ) 18 19describe ( 'mappings' , function () 20local add_mapping =function ( mapping , send ) 21local cmd ='nnoremap ' 22.. mapping 23.. " :call rpcnotify(1, 'mapped', '" 24.. send : gsub ( '<' , '<lt>' ) 25.. "')<cr>" 26command ( cmd ) 27end 28 29local check_mapping =function ( mapping , expected ) 30feed ( mapping ) 31eq ( { 'notification' , 'mapped' , { expected } } , next_msg ()) 32end 33 34before_each ( function () 35add_mapping ( '<A-l>' , '<A-l>' ) 36add_mapping ( '<A-L>' , '<A-L>' ) 37add_mapping ( '<D-l>' , '<D-l>' ) 38add_mapping ( '<D-L>' , '<D-L>' ) 39add_mapping ( '<C-L>' , '<C-L>' ) 40add_mapping ( '<C-S-L>' , '<C-S-L>' ) 41add_mapping ( '<s-up>' , '<s-up>' ) 42add_mapping ( '<s-up>' , '<s-up>' ) 43add_mapping ( '<c-s-up>' , '<c-s-up>' ) 44add_mapping ( '<c-s-a-up>' , '<c-s-a-up>' ) 45add_mapping ( '<c-s-a-d-up>' , '<c-s-a-d-up>' ) 46add_mapping ( '<c-d-a>' , '<c-d-a>' ) 47add_mapping ( '<d-1>' , '<d-1>' ) 48add_mapping ( '<khome>' , '<khome>' ) 49add_mapping ( '<kup>' , '<kup>' ) 50add_mapping ( '<kpageup>' , '<kpageup>' ) 51add_mapping ( '<kleft>' , '<kleft>' ) 52add_mapping ( '<korigin>' , '<korigin>' ) 53add_mapping ( '<kright>' , '<kright>' ) 54add_mapping ( '<kend>' , '<kend>' ) 55add_mapping ( '<kdown>' , '<kdown>' ) 56add_mapping ( '<kpagedown>' , '<kpagedown>' ) 57add_mapping ( '<kinsert>' , '<kinsert>' ) 58add_mapping ( '<kdel>' , '<kdel>' ) 59add_mapping ( '<kdivide>' , '<kdivide>' ) 60add_mapping ( '<kmultiply>' , '<kmultiply>' ) 61add_mapping ( '<kminus>' , '<kminus>' ) 62add_mapping ( '<kplus>' , '<kplus>' ) 63add_mapping ( '<kenter>' , '<kenter>' ) 64add_mapping ( '<kcomma>' , '<kcomma>' ) 65add_mapping ( '<kequal>' , '<kequal>' ) 66add_mapping ( '<find>' , '<find>' ) 67add_mapping ( '<select>' , '<select>' ) 68add_mapping ( '<f38>' , '<f38>' ) 69add_mapping ( '<f63>' , '<f63>' ) 70end ) 71 72it ( 'ok' , function () 73check_mapping ( '<A-l>' , '<A-l>' ) 74check_mapping ( '<A-L>' , '<A-L>' ) 75check_mapping ( '<A-S-l>' , '<A-L>' ) 76check_mapping ( '<A-S-L>' , '<A-L>' ) 77check_mapping ( '<D-l>' , '<D-l>' ) 78check_mapping ( '<D-L>' , '<D-L>' ) 79check_mapping ( '<D-S-l>' , '<D-L>' ) 80check_mapping ( '<D-S-L>' , '<D-L>' ) 81check_mapping ( '<C-l>' , '<C-L>' ) 82check_mapping ( '<C-L>' , '<C-L>' ) 83check_mapping ( '<C-S-l>' , '<C-S-L>' ) 84check_mapping ( '<C-S-L>' , '<C-S-L>' ) 85check_mapping ( '<s-up>' , '<s-up>' ) 86check_mapping ( '<c-s-up>' , '<c-s-up>' ) 87check_mapping ( '<s-c-up>' , '<c-s-up>' ) 88check_mapping ( '<c-s-a-up>' , '<c-s-a-up>' ) 89check_mapping ( '<s-c-a-up>' , '<c-s-a-up>' ) 90check_mapping ( '<c-a-s-up>' , '<c-s-a-up>' ) 91check_mapping ( '<s-a-c-up>' , '<c-s-a-up>' ) 92check_mapping ( '<a-c-s-up>' , '<c-s-a-up>' ) 93check_mapping ( '<a-s-c-up>' , '<c-s-a-up>' ) 94check_mapping ( '<c-s-a-d-up>' , '<c-s-a-d-up>' ) 95check_mapping ( '<s-a-d-c-up>' , '<c-s-a-d-up>' ) 96check_mapping ( '<d-s-a-c-up>' , '<c-s-a-d-up>' ) 97check_mapping ( '<c-d-a>' , '<c-d-a>' ) 98check_mapping ( '<d-c-a>' , '<c-d-a>' ) 99check_mapping ( '<d-1>' , '<d-1>' ) 100check_mapping ( '<khome>' , '<khome>' ) 101check_mapping ( '<KP7>' , '<khome>' ) 102check_mapping ( '<kup>' , '<kup>' ) 103check_mapping ( '<KP8>' , '<kup>' ) 104check_mapping ( '<kpageup>' , '<kpageup>' ) 105check_mapping ( '<KP9>' , '<kpageup>' ) 106check_mapping ( '<kleft>' , '<kleft>' ) 107check_mapping ( '<KP4>' , '<kleft>' ) 108check_mapping ( '<korigin>' , '<korigin>' ) 109check_mapping ( '<KP5>' , '<korigin>' ) 110check_mapping ( '<kright>' , '<kright>' ) 111check_mapping ( '<KP6>' , '<kright>' ) 112check_mapping ( '<kend>' , '<kend>' ) 113check_mapping ( '<KP1>' , '<kend>' ) 114check_mapping ( '<kdown>' , '<kdown>' ) 115check_mapping ( '<KP2>' , '<kdown>' ) 116check_mapping ( '<kpagedown>' , '<kpagedown>' ) 117check_mapping ( '<KP3>' , '<kpagedown>' ) 118check_mapping ( '<kinsert>' , '<kinsert>' ) 119check_mapping ( '<KP0>' , '<kinsert>' ) 120check_mapping ( '<kdel>' , '<kdel>' ) 121check_mapping ( '<KPPeriod>' , '<kdel>' ) 122check_mapping ( '<kdivide>' , '<kdivide>' ) 123check_mapping ( '<KPDiv>' , '<kdivide>' ) 124check_mapping ( '<kmultiply>' , '<kmultiply>' ) 125check_mapping ( '<KPMult>' , '<kmultiply>' ) 126check_mapping ( '<kminus>' , '<kminus>' ) 127check_mapping ( '<KPMinus>' , '<kminus>' ) 128check_mapping ( '<kplus>' , '<kplus>' ) 129check_mapping ( '<KPPlus>' , '<kplus>' ) 130check_mapping ( '<kenter>' , '<kenter>' ) 131check_mapping ( '<KPEnter>' , '<kenter>' ) 132check_mapping ( '<kcomma>' , '<kcomma>' ) 133check_mapping ( '<KPComma>' , '<kcomma>' ) 134check_mapping ( '<kequal>' , '<kequal>' ) 135check_mapping ( '<KPEquals>' , '<kequal>' ) 136check_mapping ( '<Find>' , '<find>' ) 137check_mapping ( '<Select>' , '<select>' ) 138check_mapping ( '<f38>' , '<f38>' ) 139check_mapping ( '<f63>' , '<f63>' ) 140end ) 141 142it ( 'support meta + multibyte char mapping' , function () 143add_mapping ( '<m-ä>' , '<m-ä>' ) 144check_mapping ( '<m-ä>' , '<m-ä>' ) 145end ) 146end ) 147 148describe ( 'input utf sequences that contain K_SPECIAL (0x80)' , function () 149it ( 'ok' , function () 150feed ( 'i…<esc>' ) 151expect ( '…' ) 152end ) 153 154it ( 'can be mapped' , function () 155command ( 'inoremap … E280A6' ) 156feed ( 'i…<esc>' ) 157expect ( 'E280A6' ) 158end ) 159end ) 160 161describe ( 'input utf sequences that contain CSI (0x9B)' , function () 162it ( 'ok' , function () 163feed ( 'iě<esc>' ) 164expect ( 'ě' ) 165end ) 166 167it ( 'can be mapped' , function () 168command ( 'inoremap ě C49B' ) 169feed ( 'iě<esc>' ) 170expect ( 'C49B' ) 171end ) 172end ) 173 174describe ( 'input split utf sequences' , function () 175it ( 'ok' , function () 176local str ='►' 177feed ( 'i' .. str : sub ( 1 , 1 )) 178vim . uv . sleep ( 10 ) 179feed ( str : sub ( 2 , 3 )) 180expect ( '►' ) 181end ) 182 183it ( 'can be mapped' , function () 184command ( 'inoremap ► E296BA' ) 185command ( 'set ttimeoutlen=100' ) -- CI test runners may cause timeout otherwise 186local str ='►' 187feed ( 'i' .. str : sub ( 1 , 1 )) 188vim . uv . sleep ( 10 ) 189feed ( str : sub ( 2 , 3 )) 190expect ( 'E296BA' ) 191end ) 192end ) 193 194describe ( 'input pairs' , function () 195describe ( '<tab> / <c-i>' , function () 196it ( 'ok' , function () 197feed ( 'i<tab><c-i><esc>' ) 198eq ( '\t\t' , curbuf_contents ()) 199end ) 200 201describe ( 'can be mapped separately' , function () 202it ( 'if <tab> is mapped after <c-i>' , function () 203command ( 'inoremap <c-i> CTRL-I!' ) 204command ( 'inoremap <tab> TAB!' ) 205feed ( 'i<tab><c-i><esc>' ) 206eq ( 'TAB!CTRL-I!' , curbuf_contents ()) 207end ) 208 209it ( 'if <tab> is mapped before <c-i>' , function () 210command ( 'inoremap <tab> TAB!' ) 211command ( 'inoremap <c-i> CTRL-I!' ) 212feed ( 'i<tab><c-i><esc>' ) 213eq ( 'TAB!CTRL-I!' , curbuf_contents ()) 214end ) 215end ) 216end ) 217 218describe ( '<cr> / <c-m>' , function () 219it ( 'ok' , function () 220feed ( 'iunos<c-m>dos<cr>tres<esc>' ) 221eq ( 'unos\ndos\ntres' , curbuf_contents ()) 222end ) 223 224describe ( 'can be mapped separately' , function () 225it ( 'if <cr> is mapped after <c-m>' , function () 226command ( 'inoremap <c-m> SNIPPET!' ) 227command ( 'inoremap <cr> , and then<cr>' ) 228feed ( 'iunos<c-m>dos<cr>tres<esc>' ) 229eq ( 'unosSNIPPET!dos, and then\ntres' , curbuf_contents ()) 230end ) 231 232it ( 'if <cr> is mapped before <c-m>' , function () 233command ( 'inoremap <cr> , and then<cr>' ) 234command ( 'inoremap <c-m> SNIPPET!' ) 235feed ( 'iunos<c-m>dos<cr>tres<esc>' ) 236eq ( 'unosSNIPPET!dos, and then\ntres' , curbuf_contents ()) 237end ) 238end ) 239end ) 240 241describe ( '<esc> / <c-[>' , function () 242it ( 'ok' , function () 243feed ( '2adouble<c-[>asingle<esc>' ) 244eq ( 'doubledoublesingle' , curbuf_contents ()) 245end ) 246 247describe ( 'can be mapped separately' , function () 248it ( 'if <esc> is mapped after <c-[>' , function () 249command ( 'inoremap <c-[> HALLOJ!' ) 250command ( 'inoremap <esc> ,<esc>' ) 251feed ( '2adubbel<c-[>upp<esc>' ) 252eq ( 'dubbelHALLOJ!upp,dubbelHALLOJ!upp,' , curbuf_contents ()) 253end ) 254 255it ( 'if <esc> is mapped before <c-[>' , function () 256command ( 'inoremap <esc> ,<esc>' ) 257command ( 'inoremap <c-[> HALLOJ!' ) 258feed ( '2adubbel<c-[>upp<esc>' ) 259eq ( 'dubbelHALLOJ!upp,dubbelHALLOJ!upp,' , curbuf_contents ()) 260end ) 261end ) 262end ) 263end ) 264 265it ( 'Ctrl-6 is Ctrl-^ vim-patch:8.1.2333' , function () 266command ( 'split aaa' ) 267command ( 'edit bbb' ) 268feed ( '<C-6>' ) 269eq ( 'aaa' , fn . bufname ()) 270end ) 271 272it ( 'c_CTRL-R_CTRL-R, i_CTRL-R_CTRL-R, i_CTRL-G_CTRL-K work properly vim-patch:8.1.2346' , function () 273command ( 'set timeoutlen=10' ) 274 275command ( [[let @a = 'aaa']] ) 276feed ( [[:let x = '<C-R><C-R>a'<CR>]] ) 277eq ( [[let x = 'aaa']] , eval ( '@:' )) 278 279feed ( 'a<C-R><C-R>a<Esc>' ) 280expect ( 'aaa' ) 281command ( 'bwipe!' ) 282 283feed ( 'axx<CR>yy<C-G><C-K>a<Esc>' ) 284expect ( [[ 285axx 286yy]] ) 287end ) 288 289it ( 'typing a simplifiable key at hit-enter prompt triggers mapping vim-patch:8.2.0839' , function () 290local screen =Screen . new ( 60 , 8 ) 291command ( [[nnoremap <C-6> <Cmd>echo 'hit ctrl-6'<CR>]] ) 292feed ( ':ls<CR>' ) 293screen : expect ( [[ 294| 295{1:~ }|*3 296{3: }| 297:ls | 2981 %a "[No Name]" line 1 | 299{6:Press ENTER or type command to continue}^ | 300]] ) 301feed ( '<C-6>' ) 302screen : expect ( [[ 303^ | 304{1:~ }|*6 305hit ctrl-6 | 306]] ) 307end ) 308 309it ( 'mixing simplified and unsimplified keys can trigger mapping vim-patch:8.2.0916' , function () 310command ( 'set timeoutlen=10' ) 311command ( [[imap ' <C-W>]] ) 312command ( 'imap <C-W><C-A> c-a' ) 313feed ( [[a'<C-A>]] ) 314expect ( 'c-a' ) 315end ) 316 317it ( 'unsimplified mapping works when there was a partial match vim-patch:8.2.4504' , function () 318command ( 'set timeoutlen=10' ) 319command ( 'nnoremap <C-J> a' ) 320command ( 'nnoremap <NL> x' ) 321command ( 'nnoremap <C-J>x <Nop>' ) 322fn . setline ( 1 , 'x' ) 323-- CTRL-J b should have trigger the <C-J> mapping and then insert "b" 324feed ( '<C-J>b<Esc>' ) 325expect ( 'xb' ) 326end ) 327 328describe ( 'input non-printable chars' , function () 329after_each ( function () 330os . remove ( 'Xtest-overwrite' ) 331end ) 332 333it ( "doesn't crash when echoing them back" , function () 334write_file ( 'Xtest-overwrite' , [[foobar]] ) 335local screen =Screen . new ( 60 , 8 ) 336command ( 'set shortmess-=F' ) 337 338command ( 'e Xtest-overwrite' ) 339screen : expect ( [[ 340^foobar | 341{1:~ }|*6 342"Xtest-overwrite" [noeol] 1L, 6B | 343]] ) 344 345-- Wait for some time so that the timestamp changes. 346vim . uv . sleep ( 10 ) 347write_file ( 'Xtest-overwrite' , [[smurf]] ) 348feed ( ':w<CR>' ) 349screen : expect ( [[ 350foobar | 351{1:~ }|*3 352{3: }| 353"Xtest-overwrite" | 354{9:WARNING: The file has been changed since reading it!!!} | 355{6:Do you really want to write to it (y/n)?}^ | 356]] ) 357 358feed ( 'u' ) 359screen : expect ( [[ 360foobar | 361{1:~ }|*2 362{3: }| 363"Xtest-overwrite" | 364{9:WARNING: The file has been changed since reading it!!!} | 365{6:Do you really want to write to it (y/n)?}u | 366{6:Do you really want to write to it (y/n)?}^ | 367]] ) 368 369feed ( '\005' ) 370screen : expect ( [[ 371foobar | 372{1:~ }| 373{3: }| 374"Xtest-overwrite" | 375{9:WARNING: The file has been changed since reading it!!!} | 376{6:Do you really want to write to it (y/n)?}u | 377{6:Do you really want to write to it (y/n)?}{18:^E} | 378{6:Do you really want to write to it (y/n)?}^ | 379]] ) 380 381feed ( 'n' ) 382screen : expect ( [[ 383foobar | 384{3: }| 385"Xtest-overwrite" | 386{9:WARNING: The file has been changed since reading it!!!} | 387{6:Do you really want to write to it (y/n)?}u | 388{6:Do you really want to write to it (y/n)?}{18:^E} | 389{6:Do you really want to write to it (y/n)?}n | 390{6:Press ENTER or type command to continue}^ | 391]] ) 392 393feed ( '<cr>' ) 394screen : expect ( [[ 395^foobar | 396{1:~ }|*6 397| 398]] ) 399end ) 400end ) 401 402describe ( 'event processing and input' , function () 403it ( 'not blocked by event bursts' , function () 404api . nvim_set_keymap ( 405'' , 406'<f2>' , 407"<cmd>lua vim.rpcnotify(1, 'stop') winning = true <cr>" , 408{ noremap =true } 409) 410 411exec_lua [[ 412winning = false 413burst = vim.schedule_wrap(function(tell) 414if tell then 415vim.rpcnotify(1, 'start') 416end 417-- Are we winning, son? 418if not winning then 419burst(false) 420end 421end) 422burst(true) 423]] 424 425eq ( { 'notification' , 'start' , {} } , next_msg ()) 426feed '<f2>' 427eq ( { 'notification' , 'stop' , {} } , next_msg ()) 428end ) 429end ) 430 431describe ( 'display is updated' , function () 432local screen 433before_each ( function () 434screen =Screen . new ( 60 , 8 ) 435end ) 436 437it ( 'in Insert mode after <Nop> mapping #17911' , function () 438command ( 'imap <Plug>test <Nop>' ) 439command ( 'imap <F2> abc<CR><Plug>test' ) 440feed ( 'i<F2>' ) 441screen : expect ( [[ 442abc | 443^ | 444{1:~ }|*5 445{5:-- INSERT --} | 446]] ) 447end ) 448 449it ( 'in Insert mode after empty string <expr> mapping #17911' , function () 450command ( 'imap <expr> <Plug>test ""' ) 451command ( 'imap <F2> abc<CR><Plug>test' ) 452feed ( 'i<F2>' ) 453screen : expect ( [[ 454abc | 455^ | 456{1:~ }|*5 457{5:-- INSERT --} | 458]] ) 459end ) 460end )