view src/testdir/test_winbar.vim @ 32697:e5cd5e8627da v9.0.1679

patch 9.0.1679: Cleanup Tests from leftover files Commit: https://github.com/vim/vim/commit/84bc00e9b52b1174888f2f696f8b628a83c49988 Author: Christian Brabandt <cb@256bit.org> Date: Thu Jul 13 11:45:54 2023 +0200 patch 9.0.1679: Cleanup Tests from leftover files Problem: Tests may leave leftover files around Solution: Clean up tests and remove files There were a few failures in 'linux (huge, gcc, testgui, true, true)' e.g. here: https://github.com/vim/vim/actions/runs/5497376153/jobs/10018060156 ,---- | Error detected while processing command line..script /home/runner/work/vim/vim/src/testdir/runtest.vim[585]..function RunTheTest[54]..Test_lvimgrep_crash[16]..TestTimeout[12]..VimLeavePre Autocommands for "*"..function EarlyExit[7]..FinishTesting: | line 70: | E445: Other window contains changes | E937: Attempt to delete a buffer that is in use: Xtest_stable_xxd.txt | E937: Attempt to delete a buffer that is in use: Xtest_stable_xxd.txt | E937: Attempt to delete a buffer that is in use: Xtest_stable_xxd.txtmalloc(): unsorted double linked list corrupted `---- Which is puzzling, because the Xtest_stable_xxd file should have been long gone after test_crypt.vim is run (and definitely no longer be staying around in test_quickfix.vim). So try to clean up properly after a test script is run, just in case any X<file> is still around. During testing, a found a few leftover files, which I also fixed in the relevant test-file. Unfortunately, the test workflow 'linux (huge, gcc, testgui, true, true)' now seems to fail with 'E1230: Encryption: sodium_mlock()' in test_crypt.vim. Hopefully this is only temporary.
author Christian Brabandt <cb@256bit.org>
date Tue, 08 Aug 2023 20:45:05 +0200
parents 360f286b5869
children
line wrap: on
line source

" Test WinBar

source check.vim
CheckFeature menu

source shared.vim
source screendump.vim

func Test_add_remove_menu()
  new
  amenu 1.10 WinBar.Next :let g:did_next = 11<CR>
  amenu 1.20 WinBar.Cont :let g:did_cont = 12<CR>
  redraw
  call assert_match('Next    Cont', Screenline(1))

  emenu WinBar.Next
  call assert_equal(11, g:did_next)
  emenu WinBar.Cont
  call assert_equal(12, g:did_cont)

  wincmd w
  call assert_fails('emenu WinBar.Next', 'E334:')
  wincmd p

  aunmenu WinBar.Next
  aunmenu WinBar.Cont
  close
endfunc

" Create a WinBar with three buttons.
" Columns of the button edges:
" _Next_  _Cont_  _Close_
" 2    7  10  15  18   24
func SetupWinbar()
  amenu 1.10 WinBar.Next :let g:did_next = 11<CR>
  amenu 1.20 WinBar.Cont :let g:did_cont = 12<CR>
  amenu 1.30 WinBar.Close :close<CR>
  redraw
  call assert_match('Next    Cont    Close', Screenline(1))
endfunc

func Test_click_in_winbar()
  new
  call SetupWinbar()
  let save_mouse = &mouse
  set mouse=a

  let g:did_next = 0
  let g:did_cont = 0
  for col in [1, 8, 9, 16, 17, 25, 26]
    call test_setmouse(1, col)
    call feedkeys("\<LeftMouse>", "xt")
    call assert_equal(0, g:did_next, 'col ' .. col)
    call assert_equal(0, g:did_cont, 'col ' .. col)
  endfor

  for col in range(2, 7)
    let g:did_next = 0
    call test_setmouse(1, col)
    call feedkeys("\<LeftMouse>", "xt")
    call assert_equal(11, g:did_next, 'col ' .. col)
  endfor

  for col in range(10, 15)
    let g:did_cont = 0
    call test_setmouse(1, col)
    call feedkeys("\<LeftMouse>", "xt")
    call assert_equal(12, g:did_cont, 'col ' .. col)
  endfor

  let wincount = winnr('$')
  call test_setmouse(1, 20)
  call feedkeys("\<LeftMouse>", "xt")
  call assert_equal(wincount - 1, winnr('$'))

  let &mouse = save_mouse
