2014-10-08 09:56:01 -07:00
|
|
|
-- Sanity checks for vim_* API calls via msgpack-rpc
|
2016-04-23 16:53:11 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
2015-07-27 04:39:38 -07:00
|
|
|
local Screen = require('test.functional.ui.screen')
|
2016-04-26 12:14:33 -07:00
|
|
|
local NIL = helpers.NIL
|
2015-07-27 04:39:38 -07:00
|
|
|
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
|
2016-03-06 15:26:23 -07:00
|
|
|
local os_name = helpers.os_name
|
2016-02-10 16:01:17 -07:00
|
|
|
local meths = helpers.meths
|
|
|
|
local funcs = helpers.funcs
|
2014-10-08 09:56:01 -07:00
|
|
|
|
|
|
|
describe('vim_* functions', function()
|
|
|
|
before_each(clear)
|
|
|
|
|
|
|
|
describe('command', function()
|
|
|
|
it('works', function()
|
|
|
|
local fname = os.tmpname()
|
|
|
|
nvim('command', 'new')
|
|
|
|
nvim('command', 'edit '..fname)
|
|
|
|
nvim('command', 'normal itesting\napi')
|
|
|
|
nvim('command', 'w')
|
|
|
|
local f = io.open(fname)
|
|
|
|
ok(f ~= nil)
|
2016-03-06 15:26:23 -07:00
|
|
|
if os_name() == 'windows' then
|
2015-12-29 12:23:51 -07:00
|
|
|
eq('testing\r\napi\r\n', f:read('*a'))
|
|
|
|
else
|
|
|
|
eq('testing\napi\n', f:read('*a'))
|
|
|
|
end
|
2014-10-08 09:56:01 -07:00
|
|
|
f:close()
|
|
|
|
os.remove(fname)
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('eval', function()
|
|
|
|
it('works', function()
|
|
|
|
nvim('command', 'let g:v1 = "a"')
|
|
|
|
nvim('command', 'let g:v2 = [1, 2, {"v3": 3}]')
|
|
|
|
eq({v1 = 'a', v2 = {1, 2, {v3 = 3}}}, nvim('eval', 'g:'))
|
|
|
|
end)
|
2015-02-12 10:55:13 -07:00
|
|
|
|
|
|
|
it('handles NULL-initialized strings correctly', function()
|
|
|
|
eq(1, nvim('eval',"matcharg(1) == ['', '']"))
|
|
|
|
eq({'', ''}, nvim('eval','matcharg(1)'))
|
|
|
|
end)
|
2014-10-08 09:56:01 -07:00
|
|
|
end)
|
|
|
|
|
2015-07-07 22:40:28 -07:00
|
|
|
describe('call_function', function()
|
|
|
|
it('works', function()
|
|
|
|
nvim('call_function', 'setqflist', {{{ filename = 'something', lnum = 17}}, 'r'})
|
|
|
|
eq(17, nvim('call_function', 'getqflist', {})[1].lnum)
|
|
|
|
eq(17, nvim('call_function', 'eval', {17}))
|
|
|
|
eq('foo', nvim('call_function', 'simplify', {'this/./is//redundant/../../../foo'}))
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2014-10-08 09:56:01 -07:00
|
|
|
describe('strwidth', function()
|
|
|
|
it('works', function()
|
|
|
|
eq(3, nvim('strwidth', 'abc'))
|
|
|
|
-- 6 + (neovim)
|
|
|
|
-- 19 * 2 (each japanese character occupies two cells)
|
|
|
|
eq(44, nvim('strwidth', 'neovimのデザインかなりまともなのになってる。'))
|
|
|
|
end)
|
2014-10-24 13:36:30 -07:00
|
|
|
|
|
|
|
it('cannot handle NULs', function()
|
|
|
|
eq(0, nvim('strwidth', '\0abc'))
|
|
|
|
end)
|
2014-10-08 09:56:01 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
describe('{get,set}_current_line', function()
|
|
|
|
it('works', function()
|
|
|
|
eq('', nvim('get_current_line'))
|
|
|
|
nvim('set_current_line', 'abc')
|
|
|
|
eq('abc', nvim('get_current_line'))
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2016-02-10 16:01:17 -07:00
|
|
|
describe('{get,set,del}_var', function()
|
2014-10-08 09:56:01 -07:00
|
|
|
it('works', function()
|
|
|
|
nvim('set_var', 'lua', {1, 2, {['3'] = 1}})
|
|
|
|
eq({1, 2, {['3'] = 1}}, nvim('get_var', 'lua'))
|
|
|
|
eq({1, 2, {['3'] = 1}}, nvim('eval', 'g:lua'))
|
2016-02-10 16:01:17 -07:00
|
|
|
eq(1, funcs.exists('g:lua'))
|
|
|
|
meths.del_var('lua')
|
|
|
|
eq(0, funcs.exists('g:lua'))
|
2014-10-08 09:56:01 -07:00
|
|
|
end)
|
2014-10-24 13:36:30 -07:00
|
|
|
|
2015-06-24 21:13:33 -07:00
|
|
|
it('set_var returns the old value', function()
|
|
|
|
local val1 = {1, 2, {['3'] = 1}}
|
|
|
|
local val2 = {4, 7}
|
2016-04-13 05:21:32 -07:00
|
|
|
eq(NIL, nvim('set_var', 'lua', val1))
|
2015-06-24 21:13:33 -07:00
|
|
|
eq(val1, nvim('set_var', 'lua', val2))
|
|
|
|
end)
|
|
|
|
|
2016-02-10 16:01:17 -07:00
|
|
|
it('del_var returns the old value', function()
|
|
|
|
local val1 = {1, 2, {['3'] = 1}}
|
|
|
|
local val2 = {4, 7}
|
2016-04-17 15:37:21 -07:00
|
|
|
eq(NIL, meths.set_var('lua', val1))
|
2016-02-10 16:01:17 -07:00
|
|
|
eq(val1, meths.set_var('lua', val2))
|
|
|
|
eq(val2, meths.del_var('lua'))
|
|
|
|
end)
|
|
|
|
|
2014-10-24 13:36:30 -07:00
|
|
|
it('truncates values with NULs in them', function()
|
|
|
|
nvim('set_var', 'xxx', 'ab\0cd')
|
|
|
|
eq('ab', nvim('get_var', 'xxx'))
|
|
|
|
end)
|
2014-10-08 09:56:01 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
describe('{get,set}_option', function()
|
|
|
|
it('works', function()
|
|
|
|
ok(nvim('get_option', 'equalalways'))
|
|
|
|
nvim('set_option', 'equalalways', false)
|
|
|
|
ok(not nvim('get_option', 'equalalways'))
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('{get,set}_current_buffer and get_buffers', function()
|
|
|
|
it('works', function()
|
|
|
|
eq(1, #nvim('get_buffers'))
|
|
|
|
eq(nvim('get_buffers')[1], nvim('get_current_buffer'))
|
|
|
|
nvim('command', 'new')
|
|
|
|
eq(2, #nvim('get_buffers'))
|
|
|
|
eq(nvim('get_buffers')[2], nvim('get_current_buffer'))
|
|
|
|
nvim('set_current_buffer', nvim('get_buffers')[1])
|
|
|
|
eq(nvim('get_buffers')[1], nvim('get_current_buffer'))
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('{get,set}_current_window and get_windows', function()
|
|
|
|
it('works', function()
|
|
|
|
eq(1, #nvim('get_windows'))
|
|
|
|
eq(nvim('get_windows')[1], nvim('get_current_window'))
|
|
|
|
nvim('command', 'vsplit')
|
|
|
|
nvim('command', 'split')
|
|
|
|
eq(3, #nvim('get_windows'))
|
|
|
|
eq(nvim('get_windows')[1], nvim('get_current_window'))
|
|
|
|
nvim('set_current_window', nvim('get_windows')[2])
|
|
|
|
eq(nvim('get_windows')[2], nvim('get_current_window'))
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('{get,set}_current_tabpage and get_tabpages', function()
|
|
|
|
it('works', function()
|
|
|
|
eq(1, #nvim('get_tabpages'))
|
|
|
|
eq(nvim('get_tabpages')[1], nvim('get_current_tabpage'))
|
|
|
|
nvim('command', 'tabnew')
|
|
|
|
eq(2, #nvim('get_tabpages'))
|
|
|
|
eq(2, #nvim('get_windows'))
|
|
|
|
eq(nvim('get_windows')[2], nvim('get_current_window'))
|
|
|
|
eq(nvim('get_tabpages')[2], nvim('get_current_tabpage'))
|
|
|
|
nvim('set_current_window', nvim('get_windows')[1])
|
|
|
|
-- Switching window also switches tabpages if necessary
|
|
|
|
eq(nvim('get_tabpages')[1], nvim('get_current_tabpage'))
|
|
|
|
eq(nvim('get_windows')[1], nvim('get_current_window'))
|
|
|
|
nvim('set_current_tabpage', nvim('get_tabpages')[2])
|
|
|
|
eq(nvim('get_tabpages')[2], nvim('get_current_tabpage'))
|
|
|
|
eq(nvim('get_windows')[2], nvim('get_current_window'))
|
|
|
|
end)
|
|
|
|
end)
|
2014-10-23 17:14:50 -07:00
|
|
|
|
2014-10-20 02:21:24 -07:00
|
|
|
describe('replace_termcodes', function()
|
|
|
|
it('escapes K_SPECIAL as K_SPECIAL KS_SPECIAL KE_FILLER', function()
|
2016-02-20 15:09:15 -07:00
|
|
|
eq('\128\254X', helpers.nvim('replace_termcodes', '\128', true, true, true))
|
2014-10-20 02:21:24 -07:00
|
|
|
end)
|
|
|
|
|
2016-02-20 15:09:15 -07:00
|
|
|
it('leaves non-K_SPECIAL string unchanged', function()
|
|
|
|
eq('abc', helpers.nvim('replace_termcodes', 'abc', true, true, true))
|
2014-10-20 02:21:24 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
it('converts <expressions>', function()
|
2016-02-20 15:09:15 -07:00
|
|
|
eq('\\', helpers.nvim('replace_termcodes', '<Leader>', true, true, true))
|
|
|
|
end)
|
|
|
|
|
|
|
|
it('converts <LeftMouse> to K_SPECIAL KS_EXTRA KE_LEFTMOUSE', function()
|
|
|
|
-- K_SPECIAL KS_EXTRA KE_LEFTMOUSE
|
|
|
|
-- 0x80 0xfd 0x2c
|
|
|
|
-- 128 253 44
|
|
|
|
eq('\128\253\44', helpers.nvim('replace_termcodes',
|
|
|
|
'<LeftMouse>', true, true, true))
|
2014-10-20 02:21:24 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
|
|
|
describe('feedkeys', function()
|
|
|
|
it('CSI escaping', function()
|
|
|
|
local function on_setup()
|
|
|
|
-- notice the special char(…) \xe2\80\xa6
|
|
|
|
nvim('feedkeys', ':let x1="…"\n', '', true)
|
|
|
|
|
|
|
|
-- Both replace_termcodes and feedkeys escape \x80
|
|
|
|
local inp = helpers.nvim('replace_termcodes', ':let x2="…"<CR>', true, true, true)
|
|
|
|
nvim('feedkeys', inp, '', true)
|
|
|
|
|
|
|
|
-- Disabling CSI escaping in feedkeys
|
|
|
|
inp = helpers.nvim('replace_termcodes', ':let x3="…"<CR>', true, true, true)
|
|
|
|
nvim('feedkeys', inp, '', false)
|
|
|
|
|
|
|
|
helpers.stop()
|
|
|
|
end
|
|
|
|
|
|
|
|
-- spin the loop a bit
|
|
|
|
helpers.run(nil, nil, on_setup)
|
|
|
|
|
|
|
|
eq(nvim('get_var', 'x1'), '…')
|
|
|
|
-- Because of the double escaping this is neq
|
|
|
|
neq(nvim('get_var', 'x2'), '…')
|
|
|
|
eq(nvim('get_var', 'x3'), '…')
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2015-07-27 04:39:38 -07:00
|
|
|
describe('err_write', function()
|
2015-11-17 15:31:22 -07:00
|
|
|
local screen
|
|
|
|
|
2015-07-27 04:39:38 -07:00
|
|
|
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} |
|
|
|
|
]])
|
2015-10-05 06:13:18 -07:00
|
|
|
helpers.wait()
|
2015-07-27 04:39:38 -07:00
|
|
|
|
|
|
|
-- shows up to &cmdheight lines
|
2015-10-05 06:13:18 -07:00
|
|
|
nvim_async('err_write', 'more fail\ntoo fail\n')
|
2015-07-27 04:39:38 -07:00
|
|
|
screen:expect([[
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
~ |
|
|
|
|
{1:more fail} |
|
|
|
|
{1:too fail} |
|
|
|
|
{2:Press ENTER or type command to continue}^ |
|
|
|
|
]])
|
2015-10-05 06:13:18 -07:00
|
|
|
feed('<cr>') -- exit the press ENTER screen
|
2015-07-27 04:39:38 -07:00
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|
2014-10-23 17:14:50 -07:00
|
|
|
it('can throw exceptions', function()
|
|
|
|
local status, err = pcall(nvim, 'get_option', 'invalid-option')
|
|
|
|
eq(false, status)
|
|
|
|
ok(err:match('Invalid option name') ~= nil)
|
|
|
|
end)
|
2014-10-08 09:56:01 -07:00
|
|
|
end)
|