2017-03-25 18:04:23 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
|
|
|
local Screen = require('test.functional.ui.screen')
|
|
|
|
|
2017-03-26 07:25:03 -07:00
|
|
|
local eq = helpers.eq
|
2017-03-25 18:04:23 -07:00
|
|
|
local feed = helpers.feed
|
|
|
|
local clear = helpers.clear
|
|
|
|
local meths = helpers.meths
|
2017-03-26 07:25:03 -07:00
|
|
|
local funcs = helpers.funcs
|
2017-03-25 18:04:23 -07:00
|
|
|
local source = helpers.source
|
|
|
|
|
|
|
|
local screen
|
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
clear()
|
2017-03-26 07:25:03 -07:00
|
|
|
screen = Screen.new(40, 8)
|
2017-03-25 18:04:23 -07:00
|
|
|
screen:attach()
|
|
|
|
source([[
|
2017-04-01 15:00:40 -07:00
|
|
|
highlight RBP1 guibg=Red
|
|
|
|
highlight RBP2 guibg=Yellow
|
|
|
|
highlight RBP3 guibg=Green
|
|
|
|
highlight RBP4 guibg=Blue
|
2017-03-25 18:04:23 -07:00
|
|
|
let g:NUM_LVLS = 4
|
|
|
|
function Redraw()
|
|
|
|
redraw!
|
|
|
|
return ''
|
|
|
|
endfunction
|
|
|
|
cnoremap <expr> {REDRAW} Redraw()
|
|
|
|
function RainBowParens(cmdline)
|
|
|
|
let ret = []
|
|
|
|
let i = 0
|
|
|
|
let lvl = 0
|
|
|
|
while i < len(a:cmdline)
|
|
|
|
if a:cmdline[i] is# '('
|
|
|
|
call add(ret, [i, i + 1, 'RBP' . ((lvl % g:NUM_LVLS) + 1)])
|
|
|
|
let lvl += 1
|
|
|
|
elseif a:cmdline[i] is# ')'
|
|
|
|
let lvl -= 1
|
|
|
|
call add(ret, [i, i + 1, 'RBP' . ((lvl % g:NUM_LVLS) + 1)])
|
|
|
|
endif
|
|
|
|
let i += 1
|
|
|
|
endwhile
|
|
|
|
return ret
|
|
|
|
endfunction
|
2017-03-26 07:25:03 -07:00
|
|
|
function SplittedMultibyteStart(cmdline)
|
|
|
|
let ret = []
|
|
|
|
let i = 0
|
|
|
|
while i < len(a:cmdline)
|
|
|
|
let char = nr2char(char2nr(a:cmdline[i:]))
|
|
|
|
if a:cmdline[i:i + len(char) - 1] is# char
|
|
|
|
if len(char) > 1
|
|
|
|
call add(ret, [i + 1, i + len(char), 'RBP2'])
|
|
|
|
endif
|
|
|
|
let i += len(char)
|
|
|
|
else
|
|
|
|
let i += 1
|
|
|
|
endif
|
|
|
|
endwhile
|
|
|
|
return ret
|
|
|
|
endfunction
|
|
|
|
function SplittedMultibyteEnd(cmdline)
|
|
|
|
let ret = []
|
|
|
|
let i = 0
|
|
|
|
while i < len(a:cmdline)
|
|
|
|
let char = nr2char(char2nr(a:cmdline[i:]))
|
|
|
|
if a:cmdline[i:i + len(char) - 1] is# char
|
|
|
|
if len(char) > 1
|
|
|
|
call add(ret, [i, i + 1, 'RBP1'])
|
|
|
|
endif
|
|
|
|
let i += len(char)
|
|
|
|
else
|
|
|
|
let i += 1
|
|
|
|
endif
|
|
|
|
endwhile
|
|
|
|
return ret
|
|
|
|
endfunction
|
|
|
|
function Echoing(cmdline)
|
|
|
|
echo 'HERE'
|
|
|
|
return v:_null_list
|
|
|
|
endfunction
|
|
|
|
function Echoning(cmdline)
|
|
|
|
echon 'HERE'
|
|
|
|
return v:_null_list
|
|
|
|
endfunction
|
|
|
|
function Echomsging(cmdline)
|
|
|
|
echomsg 'HERE'
|
|
|
|
return v:_null_list
|
|
|
|
endfunction
|
|
|
|
function Echoerring(cmdline)
|
|
|
|
echoerr 'HERE'
|
|
|
|
return v:_null_list
|
|
|
|
endfunction
|
|
|
|
function Redrawing(cmdline)
|
|
|
|
redraw!
|
|
|
|
return v:_null_list
|
|
|
|
endfunction
|
|
|
|
function Throwing(cmdline)
|
|
|
|
throw "ABC"
|
|
|
|
return v:_null_list
|
|
|
|
endfunction
|
|
|
|
function Halting(cmdline)
|
|
|
|
while 1
|
|
|
|
endwhile
|
|
|
|
endfunction
|
2017-03-25 18:04:23 -07:00
|
|
|
]])
|
|
|
|
screen:set_default_attr_ids({
|
2017-04-01 15:00:40 -07:00
|
|
|
RBP1={background = Screen.colors.Red},
|
|
|
|
RBP2={background = Screen.colors.Yellow},
|
|
|
|
RBP3={background = Screen.colors.Green},
|
|
|
|
RBP4={background = Screen.colors.Blue},
|
2017-03-26 07:25:03 -07:00
|
|
|
EOB={bold = true, foreground = Screen.colors.Blue1},
|
|
|
|
ERR={foreground = Screen.colors.Grey100, background = Screen.colors.Red},
|
2017-04-01 15:00:40 -07:00
|
|
|
SK={foreground = Screen.colors.Blue},
|
2017-03-25 18:04:23 -07:00
|
|
|
})
|
|
|
|
end)
|
|
|
|
|
2017-06-26 15:54:08 -07:00
|
|
|
local function set_color_cb(funcname)
|
|
|
|
meths.set_var('Nvim_color_cmdline', funcname)
|
|
|
|
end
|
|
|
|
local function start_prompt(text)
|
|
|
|
feed(':' .. (text or ''))
|
|
|
|
end
|
|
|
|
|
2017-03-25 18:04:23 -07:00
|
|
|
describe('Command-line coloring', function()
|
|
|
|
it('works', function()
|
2017-06-26 15:54:08 -07:00
|
|
|
set_color_cb('RainBowParens')
|
2017-03-25 18:04:23 -07:00
|
|
|
meths.set_option('more', false)
|
2017-06-26 15:54:08 -07:00
|
|
|
start_prompt()
|
2017-03-25 18:04:23 -07:00
|
|
|
screen:expect([[
|
|
|
|
|
|
2017-03-26 07:25:03 -07:00
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
2017-03-25 18:04:23 -07:00
|
|
|
:^ |
|
|
|
|
]])
|
|
|
|
feed('e')
|
|
|
|
screen:expect([[
|
|
|
|
|
|
2017-03-26 07:25:03 -07:00
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
2017-03-25 18:04:23 -07:00
|
|
|
:e^ |
|
|
|
|
]])
|
|
|
|
feed('cho ')
|
|
|
|
screen:expect([[
|
|
|
|
|
|
2017-03-26 07:25:03 -07:00
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
2017-03-25 18:04:23 -07:00
|
|
|
:echo ^ |
|
|
|
|
]])
|
|
|
|
feed('(')
|
|
|
|
screen:expect([[
|
|
|
|
|
|
2017-03-26 07:25:03 -07:00
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
2017-03-25 18:04:23 -07:00
|
|
|
:echo {RBP1:(}^ |
|
|
|
|
]])
|
|
|
|
feed('(')
|
|
|
|
screen:expect([[
|
|
|
|
|
|
2017-03-26 07:25:03 -07:00
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
2017-03-25 18:04:23 -07:00
|
|
|
:echo {RBP1:(}{RBP2:(}^ |
|
|
|
|
]])
|
|
|
|
feed('42')
|
|
|
|
screen:expect([[
|
|
|
|
|
|
2017-03-26 07:25:03 -07:00
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
2017-03-25 18:04:23 -07:00
|
|
|
:echo {RBP1:(}{RBP2:(}42^ |
|
|
|
|
]])
|
|
|
|
feed('))')
|
|
|
|
screen:expect([[
|
|
|
|
|
|
2017-03-26 07:25:03 -07:00
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
2017-03-25 18:04:23 -07:00
|
|
|
:echo {RBP1:(}{RBP2:(}42{RBP2:)}{RBP1:)}^ |
|
|
|
|
]])
|
|
|
|
feed('<BS>')
|
|
|
|
screen:expect([[
|
|
|
|
|
|
2017-03-26 07:25:03 -07:00
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
2017-03-25 18:04:23 -07:00
|
|
|
:echo {RBP1:(}{RBP2:(}42{RBP2:)}^ |
|
|
|
|
]])
|
2017-06-26 15:55:21 -07:00
|
|
|
-- FIXME
|
|
|
|
-- feed('{REDRAW}')
|
|
|
|
-- screen:expect([[
|
|
|
|
-- |
|
|
|
|
-- {EOB:~ }|
|
|
|
|
-- {EOB:~ }|
|
|
|
|
-- {EOB:~ }|
|
|
|
|
-- {EOB:~ }|
|
|
|
|
-- {EOB:~ }|
|
|
|
|
-- {EOB:~ }|
|
|
|
|
-- :echo {RBP1:(}{RBP2:(}42{RBP2:)}^ |
|
|
|
|
-- ]])
|
2017-03-25 18:04:23 -07:00
|
|
|
end)
|
2017-03-26 07:25:03 -07:00
|
|
|
for _, func_part in ipairs({'', 'n', 'msg'}) do
|
|
|
|
it('disables :echo' .. func_part .. ' messages', function()
|
2017-06-26 15:54:08 -07:00
|
|
|
set_color_cb('Echo' .. func_part .. 'ing')
|
|
|
|
start_prompt('echo')
|
2017-03-26 07:25:03 -07:00
|
|
|
screen:expect([[
|
|
|
|
|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
:echo^ |
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
it('does the right thing when hl start appears to split multibyte char',
|
|
|
|
function()
|
2017-06-26 15:54:08 -07:00
|
|
|
set_color_cb('SplittedMultibyteStart')
|
|
|
|
start_prompt('echo "«')
|
2017-03-26 07:25:03 -07:00
|
|
|
screen:expect([[
|
2017-04-01 15:00:40 -07:00
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
2017-03-26 07:25:03 -07:00
|
|
|
{EOB:~ }|
|
|
|
|
:echo " |
|
|
|
|
{ERR:E5405: Chunk 0 start 7 splits multibyte }|
|
|
|
|
{ERR:character} |
|
|
|
|
:echo "«^ |
|
|
|
|
]])
|
|
|
|
feed('»')
|
2017-04-01 15:00:40 -07:00
|
|
|
screen:expect([[
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
:echo " |
|
|
|
|
{ERR:E5405: Chunk 0 start 7 splits multibyte }|
|
|
|
|
{ERR:character} |
|
|
|
|
:echo "«»^ |
|
|
|
|
]])
|
2017-03-26 07:25:03 -07:00
|
|
|
end)
|
|
|
|
it('does the right thing when hl end appears to split multibyte char',
|
|
|
|
function()
|
2017-06-26 15:54:08 -07:00
|
|
|
set_color_cb('SplittedMultibyteEnd')
|
|
|
|
start_prompt('echo "«')
|
2017-03-26 07:25:03 -07:00
|
|
|
screen:expect([[
|
2017-04-01 15:00:40 -07:00
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
2017-03-26 07:25:03 -07:00
|
|
|
{EOB:~ }|
|
|
|
|
:echo " |
|
|
|
|
{ERR:E5406: Chunk 0 end 7 splits multibyte ch}|
|
|
|
|
{ERR:aracter} |
|
|
|
|
:echo "«^ |
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
it('does the right thing when errorring', function()
|
2017-04-01 15:00:40 -07:00
|
|
|
if true then return pending('echoerr does not work well now') end
|
2017-06-26 15:54:08 -07:00
|
|
|
set_color_cb('Echoerring')
|
|
|
|
start_prompt('e')
|
2017-03-26 07:25:03 -07:00
|
|
|
-- FIXME Does not work well with :echoerr: error message overwrites cmdline.
|
|
|
|
end)
|
|
|
|
it('does the right thing when throwing', function()
|
2017-04-01 15:00:40 -07:00
|
|
|
if true then return pending('Throwing does not work well now') end
|
2017-06-26 15:54:08 -07:00
|
|
|
set_color_cb('Throwing')
|
|
|
|
start_prompt('e')
|
2017-03-26 07:25:03 -07:00
|
|
|
-- FIXME Does not work well with :throw: error message overwrites cmdline.
|
|
|
|
end)
|
|
|
|
it('still executes command-line even if errored out', function()
|
2017-06-26 15:54:08 -07:00
|
|
|
set_color_cb('SplittedMultibyteStart')
|
|
|
|
start_prompt('let x = "«"\n')
|
2017-03-26 07:25:03 -07:00
|
|
|
eq('«', meths.get_var('x'))
|
|
|
|
local msg = 'E5405: Chunk 0 start 10 splits multibyte character'
|
2017-04-01 15:00:40 -07:00
|
|
|
eq('\n'..msg, funcs.execute('messages'))
|
2017-03-26 07:25:03 -07:00
|
|
|
end)
|
|
|
|
it('stops executing callback after a number of errors', function()
|
2017-06-26 15:54:08 -07:00
|
|
|
set_color_cb('SplittedMultibyteStart')
|
|
|
|
start_prompt('let x = "«»«»«»«»«»"\n')
|
2017-03-26 07:25:03 -07:00
|
|
|
eq('«»«»«»«»«»', meths.get_var('x'))
|
|
|
|
local msg = '\nE5405: Chunk 0 start 10 splits multibyte character'
|
2017-04-01 15:00:40 -07:00
|
|
|
eq(msg:rep(1), funcs.execute('messages'))
|
2017-03-26 07:25:03 -07:00
|
|
|
end)
|
|
|
|
it('allows interrupting callback with <C-c>', function()
|
2017-04-01 15:00:40 -07:00
|
|
|
if true then return pending('<C-c> does not work well enough now') end
|
2017-06-26 15:54:08 -07:00
|
|
|
set_color_cb('Halting')
|
|
|
|
start_prompt('echo 42')
|
2017-03-26 07:25:03 -07:00
|
|
|
for i = 1, 6 do
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
feed('<C-c>')
|
|
|
|
end
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
Type :quit<Enter> to exit Nvim |
|
|
|
|
]])
|
2017-06-26 15:54:08 -07:00
|
|
|
start_prompt('echo 42<CR>')
|
2017-03-26 07:25:03 -07:00
|
|
|
screen:expect([[
|
|
|
|
^ |
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
42 |
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
it('works fine with NUL, NL, CR', function()
|
2017-06-26 15:54:08 -07:00
|
|
|
set_color_cb('RainBowParens')
|
|
|
|
start_prompt('echo ("<C-v><CR><C-v><Nul><C-v><NL>")')
|
2017-03-26 07:25:03 -07:00
|
|
|
screen:expect([[
|
|
|
|
|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
|
|
|
{EOB:~ }|
|
2017-04-01 15:00:40 -07:00
|
|
|
:echo {RBP1:(}"{SK:^M^@^@}"{RBP1:)}^ |
|
2017-03-26 07:25:03 -07:00
|
|
|
]])
|
|
|
|
end)
|
|
|
|
-- TODO Check for all other errors
|
2017-03-25 18:04:23 -07:00
|
|
|
end)
|