api: vim_err_write: add tests for multiline handling

This commit is contained in:
Björn Linse 2015-07-27 13:39:38 +02:00
parent 8c2481806d
commit c8aaabc09c
3 changed files with 111 additions and 3 deletions

View File

@ -1,6 +1,8 @@
-- Sanity checks for vim_* API calls via msgpack-rpc
local helpers = require('test.functional.helpers')
local clear, nvim, eq, neq, ok = helpers.clear, helpers.nvim, helpers.eq, helpers.neq, helpers.ok
local Screen = require('test.functional.ui.screen')
local clear, nvim, eq, neq = helpers.clear, helpers.nvim, helpers.eq, helpers.neq
local ok, nvim_async, feed = helpers.ok, helpers.nvim_async, helpers.feed
describe('vim_* functions', function()
@ -177,6 +179,104 @@ describe('vim_* functions', function()
end)
end)
describe('err_write', function()
before_each(function()
clear()
screen = Screen.new(40, 8)
screen:attach()
screen:set_default_attr_ids({
[1] = {foreground = Screen.colors.White, background = Screen.colors.Red},
[2] = {bold = true, foreground = Screen.colors.SeaGreen}
})
screen:set_default_attr_ignore( {{bold=true, foreground=Screen.colors.Blue}} )
end)
it('can show one line', function()
nvim_async('err_write', 'has bork\n')
screen:expect([[
^ |
~ |
~ |
~ |
~ |
~ |
~ |
{1:has bork} |
]])
end)
it('shows return prompt when more than &cmdheight lines', function()
nvim_async('err_write', 'something happened\nvery bad\n')
screen:expect([[
~ |
~ |
~ |
~ |
~ |
{1:something happened} |
{1:very bad} |
{2:Press ENTER or type command to continue}^ |
]])
end)
it('shows return prompt after all lines are shown', function()
nvim_async('err_write', 'FAILURE\nERROR\nEXCEPTION\nTRACEBACK\n')
screen:expect([[
~ |
~ |
~ |
{1:FAILURE} |
{1:ERROR} |
{1:EXCEPTION} |
{1:TRACEBACK} |
{2:Press ENTER or type command to continue}^ |
]])
end)
it('handles multiple calls', function()
-- without linebreak text is joined to one line
nvim_async('err_write', 'very ')
nvim_async('err_write', 'fail\n')
screen:expect([[
^ |
~ |
~ |
~ |
~ |
~ |
~ |
{1:very fail} |
]])
-- shows up to &cmdheight lines
nvim_async('err_write', 'more fail\n')
nvim_async('err_write', 'too fail\n')
screen:expect([[
~ |
~ |
~ |
~ |
~ |
{1:very fail} |
{1:more fail} |
{2:Press ENTER or type command to continue}^ |
]])
-- shows the rest after return
feed('<cr>')
screen:expect([[
~ |
~ |
~ |
{1:very fail} |
{1:more fail} |
{2:Press ENTER or type command to continue} |
{1:too fail} |
{2:Press ENTER or type command to continue}^ |
]])
end)
end)
it('can throw exceptions', function()
local status, err = pcall(nvim, 'get_option', 'invalid-option')
eq(false, status)

View File

@ -246,6 +246,10 @@ local function nvim(method, ...)
return request('vim_'..method, ...)
end
local function nvim_async(method, ...)
session:notify('vim_'..method, ...)
end
local function buffer(method, ...)
return request('buffer_'..method, ...)
end
@ -341,6 +345,7 @@ return {
expect = expect,
ok = ok,
nvim = nvim,
nvim_async = nvim_async,
nvim_prog = nvim_prog,
nvim_dir = nvim_dir,
buffer = buffer,

View File

@ -489,7 +489,7 @@ function Screen:snapshot_util(attrs, ignore)
self:print_snapshot(attrs, ignore)
end
function Screen:redraw_debug(attrs, ignore)
function Screen:redraw_debug(attrs, ignore, timeout)
self:print_snapshot(attrs, ignore)
local function notification_cb(method, args)
assert(method == 'redraw')
@ -500,7 +500,10 @@ function Screen:redraw_debug(attrs, ignore)
self:print_snapshot(attrs, ignore)
return true
end
run(nil, notification_cb, nil, 250)
if timeout == nil then
timeout = 250
end
run(nil, notification_cb, nil, timeout)
end
function Screen:print_snapshot(attrs, ignore)