neovim

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

test_suspend.vim (1991B)


      1 " Test :suspend
      2 
      3 source shared.vim
      4 source term_util.vim
      5 
      6 func CheckSuspended(buf, fileExists)
      7  call WaitForAssert({-> assert_match('[$#] $', term_getline(a:buf, '.'))})
      8 
      9  if a:fileExists
     10    call assert_equal(['foo'], readfile('Xfoo'))
     11  else
     12    " Without 'autowrite', buffer should not be written.
     13    call assert_equal(0, filereadable('Xfoo'))
     14  endif
     15 
     16  call term_sendkeys(a:buf, "fg\<CR>\<C-L>")
     17  call WaitForAssert({-> assert_equal('  1 foo', term_getline(a:buf, '.'))})
     18 endfunc
     19 
     20 func Test_suspend()
     21  if !has('terminal') || !executable('/bin/sh')
     22    return
     23  endif
     24 
     25  let buf = term_start('/bin/sh')
     26  " Wait for shell prompt.
     27  call WaitForAssert({-> assert_match('[$#] $', term_getline(buf, '.'))})
     28 
     29  call term_sendkeys(buf, GetVimCommandClean()
     30        \               . " -X"
     31        \               . " -c 'set nu'"
     32        \               . " -c 'call setline(1, \"foo\")'"
     33        \               . " Xfoo\<CR>")
     34  " Cursor in terminal buffer should be on first line in spawned vim.
     35  call WaitForAssert({-> assert_equal('  1 foo', term_getline(buf, '.'))})
     36 
     37  for suspend_cmd in [":suspend\<CR>",
     38        \             ":stop\<CR>",
     39        \             ":suspend!\<CR>",
     40        \             ":stop!\<CR>",
     41        \             "\<C-Z>"]
     42    " Suspend and wait for shell prompt.
     43    call term_sendkeys(buf, suspend_cmd)
     44    call CheckSuspended(buf, 0)
     45  endfor
     46 
     47  " Test that :suspend! with 'autowrite' writes content of buffers if modified.
     48  call term_sendkeys(buf, ":set autowrite\<CR>")
     49  call assert_equal(0, filereadable('Xfoo'))
     50  call term_sendkeys(buf, ":suspend\<CR>")
     51  " Wait for shell prompt.
     52  call CheckSuspended(buf, 1)
     53 
     54  " Quit gracefully to dump coverage information.
     55  call term_sendkeys(buf, ":qall!\<CR>")
     56  call TermWait(buf)
     57  " Wait until Vim actually exited and shell shows a prompt
     58  call WaitForAssert({-> assert_match('[$#] $', term_getline(buf, '.'))})
     59  call StopShellInTerminal(buf)
     60 
     61  exe buf . 'bwipe!'
     62  call delete('Xfoo')
     63 endfunc