endfunc

func Test_click_in_other_winbar()
  new
  call SetupWinbar()
  let save_mouse = &mouse
  set mouse=a
  let winid = win_getid()

  split
  let [row, col] = win_screenpos(winid)

  " Click on Next button in other window
  let g:did_next = 0
  call test_setmouse(row, 5)
  call feedkeys("\<LeftMouse>", "xt")
  call assert_equal(11, g:did_next)

  " Click on Cont button in other window from Visual mode
  let g:did_cont = 0
  call setline(1, 'select XYZ here')
  call test_setmouse(row, 12)
  call feedkeys("0fXvfZ\<LeftMouse>x", "xt")
  call assert_equal(12, g:did_cont)
  call assert_equal('select  here', getline(1))

  " Click on Close button in other window
  let wincount = winnr('$')
  let winid = win_getid()
  call test_setmouse(row, 20)
  call feedkeys("\<LeftMouse>", "xt")
  call assert_equal(wincount - 1, winnr('$'))
  call assert_equal(winid, win_getid())

  bwipe!
endfunc

func Test_redraw_after_scroll()
  new
  amenu 1.10 WinBar.Next :let g:did_next = 11<CR>
  redraw
  call assert_equal("  Next", Screenline(1))
  echo "some\nmore"
  redraw
  call assert_equal("  Next", Screenline(1))
  bwipe!
endfunc

func Test_winbar_not_visible()
  CheckScreendump

  let lines =<< trim END
      split
      nnoremenu WinBar.Test :test
      set winminheight=0
      wincmd j
      wincmd _
  END
  call writefile(lines, 'XtestWinbarNotVisible', 'D')
  let buf = RunVimInTerminal('-S XtestWinbarNotVisible', #{rows: 10})
  call VerifyScreenDump(buf, 'Test_winbar_not_visible', {})

  " clean up
  call StopVimInTerminal(buf)
endfunction

func Test_winbar_not_visible_custom_statusline()
  CheckScreendump

  let lines =<< trim END
      split
      nnoremenu WinBar.Test :test
      set winminheight=0
      set statusline=abcde
      wincmd j
      wincmd _
  END
  call writefile(lines, 'XtestWinbarNotVisible', 'D')
  let buf = RunVimInTerminal('-S XtestWinbarNotVisible', #{rows: 10})
  call VerifyScreenDump(buf, 'Test_winbar_not_visible_custom_statusline', {})

  " clean up
  call StopVimInTerminal(buf)
endfunction

func Test_drag_statusline_with_winbar()
  call SetupWinbar()
  let save_mouse = &mouse
  set mouse=a
  set laststatus=2

  call test_setmouse(&lines - 1, 1)
  call feedkeys("\<LeftMouse>", 'xt')
  call test_setmouse(&lines - 2, 1)
  call feedkeys("\<LeftDrag>", 'xt')
  call assert_equal(2, &cmdheight)

  call test_setmouse(&lines - 2, 1)
  call feedkeys("\<LeftMouse>", 'xt')
  call test_setmouse(&lines - 3, 1)
  call feedkeys("\<LeftDrag>", 'xt')
  call assert_equal(3, &cmdheight)

  call test_setmouse(&lines - 3, 1)
  call feedkeys("\<LeftMouse>", 'xt')
  call test_setmouse(&lines - 1, 1)
  call feedkeys("\<LeftDrag>", 'xt')
  call assert_equal(1, &cmdheight)

  let &mouse = save_mouse
  set laststatus&
endfunc

" vim: shiftwidth=2 sts=2 expandtab