aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/functional/autocmd/winscrolled_spec.lua92
1 files changed, 52 insertions, 40 deletions
diff --git a/test/functional/autocmd/winscrolled_spec.lua b/test/functional/autocmd/winscrolled_spec.lua
index 1ef5a37479..01c2631b62 100644
--- a/test/functional/autocmd/winscrolled_spec.lua
+++ b/test/functional/autocmd/winscrolled_spec.lua
@@ -3,60 +3,72 @@ local helpers = require('test.functional.helpers')(after_each)
local clear = helpers.clear
local eq = helpers.eq
local eval = helpers.eval
-local source = helpers.source
+local command = helpers.command
+local feed = helpers.feed
+local meths = helpers.meths
describe('WinScrolled', function()
- before_each(clear)
+ local win_id
+
+ before_each(function()
+ clear()
+ win_id = meths.get_current_win().id
+ command(string.format('autocmd WinScrolled %d let g:matched = v:true', win_id))
+ command('let g:scrolled = 0')
+ command('autocmd WinScrolled * let g:scrolled += 1')
+ command([[autocmd WinScrolled * let g:amatch = str2nr(expand('<amatch>'))]])
+ command([[autocmd WinScrolled * let g:afile = str2nr(expand('<afile>'))]])
+ end)
+
+ after_each(function()
+ eq(true, eval('g:matched'))
+ eq(win_id, eval('g:amatch'))
+ eq(win_id, eval('g:afile'))
+ end)
it('is triggered by scrolling vertically', function()
- source([[
- set nowrap
- let width = winwidth(0)
- let line = '123' . repeat('*', width * 2)
- let lines = [line, line]
- call nvim_buf_set_lines(0, 0, -1, v:true, lines)
-
- let g:scrolled = 0
- autocmd WinScrolled * let g:scrolled += 1
- execute "normal! \<C-e>"
- ]])
+ local lines = {'123', '123'}
+ meths.buf_set_lines(0, 0, -1, true, lines)
+ eq(0, eval('g:scrolled'))
+ feed('<C-E>')
eq(1, eval('g:scrolled'))
end)
it('is triggered by scrolling horizontally', function()
- source([[
- set nowrap
- let width = winwidth(0)
- let line = '123' . repeat('*', width * 2)
- let lines = [line, line]
- call nvim_buf_set_lines(0, 0, -1, v:true, lines)
-
- let g:scrolled = 0
- autocmd WinScrolled * let g:scrolled += 1
- execute "normal! zl"
- ]])
+ command('set nowrap')
+ local width = meths.win_get_width(0)
+ local line = '123' .. ('*'):rep(width * 2)
+ local lines = {line, line}
+ meths.buf_set_lines(0, 0, -1, true, lines)
+ eq(0, eval('g:scrolled'))
+ feed('zl')
eq(1, eval('g:scrolled'))
end)
- it('is triggered when the window scrolls in insert mode', function()
- source([[
- let height = winheight(0)
- let lines = map(range(height * 2), {_, i -> string(i)})
- call nvim_buf_set_lines(0, 0, -1, v:true, lines)
-
- let g:scrolled = 0
- autocmd WinScrolled * let g:scrolled += 1
- call feedkeys("LA\<CR><Esc>", "n")
- ]])
+ it('is triggered by horizontal scrolling from cursor move', function()
+ command('set nowrap')
+ local lines = {'', '', 'Foo'}
+ meths.buf_set_lines(0, 0, -1, true, lines)
+ meths.win_set_cursor(0, {3, 0})
+ eq(0, eval('g:scrolled'))
+ feed('zl')
+ eq(1, eval('g:scrolled'))
+ feed('zl')
eq(2, eval('g:scrolled'))
+ feed('h')
+ eq(3, eval('g:scrolled'))
end)
- it('is triggered when the window is resized', function()
- source([[
- let g:scrolled = 0
- autocmd WinScrolled * let g:scrolled += 1
- wincmd v
- ]])
+ it('is triggered when the window scrolls in Insert mode', function()
+ local height = meths.win_get_height(0)
+ local lines = {}
+ for i = 1, height * 2 do
+ lines[i] = tostring(i)
+ end
+ meths.buf_set_lines(0, 0, -1, true, lines)
+ feed('L')
+ eq(0, eval('g:scrolled'))
+ feed('A<CR><Esc>')
eq(1, eval('g:scrolled'))
end)
end)