From 929d00db0f02a73aec83f35ae29345d3f239df5a Mon Sep 17 00:00:00 2001 From: Rom Grk Date: Wed, 28 Oct 2020 04:32:25 -0400 Subject: tests: add functional test for WinScrolled --- test/functional/autocmd/winscrolled_spec.lua | 47 ++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 test/functional/autocmd/winscrolled_spec.lua (limited to 'test/functional/autocmd/winscrolled_spec.lua') diff --git a/test/functional/autocmd/winscrolled_spec.lua b/test/functional/autocmd/winscrolled_spec.lua new file mode 100644 index 0000000000..00160d3771 --- /dev/null +++ b/test/functional/autocmd/winscrolled_spec.lua @@ -0,0 +1,47 @@ +local helpers = require('test.functional.helpers')(after_each) + +local clear = helpers.clear +local eq = helpers.eq +local eval = helpers.eval +local funcs = helpers.funcs +local source = helpers.source + +describe('WinScrolled', function() + before_each(clear) + + it('is triggered by scrolling in normal/visual mode', function() + source([[ + let width = winwidth(0) + let lines = [repeat('*', range(width * 2))] + call nvim_buf_set_lines(g:buf, 0, -1, v:true, lines) + + let g:scrolled = 0 + autocmd WinScrolled * let g:scrolled += 1 + normal! zl + normal! + ]]) + 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(g:buf, 0, -1, v:true, lines) + + let g:scrolled = 0 + autocmd WinScrolled * let g:scrolled += 1 + call feedkeys("LA\", "n") + ]]) + eq(1, 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 + ]]) + eq(1, eval('g:scrolled')) + end) +end) -- cgit From d9a58573fd599d006518b403385c4b7333d8d1a0 Mon Sep 17 00:00:00 2001 From: Rom Grk Date: Fri, 30 Oct 2020 03:22:52 -0400 Subject: tests: make scroll tests pass --- test/functional/autocmd/winscrolled_spec.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test/functional/autocmd/winscrolled_spec.lua') diff --git a/test/functional/autocmd/winscrolled_spec.lua b/test/functional/autocmd/winscrolled_spec.lua index 00160d3771..534fe3dbcd 100644 --- a/test/functional/autocmd/winscrolled_spec.lua +++ b/test/functional/autocmd/winscrolled_spec.lua @@ -12,22 +12,22 @@ describe('WinScrolled', function() it('is triggered by scrolling in normal/visual mode', function() source([[ let width = winwidth(0) - let lines = [repeat('*', range(width * 2))] - call nvim_buf_set_lines(g:buf, 0, -1, v:true, lines) + let lines = [repeat('*', width * 2), repeat('*', width * 2)] + call nvim_buf_set_lines(0, 0, -1, v:true, lines) let g:scrolled = 0 autocmd WinScrolled * let g:scrolled += 1 normal! zl normal! ]]) - eq(1, eval('g:scrolled')) + eq(2, 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(g:buf, 0, -1, v:true, lines) + call nvim_buf_set_lines(0, 0, -1, v:true, lines) let g:scrolled = 0 autocmd WinScrolled * let g:scrolled += 1 -- cgit From a58d06ebfce8cdbc145948bf6a6177d0e9696709 Mon Sep 17 00:00:00 2001 From: Rom Grk Date: Fri, 30 Oct 2020 14:18:08 -0400 Subject: tests: separate scroll test for horizontal/vertical scroll --- test/functional/autocmd/winscrolled_spec.lua | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'test/functional/autocmd/winscrolled_spec.lua') diff --git a/test/functional/autocmd/winscrolled_spec.lua b/test/functional/autocmd/winscrolled_spec.lua index 534fe3dbcd..646baf08ea 100644 --- a/test/functional/autocmd/winscrolled_spec.lua +++ b/test/functional/autocmd/winscrolled_spec.lua @@ -9,18 +9,34 @@ local source = helpers.source describe('WinScrolled', function() before_each(clear) - it('is triggered by scrolling in normal/visual mode', function() + it('is triggered by scrolling vertically', function() source([[ + set nowrap let width = winwidth(0) - let lines = [repeat('*', width * 2), repeat('*', width * 2)] + 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 - normal! zl - normal! + execute "normal! \" ]]) - eq(2, eval('g:scrolled')) + 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" + ]]) + eq(1, eval('g:scrolled')) end) it('is triggered when the window scrolls in insert mode', function() @@ -33,7 +49,7 @@ describe('WinScrolled', function() autocmd WinScrolled * let g:scrolled += 1 call feedkeys("LA\", "n") ]]) - eq(1, eval('g:scrolled')) + eq(2, eval('g:scrolled')) end) it('is triggered when the window is resized', function() -- cgit From cedfc1b7477060917a31d4f1c526db3da0deb15c Mon Sep 17 00:00:00 2001 From: Rom Grk Date: Fri, 6 Nov 2020 23:44:32 -0500 Subject: my fight with the linter (tome II) --- test/functional/autocmd/winscrolled_spec.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'test/functional/autocmd/winscrolled_spec.lua') diff --git a/test/functional/autocmd/winscrolled_spec.lua b/test/functional/autocmd/winscrolled_spec.lua index 646baf08ea..1ef5a37479 100644 --- a/test/functional/autocmd/winscrolled_spec.lua +++ b/test/functional/autocmd/winscrolled_spec.lua @@ -3,7 +3,6 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local eq = helpers.eq local eval = helpers.eval -local funcs = helpers.funcs local source = helpers.source describe('WinScrolled', function() -- cgit