robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
aa1d8a2702
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 =n . feed 8local eq =t . eq 9local pcall_err =t . pcall_err 10local expect =n . expect 11local eval =n . eval 12local fn =n . fn 13local insert =n . insert 14local write_file =t . write_file 15local command =n . command 16 17describe ( 'mappings with <Cmd>' , function () 18local screen 19local tmpfile ='X_ex_cmds_cmd_map' 20 21local function cmdmap ( lhs , rhs ) 22command ( 'noremap ' .. lhs .. ' <Cmd>' .. rhs .. '<cr>' ) 23command ( 'noremap! ' .. lhs .. ' <Cmd>' .. rhs .. '<cr>' ) 24end 25 26before_each ( function () 27clear () 28screen =Screen . new ( 65 , 8 ) 29screen : set_default_attr_ids ( { 30[ 1 ] ={ bold =true , foreground =Screen . colors . Blue1 } , 31[ 2 ] ={ foreground =Screen . colors . Grey100 , background =Screen . colors . Red } , 32[ 3 ] ={ bold =true , foreground =Screen . colors . SeaGreen4 } , 33[ 4 ] ={ bold =true } , 34[ 5 ] ={ foreground =Screen . colors . Black , background =Screen . colors . LightGrey } , 35[ 6 ] ={ foreground =Screen . colors . Blue1 } , 36[ 7 ] ={ bold =true , reverse =true } , 37[ 8 ] ={ background =Screen . colors . WebGray } , 38[ 9 ] ={ background =Screen . colors . LightMagenta } , 39[ 10 ] ={ foreground =Screen . colors . Red } , 40} ) 41 42cmdmap ( '<F3>' , 'let m = mode(1)' ) 43cmdmap ( '<F4>' , 'normal! ww' ) 44cmdmap ( '<F5>' , 'normal! "ay' ) 45cmdmap ( '<F6>' , 'throw "very error"' ) 46command ( [[ 47function! TextObj() 48if mode() !=# "v" 49normal! v 50end 51call cursor(1,3) 52normal! o 53call cursor(2,4) 54endfunction]] ) 55cmdmap ( '<F7>' , 'call TextObj()' ) 56insert ( [[ 57some short lines 58of test text]] ) 59feed ( 'gg' ) 60cmdmap ( '<F8>' , 'startinsert' ) 61cmdmap ( '<F9>' , 'stopinsert' ) 62command ( 'abbr foo <Cmd>let g:y = 17<cr>bar' ) 63end ) 64 65after_each ( function () 66os . remove ( tmpfile ) 67end ) 68 69it ( 'can be displayed' , function () 70command ( 'map <F3>' ) 71screen : expect ( [[ 72^some short lines | 73of test text | 74{1:~ }|*5 75{6:<F3>} {6:*} {6:<Cmd>}let m = mode(1){6:<CR>} | 76]] ) 77end ) 78 79it ( 'handles invalid mappings' , function () 80command ( 'let x = 0' ) 81command ( 'noremap <F3> <Cmd><Cmd>let x = 1<cr>' ) 82feed ( '<F3>' ) 83screen : expect ( [[ 84^some short lines | 85of test text | 86{1:~ }|*5 87{2:E1136: <Cmd> mapping must end with <CR> before second <Cmd>} | 88]] ) 89 90command ( 'noremap <F3> <Cmd>let x = 3' ) 91feed ( '<F3>' ) 92screen : expect ( [[ 93^some short lines | 94of test text | 95{1:~ }|*5 96{2:E1255: <Cmd> mapping must end with <CR>} | 97]] ) 98eq ( 0 , eval ( 'x' )) 99end ) 100 101it ( 'allows special keys and modifiers' , function () 102command ( 'noremap <F3> <Cmd>normal! <Down><CR>' ) 103feed ( '<F3>' ) 104screen : expect ( [[ 105some short lines | 106^of test text | 107{1:~ }|*5 108| 109]] ) 110 111command ( 'noremap <F3> <Cmd>normal! <C-Right><CR>' ) 112feed ( '<F3>' ) 113screen : expect ( [[ 114some short lines | 115of ^test text | 116{1:~ }|*5 117| 118]] ) 119end ) 120 121it ( 'handles string containing K_SPECIAL (0x80) bytes correctly' , function () 122command ( [[noremap <F3> <Cmd>let g:str = 'foo…bar'<CR>]] ) 123feed ( '<F3>' ) 124eq ( 'foo…bar' , eval ( 'g:str' )) 125local str =eval ( [["foo\<D-…>bar"]] ) 126command ( [[noremap <F3> <Cmd>let g:str = ']] .. str .. [['<CR>]] ) 127feed ( '<F3>' ) 128eq ( str , eval ( 'g:str' )) 129command ( [[noremap <F3> <Cmd>let g:str = 'foo<D-…>bar'<CR>]] ) 130feed ( '<F3>' ) 131eq ( str , eval ( 'g:str' )) 132end ) 133 134it ( 'works in various modes and sees correct `mode()` value' , function () 135-- normal mode 136feed ( '<F3>' ) 137eq ( 'n' , eval ( 'm' )) 138 139-- visual mode 140feed ( 'v<F3>' ) 141eq ( 'v' , eval ( 'm' )) 142-- didn't leave visual mode 143eq ( 'v' , eval ( 'mode(1)' )) 144feed ( '<esc>' ) 145eq ( 'n' , eval ( 'mode(1)' )) 146 147-- visual mapping in select mode 148feed ( 'gh<F3>' ) 149eq ( 'v' , eval ( 'm' )) 150-- didn't leave select mode 151eq ( 's' , eval ( 'mode(1)' )) 152feed ( '<esc>' ) 153eq ( 'n' , eval ( 'mode(1)' )) 154 155-- select mode mapping 156command ( 'snoremap <F3> <Cmd>let m = mode(1)<cr>' ) 157feed ( 'gh<F3>' ) 158eq ( 's' , eval ( 'm' )) 159-- didn't leave select mode 160eq ( 's' , eval ( 'mode(1)' )) 161feed ( '<esc>' ) 162eq ( 'n' , eval ( 'mode(1)' )) 163 164-- operator-pending mode 165feed ( 'd<F3>' ) 166eq ( 'no' , eval ( 'm' )) 167-- did leave operator-pending mode 168eq ( 'n' , eval ( 'mode(1)' )) 169 170--insert mode 171feed ( 'i<F3>' ) 172eq ( 'i' , eval ( 'm' )) 173eq ( 'i' , eval ( 'mode(1)' )) 174 175-- replace mode 176feed ( '<Ins><F3>' ) 177eq ( 'R' , eval ( 'm' )) 178eq ( 'R' , eval ( 'mode(1)' )) 179feed ( '<esc>' ) 180eq ( 'n' , eval ( 'mode(1)' )) 181 182-- virtual replace mode 183feed ( 'gR<F3>' ) 184eq ( 'Rv' , eval ( 'm' )) 185eq ( 'Rv' , eval ( 'mode(1)' )) 186feed ( '<esc>' ) 187eq ( 'n' , eval ( 'mode(1)' )) 188 189-- langmap works, but is not distinguished in mode(1) 190feed ( ':set iminsert=1<cr>i<F3>' ) 191eq ( 'i' , eval ( 'm' )) 192eq ( 'i' , eval ( 'mode(1)' )) 193feed ( '<esc>' ) 194eq ( 'n' , eval ( 'mode(1)' )) 195 196feed ( ':<F3>' ) 197eq ( 'c' , eval ( 'm' )) 198eq ( 'c' , eval ( 'mode(1)' )) 199feed ( '<esc>' ) 200eq ( 'n' , eval ( 'mode(1)' )) 201 202-- terminal mode 203command ( 'tnoremap <F3> <Cmd>let m = mode(1)<cr>' ) 204command ( 'split | terminal' ) 205feed ( 'i' ) 206eq ( 't' , eval ( 'mode(1)' )) 207feed ( '<F3>' ) 208eq ( 't' , eval ( 'm' )) 209eq ( 't' , eval ( 'mode(1)' )) 210end ) 211 212it ( 'works in normal mode' , function () 213cmdmap ( '<F2>' , 'let s = [mode(1), v:count, v:register]' ) 214 215-- check v:count and v:register works 216feed ( '<F2>' ) 217eq ( { 'n' , 0 , '"' } , eval ( 's' )) 218feed ( '7<F2>' ) 219eq ( { 'n' , 7 , '"' } , eval ( 's' )) 220feed ( '"e<F2>' ) 221eq ( { 'n' , 0 , 'e' } , eval ( 's' )) 222feed ( '5"k<F2>' ) 223eq ( { 'n' , 5 , 'k' } , eval ( 's' )) 224feed ( '"+2<F2>' ) 225eq ( { 'n' , 2 , '+' } , eval ( 's' )) 226 227-- text object enters visual mode 228feed ( '<F7>' ) 229screen : expect ( [[ 230so{5:me short lines} | 231{5:of ^t}est text | 232{1:~ }|*5 233{4:-- VISUAL --} | 234]] ) 235feed ( '<esc>' ) 236 237-- startinsert 238feed ( '<F8>' ) 239eq ( 'i' , eval ( 'mode(1)' )) 240feed ( '<esc>' ) 241 242eq ( 'n' , eval ( 'mode(1)' )) 243cmdmap ( ',a' , 'call feedkeys("aalpha") \\| let g:a = getline(2)' ) 244cmdmap ( ',b' , 'call feedkeys("abeta", "x") \\| let g:b = getline(2)' ) 245 246feed ( ',a<F3>' ) 247screen : expect ( [[ 248some short lines | 249of alpha^test text | 250{1:~ }|*5 251{4:-- INSERT --} | 252]] ) 253-- feedkeys were not executed immediately 254eq ( { 'n' , 'of test text' } , eval ( '[m,a]' )) 255eq ( 'i' , eval ( 'mode(1)' )) 256feed ( '<esc>' ) 257 258feed ( ',b<F3>' ) 259screen : expect ( [[ 260some short lines | 261of alphabet^atest text | 262{1:~ }|*5 263| 264]] ) 265-- feedkeys(..., 'x') was executed immediately, but insert mode gets aborted 266eq ( { 'n' , 'of alphabetatest text' } , eval ( '[m,b]' )) 267eq ( 'n' , eval ( 'mode(1)' )) 268end ) 269 270it ( 'works in :normal command' , function () 271command ( 'noremap ,x <Cmd>call append(1, "xx")\\| call append(1, "aa")<cr>' ) 272command ( 'noremap ,f <Cmd>nosuchcommand<cr>' ) 273command ( 'noremap ,e <Cmd>throw "very error"\\| call append(1, "yy")<cr>' ) 274command ( 'noremap ,m <Cmd>echoerr "The message."\\| call append(1, "zz")<cr>' ) 275command ( 276'noremap ,w <Cmd>for i in range(5)\\|if i==1\\|echoerr "Err"\\|endif\\|call append(1, i)\\|endfor<cr>' 277) 278 279feed ( ':normal ,x<cr>' ) 280screen : expect ( [[ 281^some short lines | 282aa | 283xx | 284of test text | 285{1:~ }|*3 286:normal ,x | 287]] ) 288 289eq ( 'Vim:E492: Not an editor command: nosuchcommand' , pcall_err ( command , 'normal ,f' )) 290eq ( 'very error' , pcall_err ( command , 'normal ,e' )) 291eq ( 'Vim(echoerr):The message.' , pcall_err ( command , 'normal ,m' )) 292feed ( 'w' ) 293screen : expect ( [[ 294some ^short lines | 295aa | 296xx | 297of test text | 298{1:~ }|*3 299:normal ,x | 300]] ) 301 302command ( ':%d' ) 303eq ( 'Vim(echoerr):Err' , pcall_err ( command , 'normal ,w' )) 304screen : expect ( [[ 305^ | 3060 | 307{1:~ }|*5 308--No lines in buffer-- | 309]] ) 310 311command ( ':%d' ) 312feed ( ':normal ,w<cr>' ) 313screen : expect ( [[ 314^ | 3154 | 3163 | 3172 | 3181 | 3190 | 320{1:~ }| 321{2:Err} | 322]] ) 323end ) 324 325it ( 'works in visual mode' , function () 326-- can extend visual mode 327feed ( 'v<F4>' ) 328screen : expect ( [[ 329{5:some short ^l}ines | 330of test text | 331{1:~ }|*5 332{4:-- VISUAL --} | 333]] ) 334eq ( 'v' , fn . mode ( 1 )) 335 336-- can invoke operator, ending visual mode 337feed ( '<F5>' ) 338eq ( 'n' , fn . mode ( 1 )) 339eq ( { 'some short l' } , fn . getreg ( 'a' , 1 , 1 )) 340 341-- error doesn't interrupt visual mode 342feed ( 'ggvw<F6>' ) 343screen : expect ( [[ 344{5:some s}hort lines | 345of test text | 346{1:~ }|*2 347{7: }| 348{2:Error in :} | 349{2:E605: Exception not caught: very error} | 350{3:Press ENTER or type command to continue}^ | 351]] ) 352feed ( '<cr>' ) 353eq ( 'E605: Exception not caught: very error' , eval ( 'v:errmsg' )) 354-- still in visual mode, <cr> was consumed by the error prompt 355screen : expect ( [[ 356{5:some ^s}hort lines | 357of test text | 358{1:~ }|*5 359{4:-- VISUAL --} | 360]] ) 361eq ( 'v' , fn . mode ( 1 )) 362feed ( '<F7>' ) 363screen : expect ( [[ 364so{5:me short lines} | 365{5:of ^t}est text | 366{1:~ }|*5 367{4:-- VISUAL --} | 368]] ) 369eq ( 'v' , fn . mode ( 1 )) 370 371-- startinsert gives "-- (insert) VISUAL --" mode 372feed ( '<F8>' ) 373screen : expect ( [[ 374so{5:me short lines} | 375{5:of ^t}est text | 376{1:~ }|*5 377{4:-- (insert) VISUAL --} | 378]] ) 379eq ( 'v' , eval ( 'mode(1)' )) 380feed ( '<esc>' ) 381eq ( 'i' , eval ( 'mode(1)' )) 382end ) 383 384it ( 'works in select mode' , function () 385command ( 'snoremap <F1> <cmd>throw "very error"<cr>' ) 386command ( 'snoremap <F2> <cmd>normal! <c-g>"by<cr>' ) 387-- can extend select mode 388feed ( 'gh<F4>' ) 389screen : expect ( [[ 390{5:some short ^l}ines | 391of test text | 392{1:~ }|*5 393{4:-- SELECT --} | 394]] ) 395eq ( 's' , fn . mode ( 1 )) 396 397-- visual mapping in select mode restart select mode after operator 398feed ( '<F5>' ) 399eq ( 's' , fn . mode ( 1 )) 400eq ( { 'some short l' } , fn . getreg ( 'a' , 1 , 1 )) 401 402-- select mode mapping works, and does not restart select mode 403feed ( '<F2>' ) 404eq ( 'n' , fn . mode ( 1 )) 405eq ( { 'some short l' } , fn . getreg ( 'b' , 1 , 1 )) 406 407-- error doesn't interrupt temporary visual mode 408feed ( '<esc>ggvw<c-g><F6>' ) 409screen : expect ( [[ 410{5:some s}hort lines | 411of test text | 412{1:~ }|*2 413{7: }| 414{2:Error in :} | 415{2:E605: Exception not caught: very error} | 416{3:Press ENTER or type command to continue}^ | 417]] ) 418feed ( '<cr>' ) 419eq ( 'E605: Exception not caught: very error' , eval ( 'v:errmsg' )) 420-- still in visual mode, <cr> was consumed by the error prompt 421screen : expect ( [[ 422{5:some ^s}hort lines | 423of test text | 424{1:~ }|*5 425{4:-- VISUAL --} | 426]] ) 427-- quirk: restoration of select mode is not performed 428eq ( 'v' , fn . mode ( 1 )) 429 430-- error doesn't interrupt select mode 431feed ( '<esc>ggvw<c-g><F1>' ) 432screen : expect ( [[ 433{5:some s}hort lines | 434of test text | 435{1:~ }|*2 436{7: }| 437{2:Error in :} | 438{2:E605: Exception not caught: very error} | 439{3:Press ENTER or type command to continue}^ | 440]] ) 441feed ( '<cr>' ) 442eq ( 'E605: Exception not caught: very error' , eval ( 'v:errmsg' )) 443-- still in select mode, <cr> was consumed by the error prompt 444screen : expect ( [[ 445{5:some ^s}hort lines | 446of test text | 447{1:~ }|*5 448{4:-- SELECT --} | 449]] ) 450-- quirk: restoration of select mode is not performed 451eq ( 's' , fn . mode ( 1 )) 452 453feed ( '<F7>' ) 454screen : expect ( [[ 455so{5:me short lines} | 456{5:of ^t}est text | 457{1:~ }|*5 458{4:-- SELECT --} | 459]] ) 460eq ( 's' , fn . mode ( 1 )) 461 462-- startinsert gives "-- SELECT (insert) --" mode 463feed ( '<F8>' ) 464screen : expect ( [[ 465so{5:me short lines} | 466{5:of ^t}est text | 467{1:~ }|*5 468{4:-- (insert) SELECT --} | 469]] ) 470eq ( 's' , eval ( 'mode(1)' )) 471feed ( '<esc>' ) 472eq ( 'i' , eval ( 'mode(1)' )) 473end ) 474 475it ( 'works in operator-pending mode' , function () 476feed ( 'd<F4>' ) 477expect ( [[ 478lines 479of test text]] ) 480eq ( { 'some short ' } , fn . getreg ( '"' , 1 , 1 )) 481feed ( '.' ) 482expect ( [[ 483test text]] ) 484eq ( { 'lines' , 'of ' } , fn . getreg ( '"' , 1 , 1 )) 485feed ( 'uu' ) 486expect ( [[ 487some short lines 488of test text]] ) 489 490-- error aborts operator-pending, operator not performed 491feed ( 'd<F6>' ) 492screen : expect ( [[ 493some short lines | 494of test text | 495{1:~ }|*2 496{7: }| 497{2:Error in :} | 498{2:E605: Exception not caught: very error} | 499{3:Press ENTER or type command to continue}^ | 500]] ) 501feed ( '<cr>' ) 502eq ( 'E605: Exception not caught: very error' , eval ( 'v:errmsg' )) 503expect ( [[ 504some short lines 505of test text]] ) 506 507feed ( '"bd<F7>' ) 508expect ( [[ 509soest text]] ) 510eq ( { 'me short lines' , 'of t' } , fn . getreg ( 'b' , 1 , 1 )) 511 512-- startinsert aborts operator 513feed ( 'd<F8>' ) 514eq ( 'i' , eval ( 'mode(1)' )) 515expect ( [[ 516soest text]] ) 517end ) 518 519it ( 'works in insert mode' , function () 520-- works the same as <c-o>w<c-o>w 521feed ( 'iindeed <F4>little ' ) 522screen : expect ( [[ 523indeed some short little ^lines | 524of test text | 525{1:~ }|*5 526{4:-- INSERT --} | 527]] ) 528 529feed ( '<F6>' ) 530screen : expect ( [[ 531indeed some short little lines | 532of test text | 533{1:~ }|*2 534{7: }| 535{2:Error in :} | 536{2:E605: Exception not caught: very error} | 537{3:Press ENTER or type command to continue}^ | 538]] ) 539 540feed ( '<cr>' ) 541eq ( 'E605: Exception not caught: very error' , eval ( 'v:errmsg' )) 542-- still in insert 543screen : expect ( [[ 544indeed some short little ^lines | 545of test text | 546{1:~ }|*5 547{4:-- INSERT --} | 548]] ) 549eq ( 'i' , eval ( 'mode(1)' )) 550 551-- When entering visual mode from InsertEnter autocmd, an async event, or 552-- a <cmd> mapping, vim ends up in undocumented "INSERT VISUAL" mode. If a 553-- vim patch decides to disable this mode, this test is expected to fail. 554feed ( '<F7>stuff ' ) 555screen : expect ( [[ 556in{5:deed some short little lines} | 557{5:of stuff ^t}est text | 558{1:~ }|*5 559{4:-- INSERT VISUAL --} | 560]] ) 561expect ( [[ 562indeed some short little lines 563of stuff test text]] ) 564 565feed ( '<F5>' ) 566eq ( { 'deed some short little lines' , 'of stuff t' } , fn . getreg ( 'a' , 1 , 1 )) 567 568-- still in insert 569screen : expect ( [[ 570in^deed some short little lines | 571of stuff test text | 572{1:~ }|*5 573{4:-- INSERT --} | 574]] ) 575eq ( 'i' , eval ( 'mode(1)' )) 576 577-- also works as part of abbreviation 578feed ( ' foo ' ) 579screen : expect ( [[ 580in bar ^deed some short little lines | 581of stuff test text | 582{1:~ }|*5 583{4:-- INSERT --} | 584]] ) 585eq ( 17 , eval ( 'g:y' )) 586 587-- :startinsert does nothing 588feed ( '<F8>' ) 589eq ( 'i' , eval ( 'mode(1)' )) 590 591-- :stopinsert works 592feed ( '<F9>' ) 593eq ( 'n' , eval ( 'mode(1)' )) 594end ) 595 596it ( 'works in insert completion (Ctrl-X) mode' , function () 597feed ( 'os<c-x><c-n>' ) 598screen : expect ( [[ 599some short lines | 600some^ | 601{8:some } | 602{9:short }{1: }| 603{1:~ }|*3 604{4:-- Keyword Local completion (^N^P) }{3:match 1 of 2} | 605]] ) 606 607feed ( '<f3>' ) 608eq ( 'ic' , eval ( 'm' )) 609 610-- ensure a redraw, this would have moved the cursor 611-- instead if CTRL-X mode was left. 612feed ( '<up>' ) 613screen : expect ( [[ 614some short lines | 615some^ | 616{9:some } | 617{9:short }{1: }| 618{1:~ }|*3 619{4:-- Keyword Local completion (^N^P) }{10:Back at original} | 620]] ) 621end ) 622 623it ( 'works in cmdline mode' , function () 624feed ( ':text<F3>' ) 625eq ( 'c' , eval ( 'm' )) 626-- didn't leave cmdline mode 627eq ( 'c' , eval ( 'mode(1)' )) 628feed ( '<cr>' ) 629eq ( 'n' , eval ( 'mode(1)' )) 630screen : expect ( [[ 631^some short lines | 632of test text | 633{1:~ }|*5 634{2:E492: Not an editor command: text} | 635]] ) 636 637feed ( ':echo 2<F6>' ) 638screen : expect ( [[ 639some short lines | 640of test text | 641{1:~ }| 642{7: }| 643:echo 2 | 644{2:Error in :} | 645{2:E605: Exception not caught: very error} | 646:echo 2^ | 647]] ) 648eq ( 'E605: Exception not caught: very error' , eval ( 'v:errmsg' )) 649-- didn't leave cmdline mode 650eq ( 'c' , eval ( 'mode(1)' )) 651feed ( '+2<cr>' ) 652screen : expect ( [[ 653some short lines | 654of test text | 655{7: }| 656:echo 2 | 657{2:Error in :} | 658{2:E605: Exception not caught: very error} | 6594 | 660{3:Press ENTER or type command to continue}^ | 661]] ) 662-- however, message scrolling may cause extra CR prompt 663-- This is consistent with output from async events. 664feed ( '<cr>' ) 665screen : expect ( [[ 666^some short lines | 667of test text | 668{1:~ }|*5 669| 670]] ) 671eq ( 'n' , eval ( 'mode(1)' )) 672 673feed ( ':let g:x = 3<F4>' ) 674screen : expect ( [[ 675some short lines | 676of test text | 677{1:~ }|*5 678:let g:x = 3^ | 679]] ) 680feed ( '+2<cr>' ) 681-- cursor was moved in the background 682screen : expect ( [[ 683some short ^lines | 684of test text | 685{1:~ }|*5 686:let g:x = 3+2 | 687]] ) 688eq ( 5 , eval ( 'g:x' )) 689 690feed ( ':let g:y = 7<F8>' ) 691screen : expect ( [[ 692some short lines | 693of test text | 694{1:~ }|*5 695:let g:y = 7^ | 696]] ) 697eq ( 'c' , eval ( 'mode(1)' )) 698feed ( '+2<cr>' ) 699-- startinsert takes effect after leaving cmdline mode 700screen : expect ( [[ 701some short ^lines | 702of test text | 703{1:~ }|*5 704{4:-- INSERT --} | 705]] ) 706eq ( 'i' , eval ( 'mode(1)' )) 707eq ( 9 , eval ( 'g:y' )) 708end ) 709 710it ( "doesn't crash when invoking cmdline mode recursively #8859" , function () 711cmdmap ( '<F2>' , 'norm! :foo' ) 712feed ( ':bar' ) 713screen : expect ( [[ 714some short lines | 715of test text | 716{1:~ }|*5 717:bar^ | 718]] ) 719 720feed ( '<f2>x' ) 721screen : expect ( [[ 722some short lines | 723of test text | 724{1:~ }|*5 725:barx^ | 726]] ) 727end ) 728 729it ( 'works with <SID> mappings' , function () 730command ( 'new!' ) 731write_file ( 732tmpfile , 733[[ 734map <f2> <Cmd>call <SID>do_it()<Cr> 735function! s:do_it() 736let g:x = 10 737endfunction 738]] 739) 740command ( 'source ' .. tmpfile ) 741feed ( '<f2>' ) 742eq ( '' , eval ( 'v:errmsg' )) 743eq ( 10 , eval ( 'g:x' )) 744end ) 745end )