local helpers = require('test.functional.helpers')(after_each) local plugin_helpers = require('test.functional.plugin.helpers') local Screen = require('test.functional.ui.screen') local command, eval, rawfeed = helpers.command, helpers.eval, helpers.rawfeed before_each(function() plugin_helpers.reset() helpers.clear() command('syntax on') command('set filetype=man') end) describe(':Man', function() describe('man.lua: highlight_line()', function() local screen before_each(function() command('syntax off') -- Ignore syntax groups screen = Screen.new(52, 5) screen:set_default_attr_ids({ b = { bold = true }, i = { italic = true }, u = { underline = true }, bi = { bold = true, italic = true }, biu = { bold = true, italic = true, underline = true }, }) screen:set_default_attr_ignore({ { foreground = Screen.colors.Blue }, -- control chars { bold = true, foreground = Screen.colors.Blue } -- empty line '~'s }) screen:attach() end) after_each(function() screen:detach() end) it('clears backspaces from text and adds highlights', function() rawfeed([[ ithis iiss aa test with _o_v_e_r_s_t_r_u_c_k text]]) screen:expect([[ this i^His^Hs a^Ha test | with _^Ho_^Hv_^He_^Hr_^Hs_^Ht_^Hr_^Hu_^Hc_^Hk tex^t | ~ | ~ | | ]]) eval('man#init_pager()') screen:expect([[ ^this {b:is} {b:a} test | with {u:overstruck} text | ~ | ~ | | ]]) end) it('clears escape sequences from text and adds highlights', function() rawfeed([[ ithis [1mis [3ma [4mtest[0m [4mwith[24m [4mescaped[24m [4mtext[24m]]) screen:expect([=[ this ^[[1mis ^[[3ma ^[[4mtest^[[0m | ^[[4mwith^[[24m ^[[4mescaped^[[24m ^[[4mtext^[[24^m | ~ | ~ | | ]=]) eval('man#init_pager()') screen:expect([[ ^this {b:is }{bi:a }{biu:test} | {u:with} {u:escaped} {u:text} | ~ | ~ | | ]]) end) it('highlights multibyte text', function() rawfeed([[ ithis iiss ああ test with _ö_v_e_r_s_t_r_u_̃_c_k te[3mxt¶[0m]]) eval('man#init_pager()') screen:expect([[ ^this {b:is} {b:あ} test | with {u:överstrũck} te{i:xt¶} | ~ | ~ | | ]]) end) it('highlights underscores based on context', function() rawfeed([[ i__bbeeggiinnss mmiidd__ddllee _m_i_d___d_l_e]]) eval('man#init_pager()') screen:expect([[ {b:^_begins} | {b:mid_dle} | {u:mid_dle} | ~ | | ]]) end) it('highlights various bullet formats', function() rawfeed([[ i· ·· +o ++oo double]]) eval('man#init_pager()') screen:expect([[ ^· {b:·} | {b:·} | {b:·} double | ~ | | ]]) end) end) end)