neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

test_messages.vim (26167B)


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