From 134c0f0bdb50b16d443b103fc1a81c9ae5c7c017 Mon Sep 17 00:00:00 2001 From: Gabriel Holodak Date: Fri, 1 Dec 2017 01:06:35 -0500 Subject: Add functional tests for man highlighting --- test/functional/plugin/man_spec.lua | 181 ++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 test/functional/plugin/man_spec.lua (limited to 'test/functional/plugin/man_spec.lua') diff --git a/test/functional/plugin/man_spec.lua b/test/functional/plugin/man_spec.lua new file mode 100644 index 0000000000..53384a9d47 --- /dev/null +++ b/test/functional/plugin/man_spec.lua @@ -0,0 +1,181 @@ +local helpers = require('test.functional.helpers')(after_each) +local plugin_helpers = require('test.functional.plugin.helpers') + +local Screen = require('test.functional.ui.screen') + +local buffer, command, eval = helpers.buffer, helpers.command, helpers.eval + +before_each(function() + plugin_helpers.reset() + helpers.clear() + command('syntax on') + command('set filetype=man') +end) + +describe('In autoload/man.vim', function() + describe('function man#highlight_formatted_text', function() + local screen + + before_each(function() + command('syntax off') -- Ignore syntax groups + screen = Screen.new(52, 5) + screen:attach() + end) + + after_each(function() + screen:detach() + end) + + local function expect(string) + screen:expect(string, + { + b = { bold = true }, + i = { italic = true }, + u = { underline = true }, + bi = { bold = true, italic = true }, + biu = { bold = true, italic = true, underline = true }, + }, + {{ bold = true, foreground = Screen.colors.Blue }}) + end + + local function expect_without_highlights(string) + screen:expect(string, nil, true) + end + + local function insert_lines(...) + buffer('set_lines', 0, 0, 1, false, { ... }) + end + + it('clears backspaces from text', function() + insert_lines( + "this i\bis\bs a\ba test", + "with _\bo_\bv_\be_\br_\bs_\bt_\br_\bu_\bc_\bk text" + ) + + expect_without_highlights([[ + ^this i^His^Hs a^Ha test | + with _^Ho_^Hv_^He_^Hr_^Hs_^Ht_^Hr_^Hu_^Hc_^Hk text | + ~ | + ~ | + | + ]]) + + eval('man#highlight_formatted_text()') + + expect_without_highlights([[ + ^this is a test | + with overstruck text | + ~ | + ~ | + | + ]]) + end) + + it('clears escape sequences from text', function() + insert_lines( + "this \027[1mis \027[3ma \027[4mtest\027[0m", + "\027[4mwith\027[24m \027[4mescaped\027[24m \027[4mtext\027[24m" + ) + + expect_without_highlights([[ + ^this ^[[1mis ^[[3ma ^[[4mtest^[[0m | + ^[[4mwith^[[24m ^[[4mescaped^[[24m ^[[4mtext^[[24m | + ~ | + ~ | + | + ]]) + + eval('man#highlight_formatted_text()') + + expect_without_highlights([[ + ^this is a test | + with escaped text | + ~ | + ~ | + | + ]]) + end) + + it('highlights overstruck text', function() + insert_lines( + "this i\bis\bs a\ba test", + "with _\bo_\bv_\be_\br_\bs_\bt_\br_\bu_\bc_\bk text" + ) + eval('man#highlight_formatted_text()') + + expect([[ + ^this {b:is} {b:a} test | + with {u:overstruck} text | + ~ | + ~ | + | + ]]) + end) + + it('highlights escape sequences in text', function() + insert_lines( + "this \027[1mis \027[3ma \027[4mtest\027[0m", + "\027[4mwith\027[24m \027[4mescaped\027[24m \027[4mtext\027[24m" + ) + eval('man#highlight_formatted_text()') + + expect([[ + ^this {b:is }{bi:a }{biu:test} | + {u:with} {u:escaped} {u:text} | + ~ | + ~ | + | + ]]) + end) + + it('highlights multibyte text', function() + insert_lines( + "this i\bis\bs あ\bあ test", + "with _\bö_\bv_\be_\br_\bs_\bt_\br_\bu_\bc_\bk te\027[3mxt¶\027[0m" + ) + eval('man#highlight_formatted_text()') + + expect([[ + ^this {b:is} {b:あ} test | + with {u:överstruck} te{i:xt¶} | + ~ | + ~ | + | + ]]) + end) + + it('highlights underscores based on context', function() + insert_lines( + "_\b_b\bbe\beg\bgi\bin\bns\bs", + "m\bmi\bid\bd_\b_d\bdl\ble\be", + "_\bm_\bi_\bd_\b__\bd_\bl_\be" + ) + eval('man#highlight_formatted_text()') + + expect([[ + {b:^_begins} | + {b:mid_dle} | + {u:mid_dle} | + ~ | + | + ]]) + end) + + it('highlights various bullet formats', function() + insert_lines( + "· ·\b·", + "+\bo", + "+\b+\bo\bo double" + ) + eval('man#highlight_formatted_text()') + + expect([[ + ^· {b:·} | + {b:·} | + {b:·} double | + ~ | + | + ]]) + end) + end) +end) -- cgit From eb44519b5debf740f692bb4ea19ad83b29749484 Mon Sep 17 00:00:00 2001 From: Gabriel Holodak Date: Sun, 24 Dec 2017 12:16:58 -0500 Subject: Address PR comments --- test/functional/plugin/man_spec.lua | 148 +++++++++++++----------------------- 1 file changed, 51 insertions(+), 97 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 53384a9d47..479fd6e7a5 100644 --- a/test/functional/plugin/man_spec.lua +++ b/test/functional/plugin/man_spec.lua @@ -3,7 +3,7 @@ local plugin_helpers = require('test.functional.plugin.helpers') local Screen = require('test.functional.ui.screen') -local buffer, command, eval = helpers.buffer, helpers.command, helpers.eval +local command, eval, rawfeed = helpers.command, helpers.eval, helpers.rawfeed before_each(function() plugin_helpers.reset() @@ -19,107 +19,64 @@ describe('In autoload/man.vim', function() before_each(function() command('syntax off') -- Ignore syntax groups screen = Screen.new(52, 5) - screen:attach() - end) - - after_each(function() - screen:detach() - end) - - local function expect(string) - screen:expect(string, - { + 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 }, - }, - {{ bold = true, foreground = Screen.colors.Blue }}) - end - - local function expect_without_highlights(string) - screen:expect(string, nil, true) - end - - local function insert_lines(...) - buffer('set_lines', 0, 0, 1, false, { ... }) - end - - it('clears backspaces from text', function() - insert_lines( - "this i\bis\bs a\ba test", - "with _\bo_\bv_\be_\br_\bs_\bt_\br_\bu_\bc_\bk text" - ) - - expect_without_highlights([[ - ^this i^His^Hs a^Ha test | - with _^Ho_^Hv_^He_^Hr_^Hs_^Ht_^Hr_^Hu_^Hc_^Hk text | - ~ | - ~ | - | - ]]) - - eval('man#highlight_formatted_text()') + }) + screen:set_default_attr_ignore({ + { foreground = Screen.colors.Blue }, -- control chars + { bold = true, foreground = Screen.colors.Blue } -- empty line '~'s + }) + screen:attach() + end) - expect_without_highlights([[ - ^this is a test | - with overstruck text | - ~ | - ~ | - | - ]]) + after_each(function() + screen:detach() end) - it('clears escape sequences from text', function() - insert_lines( - "this \027[1mis \027[3ma \027[4mtest\027[0m", - "\027[4mwith\027[24m \027[4mescaped\027[24m \027[4mtext\027[24m" - ) + 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]]) - expect_without_highlights([[ - ^this ^[[1mis ^[[3ma ^[[4mtest^[[0m | - ^[[4mwith^[[24m ^[[4mescaped^[[24m ^[[4mtext^[[24m | + screen:expect([[ + this i^His^Hs a^Ha test | + with _^Ho_^Hv_^He_^Hr_^Hs_^Ht_^Hr_^Hu_^Hc_^Hk tex^t | ~ | ~ | | ]]) - eval('man#highlight_formatted_text()') + eval('man#init_pager()') - expect_without_highlights([[ - ^this is a test | - with escaped text | + screen:expect([[ + ^this {b:is} {b:a} test | + with {u:overstruck} text | ~ | ~ | | ]]) end) - it('highlights overstruck text', function() - insert_lines( - "this i\bis\bs a\ba test", - "with _\bo_\bv_\be_\br_\bs_\bt_\br_\bu_\bc_\bk text" - ) - eval('man#highlight_formatted_text()') + it('clears escape sequences from text and adds highlights', function() + rawfeed([[ + ithis [1mis [3ma [4mtest[0m + [4mwith[24m [4mescaped[24m [4mtext[24m]]) - expect([[ - ^this {b:is} {b:a} test | - with {u:overstruck} text | + screen:expect([[ + this ^[[1mis ^[[3ma ^[[4mtest^[[0m | + ^[[4mwith^[[24m ^[[4mescaped^[[24m ^[[4mtext^[[24^m | ~ | ~ | | ]]) - end) - it('highlights escape sequences in text', function() - insert_lines( - "this \027[1mis \027[3ma \027[4mtest\027[0m", - "\027[4mwith\027[24m \027[4mescaped\027[24m \027[4mtext\027[24m" - ) - eval('man#highlight_formatted_text()') + eval('man#init_pager()') - expect([[ + screen:expect([[ ^this {b:is }{bi:a }{biu:test} | {u:with} {u:escaped} {u:text} | ~ | @@ -129,15 +86,14 @@ describe('In autoload/man.vim', function() end) it('highlights multibyte text', function() - insert_lines( - "this i\bis\bs あ\bあ test", - "with _\bö_\bv_\be_\br_\bs_\bt_\br_\bu_\bc_\bk te\027[3mxt¶\027[0m" - ) - eval('man#highlight_formatted_text()') + rawfeed([[ + ithis iiss ああ test + with _ö_v_e_r_s_t_r_u_̃_c_k te[3mxt¶[0m]]) + eval('man#init_pager()') - expect([[ + screen:expect([[ ^this {b:is} {b:あ} test | - with {u:överstruck} te{i:xt¶} | + with {u:överstrũck} te{i:xt¶} | ~ | ~ | | @@ -145,14 +101,13 @@ describe('In autoload/man.vim', function() end) it('highlights underscores based on context', function() - insert_lines( - "_\b_b\bbe\beg\bgi\bin\bns\bs", - "m\bmi\bid\bd_\b_d\bdl\ble\be", - "_\bm_\bi_\bd_\b__\bd_\bl_\be" - ) - eval('man#highlight_formatted_text()') - - expect([[ + 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} | @@ -162,14 +117,13 @@ describe('In autoload/man.vim', function() end) it('highlights various bullet formats', function() - insert_lines( - "· ·\b·", - "+\bo", - "+\b+\bo\bo double" - ) - eval('man#highlight_formatted_text()') - - expect([[ + rawfeed([[ + i· ·· + +o + ++oo double]]) + eval('man#init_pager()') + + screen:expect([[ ^· {b:·} | {b:·} | {b:·} double | -- cgit From e243dbdc328b53926009153bd7fca32ebfc1abb2 Mon Sep 17 00:00:00 2001 From: James McCoy Date: Thu, 1 Feb 2018 14:30:31 -0500 Subject: test: man_spec: Fix use of nested [[ quoting Lua (not LuaJIT) complains about the "^[[" strings inside the expect, since it sees them as nested quotes. Change the quoting to [=[ ]=] to avoid the issue. --- test/functional/plugin/man_spec.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 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 dc189b8f8e..e5da7932a5 100644 --- a/test/functional/plugin/man_spec.lua +++ b/test/functional/plugin/man_spec.lua @@ -66,13 +66,13 @@ describe(':Man', function() ithis [1mis [3ma [4mtest[0m [4mwith[24m [4mescaped[24m [4mtext[24m]]) - screen:expect([[ + screen:expect([=[ this ^[[1mis ^[[3ma ^[[4mtest^[[0m | ^[[4mwith^[[24m ^[[4mescaped^[[24m ^[[4mtext^[[24^m | ~ | ~ | | - ]]) + ]=]) eval('man#init_pager()') -- cgit