diff options
Diffstat (limited to 'test/functional/api/vim_spec.lua')
-rw-r--r-- | test/functional/api/vim_spec.lua | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index a3d57662b3..110b3a4b16 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -11,6 +11,7 @@ local meth_pcall = helpers.meth_pcall local meths = helpers.meths local ok, nvim_async, feed = helpers.ok, helpers.nvim_async, helpers.feed local os_name = helpers.os_name +local parse_context = helpers.parse_context local request = helpers.request local source = helpers.source local next_msg = helpers.next_msg @@ -680,6 +681,65 @@ describe('API', function() end) end) + describe('nvim_get_context', function() + it('returns context dictionary of current editor state', function() + local ctx_items = {'regs', 'jumps', 'buflist', 'gvars'} + eq({}, parse_context(nvim('get_context', ctx_items))) + + feed('i1<cr>2<cr>3<c-[>ddddddqahjklquuu') + feed('gg') + feed('G') + command('edit! BUF1') + command('edit BUF2') + nvim('set_var', 'one', 1) + nvim('set_var', 'Two', 2) + nvim('set_var', 'THREE', 3) + + local expected_ctx = { + ['regs'] = { + {['rt'] = 1, ['rc'] = {'1'}, ['n'] = 49, ['ru'] = true}, + {['rt'] = 1, ['rc'] = {'2'}, ['n'] = 50}, + {['rt'] = 1, ['rc'] = {'3'}, ['n'] = 51}, + {['rc'] = {'hjkl'}, ['n'] = 97}, + }, + + ['jumps'] = eval(([[ + filter(map(add( + getjumplist()[0], { 'bufnr': bufnr('%'), 'lnum': getcurpos()[1] }), + 'filter( + { "f": expand("#".v:val.bufnr.":p"), "l": v:val.lnum }, + { k, v -> k != "l" || v != 1 })'), '!empty(v:val.f)') + ]]):gsub('\n', '')), + + ['buflist'] = eval([[ + filter(map(getbufinfo(), '{ "f": v:val.name }'), '!empty(v:val.f)') + ]]), + + ['gvars'] = {{'one', 1}, {'Two', 2}, {'THREE', 3}}, + } + + eq(expected_ctx, parse_context(nvim('get_context', ctx_items))) + end) + end) + + describe('nvim_load_context', function() + it('sets current editor state to given context dictionary', function() + local ctx_items = {'regs', 'jumps', 'buflist', 'gvars'} + eq({}, parse_context(nvim('get_context', ctx_items))) + + nvim('set_var', 'one', 1) + nvim('set_var', 'Two', 2) + nvim('set_var', 'THREE', 3) + local ctx = nvim('get_context', ctx_items) + nvim('set_var', 'one', 'a') + nvim('set_var', 'Two', 'b') + nvim('set_var', 'THREE', 'c') + eq({'a', 'b' ,'c'}, eval('[g:one, g:Two, g:THREE]')) + nvim('load_context', ctx) + eq({1, 2 ,3}, eval('[g:one, g:Two, g:THREE]')) + end) + end) + describe('nvim_replace_termcodes', function() it('escapes K_SPECIAL as K_SPECIAL KS_SPECIAL KE_FILLER', function() eq('\128\254X', helpers.nvim('replace_termcodes', '\128', true, true, true)) |