robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
af37d459a6
master
1" Tests for :messages, :echomsg, :echoerr 2 3source check.vim 4source shared.vim 5source term_util.vim 6source view_util.vim 7source screendump.vim 8 9func Test_messages () 10let oldmore = & more 11try 12set nomore 13 14let arr = map ( range ( 10 ), '"hello" . v:val' ) 15for s in arr 16echomsg s |redraw 17endfor 18 19" get last two messages 20redir => result 212 messages |redraw 22redir END 23let msg_list = split ( result , "\n" ) 24call assert_equal ([ "hello8" , "hello9" ], msg_list ) 25 26" clear messages without last one 271 messages clear 28let msg_list = GetMessages () 29call assert_equal ([ 'hello9' ], msg_list ) 30 31" clear all messages 32messages clear 33let msg_list = GetMessages () 34call assert_equal ([], msg_list ) 35finally 36let & more = oldmore 37endtry 38 39call assert_fails ( 'message 1' , 'E474:' ) 40endfunc 41 42" Patch 7.4.1696 defined the "clearmode()" command for clearing the mode 43" indicator (e.g., "-- INSERT --") when ":stopinsert" is invoked. Message 44" output could then be disturbed when 'cmdheight' was greater than one. 45" This test ensures that the bugfix for this issue remains in place. 46func Test_stopinsert_does_not_break_message_output () 47set cmdheight = 2 48redraw ! 49 50stopinsert |echo 'test echo' 51call assert_equal ( 116 , screenchar ( & lines - 1 , 1 )) 52call assert_equal ( 32 , screenchar ( & lines , 1 )) 53redraw ! 54 55stopinsert |echomsg 'test echomsg' 56call assert_equal ( 116 , screenchar ( & lines - 1 , 1 )) 57call assert_equal ( 32 , screenchar ( & lines , 1 )) 58redraw ! 59 60set cmdheight & 61endfunc 62 63func Test_message_completion () 64call feedkeys ( ":message \<C-A>\<C-B>\"\<CR>" , 'tx' ) 65call assert_equal ( '"message clear' , @:) 66endfunc 67 68func Test_echomsg () 69call assert_equal ( "\nhello" , execute ( ':echomsg "hello"' )) 70call assert_equal ( "\n" , execute ( ':echomsg ""' )) 71call assert_equal ( "\n12345" , execute ( ':echomsg 12345' )) 72call assert_equal ( "\n[]" , execute ( ':echomsg []' )) 73call assert_equal ( "\n[1, 2, 3]" , execute ( ':echomsg [1, 2, 3]' )) 74call assert_equal ( "\n[1, 2, []]" , execute ( ':echomsg [1, 2, v:_null_list]' )) 75call assert_equal ( "\n{}" , execute ( ':echomsg {}' )) 76call assert_equal ( "\n{'a': 1, 'b': 2}" , execute ( ':echomsg {"a": 1, "b": 2}' )) 77if has ( 'float' ) 78call assert_equal ( "\n1.23" , execute ( ':echomsg 1.23' )) 79endif 80call assert_match ( "function('<lambda>\\d*')" , execute ( ':echomsg {-> 1234}' )) 81endfunc 82 83func Test_echoerr () 84CheckFunction test_ignore_error 85call test_ignore_error ( 'IgNoRe' ) 86call assert_equal ( "\nIgNoRe hello" , execute ( ':echoerr "IgNoRe hello"' )) 87call assert_equal ( "\n12345 IgNoRe" , execute ( ':echoerr 12345 "IgNoRe"' )) 88call assert_equal ( "\n[1, 2, 'IgNoRe']" , execute ( ':echoerr [1, 2, "IgNoRe"]' )) 89call assert_equal ( "\n{'IgNoRe': 2, 'a': 1}" , execute ( ':echoerr {"a": 1, "IgNoRe": 2}' )) 90if has ( 'float' ) 91call assert_equal ( "\n1.23 IgNoRe" , execute ( ':echoerr 1.23 "IgNoRe"' )) 92endif 93eval '<lambda>' ->test_ignore_error () 94call assert_match ( "function('<lambda>\\d*')" , execute ( ':echoerr {-> 1234}' )) 95call test_ignore_error ( 'RESET' ) 96endfunc 97 98func Test_mode_message_at_leaving_insert_by_ctrl_c () 99if ! has ( 'terminal' ) || has ( 'gui_running' ) 100return 101endif 102 103" Set custom statusline built by user-defined function. 104let testfile = 'Xtest.vim' 105call writefile ([ 106 \'func StatusLine() abort' , 107 \' return ""' , 108 \'endfunc' , 109 \'set statusline=%!StatusLine()' , 110 \'set laststatus=2' , 111 \], testfile ) 112 113let rows = 10 114let buf = term_start ([ GetVimProg (), '--clean' , '-S' , testfile ], { 'term_rows' : rows }) 115call TermWait ( buf , 100 ) 116call assert_equal ( 'run' , job_status ( term_getjob ( buf ))) 117 118call term_sendkeys ( buf , "i" ) 119call WaitForAssert ({ ->assert_match ( '^-- INSERT --\s*$' , term_getline ( buf , rows ))}) 120call term_sendkeys ( buf , "\<C-C>" ) 121call WaitForAssert ({ ->assert_match ( '^\s*$' , term_getline ( buf , rows ))}) 122 123call term_sendkeys ( buf , ":qall!\<CR>" ) 124call WaitForAssert ({ ->assert_equal ( 'dead' , job_status ( term_getjob ( buf )))}) 125exe buf . 'bwipe!' 126call delete ( testfile ) 127endfunc 128 129func Test_mode_message_at_leaving_insert_with_esc_mapped () 130if ! has ( 'terminal' ) || has ( 'gui_running' ) 131return 132endif 133 134" Set custom statusline built by user-defined function. 135let testfile = 'Xtest.vim' 136call writefile ([ 137 \'set laststatus=2' , 138 \'inoremap <Esc> <Esc>00' , 139 \], testfile ) 140 141let rows = 10 142let buf = term_start ([ GetVimProg (), '--clean' , '-S' , testfile ], { 'term_rows' : rows }) 143call WaitForAssert ({ ->assert_match ( '0,0-1\s*All$' , term_getline ( buf , rows - 1 ))}) 144call assert_equal ( 'run' , job_status ( term_getjob ( buf ))) 145 146call term_sendkeys ( buf , "i" ) 147call WaitForAssert ({ ->assert_match ( '^-- INSERT --\s*$' , term_getline ( buf , rows ))}) 148call term_sendkeys ( buf , "\<Esc>" ) 149call WaitForAssert ({ ->assert_match ( '^\s*$' , term_getline ( buf , rows ))}) 150 151call term_sendkeys ( buf , ":qall!\<CR>" ) 152call WaitForAssert ({ ->assert_equal ( 'dead' , job_status ( term_getjob ( buf )))}) 153exe buf . 'bwipe!' 154call delete ( testfile ) 155endfunc 156 157func Test_echospace () 158set noruler noshowcmd laststatus = 1 159call assert_equal ( & columns - 1 , v: echospace ) 160split 161call assert_equal ( & columns - 1 , v: echospace ) 162set ruler 163call assert_equal ( & columns - 1 , v: echospace ) 164close 165call assert_equal ( & columns - 19 , v: echospace ) 166set showcmd noruler 167call assert_equal ( & columns - 12 , v: echospace ) 168set showcmd ruler 169call assert_equal ( & columns - 29 , v: echospace ) 170set showcmdloc = statusline 171call assert_equal ( & columns - 19 , v: echospace ) 172set showcmdloc = tabline 173call assert_equal ( & columns - 19 , v: echospace ) 174call assert_fails ( 'set showcmdloc=leap' , 'E474:' ) 175call assert_equal ( & columns - 19 , v: echospace ) 176set showcmdloc = last 177call assert_equal ( & columns - 29 , v: echospace ) 178call assert_fails ( 'set showcmdloc=jump' , 'E474:' ) 179call assert_equal ( & columns - 29 , v: echospace ) 180 181set ruler & showcmd & showcmdloc & 182endfunc 183 184func Test_warning_scroll () 185CheckRunVimInTerminal 186let lines =<< trim END 187call test_override('ui_delay', 50) 188set noruler 189set readonly 190undo 191END 192call writefile ( lines , 'XTestWarningScroll' , 'D' ) 193let buf = RunVimInTerminal ( '' , #{ rows : 8 }) 194 195" When the warning comes from a script, messages are scrolled so that the 196" stacktrace is visible. 197call term_sendkeys ( buf , ":source XTestWarningScroll\n" ) 198" only match the final colon in the line that shows the source 199call WaitForAssert ({ ->assert_match ( ':$' , term_getline ( buf , 5 ))}) 200call WaitForAssert ({ ->assert_equal ( 'line 4:W10: Warning: Changing a readonly file' , term_getline ( buf , 6 ))}) 201call WaitForAssert ({ ->assert_equal ( 'Already at oldest change' , term_getline ( buf , 7 ))}) 202call WaitForAssert ({ ->assert_equal ( 'Press ENTER or type command to continue' , term_getline ( buf , 8 ))}) 203call term_sendkeys ( buf , "\n" ) 204 205" When the warning does not come from a script, messages are not scrolled. 206call term_sendkeys ( buf , ":enew\n" ) 207call term_sendkeys ( buf , ":set readonly\n" ) 208call term_sendkeys ( buf , 'u' ) 209call WaitForAssert ({ ->assert_equal ( 'W10: Warning: Changing a readonly file' , term_getline ( buf , 8 ))}) 210call WaitForAssert ({ ->assert_equal ( 'Already at oldest change' , term_getline ( buf , 8 ))}) 211 212" clean up 213call StopVimInTerminal ( buf ) 214endfunc 215 216" Test more-prompt (see :help more-prompt). 217func Test_message_more () 218CheckRunVimInTerminal 219 220let buf = RunVimInTerminal ( '' , { 'rows' : 6 }) 221let chan = buf ->term_getjob () ->job_getchannel () 222call term_sendkeys ( buf , ":call setline(1, range(1, 100))\n" ) 223 224call term_sendkeys ( buf , ":%pfoo\<C-H>\<C-H>\<C-H>#" ) 225call WaitForAssert ({ ->assert_equal ( ':%p#' , term_getline ( buf , 6 ))}) 226call term_sendkeys ( buf , "\n" ) 227call WaitForAssert ({ ->assert_equal ( ' 5 5' , term_getline ( buf , 5 ))}) 228call WaitForAssert ({ ->assert_equal ( '-- More --' , term_getline ( buf , 6 ))}) 229 230call term_sendkeys ( buf , '?' ) 231call WaitForAssert ({ ->assert_equal ( ' 5 5' , term_getline ( buf , 5 ))}) 232call WaitForAssert ({ ->assert_equal ( '-- More -- SPACE/d/j: screen/page/line down, b/u/k: up, q: quit ' , term_getline ( buf , 6 ))}) 233 234" Down a line with j, <CR>, <NL> or <Down>. 235call term_sendkeys ( buf , "j" ) 236call WaitForAssert ({ ->assert_equal ( ' 6 6' , term_getline ( buf , 5 ))}) 237call WaitForAssert ({ ->assert_equal ( '-- More --' , term_getline ( buf , 6 ))}) 238call term_sendkeys ( buf , "\<NL>" ) 239call WaitForAssert ({ ->assert_equal ( ' 7 7' , term_getline ( buf , 5 ))}) 240call term_sendkeys ( buf , "\<CR>" ) 241call WaitForAssert ({ ->assert_equal ( ' 8 8' , term_getline ( buf , 5 ))}) 242call term_sendkeys ( buf , "\<Down>" ) 243call WaitForAssert ({ ->assert_equal ( ' 9 9' , term_getline ( buf , 5 ))}) 244 245" Down a screen with <Space>, f, <C-F> or <PageDown>. 246call term_sendkeys ( buf , 'f' ) 247call WaitForAssert ({ ->assert_equal ( ' 14 14' , term_getline ( buf , 5 ))}) 248call WaitForAssert ({ ->assert_equal ( '-- More --' , term_getline ( buf , 6 ))}) 249call term_sendkeys ( buf , "\<C-F>" ) 250call WaitForAssert ({ ->assert_equal ( ' 19 19' , term_getline ( buf , 5 ))}) 251call term_sendkeys ( buf , ' ' ) 252call WaitForAssert ({ ->assert_equal ( ' 24 24' , term_getline ( buf , 5 ))}) 253call term_sendkeys ( buf , "\<PageDown>" ) 254call WaitForAssert ({ ->assert_equal ( ' 29 29' , term_getline ( buf , 5 ))}) 255 256" Down a page (half a screen) with d. 257call term_sendkeys ( buf , 'd' ) 258call WaitForAssert ({ ->assert_equal ( ' 32 32' , term_getline ( buf , 5 ))}) 259 260" Down all the way with 'G'. 261call term_sendkeys ( buf , 'G' ) 262call WaitForAssert ({ ->assert_equal ( '100 100' , term_getline ( buf , 5 ))}) 263call WaitForAssert ({ ->assert_equal ( 'Press ENTER or type command to continue' , term_getline ( buf , 6 ))}) 264 265" Up a line k, <BS> or <Up>. 266call term_sendkeys ( buf , 'k' ) 267call WaitForAssert ({ ->assert_equal ( ' 99 99' , term_getline ( buf , 5 ))}) 268call term_sendkeys ( buf , "\<BS>" ) 269call WaitForAssert ({ ->assert_equal ( ' 98 98' , term_getline ( buf , 5 ))}) 270call term_sendkeys ( buf , "\<Up>" ) 271call WaitForAssert ({ ->assert_equal ( ' 97 97' , term_getline ( buf , 5 ))}) 272 273" Up a screen with b, <C-B> or <PageUp>. 274call term_sendkeys ( buf , 'b' ) 275call WaitForAssert ({ ->assert_equal ( ' 92 92' , term_getline ( buf , 5 ))}) 276call term_sendkeys ( buf , "\<C-B>" ) 277call WaitForAssert ({ ->assert_equal ( ' 87 87' , term_getline ( buf , 5 ))}) 278call term_sendkeys ( buf , "\<PageUp>" ) 279call WaitForAssert ({ ->assert_equal ( ' 82 82' , term_getline ( buf , 5 ))}) 280 281" Up a page (half a screen) with u. 282call term_sendkeys ( buf , 'u' ) 283call WaitForAssert ({ ->assert_equal ( ' 79 79' , term_getline ( buf , 5 ))}) 284 285" Test <C-F> and <C-B> with different keyboard protocols. 286for [ ctrl_f , ctrl_b ] in [ 287 \[ GetEscCodeCSI27 ( 'f' , 5 ), GetEscCodeCSI27 ( 'b' , 5 )], 288 \[ GetEscCodeCSI27 ( 'F' , 5 ), GetEscCodeCSI27 ( 'B' , 5 )], 289 \[ GetEscCodeCSIu ( 'f' , 5 ), GetEscCodeCSIu ( 'b' , 5 )], 290 \[ GetEscCodeCSIu ( 'F' , 5 ), GetEscCodeCSIu ( 'B' , 5 )], 291 \] 292call ch_sendraw ( chan , ctrl_f ) 293call WaitForAssert ({ ->assert_equal ( ' 84 84' , term_getline ( buf , 5 ))}) 294call ch_sendraw ( chan , ctrl_b ) 295call WaitForAssert ({ ->assert_equal ( ' 79 79' , term_getline ( buf , 5 ))}) 296endfor 297 298" Up all the way with 'g'. 299call term_sendkeys ( buf , 'g' ) 300call WaitForAssert ({ ->assert_equal ( ' 4 4' , term_getline ( buf , 5 ))}) 301call WaitForAssert ({ ->assert_equal ( ':%p#' , term_getline ( buf , 1 ))}) 302call WaitForAssert ({ ->assert_equal ( '-- More --' , term_getline ( buf , 6 ))}) 303 304" All the way down. Pressing f or Ctrl-F should do nothing but pressing 305" space should end the more prompt. 306call term_sendkeys ( buf , 'G' ) 307call WaitForAssert ({ ->assert_equal ( '100 100' , term_getline ( buf , 5 ))}) 308call WaitForAssert ({ ->assert_equal ( 'Press ENTER or type command to continue' , term_getline ( buf , 6 ))}) 309call term_sendkeys ( buf , 'f' ) 310call WaitForAssert ({ ->assert_equal ( '100 100' , term_getline ( buf , 5 ))}) 311call WaitForAssert ({ ->assert_equal ( 'Press ENTER or type command to continue' , term_getline ( buf , 6 ))}) 312call term_sendkeys ( buf , "\<C-F>" ) 313call WaitForAssert ({ ->assert_equal ( '100 100' , term_getline ( buf , 5 ))}) 314call WaitForAssert ({ ->assert_equal ( 'Press ENTER or type command to continue' , term_getline ( buf , 6 ))}) 315call term_sendkeys ( buf , ' ' ) 316call WaitForAssert ({ ->assert_equal ( '100' , term_getline ( buf , 5 ))}) 317 318" Pressing g< shows the previous command output. 319call term_sendkeys ( buf , 'g<' ) 320call WaitForAssert ({ ->assert_equal ( '100 100' , term_getline ( buf , 5 ))}) 321call WaitForAssert ({ ->assert_equal ( 'Press ENTER or type command to continue' , term_getline ( buf , 6 ))}) 322 323" A command line that doesn't print text is appended to scrollback, 324" even if it invokes a nested command line. 325call term_sendkeys ( buf , ":\<C-R>=':'\<CR>:\<CR>g<" ) 326call WaitForAssert ({ ->assert_equal ( '100 100' , term_getline ( buf , 4 ))}) 327call WaitForAssert ({ ->assert_equal ( ':::' , term_getline ( buf , 5 ))}) 328call WaitForAssert ({ ->assert_equal ( 'Press ENTER or type command to continue' , term_getline ( buf , 6 ))}) 329 330call term_sendkeys ( buf , ":%p#\n" ) 331call WaitForAssert ({ ->assert_equal ( ' 5 5' , term_getline ( buf , 5 ))}) 332call WaitForAssert ({ ->assert_equal ( '-- More --' , term_getline ( buf , 6 ))}) 333 334" Stop command output with q, <Esc> or CTRL-C. 335call term_sendkeys ( buf , 'q' ) 336call WaitForAssert ({ ->assert_equal ( '100' , term_getline ( buf , 5 ))}) 337 338" Execute a : command from the more prompt 339call term_sendkeys ( buf , ":%p#\n" ) 340call term_wait ( buf ) 341call WaitForAssert ({ ->assert_equal ( '-- More --' , term_getline ( buf , 6 ))}) 342call term_sendkeys ( buf , ":" ) 343call term_wait ( buf ) 344call WaitForAssert ({ ->assert_equal ( ':' , term_getline ( buf , 6 ))}) 345call term_sendkeys ( buf , "echo 'Hello'\n" ) 346call term_wait ( buf ) 347call WaitForAssert ({ ->assert_equal ( 'Hello ' , term_getline ( buf , 5 ))}) 348 349call StopVimInTerminal ( buf ) 350endfunc 351 352func Test_message_more_recording () 353CheckRunVimInTerminal 354let buf = RunVimInTerminal ( '' , { 'rows' : 6 }) 355call term_sendkeys ( buf , ":call setline(1, range(1, 100))\n" ) 356call term_sendkeys ( buf , ":%p\n" ) 357call WaitForAssert ({ ->assert_equal ( '-- More --' , term_getline ( buf , 6 ))}) 358call term_sendkeys ( buf , 'G' ) 359call WaitForAssert ({ ->assert_equal ( 'Press ENTER or type command to continue' , term_getline ( buf , 6 ))}) 360 361" Hitting 'q' at the end of the more prompt should not start recording 362call term_sendkeys ( buf , 'q' ) 363call WaitForAssert ({ ->assert_equal ( 5 , term_getcursor ( buf )[ 0 ])}) 364" Hitting 'k' now should move the cursor up instead of recording keys 365call term_sendkeys ( buf , 'k' ) 366call WaitForAssert ({ ->assert_equal ( 4 , term_getcursor ( buf )[ 0 ])}) 367 368call StopVimInTerminal ( buf ) 369endfunc 370 371" Test more-prompt scrollback 372func Test_message_more_scrollback () 373CheckScreendump 374CheckRunVimInTerminal 375 376let lines =<< trim END 377set t_ut= 378hi Normal ctermfg=15 ctermbg=0 379for i in range(100) 380echo i 381endfor 382END 383call writefile ( lines , 'XmoreScrollback' , 'D' ) 384let buf = RunVimInTerminal ( '-S XmoreScrollback' , { 'rows' : 10 }) 385call VerifyScreenDump ( buf , 'Test_more_scrollback_1' , {}) 386 387call term_sendkeys ( buf , 'f' ) 388call TermWait ( buf ) 389call term_sendkeys ( buf , 'b' ) 390call VerifyScreenDump ( buf , 'Test_more_scrollback_2' , {}) 391 392call term_sendkeys ( buf , "\<C-F>" ) 393call TermWait ( buf ) 394call term_sendkeys ( buf , "\<C-B>" ) 395call VerifyScreenDump ( buf , 'Test_more_scrollback_2' , {}) 396 397call term_sendkeys ( buf , 'q' ) 398call TermWait ( buf ) 399call StopVimInTerminal ( buf ) 400endfunc 401 402func Test_message_not_cleared_after_mode () 403CheckScreendump 404CheckRunVimInTerminal 405 406let lines =<< trim END 407nmap <silent> gx :call DebugSilent('normal')<CR> 408vmap <silent> gx :call DebugSilent('visual')<CR> 409function DebugSilent(arg) 410echomsg "from DebugSilent" a:arg 411endfunction 412set showmode 413set cmdheight=1 414call test_settime(1) 415call setline(1, ['one', 'NoSuchFile', 'three']) 416END 417call writefile ( lines , 'XmessageMode' , 'D' ) 418let buf = RunVimInTerminal ( '-S XmessageMode' , { 'rows' : 10 }) 419 420call term_sendkeys ( buf , 'gx' ) 421call TermWait ( buf ) 422call VerifyScreenDump ( buf , 'Test_message_not_cleared_after_mode_1' , {}) 423 424" removing the mode message used to also clear the intended message 425call term_sendkeys ( buf , 'vEgx' ) 426call TermWait ( buf ) 427call VerifyScreenDump ( buf , 'Test_message_not_cleared_after_mode_2' , {}) 428 429" removing the mode message used to also clear the error message 430call term_sendkeys ( buf , ":set cmdheight=2\<CR>" ) 431call term_sendkeys ( buf , '2GvEgf' ) 432call TermWait ( buf ) 433call VerifyScreenDump ( buf , 'Test_message_not_cleared_after_mode_3' , {}) 434 435call StopVimInTerminal ( buf ) 436endfunc 437 438func Test_mode_cleared_after_silent_message () 439CheckScreendump 440CheckRunVimInTerminal 441 442let lines =<< trim END 443edit XsilentMessageMode.txt 444call setline(1, 'foobar') 445autocmd TextChanged * silent update 446END 447call writefile ( lines , 'XsilentMessageMode' , 'D' ) 448let buf = RunVimInTerminal ( '-S XsilentMessageMode' , { 'rows' : 10 }) 449 450call term_sendkeys ( buf , 'v' ) 451call WaitForAssert ({ ->assert_match ( 'VISUAL.*\d\+\s\+\d' , term_getline ( buf , 10 ))}, 1000 ) 452call VerifyScreenDump ( buf , 'Test_mode_cleared_after_silent_message_1' , {}) 453 454call term_sendkeys ( buf , 'd' ) 455call TermWait ( buf ) 456call VerifyScreenDump ( buf , 'Test_mode_cleared_after_silent_message_2' , {}) 457 458call StopVimInTerminal ( buf ) 459call delete ( 'XsilentMessageMode.txt' ) 460endfunc 461 462" Test verbose message before echo command 463func Test_echo_verbose_system () 464CheckScreendump 465CheckRunVimInTerminal 466CheckUnix " needs the " seq" command 467CheckNotMac " the macos TMPDIR is too long for snapshot testing 468 469let buf = RunVimInTerminal ( '' , { 'rows' : 10 }) 470" give it some time to handle DECRQM response 471call TermWait ( buf , 50 ) 472call term_sendkeys ( buf , ":4 verbose echo system('seq 20')\<CR>" ) 473" Note that the screendump is filtered to remove the name of the temp file 474call VerifyScreenDump ( buf , 'Test_verbose_system_1' , {}) 475 476" display a page and go back, results in exactly the same view 477call term_sendkeys ( buf , ' ' ) 478call TermWait ( buf , 50 ) 479call term_sendkeys ( buf , 'b' ) 480call VerifyScreenDump ( buf , 'Test_verbose_system_1' , {}) 481 482" do the same with 'cmdheight' set to 2 483call term_sendkeys ( buf , 'q' ) 484call TermWait ( buf ) 485call term_sendkeys ( buf , ":set ch=2\<CR>" ) 486call TermWait ( buf ) 487call term_sendkeys ( buf , ":4 verbose echo system('seq 20')\<CR>" ) 488call VerifyScreenDump ( buf , 'Test_verbose_system_2' , {}) 489 490call term_sendkeys ( buf , ' ' ) 491call TermWait ( buf , 50 ) 492call term_sendkeys ( buf , 'b' ) 493call VerifyScreenDump ( buf , 'Test_verbose_system_2' , {}) 494 495call term_sendkeys ( buf , 'q' ) 496call TermWait ( buf ) 497call StopVimInTerminal ( buf ) 498endfunc 499 500 501func Test_ask_yesno () 502CheckRunVimInTerminal 503let buf = RunVimInTerminal ( '' , { 'rows' : 6 }) 504call term_sendkeys ( buf , ":call setline(1, range(1, 2))\n" ) 505 506call term_sendkeys ( buf , ":2,1s/^/n/\n" ) 507call WaitForAssert ({ ->assert_equal ( 'Backwards range given, OK to swap (y/n)?' , term_getline ( buf , 6 ))}) 508call term_sendkeys ( buf , "n" ) 509call WaitForAssert ({ ->assert_match ( '^Backwards range given, OK to swap (y/n)?n *1,1 *All$' , term_getline ( buf , 6 ))}) 510call WaitForAssert ({ ->assert_equal ( '1' , term_getline ( buf , 1 ))}) 511 512call term_sendkeys ( buf , ":2,1s/^/Esc/\n" ) 513call WaitForAssert ({ ->assert_equal ( 'Backwards range given, OK to swap (y/n)?' , term_getline ( buf , 6 ))}) 514call term_sendkeys ( buf , "\<Esc>" ) 515call WaitForAssert ({ ->assert_match ( '^Backwards range given, OK to swap (y/n)?n *1,1 *All$' , term_getline ( buf , 6 ))}) 516call WaitForAssert ({ ->assert_equal ( '1' , term_getline ( buf , 1 ))}) 517 518call term_sendkeys ( buf , ":2,1s/^/y/\n" ) 519call WaitForAssert ({ ->assert_equal ( 'Backwards range given, OK to swap (y/n)?' , term_getline ( buf , 6 ))}) 520call term_sendkeys ( buf , "y" ) 521call WaitForAssert ({ ->assert_match ( '^Backwards range given, OK to swap (y/n)?y *2,1 *All$' , term_getline ( buf , 6 ))}) 522call WaitForAssert ({ ->assert_equal ( 'y1' , term_getline ( buf , 1 ))}) 523call WaitForAssert ({ ->assert_equal ( 'y2' , term_getline ( buf , 2 ))}) 524 525call StopVimInTerminal ( buf ) 526endfunc 527 528func Test_null () 529echom v: _null_list 530echom v: _null_dict 531echom v: _null_blob 532echom v: _null_string 533" Nvim doesn't have NULL functions 534" echom test_null_function() 535" Nvim doesn't have NULL partials 536" echom test_null_partial() 537if has ( 'job' ) 538echom test_null_job () 539echom test_null_channel () 540endif 541endfunc 542 543func Test_mapping_at_hit_return_prompt () 544nnoremap < C-B > :echo "hit ctrl-b"< CR > 545call feedkeys ( ":ls\<CR>" , "xt" ) 546call feedkeys ( "\<*C-B>" , "xt" ) 547call assert_match ( 'hit ctrl-b' , Screenline ( & lines - 1 )) 548nunmap <C-B> 549endfunc 550 551func Test_quit_long_message () 552CheckScreendump 553 554let content =<< trim END 555echom range(9999)->join("\x01") 556END 557call writefile ( content , 'Xtest_quit_message' , 'D' ) 558let buf = RunVimInTerminal ( '-S Xtest_quit_message' , #{ rows : 10 , wait_for_ruler : 0 }) 559call WaitForAssert ({ ->assert_match ( '^-- More --' , term_getline ( buf , 10 ))}) 560call term_sendkeys ( buf , "q" ) 561call VerifyScreenDump ( buf , 'Test_quit_long_message' , {}) 562 563" clean up 564call StopVimInTerminal ( buf ) 565endfunc 566 567" this was missing a terminating NUL 568func Test_echo_string_partial () 569function CountSpaces () 570endfunction 571call assert_equal ( "function('CountSpaces', [{'ccccccccccc': ['ab', 'cd'], 'aaaaaaaaaaa': v:false, 'bbbbbbbbbbbb': ''}])" , string ( function ( 'CountSpaces' , [#{ aaaaaaaaaaa : v: false , bbbbbbbbbbbb : '' , ccccccccccc : [ 'ab' , 'cd' ]}]))) 572endfunc 573 574" Test that fileinfo is shown properly when 'cmdheight' has just decreased 575" due to switching tabpage and 'shortmess' doesn't contain 'o' or 'O'. 576func Test_fileinfo_tabpage_cmdheight () 577CheckRunVimInTerminal 578 579let content =<< trim END 580set shortmess-=o 581set shortmess-=O 582set shortmess-=F 583tabnew 584set cmdheight=2 585tabprev 586edit Xfileinfo.txt 587END 588 589call writefile ( content , 'Xtest_fileinfo_tabpage_cmdheight' , 'D' ) 590let buf = RunVimInTerminal ( '-S Xtest_fileinfo_tabpage_cmdheight' , #{ rows : 6 }) 591call WaitForAssert ({ ->assert_match ( '^"Xfileinfo.txt" \[New\]' , term_getline ( buf , 6 ))}) 592 593" clean up 594call StopVimInTerminal ( buf ) 595endfunc 596 597" Message output was previously overwritten by the fileinfo display, shown 598" when switching buffers. If a buffer is switched to, then a message if 599" echoed, we should show the message, rather than overwriting it with 600" fileinfo. 601func Test_fileinfo_after_echo () 602CheckScreendump 603 604let content =<< trim END 605file a.txt 606 607hide edit b.txt 608call setline(1, "hi") 609setlocal modified 610 611hide buffer a.txt 612 613autocmd CursorHold * buf b.txt | w | echo "'b' written" 614END 615 616call writefile ( content , 'Xtest_fileinfo_after_echo' ) 617let buf = RunVimInTerminal ( '-S Xtest_fileinfo_after_echo' , #{ rows : 6 }) 618call term_sendkeys ( buf , ":set updatetime=50\<CR>" ) 619call term_sendkeys ( buf , "0$" ) 620call VerifyScreenDump ( buf , 'Test_fileinfo_after_echo' , {}) 621 622call term_sendkeys ( buf , ":q\<CR>" ) 623 624" clean up 625call StopVimInTerminal ( buf ) 626call delete ( 'Xtest_fileinfo_after_echo' ) 627call delete ( 'b.txt' ) 628endfunc 629 630func Test_cmdheight_zero () 631enew 632set cmdheight = 0 633set showcmd 634redraw ! 635 636echo 'test echo' 637call assert_equal ( 116 , screenchar ( & lines , 1 )) 638redraw ! 639 640echomsg 'test echomsg' 641call assert_equal ( 116 , screenchar ( & lines , 1 )) 642redraw ! 643 644call feedkeys ( ":ls\<CR>" , "xt" ) 645call assert_equal ( ':ls' , Screenline ( & lines - 1 )) 646redraw ! 647 648let char = getchar ( 0 ) 649call assert_match ( char , 0 ) 650 651" Check change/restore cmdheight when macro 652call feedkeys ( "qa" , "xt" ) 653call assert_equal ( 0 , & cmdheight ) 654call feedkeys ( "q" , "xt" ) 655call assert_equal ( 0 , & cmdheight ) 656 657call setline ( 1 , 'somestring' ) 658call feedkeys ( "y" , "n" ) 659 %s /somestring/otherstring/gc 660call assert_equal ( 'otherstring' , getline ( 1 )) 661 662call feedkeys ( "g\<C-g>" , "xt" ) 663call assert_match ( 664 \'Col 1 of 11; Line 1 of 1; Word 1 of 1' , 665 \Screenline ( & lines )) 666 667" Check split behavior 668for i in range ( 1 , 10 ) 669split 670endfor 671only 672call assert_equal ( 0 , & cmdheight ) 673 674" Check that pressing ":" should not scroll a window 675" Check for what patch 9.0.0115 fixes 676botright 10 new 677call setline ( 1 , range ( 12 )) 6787 679call feedkeys ( ":\"\<C-R>=line('w0')\<CR>\<CR>" , "xt" ) 680call assert_equal ( '"1' , @:) 681 682bwipe ! 683bwipe ! 684set cmdheight & 685set showcmd & 686tabnew 687tabonly 688endfunc 689 690func Test_messagesopt_history () 691" After setting 'messagesopt' "history" to 2 and outputting a message 4 times 692" with :echomsg, is the number of output lines of :messages 2? 693set messagesopt = hit-enter,history:2 694echomsg 'foo' 695echomsg 'bar' 696echomsg 'baz' 697echomsg 'foobar' 698call assert_equal ([ 'baz' , 'foobar' ], GetMessages ()) 699 700" When the number of messages is 10 and 'messagesopt' "history" is changed to 701" 5, is the number of output lines of :messages 5? 702set messagesopt = hit-enter,history:10 703for num in range ( 1 , 10 ) 704echomsg num 705endfor 706set messagesopt = hit-enter,history:5 707call assert_equal ( 5 , len ( GetMessages ())) 708 709" Check empty list 710set messagesopt = hit-enter,history:0 711call assert_true ( empty ( GetMessages ())) 712 713set messagesopt & 714endfunc 715 716func Test_messagesopt_wait () 717CheckRunVimInTerminal 718 719let buf = RunVimInTerminal ( '' , { 'rows' : 6 , 'cols' : 45 }) 720call term_sendkeys ( buf , ":set cmdheight=1\n" ) 721 722" Check hit-enter prompt 723call term_sendkeys ( buf , ":set messagesopt=hit-enter,history:500\n" ) 724call term_sendkeys ( buf , ":echo 'foo' | echo 'bar' | echo 'baz'\n" ) 725call WaitForAssert ({ ->assert_equal ( 'Press ENTER or type command to continue' , term_getline ( buf , 6 ))}) 726 727" Check no hit-enter prompt when "wait:" is set 728call term_sendkeys ( buf , ":set messagesopt=wait:100,history:500\n" ) 729call term_sendkeys ( buf , ":echo 'foo' | echo 'bar' | echo 'baz'\n" ) 730call WaitForAssert ({ ->assert_equal ( ' 0,0-1 All' , term_getline ( buf , 6 ))}) 731 732" clean up 733call StopVimInTerminal ( buf ) 734endfunc 735 736" Check that using a long 'formatprg' doesn't cause a hit-enter prompt or 737" wrong cursor position. 738func Test_long_formatprg_no_hit_enter () 739CheckScreendump 740CheckExecutable sed 741 742let lines =<< trim END 743setlocal scrolloff=0 744call setline(1, range(1, 40)) 745let &l:formatprg = $'sed{repeat(' ', &columns)}p' 746normal 20Gmz 747normal 10Gzt 748END 749call writefile ( lines , 'XtestLongFormatprg' , 'D' ) 750let buf = RunVimInTerminal ( '-S XtestLongFormatprg' , #{ rows : 10 }) 751call VerifyScreenDump ( buf , 'Test_long_formatprg_no_hit_enter_1' , {}) 752call term_sendkeys ( buf , 'gq2j' ) 753call VerifyScreenDump ( buf , 'Test_long_formatprg_no_hit_enter_2' , {}) 754call term_sendkeys ( buf , ":messages\<CR>" ) 755call VerifyScreenDump ( buf , 'Test_long_formatprg_no_hit_enter_3' , {}) 756 757" clean up 758call StopVimInTerminal ( buf ) 759endfunc 760 761" A message shown while a mapping is still being processed must not eat the 762" mapping's remaining keys. 763" If a mapping starts cmdline after multiline messages exceeding 'cmdheight', 764" the messages should still be visible. 765func Test_hit_enter_during_mapping () 766CheckRunVimInTerminal 767 768let lines =<< trim END 769set ruler 770call setline(1, range(1, 20)) 771" The 8-line :echo leads to a hit-enter prompt. 772nnoremap X :echo "a\nb\nc\nd\ne\nf\ng\nh"<CR>gg 773nnoremap \b :echo "a\nb\nc\nd\ne\nf\ng\nh"<CR>:b<Space> 774normal! 10G 775END 776call writefile ( lines , 'XtestHitEnterMap' , 'D' ) 777let buf = RunVimInTerminal ( '-S XtestHitEnterMap' , #{ rows : 10 }) 778call WaitForAssert ({ ->assert_match ( ' 10,1 ' , term_getline ( buf , 10 ))}) 779 780call term_sendkeys ( buf , "X" ) 781" Without the fix the hit-enter prompt eats the mapping's "g" keys and the 782" cursor stays put. With the fix "gg" runs and moves the cursor to line 1. 783call WaitForAssert ({ ->assert_match ( ' 1,1 ' , term_getline ( buf , 10 ))}) 784call assert_notmatch ( 'Press ENTER' , term_getline ( buf , 10 )) 785 786call term_sendkeys ( buf , '\b' ) 787call WaitForAssert ({ ->assert_match ( '^:b ' , term_getline ( buf , 10 ))}) 788call assert_match ( '^a *$' , term_getline ( buf , 2 )) 789call assert_match ( '^b *$' , term_getline ( buf , 3 )) 790call assert_match ( '^c *$' , term_getline ( buf , 4 )) 791call assert_match ( '^d *$' , term_getline ( buf , 5 )) 792call assert_match ( '^e *$' , term_getline ( buf , 6 )) 793call assert_match ( '^f *$' , term_getline ( buf , 7 )) 794call assert_match ( '^g *$' , term_getline ( buf , 8 )) 795call assert_match ( '^h *$' , term_getline ( buf , 9 )) 796 797" clean up 798call StopVimInTerminal ( buf ) 799endfunc 800 801" Test that fileinfo is shown after deleting the last listed buffer with :bd 802func Test_fileinfo_after_last_bd () 803CheckRunVimInTerminal 804 805let content =<< trim END 806set shortmess-=F 807edit xxx 808edit yyy 809END 810 811call writefile ( content , 'Xtest_fileinfo_last_bd' , 'D' ) 812let buf = RunVimInTerminal ( '-S Xtest_fileinfo_last_bd' , #{ rows : 10 }) 813call WaitForAssert ({ ->assert_match ( '^"yyy" \[New\]' , term_getline ( buf , 10 ))}) 814 815call term_sendkeys ( buf , ":bd\<CR>" ) 816call WaitForAssert ({ ->assert_match ( '^"xxx" \[New\]' , term_getline ( buf , 10 ))}) 817 818call term_sendkeys ( buf , ":bd\<CR>" ) 819call WaitForAssert ({ ->assert_match ( '^\"\[No Name\]\" --No lines in buffer--' , term_getline ( buf , 10 ))}) 820 821" clean up 822call StopVimInTerminal ( buf ) 823endfunc 824 825func Test_undo_messages () 826new 827 828" Normal undo/redo messages 829redir => result 830call setline ( 1 , 'foo' ) 831undo 832undo 833redo 834redo 835redir END 836let msg_list = split ( result , "\n" ) 837call assert_match ( "^1 line less; before #1" , msg_list [ 0 ]) 838call assert_equal ( "Already at oldest change" , msg_list [ 1 ]) 839call assert_match ( "^1 more line; after #1" , msg_list [ 2 ]) 840call assert_equal ( "Already at newest change" , msg_list [ 3 ]) 841 842" Ignore undo/redo messages 843redir => result 844set shortmess += u 845call setline ( 1 , 'foo' ) 846undo 847undo 848redo 849redo 850redir END 851let msg_list = split ( result , "\n" ) 852call assert_equal ([], msg_list ) 853set shortmess & 854 855" undo_time() path: :earlier and :later go through a separate 856" message site than u_doit(); make sure SHM_UNDO suppresses it too. 857enew ! 858call setline ( 1 , 'a' ) 859call setline ( 1 , 'b' ) 860call setline ( 1 , 'c' ) 861 862redir => result 863earlier 1 864earlier 999 865earlier 999 866later 1 867later 999 868redir END 869let msg_list = split ( result , "\n" ) 870call assert_match ( '^1 line less; before #' , msg_list [ 0 ]) 871call assert_match ( '^1 changes; before #' , msg_list [ 1 ]) 872call assert_match ( '^1 changes; before #' , msg_list [ 2 ]) 873call assert_match ( '^1 more line; after #' , msg_list [ 3 ]) 874call assert_equal ( 'Already at newest change' , msg_list [ 4 ]) 875 876set shortmess += u 877redir => result 878earlier 1 879earlier 999 880later 1 881later 999 882later 999 883redir END 884call assert_equal ([], split ( result , "\n" )) 885 886set shortmess & 887bwipe ! 888endfunc 889 890" vim: shiftwidth=2 sts=2 expandtab