test/API: validate channel arg (#8245)

This commit is contained in:
Justin M. Keyes 2018-04-08 03:01:15 +02:00 committed by GitHub
parent 929a732d00
commit fa6415f13f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 24 deletions

View File

@ -56,7 +56,8 @@ void nvim_ui_attach(uint64_t channel_id, Integer width, Integer height,
FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY
{
if (pmap_has(uint64_t)(connected_uis, channel_id)) {
api_set_error(err, kErrorTypeException, "UI already attached for channel");
api_set_error(err, kErrorTypeException,
"UI already attached to channel: %" PRId64, channel_id);
return;
}
@ -130,7 +131,8 @@ void nvim_ui_detach(uint64_t channel_id, Error *err)
FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY
{
if (!pmap_has(uint64_t)(connected_uis, channel_id)) {
api_set_error(err, kErrorTypeException, "UI is not attached for channel");
api_set_error(err, kErrorTypeException,
"UI not attached to channel: %" PRId64, channel_id);
return;
}
remote_ui_disconnect(channel_id);
@ -142,7 +144,8 @@ void nvim_ui_try_resize(uint64_t channel_id, Integer width,
FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY
{
if (!pmap_has(uint64_t)(connected_uis, channel_id)) {
api_set_error(err, kErrorTypeException, "UI is not attached for channel");
api_set_error(err, kErrorTypeException,
"UI not attached to channel: %" PRId64, channel_id);
return;
}
@ -163,7 +166,8 @@ void nvim_ui_set_option(uint64_t channel_id, String name,
FUNC_API_SINCE(1) FUNC_API_REMOTE_ONLY
{
if (!pmap_has(uint64_t)(connected_uis, channel_id)) {
api_set_error(error, kErrorTypeException, "UI is not attached for channel");
api_set_error(error, kErrorTypeException,
"UI not attached to channel: %" PRId64, channel_id);
return;
}
UI *ui = pmap_get(uint64_t)(connected_uis, channel_id);
@ -209,7 +213,7 @@ static void ui_set_option(UI *ui, String name, Object value, Error *error)
return;
}
api_set_error(error, kErrorTypeValidation, "No such ui option");
api_set_error(error, kErrorTypeValidation, "No such UI option");
#undef UI_EXT_OPTION
}

View File

@ -0,0 +1,39 @@
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')
local clear = helpers.clear
local eq = helpers.eq
local eval = helpers.eval
local request = helpers.request
describe('nvim_ui_attach()', function()
before_each(function()
clear()
end)
it('handles very large width/height #2180', function()
local screen = Screen.new(999, 999)
screen:attach()
eq(999, eval('&lines'))
eq(999, eval('&columns'))
end)
it('invalid option returns error', function()
local screen = Screen.new()
local status, rv = pcall(function() screen:attach({foo={'foo'}}) end)
eq(false, status)
eq('No such UI option', rv:match("No such .*"))
end)
it('validates channel arg', function()
assert.has_error(function() request('nvim_ui_try_resize', 40, 10) end,
'UI not attached to channel: 1')
assert.has_error(function() request('nvim_ui_set_option', 'rgb', true) end,
'UI not attached to channel: 1')
assert.has_error(function() request('nvim_ui_detach') end,
'UI not attached to channel: 1')
local screen = Screen.new()
screen:attach({rgb=false})
assert.has_error(function()
request('nvim_ui_attach', 40, 10, { rgb=false })
end,
'UI already attached to channel: 1')
end)
end)

View File

@ -4,7 +4,6 @@ local spawn, set_session, clear = helpers.spawn, helpers.set_session, helpers.cl
local feed, command = helpers.feed, helpers.command
local insert = helpers.insert
local eq = helpers.eq
local eval = helpers.eval
local iswin = helpers.iswin
describe('screen', function()
@ -631,21 +630,3 @@ describe('Screen', function()
end)
end)
end)
describe('nvim_ui_attach()', function()
before_each(function()
clear()
end)
it('handles very large width/height #2180', function()
local screen = Screen.new(999, 999)
screen:attach()
eq(999, eval('&lines'))
eq(999, eval('&columns'))
end)
it('invalid option returns error', function()
local screen = Screen.new()
local status, rv = pcall(function() screen:attach({foo={'foo'}}) end)
eq(false, status)
eq('No such ui option', rv:match("No such .*"))
end)
end)