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/plugin/man_spec.lua | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'test/functional/plugin/man_spec.lua') diff --git a/test/functional/plugin/man_spec.lua b/test/functional/plugin/man_spec.lua index 815ddbc523..f16fca51f9 100644 --- a/test/functional/plugin/man_spec.lua +++ b/test/functional/plugin/man_spec.lua @@ -71,8 +71,7 @@ describe(':Man', function() screen:expect{grid=[[ this i{c:^H}is{c:^H}s a{c:^H}a test | with _{c:^H}o_{c:^H}v_{c:^H}e_{c:^H}r_{c:^H}s_{c:^H}t_{c:^H}r_{c:^H}u_{c:^H}c_{c:^H}k tex^t | - {eob:~ }| - {eob:~ }| + {eob:~ }|*2 | ]]} @@ -81,8 +80,7 @@ describe(':Man', function() screen:expect([[ ^this {b:is} {b:a} test | with {i:overstruck} text | - {eob:~ }| - {eob:~ }| + {eob:~ }|*2 | ]]) end) @@ -95,8 +93,7 @@ describe(':Man', function() screen:expect{grid=[=[ this {c:^[}[1mis {c:^[}[3ma {c:^[}[4mtest{c:^[}[0m | {c:^[}[4mwith{c:^[}[24m {c:^[}[4mescaped{c:^[}[24m {c:^[}[4mtext{c:^[}[24^m | - {eob:~ }| - {eob:~ }| + {eob:~ }|*2 | ]=]} @@ -105,8 +102,7 @@ describe(':Man', function() screen:expect([[ ^this {b:is }{bi:a }{biu:test} | {u:with} {u:escaped} {u:text} | - {eob:~ }| - {eob:~ }| + {eob:~ }|*2 | ]]) end) @@ -120,8 +116,7 @@ describe(':Man', function() screen:expect([[ ^this {b:is} {b:あ} test | with {i:överstrũck} te{i:xt¶} | - {eob:~ }| - {eob:~ }| + {eob:~ }|*2 | ]]) end) -- 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/plugin/man_spec.lua | 115 +++++++++++++++++++++--------------- 1 file changed, 68 insertions(+), 47 deletions(-) (limited to 'test/functional/plugin/man_spec.lua') diff --git a/test/functional/plugin/man_spec.lua b/test/functional/plugin/man_spec.lua index f16fca51f9..ed9f21edf3 100644 --- a/test/functional/plugin/man_spec.lua +++ b/test/functional/plugin/man_spec.lua @@ -49,7 +49,7 @@ describe(':Man', function() before_each(function() command('syntax on') command('set filetype=man') - command('syntax off') -- Ignore syntax groups + command('syntax off') -- Ignore syntax groups screen = Screen.new(52, 5) screen:set_default_attr_ids({ b = { bold = true }, @@ -58,24 +58,28 @@ describe(':Man', function() bi = { bold = true, italic = true }, biu = { bold = true, italic = true, underline = true }, c = { foreground = Screen.colors.Blue }, -- control chars - eob = { bold = true, foreground = Screen.colors.Blue } -- empty line '~'s + eob = { bold = true, foreground = Screen.colors.Blue }, -- empty line '~'s }) screen:attach() end) it('clears backspaces from text and adds highlights', function() - rawfeed([[ + rawfeed( + [[ ithis iiss aa test - with _o_v_e_r_s_t_r_u_c_k text]]) + with _o_v_e_r_s_t_r_u_c_k text]] + ) - screen:expect{grid=[[ + screen:expect { + grid = [[ this i{c:^H}is{c:^H}s a{c:^H}a test | with _{c:^H}o_{c:^H}v_{c:^H}e_{c:^H}r_{c:^H}s_{c:^H}t_{c:^H}r_{c:^H}u_{c:^H}c_{c:^H}k tex^t | {eob:~ }|*2 | - ]]} + ]], + } - exec_lua[[require'man'.init_pager()]] + exec_lua [[require'man'.init_pager()]] screen:expect([[ ^this {b:is} {b:a} test | @@ -86,18 +90,22 @@ describe(':Man', function() end) it('clears escape sequences from text and adds highlights', function() - rawfeed([[ + rawfeed( + [[ ithis [1mis [3ma [4mtest[0m - [4mwith[24m [4mescaped[24m [4mtext[24m]]) + [4mwith[24m [4mescaped[24m [4mtext[24m]] + ) - screen:expect{grid=[=[ + screen:expect { + grid = [=[ this {c:^[}[1mis {c:^[}[3ma {c:^[}[4mtest{c:^[}[0m | {c:^[}[4mwith{c:^[}[24m {c:^[}[4mescaped{c:^[}[24m {c:^[}[4mtext{c:^[}[24^m | {eob:~ }|*2 | - ]=]} + ]=], + } - exec_lua[[require'man'.init_pager()]] + exec_lua [[require'man'.init_pager()]] screen:expect([[ ^this {b:is }{bi:a }{biu:test} | @@ -108,10 +116,12 @@ describe(':Man', function() end) it('highlights multibyte text', function() - rawfeed([[ + rawfeed( + [[ ithis iiss ああ test - with _ö_v_e_r_s_t_r_u_̃_c_k te[3mxt¶[0m]]) - exec_lua[[require'man'.init_pager()]] + with _ö_v_e_r_s_t_r_u_̃_c_k te[3mxt¶[0m]] + ) + exec_lua [[require'man'.init_pager()]] screen:expect([[ ^this {b:is} {b:あ} test | @@ -122,11 +132,13 @@ describe(':Man', function() end) it('highlights underscores based on context', function() - rawfeed([[ + rawfeed( + [[ i__bbeeggiinnss mmiidd__ddllee - _m_i_d___d_l_e]]) - exec_lua[[require'man'.init_pager()]] + _m_i_d___d_l_e]] + ) + exec_lua [[require'man'.init_pager()]] screen:expect([[ {b:^_begins} | @@ -142,7 +154,7 @@ describe(':Man', function() i· ·· +o ++oo double]]) - exec_lua[[require'man'.init_pager()]] + exec_lua [[require'man'.init_pager()]] screen:expect([[ ^· {b:·} | @@ -159,7 +171,7 @@ describe(':Man', function() [44m 4 [45m 5 [46m 6 [47m 7 [100m 8 [101m 9 [102m 10 [103m 11 [104m 12 [105m 13 [106m 14 [107m 15 [48:5:16m 16 ]]) - exec_lua[[require'man'.init_pager()]] + exec_lua [[require'man'.init_pager()]] screen:expect([[ ^ 0 1 2 3 | @@ -173,8 +185,14 @@ describe(':Man', function() it('q quits in "$MANPAGER mode" (:Man!) #18281', function() -- This will hang if #18281 regresses. - local args = {nvim_prog, '--headless', '+autocmd VimLeave * echo "quit works!!"', '+Man!', '+call nvim_input("q")'} - matches('quit works!!', funcs.system(args, {'manpage contents'})) + local args = { + nvim_prog, + '--headless', + '+autocmd VimLeave * echo "quit works!!"', + '+Man!', + '+call nvim_input("q")', + } + matches('quit works!!', funcs.system(args, { 'manpage contents' })) end) it('reports non-existent man pages for absolute paths', function() @@ -183,41 +201,44 @@ describe(':Man', function() -- actual_file must be an absolute path to an existent file for us to test against it matches('^/.+', actual_file) write_file(actual_file, '') - local args = {nvim_prog, '--headless', '+:Man ' .. actual_file, '+q'} - matches(('Error detected while processing command line:\r\n' .. - 'man.lua: "no manual entry for %s"'):format(pesc(actual_file)), - funcs.system(args, {''})) + local args = { nvim_prog, '--headless', '+:Man ' .. actual_file, '+q' } + matches( + ('Error detected while processing command line:\r\n' .. 'man.lua: "no manual entry for %s"'):format( + pesc(actual_file) + ), + funcs.system(args, { '' }) + ) os.remove(actual_file) end) it('tries variants with spaces, underscores #22503', function() eq({ - {'', 'NAME WITH SPACES'}, - {'', 'NAME_WITH_SPACES'}, - }, get_search_history('NAME WITH SPACES')) + { '', 'NAME WITH SPACES' }, + { '', 'NAME_WITH_SPACES' }, + }, get_search_history('NAME WITH SPACES')) eq({ - {'3', 'some other man'}, - {'3', 'some_other_man'}, - }, get_search_history('3 some other man')) + { '3', 'some other man' }, + { '3', 'some_other_man' }, + }, get_search_history('3 some other man')) eq({ - {'3x', 'some other man'}, - {'3x', 'some_other_man'}, - }, get_search_history('3X some other man')) + { '3x', 'some other man' }, + { '3x', 'some_other_man' }, + }, get_search_history('3X some other man')) eq({ - {'3tcl', 'some other man'}, - {'3tcl', 'some_other_man'}, - }, get_search_history('3tcl some other man')) + { '3tcl', 'some other man' }, + { '3tcl', 'some_other_man' }, + }, get_search_history('3tcl some other man')) eq({ - {'n', 'some other man'}, - {'n', 'some_other_man'}, - }, get_search_history('n some other man')) + { 'n', 'some other man' }, + { 'n', 'some_other_man' }, + }, get_search_history('n some other man')) eq({ - {'', '123some other man'}, - {'', '123some_other_man'}, - }, get_search_history('123some other man')) + { '', '123some other man' }, + { '', '123some_other_man' }, + }, get_search_history('123some other man')) eq({ - {'1', 'other_man'}, - {'1', 'other_man'}, - }, get_search_history('other_man(1)')) + { '1', 'other_man' }, + { '1', 'other_man' }, + }, get_search_history('other_man(1)')) end) end) -- cgit From d33e1da9b7f7e886219cfdd20b9bbfaccdc43be9 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 11:28:20 +0000 Subject: test: do not inject vim module into global helpers --- test/functional/plugin/man_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/plugin/man_spec.lua') diff --git a/test/functional/plugin/man_spec.lua b/test/functional/plugin/man_spec.lua index ed9f21edf3..532210582a 100644 --- a/test/functional/plugin/man_spec.lua +++ b/test/functional/plugin/man_spec.lua @@ -9,7 +9,7 @@ local matches = helpers.matches local write_file = helpers.write_file local tmpname = helpers.tmpname local eq = helpers.eq -local pesc = helpers.pesc +local pesc = vim.pesc local skip = helpers.skip local is_ci = helpers.is_ci -- 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/plugin/man_spec.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test/functional/plugin/man_spec.lua') diff --git a/test/functional/plugin/man_spec.lua b/test/functional/plugin/man_spec.lua index 532210582a..5bfa566729 100644 --- a/test/functional/plugin/man_spec.lua +++ b/test/functional/plugin/man_spec.lua @@ -3,7 +3,7 @@ local Screen = require('test.functional.ui.screen') local command, rawfeed = helpers.command, helpers.rawfeed local clear = helpers.clear local exec_lua = helpers.exec_lua -local funcs = helpers.funcs +local fn = helpers.fn local nvim_prog = helpers.nvim_prog local matches = helpers.matches local write_file = helpers.write_file @@ -33,7 +33,7 @@ local function get_search_history(name) end clear() -if funcs.executable('man') == 0 then +if fn.executable('man') == 0 then pending('missing "man" command', function() end) return end @@ -192,7 +192,7 @@ describe(':Man', function() '+Man!', '+call nvim_input("q")', } - matches('quit works!!', funcs.system(args, { 'manpage contents' })) + matches('quit works!!', fn.system(args, { 'manpage contents' })) end) it('reports non-existent man pages for absolute paths', function() @@ -206,7 +206,7 @@ describe(':Man', function() ('Error detected while processing command line:\r\n' .. 'man.lua: "no manual entry for %s"'):format( pesc(actual_file) ), - funcs.system(args, { '' }) + fn.system(args, { '' }) ) os.remove(actual_file) end) -- cgit