From 160a019ffa104eebd65f4037729954d98aca6ad0 Mon Sep 17 00:00:00 2001 From: Eriks Muhins Date: Fri, 3 Mar 2023 21:44:13 +0200 Subject: feat(man.lua): support spaces in manpage names Problem: :Man command errors if given more than two arguments. Thus, it is impossible to open man pages that contain spaces in their names. Solution: Adjust :Man so that it tries variants with spaces and underscores, and uses the first found. --- test/functional/plugin/man_spec.lua | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (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 58da059be6..a1a7274e5d 100644 --- a/test/functional/plugin/man_spec.lua +++ b/test/functional/plugin/man_spec.lua @@ -10,6 +10,26 @@ local write_file = helpers.write_file local tmpname = helpers.tmpname local skip = helpers.skip local is_ci = helpers.is_ci +local table_contains = vim.tbl_contains + +-- Returns a table composed of all man page name arguments +-- that were passed to search_for_path after attempting to +-- open 'name'. +local function get_search_history(name) + local as_table = string.gsub(name, ' ', '\', \'') + as_table = '\'' .. as_table .. '\'' + local code = ([[ + local man = require('runtime.lua.man') + local res = {} + man.attempt_to_get_path = function(sect, name, silent) + table.insert(res, name) + return nil + end + pcall(man.open_page, 0, {tab = 0}, {%s}) + return res + ]]):format(as_table) + return exec_lua(code) +end clear() if funcs.executable('man') == 0 then @@ -173,4 +193,10 @@ describe(':Man', function() funcs.system(args, {''})) os.remove(actual_file) end) + + it('searches for manpage name with variants with spaces, underscores', function() + local tried = get_search_history('NAME WITH SPACES') + table_contains(tried, 'NAME WITH SPACES') + table_contains(tried, 'NAME_WITH_SPACES') + end) end) -- cgit From 304477ff3504373a336c83127654e65eddfa2ef9 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 7 Mar 2023 15:13:09 +0100 Subject: fix(man.lua): tests, naming --- test/functional/plugin/man_spec.lua | 39 +++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 15 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 a1a7274e5d..9730bf4bf6 100644 --- a/test/functional/plugin/man_spec.lua +++ b/test/functional/plugin/man_spec.lua @@ -8,27 +8,27 @@ local nvim_prog = helpers.nvim_prog local matches = helpers.matches local write_file = helpers.write_file local tmpname = helpers.tmpname +local eq = helpers.eq local skip = helpers.skip local is_ci = helpers.is_ci -local table_contains = vim.tbl_contains --- Returns a table composed of all man page name arguments --- that were passed to search_for_path after attempting to --- open 'name'. +-- Collects all names passed to find_path() after attempting ":Man foo". local function get_search_history(name) - local as_table = string.gsub(name, ' ', '\', \'') - as_table = '\'' .. as_table .. '\'' - local code = ([[ + local args = vim.split(name, ' ') + local code = [[ + local args = ... local man = require('runtime.lua.man') local res = {} - man.attempt_to_get_path = function(sect, name, silent) + man.find_path = function(sect, name) table.insert(res, name) return nil end - pcall(man.open_page, 0, {tab = 0}, {%s}) + local ok, rv = pcall(man.open_page, 0, {tab = 0}, args) + assert(not ok) + assert(rv and rv:match('no manual entry')) return res - ]]):format(as_table) - return exec_lua(code) + ]] + return exec_lua(code, args) end clear() @@ -194,9 +194,18 @@ describe(':Man', function() os.remove(actual_file) end) - it('searches for manpage name with variants with spaces, underscores', function() - local tried = get_search_history('NAME WITH SPACES') - table_contains(tried, 'NAME WITH SPACES') - table_contains(tried, 'NAME_WITH_SPACES') + it('tries variants with spaces, underscores #22503', function() + eq({ + 'NAME WITH SPACES', + 'NAME_WITH_SPACES', + }, get_search_history('NAME WITH SPACES')) + eq({ + 'some other man', + 'some_other_man', + }, get_search_history('3 some other man')) + eq({ + 'other_man', + 'other_man', + }, get_search_history('other_man(1)')) end) end) -- cgit From 3001d86aea184f8b015c1bfffd2db42c946f8a84 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 8 May 2023 15:22:58 +0800 Subject: test: add more tests for :Man section extraction --- test/functional/plugin/man_spec.lua | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 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 9730bf4bf6..d5c1a78fc8 100644 --- a/test/functional/plugin/man_spec.lua +++ b/test/functional/plugin/man_spec.lua @@ -20,10 +20,10 @@ local function get_search_history(name) local man = require('runtime.lua.man') local res = {} man.find_path = function(sect, name) - table.insert(res, name) + table.insert(res, {sect, name}) return nil end - local ok, rv = pcall(man.open_page, 0, {tab = 0}, args) + local ok, rv = pcall(man.open_page, -1, {tab = 0}, args) assert(not ok) assert(rv and rv:match('no manual entry')) return res @@ -196,16 +196,32 @@ describe(':Man', function() it('tries variants with spaces, underscores #22503', function() eq({ - 'NAME WITH SPACES', - 'NAME_WITH_SPACES', + {'', 'NAME WITH SPACES'}, + {'', 'NAME_WITH_SPACES'}, }, get_search_history('NAME WITH SPACES')) eq({ - 'some other man', - 'some_other_man', + {'3', 'some other man'}, + {'3', 'some_other_man'}, }, get_search_history('3 some other man')) eq({ - 'other_man', - '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')) + eq({ + {'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')) + eq({ + {'1', 'other_man'}, + {'1', 'other_man'}, }, get_search_history('other_man(1)')) end) end) -- cgit From 054839437e63a7cc985e266052a1539c560a0682 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 17 Sep 2023 06:07:53 +0800 Subject: test(plugin/man_spec): use pesc() on actual_file in pattern (#25199) --- test/functional/plugin/man_spec.lua | 3 ++- 1 file changed, 2 insertions(+), 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 d5c1a78fc8..815ddbc523 100644 --- a/test/functional/plugin/man_spec.lua +++ b/test/functional/plugin/man_spec.lua @@ -9,6 +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 skip = helpers.skip local is_ci = helpers.is_ci @@ -189,7 +190,7 @@ describe(':Man', function() 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(actual_file), + 'man.lua: "no manual entry for %s"'):format(pesc(actual_file)), funcs.system(args, {''})) os.remove(actual_file) end) -- cgit