" Test for 'scroll', 'scrolloff', 'smoothscroll', etc.
source check.vim
source screendump.vim
source mouse.vim
func Test_reset_scroll()
let scr = &l:scroll
setlocal scroll=1
setlocal scroll&
call assert_equal(scr, &l:scroll)
setlocal scroll=1
setlocal scroll=0
call assert_equal(scr, &l:scroll)
try
execute 'setlocal scroll=' . (winheight(0) + 1)
" not reached
call assert_false(1)
catch
call assert_exception('E49:')
endtry
split
let scr = &l:scroll
setlocal scroll=1
setlocal scroll&
call assert_equal(scr, &l:scroll)
setlocal scroll=1
setlocal scroll=0
call assert_equal(scr, &l:scroll)
quit!
endfunc
func Test_scolloff_even_line_count()
new
resize 6
setlocal scrolloff=3
call setline(1, range(20))
normal 2j
call assert_equal(1, getwininfo(win_getid())[0].topline)
normal j
call assert_equal(1, getwininfo(win_getid())[0].topline)
normal j
call assert_equal(2, getwininfo(win_getid())[0].topline)
normal j
call assert_equal(3, getwininfo(win_getid())[0].topline)
bwipe!
endfunc
func Test_mouse_scroll_inactive_with_cursorbind()
for scb in [0, 1]
for so in [0, 1, 2]
let msg = $'scb={scb} so={so}'
new | only
let w1 = win_getid()
setlocal cursorbind
let &l:scb = scb
let &l:so = so
call setline(1, range(101, 109))
rightbelow vnew
let w2 = win_getid()
setlocal cursorbind
let &l:scb = scb
let &l:so = so
call setline(1, range(101, 109))
normal! $
call assert_equal(3, col('.', w1), msg)
call assert_equal(3, col('.', w2), msg)
call test_setmouse(1, 1)
call feedkeys("\<ScrollWheelDown>", 'xt')
call assert_equal(4, line('w0', w1), msg)
call assert_equal(4 + so, line('.', w1), msg)
call assert_equal(1, line('w0', w2), msg)
call assert_equal(1, line('.', w2), msg)
call feedkeys("\<ScrollWheelDown>", 'xt')
call assert_equal(7, line('w0', w1), msg)
call assert_equal(7 + so, line('.', w1), msg)
call assert_equal(1, line('w0', w2), msg)
call assert_equal(1, line('.', w2), msg)
call feedkeys("\<ScrollWheelUp>", 'xt')
call assert_equal(4, line('w0', w1), msg)
call assert_equal(7 + so, line('.', w1), msg)
call assert_equal(1, line('w0', w2), msg)
call assert_equal(1, line('.', w2), msg)
call feedkeys("\<ScrollWheelUp>", 'xt')
call assert_equal(1, line('w0', w1), msg)
call assert_equal(7 + so, line('.', w1), msg)
call assert_equal(1, line('w0', w2), msg)
call assert_equal(1, line('.', w2), msg)
normal! 0
call assert_equal(1, line('.', w1), msg)
call assert_equal(1, col('.', w1), msg)
call assert_equal(1, line('.', w2), msg)
call assert_equal(1, col('.', w2), msg)
bwipe!
bwipe!
endfor
endfor
endfunc
func Test_CtrlE_CtrlY_stop_at_end()
enew
call setline(1, ['one', 'two'])
set number
exe "normal \<C-Y>"
call assert_equal([" 1 one "], ScreenLines(1, 10))
exe "normal \<C-E>\<C-E>\<C-E>"
call assert_equal([" 2 two "], ScreenLines(1, 10))
bwipe!
set nonumber
endfunc
func Test_smoothscroll_CtrlE_CtrlY()
CheckScreendump
let lines =<< trim END
vim9script
setline(1, [
'line one',
'word '->repeat(