From 1037ce2e461034a20e35ad59969fd05d5ad68b91 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 9 Dec 2023 20:42:00 +0800 Subject: test: avoid repeated screen lines in expected states This is the command invoked repeatedly to make the changes: :%s/^\(.*\)|\%(\*\(\d\+\)\)\?$\n\1|\%(\*\(\d\+\)\)\?$/\=submatch(1)..'|*'..(max([str2nr(submatch(2)),1])+max([str2nr(submatch(3)),1]))/g --- test/functional/vimscript/timer_spec.lua | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'test/functional/vimscript/timer_spec.lua') diff --git a/test/functional/vimscript/timer_spec.lua b/test/functional/vimscript/timer_spec.lua index a58cd6ae7f..93d88f6338 100644 --- a/test/functional/vimscript/timer_spec.lua +++ b/test/functional/vimscript/timer_spec.lua @@ -133,9 +133,7 @@ describe('timers', function() screen:expect([[ ^ITEM 1 | ITEM 2 | - {1:~ }| - {1:~ }| - {1:~ }| + {1:~ }|*3 | ]]) nvim_async("command", "let g:cont = 1") @@ -144,8 +142,7 @@ describe('timers', function() ^ITEM 1 | ITEM 2 | ITEM 3 | - {1:~ }| - {1:~ }| + {1:~ }|*2 | ]]) @@ -155,8 +152,7 @@ describe('timers', function() ^ITEM 1 | ITEM 2 | ITEM 3 | - {1:~ }| - {1:~ }| + {1:~ }|*2 | ]], unchanged=true} end) @@ -244,10 +240,7 @@ describe('timers', function() feed(":good") screen:expect([[ | - {0:~ }| - {0:~ }| - {0:~ }| - {0:~ }| + {0:~ }|*4 :good^ | ]]) command('let g:val = 1') -- cgit From 04f2f864e270e772c6326cefdf24947f0130e492 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 3 Jan 2024 02:09:18 +0100 Subject: refactor: format test/* --- test/functional/vimscript/timer_spec.lua | 85 +++++++++++++++++--------------- 1 file changed, 44 insertions(+), 41 deletions(-) (limited to 'test/functional/vimscript/timer_spec.lua') diff --git a/test/functional/vimscript/timer_spec.lua b/test/functional/vimscript/timer_spec.lua index 93d88f6338..0293d30380 100644 --- a/test/functional/vimscript/timer_spec.lua +++ b/test/functional/vimscript/timer_spec.lua @@ -22,20 +22,20 @@ describe('timers', function() it('works one-shot', function() eq(0, eval("[timer_start(10, 'MyHandler'), g:val][1]")) run(nil, nil, nil, load_adjust(100)) - eq(1,eval("g:val")) + eq(1, eval('g:val')) end) it('works one-shot when repeat=0', function() eq(0, eval("[timer_start(10, 'MyHandler', {'repeat': 0}), g:val][1]")) run(nil, nil, nil, load_adjust(100)) - eq(1, eval("g:val")) + eq(1, eval('g:val')) end) it('works with repeat two', function() eq(0, eval("[timer_start(10, 'MyHandler', {'repeat': 2}), g:val][1]")) run(nil, nil, nil, load_adjust(20)) retry(nil, load_adjust(300), function() - eq(2, eval("g:val")) + eq(2, eval('g:val')) end) end) @@ -52,12 +52,12 @@ describe('timers', function() endfunc ]]) eval("timer_start(10, 'MyHandler', {'repeat': -1})") - nvim_async("command", "sleep 10") - eq(-1, eval("g:val")) -- timer did nothing yet. - nvim_async("command", "let g:val = 0") + nvim_async('command', 'sleep 10') + eq(-1, eval('g:val')) -- timer did nothing yet. + nvim_async('command', 'let g:val = 0') run(nil, nil, nil, load_adjust(20)) retry(nil, nil, function() - eq(2, eval("g:val")) + eq(2, eval('g:val')) end) end) @@ -65,52 +65,53 @@ describe('timers', function() -- timer_start does still not invoke the callback immediately eq(0, eval("[timer_start(0, 'MyHandler', {'repeat': 1000}), g:val][1]")) retry(nil, nil, function() - eq(1000, eval("g:val")) + eq(1000, eval('g:val')) end) end) it('can be started during sleep', function() - nvim_async("command", "sleep 10") + nvim_async('command', 'sleep 10') -- this also tests that remote requests works during sleep eq(0, eval("[timer_start(10, 'MyHandler', {'repeat': 2}), g:val][1]")) run(nil, nil, nil, load_adjust(20)) - retry(nil, load_adjust(300), function() eq(2,eval("g:val")) end) + retry(nil, load_adjust(300), function() + eq(2, eval('g:val')) + end) end) it('are paused when event processing is disabled', function() command("call timer_start(5, 'MyHandler', {'repeat': -1})") run(nil, nil, nil, load_adjust(10)) - local count = eval("g:val") + local count = eval('g:val') -- shows two line error message and thus invokes the return prompt. -- if we start to allow event processing here, we need to change this test. feed(':throw "fatal error"') run(nil, nil, nil, load_adjust(30)) - feed("") - local diff = eval("g:val") - count - assert(0 <= diff and diff <= 4, - 'expected (0 <= diff <= 4), got: '..tostring(diff)) + feed('') + local diff = eval('g:val') - count + assert(0 <= diff and diff <= 4, 'expected (0 <= diff <= 4), got: ' .. tostring(diff)) end) it('are triggered in blocking getchar() call', function() command("call timer_start(5, 'MyHandler', {'repeat': -1})") - nvim_async("command", "let g:val = 0 | let g:c = getchar()") + nvim_async('command', 'let g:val = 0 | let g:c = getchar()') retry(nil, nil, function() - local val = eval("g:val") + local val = eval('g:val') ok(val >= 2, '>= 2', tostring(val)) - eq(0, eval("getchar(1)")) + eq(0, eval('getchar(1)')) end) - feed("c") - eq(99, eval("g:c")) + feed('c') + eq(99, eval('g:c')) end) it('can invoke redraw in blocking getchar() call', function() local screen = Screen.new(40, 6) screen:attach() screen:set_default_attr_ids({ - [1] = {bold=true, foreground=Screen.colors.Blue}, + [1] = { bold = true, foreground = Screen.colors.Blue }, }) - curbufmeths.set_lines(0, -1, true, {"ITEM 1", "ITEM 2"}) + curbufmeths.set_lines(0, -1, true, { 'ITEM 1', 'ITEM 2' }) source([[ let g:cont = 0 func! AddItem(timer) @@ -127,8 +128,8 @@ describe('timers', function() redraw endfunc ]]) - nvim_async("command", "let g:c2 = getchar()") - nvim_async("command", "call timer_start("..load_adjust(100)..", 'AddItem', {'repeat': -1})") + nvim_async('command', 'let g:c2 = getchar()') + nvim_async('command', 'call timer_start(' .. load_adjust(100) .. ", 'AddItem', {'repeat': -1})") screen:expect([[ ^ITEM 1 | @@ -136,7 +137,7 @@ describe('timers', function() {1:~ }|*3 | ]]) - nvim_async("command", "let g:cont = 1") + nvim_async('command', 'let g:cont = 1') screen:expect([[ ^ITEM 1 | @@ -146,15 +147,18 @@ describe('timers', function() | ]]) - feed("3") - eq(51, eval("g:c2")) - screen:expect{grid=[[ + feed('3') + eq(51, eval('g:c2')) + screen:expect { + grid = [[ ^ITEM 1 | ITEM 2 | ITEM 3 | {1:~ }|*2 | - ]], unchanged=true} + ]], + unchanged = true, + } end) it('can be stopped', function() @@ -162,9 +166,9 @@ describe('timers', function() eq(0, t_init_val[2]) run(nil, nil, nil, load_adjust(30)) funcs.timer_stop(t_init_val[1]) - local count = eval("g:val") + local count = eval('g:val') run(nil, load_adjust(300), nil, load_adjust(30)) - local count2 = eval("g:val") + local count2 = eval('g:val') -- when count is eval:ed after timer_stop this should be non-racy eq(count, count2) end) @@ -180,10 +184,10 @@ describe('timers', function() endif endfunc ]]) - eq(0, eval("g:val")) + eq(0, eval('g:val')) command("call timer_start(10, 'MyHandler', {'repeat': -1})") retry(nil, nil, function() - eq(3, eval("g:val")) + eq(3, eval('g:val')) end) end) @@ -197,8 +201,8 @@ describe('timers', function() command("call timer_start(2, 'MyHandler', {'repeat': 3})") command("call timer_start(4, 'MyHandler2', {'repeat': 2})") retry(nil, nil, function() - eq(3, eval("g:val")) - eq(2, eval("g:val2")) + eq(3, eval('g:val')) + eq(2, eval('g:val2')) end) end) @@ -214,15 +218,14 @@ describe('timers', function() command("call timer_start(5, 'MyHandler', {'repeat': 1})") run(nil, nil, nil, load_adjust(20)) retry(nil, load_adjust(150), function() - eq(1, eval("g:val")) + eq(1, eval('g:val')) end) end) - it("doesn't mess up the cmdline", function() local screen = Screen.new(40, 6) screen:attach() - screen:set_default_attr_ids( {[0] = {bold=true, foreground=255}} ) + screen:set_default_attr_ids({ [0] = { bold = true, foreground = 255 } }) source([[ let g:val = 0 func! MyHandler(timer) @@ -237,7 +240,7 @@ describe('timers', function() endfunc ]]) command("call timer_start(100, 'MyHandler', {'repeat': -1})") - feed(":good") + feed(':good') screen:expect([[ | {0:~ }|*4 @@ -255,7 +258,7 @@ describe('timers', function() call execute('echo ''execute() should be disallowed''', '') endfunction ]] - eq("Vim(call):E48: Not allowed in sandbox", exc_exec("sandbox call timer_start(0, 'Scary')")) + eq('Vim(call):E48: Not allowed in sandbox', exc_exec("sandbox call timer_start(0, 'Scary')")) end) it('can be triggered after an empty string mapping #17257', function() @@ -263,6 +266,6 @@ describe('timers', function() screen:attach() command([=[imap [timer_start(0, { _ -> execute("throw 'x'", "") }), ''][-1]]=]) feed('i') - screen:expect({any='E605: Exception not caught: x'}) + screen:expect({ any = 'E605: Exception not caught: x' }) end) end) -- cgit From 4f81f506f96f8b5bfcf00e952ceb492d3ce9dc6e Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 13:11:28 +0000 Subject: test: normalise nvim bridge functions - remove helpers.cur*meths - remove helpers.nvim --- test/functional/vimscript/timer_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/functional/vimscript/timer_spec.lua') diff --git a/test/functional/vimscript/timer_spec.lua b/test/functional/vimscript/timer_spec.lua index 0293d30380..02a5880949 100644 --- a/test/functional/vimscript/timer_spec.lua +++ b/test/functional/vimscript/timer_spec.lua @@ -4,7 +4,7 @@ local feed, eq, eval, ok = helpers.feed, helpers.eq, helpers.eval, helpers.ok local source, nvim_async, run = helpers.source, helpers.nvim_async, helpers.run local clear, command, funcs = helpers.clear, helpers.command, helpers.funcs local exc_exec = helpers.exc_exec -local curbufmeths = helpers.curbufmeths +local meths = helpers.meths local load_adjust = helpers.load_adjust local retry = helpers.retry @@ -111,7 +111,7 @@ describe('timers', function() [1] = { bold = true, foreground = Screen.colors.Blue }, }) - curbufmeths.set_lines(0, -1, true, { 'ITEM 1', 'ITEM 2' }) + meths.nvim_buf_set_lines(0, 0, -1, true, { 'ITEM 1', 'ITEM 2' }) source([[ let g:cont = 0 func! AddItem(timer) -- cgit From 795f896a5772d5e0795f86642bdf90c82efac45c Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 17:59:57 +0000 Subject: test: rename (meths, funcs) -> (api, fn) --- test/functional/vimscript/timer_spec.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test/functional/vimscript/timer_spec.lua') diff --git a/test/functional/vimscript/timer_spec.lua b/test/functional/vimscript/timer_spec.lua index 02a5880949..3f53c21e7a 100644 --- a/test/functional/vimscript/timer_spec.lua +++ b/test/functional/vimscript/timer_spec.lua @@ -2,9 +2,9 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local feed, eq, eval, ok = helpers.feed, helpers.eq, helpers.eval, helpers.ok local source, nvim_async, run = helpers.source, helpers.nvim_async, helpers.run -local clear, command, funcs = helpers.clear, helpers.command, helpers.funcs +local clear, command, fn = helpers.clear, helpers.command, helpers.fn local exc_exec = helpers.exc_exec -local meths = helpers.meths +local api = helpers.api local load_adjust = helpers.load_adjust local retry = helpers.retry @@ -111,7 +111,7 @@ describe('timers', function() [1] = { bold = true, foreground = Screen.colors.Blue }, }) - meths.nvim_buf_set_lines(0, 0, -1, true, { 'ITEM 1', 'ITEM 2' }) + api.nvim_buf_set_lines(0, 0, -1, true, { 'ITEM 1', 'ITEM 2' }) source([[ let g:cont = 0 func! AddItem(timer) @@ -165,7 +165,7 @@ describe('timers', function() local t_init_val = eval("[timer_start(5, 'MyHandler', {'repeat': -1}), g:val]") eq(0, t_init_val[2]) run(nil, nil, nil, load_adjust(30)) - funcs.timer_stop(t_init_val[1]) + fn.timer_stop(t_init_val[1]) local count = eval('g:val') run(nil, load_adjust(300), nil, load_adjust(30)) local count2 = eval('g:val') -- cgit From b536e0ba37addaea5507b054120e4c1e122c4405 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 15 Jan 2024 16:10:51 +0000 Subject: test: big cleanup followup Followup to 07a7c0ec --- test/functional/vimscript/timer_spec.lua | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'test/functional/vimscript/timer_spec.lua') diff --git a/test/functional/vimscript/timer_spec.lua b/test/functional/vimscript/timer_spec.lua index 3f53c21e7a..046d451888 100644 --- a/test/functional/vimscript/timer_spec.lua +++ b/test/functional/vimscript/timer_spec.lua @@ -1,7 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local feed, eq, eval, ok = helpers.feed, helpers.eq, helpers.eval, helpers.ok -local source, nvim_async, run = helpers.source, helpers.nvim_async, helpers.run +local source, async_meths, run = helpers.source, helpers.async_meths, helpers.run local clear, command, fn = helpers.clear, helpers.command, helpers.fn local exc_exec = helpers.exc_exec local api = helpers.api @@ -52,9 +52,9 @@ describe('timers', function() endfunc ]]) eval("timer_start(10, 'MyHandler', {'repeat': -1})") - nvim_async('command', 'sleep 10') + async_meths.nvim_command('sleep 10') eq(-1, eval('g:val')) -- timer did nothing yet. - nvim_async('command', 'let g:val = 0') + async_meths.nvim_command('let g:val = 0') run(nil, nil, nil, load_adjust(20)) retry(nil, nil, function() eq(2, eval('g:val')) @@ -70,7 +70,7 @@ describe('timers', function() end) it('can be started during sleep', function() - nvim_async('command', 'sleep 10') + async_meths.nvim_command('sleep 10') -- this also tests that remote requests works during sleep eq(0, eval("[timer_start(10, 'MyHandler', {'repeat': 2}), g:val][1]")) run(nil, nil, nil, load_adjust(20)) @@ -94,7 +94,7 @@ describe('timers', function() it('are triggered in blocking getchar() call', function() command("call timer_start(5, 'MyHandler', {'repeat': -1})") - nvim_async('command', 'let g:val = 0 | let g:c = getchar()') + async_meths.nvim_command('let g:val = 0 | let g:c = getchar()') retry(nil, nil, function() local val = eval('g:val') ok(val >= 2, '>= 2', tostring(val)) @@ -128,8 +128,10 @@ describe('timers', function() redraw endfunc ]]) - nvim_async('command', 'let g:c2 = getchar()') - nvim_async('command', 'call timer_start(' .. load_adjust(100) .. ", 'AddItem', {'repeat': -1})") + async_meths.nvim_command('let g:c2 = getchar()') + async_meths.nvim_command( + 'call timer_start(' .. load_adjust(100) .. ", 'AddItem', {'repeat': -1})" + ) screen:expect([[ ^ITEM 1 | @@ -137,7 +139,7 @@ describe('timers', function() {1:~ }|*3 | ]]) - nvim_async('command', 'let g:cont = 1') + async_meths.nvim_command('let g:cont = 1') screen:expect([[ ^ITEM 1 | -- cgit