functests: Abstract away some ways to enter cmdline coloring mode

Reason: should actually switch to using input() coloring because other coloring 
variants are eventually going away.
This commit is contained in:
ZyX
2017-06-27 01:54:08 +03:00
parent 072a853fa2
commit 71616fce0b

View File

@@ -113,11 +113,18 @@ before_each(function()
}) })
end) end)
local function set_color_cb(funcname)
meths.set_var('Nvim_color_cmdline', funcname)
end
local function start_prompt(text)
feed(':' .. (text or ''))
end
describe('Command-line coloring', function() describe('Command-line coloring', function()
it('works', function() it('works', function()
meths.set_var('Nvim_color_cmdline', 'RainBowParens') set_color_cb('RainBowParens')
meths.set_option('more', false) meths.set_option('more', false)
feed(':') start_prompt()
screen:expect([[ screen:expect([[
| |
{EOB:~ }| {EOB:~ }|
@@ -219,8 +226,8 @@ describe('Command-line coloring', function()
end) end)
for _, func_part in ipairs({'', 'n', 'msg'}) do for _, func_part in ipairs({'', 'n', 'msg'}) do
it('disables :echo' .. func_part .. ' messages', function() it('disables :echo' .. func_part .. ' messages', function()
meths.set_var('Nvim_color_cmdline', 'Echo' .. func_part .. 'ing') set_color_cb('Echo' .. func_part .. 'ing')
feed(':echo') start_prompt('echo')
screen:expect([[ screen:expect([[
| |
{EOB:~ }| {EOB:~ }|
@@ -235,8 +242,8 @@ describe('Command-line coloring', function()
end end
it('does the right thing when hl start appears to split multibyte char', it('does the right thing when hl start appears to split multibyte char',
function() function()
meths.set_var('Nvim_color_cmdline', 'SplittedMultibyteStart') set_color_cb('SplittedMultibyteStart')
feed(':echo "«') start_prompt('echo "«')
screen:expect([[ screen:expect([[
{EOB:~ }| {EOB:~ }|
{EOB:~ }| {EOB:~ }|
@@ -261,8 +268,8 @@ describe('Command-line coloring', function()
end) end)
it('does the right thing when hl end appears to split multibyte char', it('does the right thing when hl end appears to split multibyte char',
function() function()
meths.set_var('Nvim_color_cmdline', 'SplittedMultibyteEnd') set_color_cb('SplittedMultibyteEnd')
feed(':echo "«') start_prompt('echo "«')
screen:expect([[ screen:expect([[
{EOB:~ }| {EOB:~ }|
{EOB:~ }| {EOB:~ }|
@@ -276,34 +283,34 @@ describe('Command-line coloring', function()
end) end)
it('does the right thing when errorring', function() it('does the right thing when errorring', function()
if true then return pending('echoerr does not work well now') end if true then return pending('echoerr does not work well now') end
meths.set_var('Nvim_color_cmdline', 'Echoerring') set_color_cb('Echoerring')
feed(':e') start_prompt('e')
-- FIXME Does not work well with :echoerr: error message overwrites cmdline. -- FIXME Does not work well with :echoerr: error message overwrites cmdline.
end) end)
it('does the right thing when throwing', function() it('does the right thing when throwing', function()
if true then return pending('Throwing does not work well now') end if true then return pending('Throwing does not work well now') end
meths.set_var('Nvim_color_cmdline', 'Throwing') set_color_cb('Throwing')
feed(':e') start_prompt('e')
-- FIXME Does not work well with :throw: error message overwrites cmdline. -- FIXME Does not work well with :throw: error message overwrites cmdline.
end) end)
it('still executes command-line even if errored out', function() it('still executes command-line even if errored out', function()
meths.set_var('Nvim_color_cmdline', 'SplittedMultibyteStart') set_color_cb('SplittedMultibyteStart')
feed(':let x = "«"\n') start_prompt('let x = "«"\n')
eq('«', meths.get_var('x')) eq('«', meths.get_var('x'))
local msg = 'E5405: Chunk 0 start 10 splits multibyte character' local msg = 'E5405: Chunk 0 start 10 splits multibyte character'
eq('\n'..msg, funcs.execute('messages')) eq('\n'..msg, funcs.execute('messages'))
end) end)
it('stops executing callback after a number of errors', function() it('stops executing callback after a number of errors', function()
meths.set_var('Nvim_color_cmdline', 'SplittedMultibyteStart') set_color_cb('SplittedMultibyteStart')
feed(':let x = "«»«»«»«»«»"\n') start_prompt('let x = "«»«»«»«»«»"\n')
eq('«»«»«»«»«»', meths.get_var('x')) eq('«»«»«»«»«»', meths.get_var('x'))
local msg = '\nE5405: Chunk 0 start 10 splits multibyte character' local msg = '\nE5405: Chunk 0 start 10 splits multibyte character'
eq(msg:rep(1), funcs.execute('messages')) eq(msg:rep(1), funcs.execute('messages'))
end) end)
it('allows interrupting callback with <C-c>', function() it('allows interrupting callback with <C-c>', function()
if true then return pending('<C-c> does not work well enough now') end if true then return pending('<C-c> does not work well enough now') end
meths.set_var('Nvim_color_cmdline', 'Halting') set_color_cb('Halting')
feed(':echo 42') start_prompt('echo 42')
for i = 1, 6 do for i = 1, 6 do
screen:expect([[ screen:expect([[
^ | ^ |
@@ -327,7 +334,7 @@ describe('Command-line coloring', function()
{EOB:~ }| {EOB:~ }|
Type :quit<Enter> to exit Nvim | Type :quit<Enter> to exit Nvim |
]]) ]])
feed(':echo 42<CR>') start_prompt('echo 42<CR>')
screen:expect([[ screen:expect([[
^ | ^ |
{EOB:~ }| {EOB:~ }|
@@ -340,8 +347,8 @@ describe('Command-line coloring', function()
]]) ]])
end) end)
it('works fine with NUL, NL, CR', function() it('works fine with NUL, NL, CR', function()
meths.set_var('Nvim_color_cmdline', 'RainBowParens') set_color_cb('RainBowParens')
feed(':echo ("<C-v><CR><C-v><Nul><C-v><NL>")') start_prompt('echo ("<C-v><CR><C-v><Nul><C-v><NL>")')
screen:expect([[ screen:expect([[
| |
{EOB:~ }| {EOB:~ }|