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/execute_spec.lua | 35 +++++++----------------------- 1 file changed, 8 insertions(+), 27 deletions(-) (limited to 'test/functional/vimscript/execute_spec.lua') diff --git a/test/functional/vimscript/execute_spec.lua b/test/functional/vimscript/execute_spec.lua index bb28938708..de5c32fb6c 100644 --- a/test/functional/vimscript/execute_spec.lua +++ b/test/functional/vimscript/execute_spec.lua @@ -114,8 +114,7 @@ describe('execute()', function() feed(':echo execute("hi ErrorMsg")') screen:expect([[ | - {1:~ }| - {1:~ }| + {1:~ }|*2 {2: }| | ErrorMsg xxx ctermfg=15 ctermbg=1 guifg=White guibg=Red | @@ -187,30 +186,21 @@ describe('execute()', function() feed([[:call Test1()]]) screen:expect([[ ^ | - ~ | - ~ | - ~ | - ~ | + ~ |*4 ABCD | ]]) feed([[:call Test2()]]) screen:expect([[ ^ | - ~ | - ~ | - ~ | - ~ | + ~ |*4 1234ABCD | ]]) feed([[:call Test3()]]) screen:expect([[ ^ | - ~ | - ~ | - ~ | - ~ | + ~ |*4 1234ABCDXZYZ | ]]) @@ -231,10 +221,7 @@ describe('execute()', function() feed([[:call Test5()]]) screen:expect([[ ^ | - ~ | - ~ | - ~ | - ~ | + ~ |*4 1234ABCD | ]]) @@ -273,9 +260,7 @@ describe('execute()', function() command('let g:mes = execute("echon 42", "")') screen:expect([[ ^ | - ~ | - ~ | - ~ | + ~ |*3 42 | ]]) eq('42', eval('g:mes')) @@ -295,9 +280,7 @@ describe('execute()', function() command('let g:mes = execute("echon 42")') screen:expect([[ ^ | - ~ | - ~ | - ~ | + ~ |*3 | ]]) eq('42', eval('g:mes')) @@ -305,9 +288,7 @@ describe('execute()', function() command('let g:mes = execute("echon 13", "silent")') screen:expect{grid=[[ ^ | - ~ | - ~ | - ~ | + ~ |*3 | ]], unchanged=true} eq('13', eval('g:mes')) -- 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/execute_spec.lua | 46 +++++++++++++++++++----------- 1 file changed, 29 insertions(+), 17 deletions(-) (limited to 'test/functional/vimscript/execute_spec.lua') diff --git a/test/functional/vimscript/execute_spec.lua b/test/functional/vimscript/execute_spec.lua index de5c32fb6c..3124c02c2f 100644 --- a/test/functional/vimscript/execute_spec.lua +++ b/test/functional/vimscript/execute_spec.lua @@ -26,8 +26,8 @@ describe('execute()', function() end) it('captures the concatenated outputs of a List of commands', function() - eq("foobar", funcs.execute({'echon "foo"', 'echon "bar"'})) - eq("\nfoo\nbar", funcs.execute({'echo "foo"', 'echo "bar"'})) + eq('foobar', funcs.execute({ 'echon "foo"', 'echon "bar"' })) + eq('\nfoo\nbar', funcs.execute({ 'echo "foo"', 'echo "bar"' })) end) it('supports nested execute("execute(...)")', function() @@ -104,26 +104,31 @@ describe('execute()', function() end) it('captures output with highlights', function() - eq('\nErrorMsg xxx ctermfg=15 ctermbg=1 guifg=White guibg=Red', - eval('execute("hi ErrorMsg")')) + eq( + '\nErrorMsg xxx ctermfg=15 ctermbg=1 guifg=White guibg=Red', + eval('execute("hi ErrorMsg")') + ) end) it('does not corrupt the command display #5422', function() local screen = Screen.new(70, 7) screen:attach() feed(':echo execute("hi ErrorMsg")') - screen:expect([[ + screen:expect( + [[ | {1:~ }|*2 {2: }| | ErrorMsg xxx ctermfg=15 ctermbg=1 guifg=White guibg=Red | {3:Press ENTER or type command to continue}^ | - ]], { - [1] = {bold = true, foreground = Screen.colors.Blue1}, - [2] = {bold = true, reverse = true}, - [3] = {bold = true, foreground = Screen.colors.SeaGreen4}, - }) + ]], + { + [1] = { bold = true, foreground = Screen.colors.Blue1 }, + [2] = { bold = true, reverse = true }, + [3] = { bold = true, foreground = Screen.colors.SeaGreen4 }, + } + ) feed('') end) @@ -250,7 +255,7 @@ describe('execute()', function() -- with how nvim currently displays the output. it('captures shell-command output', function() local win_lf = is_os('win') and '\13' or '' - eq('\n:!echo foo\r\n\nfoo'..win_lf..'\n', funcs.execute('!echo foo')) + eq('\n:!echo foo\r\n\nfoo' .. win_lf .. '\n', funcs.execute('!echo foo')) end) describe('{silent} argument', function() @@ -268,10 +273,14 @@ describe('execute()', function() it('gives E493 instead of prompting on backwards range for ""', function() command('split') - eq('Vim(windo):E493: Backwards range given: 2,1windo echo', - pcall_err(funcs.execute, '2,1windo echo', '')) - eq('Vim(windo):E493: Backwards range given: 2,1windo echo', - pcall_err(funcs.execute, {'2,1windo echo'}, '')) + eq( + 'Vim(windo):E493: Backwards range given: 2,1windo echo', + pcall_err(funcs.execute, '2,1windo echo', '') + ) + eq( + 'Vim(windo):E493: Backwards range given: 2,1windo echo', + pcall_err(funcs.execute, { '2,1windo echo' }, '') + ) end) it('captures but does not display output for "silent"', function() @@ -286,11 +295,14 @@ describe('execute()', function() eq('42', eval('g:mes')) command('let g:mes = execute("echon 13", "silent")') - screen:expect{grid=[[ + screen:expect { + grid = [[ ^ | ~ |*3 | - ]], unchanged=true} + ]], + unchanged = true, + } eq('13', eval('g:mes')) end) -- 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/execute_spec.lua | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'test/functional/vimscript/execute_spec.lua') diff --git a/test/functional/vimscript/execute_spec.lua b/test/functional/vimscript/execute_spec.lua index 3124c02c2f..29488ed31c 100644 --- a/test/functional/vimscript/execute_spec.lua +++ b/test/functional/vimscript/execute_spec.lua @@ -5,7 +5,7 @@ local clear = helpers.clear local source = helpers.source local exc_exec = helpers.exc_exec local pcall_err = helpers.pcall_err -local funcs = helpers.funcs +local fn = helpers.fn local Screen = require('test.functional.ui.screen') local command = helpers.command local feed = helpers.feed @@ -22,16 +22,16 @@ describe('execute()', function() silent! messages redir END ]]) - eq(eval('g:__redir_output'), funcs.execute('messages')) + eq(eval('g:__redir_output'), fn.execute('messages')) end) it('captures the concatenated outputs of a List of commands', function() - eq('foobar', funcs.execute({ 'echon "foo"', 'echon "bar"' })) - eq('\nfoo\nbar', funcs.execute({ 'echo "foo"', 'echo "bar"' })) + eq('foobar', fn.execute({ 'echon "foo"', 'echon "bar"' })) + eq('\nfoo\nbar', fn.execute({ 'echo "foo"', 'echo "bar"' })) end) it('supports nested execute("execute(...)")', function() - eq('42', funcs.execute([[echon execute("echon execute('echon 42')")]])) + eq('42', fn.execute([[echon execute("echon execute('echon 42')")]])) end) it('supports nested :redir to a variable', function() @@ -54,7 +54,7 @@ describe('execute()', function() return a endfunction ]]) - eq('top1bar1foobar2bar3', funcs.execute('echon "top1"|call g:Bar()')) + eq('top1bar1foobar2bar3', fn.execute('echon "top1"|call g:Bar()')) end) it('supports nested :redir to a register', function() @@ -76,17 +76,17 @@ describe('execute()', function() return @a endfunction ]]) - eq('top1bar1foobar2bar3', funcs.execute('echon "top1"|call g:Bar()')) + eq('top1bar1foobar2bar3', fn.execute('echon "top1"|call g:Bar()')) -- :redir itself doesn't nest, so the redirection ends in g:Foo eq('bar1foo', eval('@a')) end) it('captures a transformed string', function() - eq('^A', funcs.execute('echon "\\"')) + eq('^A', fn.execute('echon "\\"')) end) it('returns empty string if the argument list is empty', function() - eq('', funcs.execute({})) + eq('', fn.execute({})) eq(0, exc_exec('let g:ret = execute(v:_null_list)')) eq('', eval('g:ret')) end) @@ -255,7 +255,7 @@ describe('execute()', function() -- with how nvim currently displays the output. it('captures shell-command output', function() local win_lf = is_os('win') and '\13' or '' - eq('\n:!echo foo\r\n\nfoo' .. win_lf .. '\n', funcs.execute('!echo foo')) + eq('\n:!echo foo\r\n\nfoo' .. win_lf .. '\n', fn.execute('!echo foo')) end) describe('{silent} argument', function() @@ -275,11 +275,11 @@ describe('execute()', function() command('split') eq( 'Vim(windo):E493: Backwards range given: 2,1windo echo', - pcall_err(funcs.execute, '2,1windo echo', '') + pcall_err(fn.execute, '2,1windo echo', '') ) eq( 'Vim(windo):E493: Backwards range given: 2,1windo echo', - pcall_err(funcs.execute, { '2,1windo echo' }, '') + pcall_err(fn.execute, { '2,1windo echo' }, '') ) end) -- cgit