2024-04-20 08:44:13 -07:00
|
|
|
local t = require('test.testutil')
|
|
|
|
local n = require('test.functional.testnvim')()
|
2017-11-30 23:06:35 -07:00
|
|
|
local Screen = require('test.functional.ui.screen')
|
2024-04-20 08:44:13 -07:00
|
|
|
|
|
|
|
local command, feed = n.command, n.feed
|
|
|
|
local clear = n.clear
|
|
|
|
local exec_lua = n.exec_lua
|
|
|
|
local fn = n.fn
|
|
|
|
local nvim_prog = n.nvim_prog
|
2024-04-08 02:03:20 -07:00
|
|
|
local matches = t.matches
|
|
|
|
local tmpname = t.tmpname
|
|
|
|
local eq = t.eq
|
2024-01-12 04:28:20 -07:00
|
|
|
local pesc = vim.pesc
|
2024-04-08 02:03:20 -07:00
|
|
|
local skip = t.skip
|
|
|
|
local is_ci = t.is_ci
|
2023-03-03 12:44:13 -07:00
|
|
|
|
2023-03-07 07:13:09 -07:00
|
|
|
-- Collects all names passed to find_path() after attempting ":Man foo".
|
2023-03-03 12:44:13 -07:00
|
|
|
local function get_search_history(name)
|
2024-08-11 01:27:48 -07:00
|
|
|
return exec_lua(function()
|
|
|
|
local args = vim.split(name, ' ')
|
2024-08-15 07:02:20 -07:00
|
|
|
local man = require('man')
|
2023-03-03 12:44:13 -07:00
|
|
|
local res = {}
|
2024-08-11 01:27:48 -07:00
|
|
|
--- @diagnostic disable-next-line:duplicate-set-field
|
|
|
|
man.find_path = function(sect, name0)
|
|
|
|
table.insert(res, { sect, name0 })
|
2023-03-03 12:44:13 -07:00
|
|
|
return nil
|
|
|
|
end
|
2024-08-11 01:27:48 -07:00
|
|
|
local ok, rv = pcall(man.open_page, -1, { tab = 0 }, args)
|
2023-03-07 07:13:09 -07:00
|
|
|
assert(not ok)
|
|
|
|
assert(rv and rv:match('no manual entry'))
|
2023-03-03 12:44:13 -07:00
|
|
|
return res
|
2024-08-11 01:27:48 -07:00
|
|
|
end)
|
2023-03-03 12:44:13 -07:00
|
|
|
end
|
2017-11-30 23:06:35 -07:00
|
|
|
|
2022-08-30 15:13:52 -07:00
|
|
|
clear()
|
2024-01-12 10:59:57 -07:00
|
|
|
if fn.executable('man') == 0 then
|
2022-08-30 15:13:52 -07:00
|
|
|
pending('missing "man" command', function() end)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2018-01-09 02:10:22 -07:00
|
|
|
describe(':Man', function()
|
2022-05-13 07:49:08 -07:00
|
|
|
before_each(function()
|
|
|
|
clear()
|
|
|
|
end)
|
|
|
|
|
2018-01-09 02:10:22 -07:00
|
|
|
describe('man.lua: highlight_line()', function()
|
2024-03-25 12:06:28 -07:00
|
|
|
local screen --- @type test.functional.ui.screen
|
2017-11-30 23:06:35 -07:00
|
|
|
|
|
|
|
before_each(function()
|
2019-06-18 13:35:35 -07:00
|
|
|
command('syntax on')
|
|
|
|
command('set filetype=man')
|
|
|
|
command('syntax off') -- Ignore syntax groups
|
2017-11-30 23:06:35 -07:00
|
|
|
screen = Screen.new(52, 5)
|
2017-12-24 10:16:58 -07:00
|
|
|
screen:set_default_attr_ids({
|
2017-11-30 23:06:35 -07:00
|
|
|
b = { bold = true },
|
|
|
|
i = { italic = true },
|
|
|
|
u = { underline = true },
|
|
|
|
bi = { bold = true, italic = true },
|
|
|
|
biu = { bold = true, italic = true, underline = true },
|
2019-10-12 04:29:51 -07:00
|
|
|
c = { foreground = Screen.colors.Blue }, -- control chars
|
|
|
|
eob = { bold = true, foreground = Screen.colors.Blue }, -- empty line '~'s
|
2017-12-24 10:16:58 -07:00
|
|
|
})
|
|
|
|
end)
|
2017-11-30 23:06:35 -07:00
|
|
|
|
2017-12-24 10:16:58 -07:00
|
|
|
it('clears backspaces from text and adds highlights', function()
|
2024-03-25 12:06:28 -07:00
|
|
|
feed(
|
2017-12-24 10:16:58 -07:00
|
|
|
[[
|
|
|
|
ithis i<C-v><C-h>is<C-v><C-h>s a<C-v><C-h>a test
|
|
|
|
with _<C-v><C-h>o_<C-v><C-h>v_<C-v><C-h>e_<C-v><C-h>r_<C-v><C-h>s_<C-v><C-h>t_<C-v><C-h>r_<C-v><C-h>u_<C-v><C-h>c_<C-v><C-h>k text<ESC>]]
|
|
|
|
)
|
2017-11-30 23:06:35 -07:00
|
|
|
|
2019-10-12 04:29:51 -07:00
|
|
|
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 |
|
2023-12-09 05:42:00 -07:00
|
|
|
{eob:~ }|*2
|
2019-10-12 04:29:51 -07:00
|
|
|
|
|
|
|
|
]],
|
|
|
|
}
|
2017-11-30 23:06:35 -07:00
|
|
|
|
2022-09-02 07:20:29 -07:00
|
|
|
exec_lua [[require'man'.init_pager()]]
|
2017-11-30 23:06:35 -07:00
|
|
|
|
2017-12-24 10:16:58 -07:00
|
|
|
screen:expect([[
|
|
|
|
^this {b:is} {b:a} test |
|
2023-02-01 10:21:42 -07:00
|
|
|
with {i:overstruck} text |
|
2023-12-09 05:42:00 -07:00
|
|
|
{eob:~ }|*2
|
2017-11-30 23:06:35 -07:00
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
2017-12-24 10:16:58 -07:00
|
|
|
it('clears escape sequences from text and adds highlights', function()
|
2024-03-25 12:06:28 -07:00
|
|
|
feed(
|
2017-12-24 10:16:58 -07:00
|
|
|
[[
|
|
|
|
ithis <C-v><ESC>[1mis <C-v><ESC>[3ma <C-v><ESC>[4mtest<C-v><ESC>[0m
|
|
|
|
<C-v><ESC>[4mwith<C-v><ESC>[24m <C-v><ESC>[4mescaped<C-v><ESC>[24m <C-v><ESC>[4mtext<C-v><ESC>[24m<ESC>]]
|
|
|
|
)
|
2017-11-30 23:06:35 -07:00
|
|
|
|
2019-10-12 04:29:51 -07:00
|
|
|
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 |
|
2023-12-09 05:42:00 -07:00
|
|
|
{eob:~ }|*2
|
2019-10-12 04:29:51 -07:00
|
|
|
|
|
|
|
|
]=],
|
|
|
|
}
|
2017-11-30 23:06:35 -07:00
|
|
|
|
2022-09-02 07:20:29 -07:00
|
|
|
exec_lua [[require'man'.init_pager()]]
|
2017-11-30 23:06:35 -07:00
|
|
|
|
2017-12-24 10:16:58 -07:00
|
|
|
screen:expect([[
|
2017-11-30 23:06:35 -07:00
|
|
|
^this {b:is }{bi:a }{biu:test} |
|
|
|
|
{u:with} {u:escaped} {u:text} |
|
2023-12-09 05:42:00 -07:00
|
|
|
{eob:~ }|*2
|
2017-11-30 23:06:35 -07:00
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
2024-06-07 12:43:17 -07:00
|
|
|
it('clears OSC 8 hyperlink markup from text', function()
|
|
|
|
feed(
|
|
|
|
[[
|
|
|
|
ithis <C-v><ESC>]8;;http://example.com<C-v><ESC>\Link Title<C-v><ESC>]8;;<C-v><ESC>\<ESC>]]
|
|
|
|
)
|
|
|
|
|
|
|
|
screen:expect {
|
|
|
|
grid = [=[
|
|
|
|
this {c:^[}]8;;http://example.com{c:^[}\Link Title{c:^[}]8;;{c:^[}^\ |
|
|
|
|
{eob:~ }|*3
|
|
|
|
|
|
|
|
|
]=],
|
|
|
|
}
|
|
|
|
|
|
|
|
exec_lua [[require'man'.init_pager()]]
|
|
|
|
|
|
|
|
screen:expect([[
|
|
|
|
^this Link Title |
|
|
|
|
{eob:~ }|*3
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
2017-11-30 23:06:35 -07:00
|
|
|
it('highlights multibyte text', function()
|
2024-03-25 12:06:28 -07:00
|
|
|
feed(
|
2017-12-24 10:16:58 -07:00
|
|
|
[[
|
|
|
|
ithis i<C-v><C-h>is<C-v><C-h>s あ<C-v><C-h>あ test
|
|
|
|
with _<C-v><C-h>ö_<C-v><C-h>v_<C-v><C-h>e_<C-v><C-h>r_<C-v><C-h>s_<C-v><C-h>t_<C-v><C-h>r_<C-v><C-h>u_<C-v><C-h>̃_<C-v><C-h>c_<C-v><C-h>k te<C-v><ESC>[3mxt¶<C-v><ESC>[0m<ESC>]]
|
|
|
|
)
|
2022-09-02 07:20:29 -07:00
|
|
|
exec_lua [[require'man'.init_pager()]]
|
2017-11-30 23:06:35 -07:00
|
|
|
|
2017-12-24 10:16:58 -07:00
|
|
|
screen:expect([[
|
2017-11-30 23:06:35 -07:00
|
|
|
^this {b:is} {b:あ} test |
|
2023-02-01 10:21:42 -07:00
|
|
|
with {i:överstrũck} te{i:xt¶} |
|
2023-12-09 05:42:00 -07:00
|
|
|
{eob:~ }|*2
|
2017-11-30 23:06:35 -07:00
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('highlights underscores based on context', function()
|
2024-03-25 12:06:28 -07:00
|
|
|
feed(
|
2017-12-24 10:16:58 -07:00
|
|
|
[[
|
|
|
|
i_<C-v><C-h>_b<C-v><C-h>be<C-v><C-h>eg<C-v><C-h>gi<C-v><C-h>in<C-v><C-h>ns<C-v><C-h>s
|
|
|
|
m<C-v><C-h>mi<C-v><C-h>id<C-v><C-h>d_<C-v><C-h>_d<C-v><C-h>dl<C-v><C-h>le<C-v><C-h>e
|
|
|
|
_<C-v><C-h>m_<C-v><C-h>i_<C-v><C-h>d_<C-v><C-h>__<C-v><C-h>d_<C-v><C-h>l_<C-v><C-h>e<ESC>]]
|
|
|
|
)
|
2022-09-02 07:20:29 -07:00
|
|
|
exec_lua [[require'man'.init_pager()]]
|
2017-12-24 10:16:58 -07:00
|
|
|
|
|
|
|
screen:expect([[
|
2017-11-30 23:06:35 -07:00
|
|
|
{b:^_begins} |
|
|
|
|
{b:mid_dle} |
|
2023-02-01 10:21:42 -07:00
|
|
|
{i:mid_dle} |
|
2019-10-12 04:29:51 -07:00
|
|
|
{eob:~ }|
|
2017-11-30 23:06:35 -07:00
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('highlights various bullet formats', function()
|
2024-03-25 12:06:28 -07:00
|
|
|
feed([[
|
2017-12-24 10:16:58 -07:00
|
|
|
i· ·<C-v><C-h>·
|
|
|
|
+<C-v><C-h>o
|
|
|
|
+<C-v><C-h>+<C-v><C-h>o<C-v><C-h>o double<ESC>]])
|
2022-09-02 07:20:29 -07:00
|
|
|
exec_lua [[require'man'.init_pager()]]
|
2017-12-24 10:16:58 -07:00
|
|
|
|
|
|
|
screen:expect([[
|
2017-11-30 23:06:35 -07:00
|
|
|
^· {b:·} |
|
|
|
|
{b:·} |
|
|
|
|
{b:·} double |
|
2019-10-12 04:29:51 -07:00
|
|
|
{eob:~ }|
|
2017-11-30 23:06:35 -07:00
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
2019-06-18 13:35:35 -07:00
|
|
|
|
|
|
|
it('handles : characters in input', function()
|
2024-03-25 12:06:28 -07:00
|
|
|
feed([[
|
2019-06-18 13:35:35 -07:00
|
|
|
i<C-v><C-[>[40m 0 <C-v><C-[>[41m 1 <C-v><C-[>[42m 2 <C-v><C-[>[43m 3
|
|
|
|
<C-v><C-[>[44m 4 <C-v><C-[>[45m 5 <C-v><C-[>[46m 6 <C-v><C-[>[47m 7 <C-v><C-[>[100m 8 <C-v><C-[>[101m 9
|
|
|
|
<C-v><C-[>[102m 10 <C-v><C-[>[103m 11 <C-v><C-[>[104m 12 <C-v><C-[>[105m 13 <C-v><C-[>[106m 14 <C-v><C-[>[107m 15
|
|
|
|
<C-v><C-[>[48:5:16m 16 <ESC>]])
|
2022-09-02 07:20:29 -07:00
|
|
|
exec_lua [[require'man'.init_pager()]]
|
2019-06-18 13:35:35 -07:00
|
|
|
|
|
|
|
screen:expect([[
|
|
|
|
^ 0 1 2 3 |
|
|
|
|
4 5 6 7 8 9 |
|
|
|
|
10 11 12 13 14 15 |
|
|
|
|
16 |
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
2017-11-30 23:06:35 -07:00
|
|
|
end)
|
2022-05-13 07:49:08 -07:00
|
|
|
|
|
|
|
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!',
|
2024-04-26 11:14:45 -07:00
|
|
|
'+tag ls',
|
2022-05-13 07:49:08 -07:00
|
|
|
'+call nvim_input("q")',
|
|
|
|
}
|
2024-01-12 10:59:57 -07:00
|
|
|
matches('quit works!!', fn.system(args, { 'manpage contents' }))
|
2022-05-13 07:49:08 -07:00
|
|
|
end)
|
2022-10-17 02:37:44 -07:00
|
|
|
|
|
|
|
it('reports non-existent man pages for absolute paths', function()
|
2022-11-21 17:13:30 -07:00
|
|
|
skip(is_ci('cirrus'))
|
2022-10-17 02:37:44 -07:00
|
|
|
local actual_file = tmpname()
|
|
|
|
-- actual_file must be an absolute path to an existent file for us to test against it
|
|
|
|
matches('^/.+', 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(
|
2023-09-16 15:07:53 -07:00
|
|
|
pesc(actual_file)
|
|
|
|
),
|
2024-01-12 10:59:57 -07:00
|
|
|
fn.system(args, { '' })
|
2024-01-02 18:09:18 -07:00
|
|
|
)
|
2022-10-17 02:37:44 -07:00
|
|
|
os.remove(actual_file)
|
|
|
|
end)
|
2023-03-03 12:44:13 -07:00
|
|
|
|
2023-03-07 07:13:09 -07:00
|
|
|
it('tries variants with spaces, underscores #22503', function()
|
|
|
|
eq({
|
2023-05-08 00:22:58 -07:00
|
|
|
{ '', 'NAME WITH SPACES' },
|
|
|
|
{ '', 'NAME_WITH_SPACES' },
|
2023-03-07 07:13:09 -07:00
|
|
|
}, get_search_history('NAME WITH SPACES'))
|
|
|
|
eq({
|
2023-05-08 00:22:58 -07:00
|
|
|
{ '3', 'some other man' },
|
|
|
|
{ '3', 'some_other_man' },
|
2023-03-07 07:13:09 -07:00
|
|
|
}, get_search_history('3 some other man'))
|
|
|
|
eq({
|
2023-05-08 00:22:58 -07:00
|
|
|
{ '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' },
|
2023-03-07 07:13:09 -07:00
|
|
|
}, get_search_history('other_man(1)'))
|
2023-03-03 12:44:13 -07:00
|
|
|
end)
|
2017-11-30 23:06:35 -07:00
|
|
|
end)
|