diff options
Diffstat (limited to 'test/functional/api/vim_spec.lua')
-rw-r--r-- | test/functional/api/vim_spec.lua | 134 |
1 files changed, 73 insertions, 61 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index c4976ea06b..6b30c0e81c 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -7,13 +7,14 @@ local ok, nvim_async, feed = helpers.ok, helpers.nvim_async, helpers.feed local os_name = helpers.os_name local meths = helpers.meths local funcs = helpers.funcs +local request = helpers.request describe('vim_* functions', function() before_each(clear) describe('command', function() it('works', function() - local fname = os.tmpname() + local fname = helpers.tmpname() nvim('command', 'new') nvim('command', 'edit '..fname) nvim('command', 'normal itesting\napi') @@ -41,6 +42,10 @@ describe('vim_* functions', function() eq(1, nvim('eval',"matcharg(1) == ['', '']")) eq({'', ''}, nvim('eval','matcharg(1)')) end) + + it('works under deprecated name', function() + eq(2, request("vim_eval", "1+1")) + end) end) describe('call_function', function() @@ -83,19 +88,19 @@ describe('vim_* functions', function() eq(0, funcs.exists('g:lua')) end) - it('set_var returns the old value', function() + it('vim_set_var returns the old value', function() local val1 = {1, 2, {['3'] = 1}} local val2 = {4, 7} - eq(NIL, nvim('set_var', 'lua', val1)) - eq(val1, nvim('set_var', 'lua', val2)) + eq(NIL, request('vim_set_var', 'lua', val1)) + eq(val1, request('vim_set_var', 'lua', val2)) end) - it('del_var returns the old value', function() + it('vim_del_var returns the old value', function() local val1 = {1, 2, {['3'] = 1}} local val2 = {4, 7} - eq(NIL, meths.set_var('lua', val1)) - eq(val1, meths.set_var('lua', val2)) - eq(val2, meths.del_var('lua')) + eq(NIL, request('vim_set_var', 'lua', val1)) + eq(val1, request('vim_set_var', 'lua', val2)) + eq(val2, request('vim_del_var', 'lua')) end) it('truncates values with NULs in them', function() @@ -112,47 +117,47 @@ describe('vim_* functions', function() end) end) - describe('{get,set}_current_buffer and get_buffers', function() + describe('{get,set}_current_buf and list_bufs', function() it('works', function() - eq(1, #nvim('get_buffers')) - eq(nvim('get_buffers')[1], nvim('get_current_buffer')) + eq(1, #nvim('list_bufs')) + eq(nvim('list_bufs')[1], nvim('get_current_buf')) 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')) + eq(2, #nvim('list_bufs')) + eq(nvim('list_bufs')[2], nvim('get_current_buf')) + nvim('set_current_buf', nvim('list_bufs')[1]) + eq(nvim('list_bufs')[1], nvim('get_current_buf')) end) end) - describe('{get,set}_current_window and get_windows', function() + describe('{get,set}_current_win and list_wins', function() it('works', function() - eq(1, #nvim('get_windows')) - eq(nvim('get_windows')[1], nvim('get_current_window')) + eq(1, #nvim('list_wins')) + eq(nvim('list_wins')[1], nvim('get_current_win')) 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')) + eq(3, #nvim('list_wins')) + eq(nvim('list_wins')[1], nvim('get_current_win')) + nvim('set_current_win', nvim('list_wins')[2]) + eq(nvim('list_wins')[2], nvim('get_current_win')) end) end) - describe('{get,set}_current_tabpage and get_tabpages', function() + describe('{get,set}_current_tabpage and list_tabpages', function() it('works', function() - eq(1, #nvim('get_tabpages')) - eq(nvim('get_tabpages')[1], nvim('get_current_tabpage')) + eq(1, #nvim('list_tabpages')) + eq(nvim('list_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]) + eq(2, #nvim('list_tabpages')) + eq(2, #nvim('list_wins')) + eq(nvim('list_wins')[2], nvim('get_current_win')) + eq(nvim('list_tabpages')[2], nvim('get_current_tabpage')) + nvim('set_current_win', nvim('list_wins')[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')) + eq(nvim('list_tabpages')[1], nvim('get_current_tabpage')) + eq(nvim('list_wins')[1], nvim('get_current_win')) + nvim('set_current_tabpage', nvim('list_tabpages')[2]) + eq(nvim('list_tabpages')[2], nvim('get_current_tabpage')) + eq(nvim('list_wins')[2], nvim('get_current_win')) end) end) @@ -213,22 +218,22 @@ describe('vim_* functions', function() screen = Screen.new(40, 8) screen:attach() screen:set_default_attr_ids({ + [0] = {bold=true, foreground=Screen.colors.Blue}, [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([[ ^ | - ~ | - ~ | - ~ | - ~ | - ~ | - ~ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| {1:has bork} | ]]) end) @@ -236,11 +241,11 @@ describe('vim_* functions', function() it('shows return prompt when more than &cmdheight lines', function() nvim_async('err_write', 'something happened\nvery bad\n') screen:expect([[ - ~ | - ~ | - ~ | - ~ | - ~ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| {1:something happened} | {1:very bad} | {2:Press ENTER or type command to continue}^ | @@ -250,9 +255,9 @@ describe('vim_* functions', function() it('shows return prompt after all lines are shown', function() nvim_async('err_write', 'FAILURE\nERROR\nEXCEPTION\nTRACEBACK\n') screen:expect([[ - ~ | - ~ | - ~ | + {0:~ }| + {0:~ }| + {0:~ }| {1:FAILURE} | {1:ERROR} | {1:EXCEPTION} | @@ -267,12 +272,12 @@ describe('vim_* functions', function() nvim_async('err_write', 'fail\n') screen:expect([[ ^ | - ~ | - ~ | - ~ | - ~ | - ~ | - ~ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| {1:very fail} | ]]) helpers.wait() @@ -280,11 +285,11 @@ describe('vim_* functions', function() -- shows up to &cmdheight lines nvim_async('err_write', 'more fail\ntoo fail\n') screen:expect([[ - ~ | - ~ | - ~ | - ~ | - ~ | + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| + {0:~ }| {1:more fail} | {1:too fail} | {2:Press ENTER or type command to continue}^ | @@ -298,4 +303,11 @@ describe('vim_* functions', function() eq(false, status) ok(err:match('Invalid option name') ~= nil) end) + + it("doesn't leak memory on incorrect argument types", function() + local status, err = pcall(nvim, 'set_current_dir',{'not', 'a', 'dir'}) + eq(false, status) + ok(err:match(': Wrong type for argument 1, expecting String') ~= nil) + end) + end) |