diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2019-09-14 19:53:33 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-14 19:53:33 -0700 |
commit | 86e819d492faa2494ffe0e86f37c49eb4c0f2e56 (patch) | |
tree | 63a0fde18014ec2be04cadc81486cf7fe5243ef6 /test | |
parent | 2e0e592ea29ea7d2da333824a93aa543a6f7f390 (diff) | |
parent | ffdf8c4c1227874a62b950cc7138005b40004c6a (diff) | |
download | rneovim-86e819d492faa2494ffe0e86f37c49eb4c0f2e56.tar.gz rneovim-86e819d492faa2494ffe0e86f37c49eb4c0f2e56.tar.bz2 rneovim-86e819d492faa2494ffe0e86f37c49eb4c0f2e56.zip |
Merge #11021 from justinmk/ctx-rename-buflist
API: Context: "opts" param, et al.
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/api/vim_spec.lua | 26 | ||||
-rw-r--r-- | test/functional/eval/ctx_functions_spec.lua | 30 | ||||
-rw-r--r-- | test/functional/helpers.lua | 4 |
3 files changed, 35 insertions, 25 deletions
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index c34e7a0945..8b77dbcaa6 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -894,9 +894,17 @@ describe('API', function() 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))) + it('validates args', function() + eq('unexpected key: blah', + pcall_err(nvim, 'get_context', {blah={}})) + eq('invalid value for key: types', + pcall_err(nvim, 'get_context', {types=42})) + eq('unexpected type: zub', + pcall_err(nvim, 'get_context', {types={'jumps', 'zub', 'zam',}})) + end) + it('returns map of current editor state', function() + local opts = {types={'regs', 'jumps', 'bufs', 'gvars'}} + eq({}, parse_context(nvim('get_context', {}))) feed('i1<cr>2<cr>3<c-[>ddddddqahjklquuu') feed('gg') @@ -921,26 +929,28 @@ describe('API', function() { k, v -> k != "l" || v != 1 })'), '!empty(v:val.f)') ]]):gsub('\n', '')), - ['buflist'] = eval([[ + ['bufs'] = 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))) + eq(expected_ctx, parse_context(nvim('get_context', opts))) + eq(expected_ctx, parse_context(nvim('get_context', {}))) + eq(expected_ctx, parse_context(nvim('get_context', {types={}}))) 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))) + local opts = {types={'regs', 'jumps', 'bufs', 'gvars'}} + eq({}, parse_context(nvim('get_context', opts))) nvim('set_var', 'one', 1) nvim('set_var', 'Two', 2) nvim('set_var', 'THREE', 3) - local ctx = nvim('get_context', ctx_items) + local ctx = nvim('get_context', opts) nvim('set_var', 'one', 'a') nvim('set_var', 'Two', 'b') nvim('set_var', 'THREE', 'c') diff --git a/test/functional/eval/ctx_functions_spec.lua b/test/functional/eval/ctx_functions_spec.lua index 7dde5d3194..c81dad9645 100644 --- a/test/functional/eval/ctx_functions_spec.lua +++ b/test/functional/eval/ctx_functions_spec.lua @@ -82,21 +82,21 @@ describe('context functions', function() command('edit '..fname1) command('edit '..fname2) command('edit TEST') - local buflist = call('map', call('getbufinfo'), 'v:val.name') + local bufs = call('map', call('getbufinfo'), 'v:val.name') call('ctxpush') - call('ctxpush', {'buflist'}) + call('ctxpush', {'bufs'}) command('%bwipeout') eq({''}, call('map', call('getbufinfo'), 'v:val.name')) call('ctxpop') - eq({'', unpack(buflist)}, call('map', call('getbufinfo'), 'v:val.name')) + eq({'', unpack(bufs)}, call('map', call('getbufinfo'), 'v:val.name')) command('%bwipeout') eq({''}, call('map', call('getbufinfo'), 'v:val.name')) call('ctxpop') - eq({'', unpack(buflist)}, call('map', call('getbufinfo'), 'v:val.name')) + eq({'', unpack(bufs)}, call('map', call('getbufinfo'), 'v:val.name')) end) it('saves and restores global variables properly', function() @@ -297,8 +297,8 @@ describe('context functions', function() ]]):gsub('\n', '')) } - local with_buflist = { - ['buflist'] = eval([[ + local with_bufs = { + ['bufs'] = eval([[ filter(map(getbufinfo(), '{ "f": v:val.name }'), '!empty(v:val.f)') ]]) } @@ -310,7 +310,7 @@ describe('context functions', function() local with_all = { ['regs'] = with_regs['regs'], ['jumps'] = with_jumps['jumps'], - ['buflist'] = with_buflist['buflist'], + ['bufs'] = with_bufs['bufs'], ['gvars'] = with_gvars['gvars'], } @@ -323,16 +323,16 @@ describe('context functions', function() eq(with_gvars, parse_context(call('ctxget', 0))) eq(with_all, parse_context(call('ctxget', 1))) - call('ctxpush', {'buflist'}) - eq(with_buflist, parse_context(call('ctxget'))) - eq(with_buflist, parse_context(call('ctxget', 0))) + call('ctxpush', {'bufs'}) + eq(with_bufs, parse_context(call('ctxget'))) + eq(with_bufs, parse_context(call('ctxget', 0))) eq(with_gvars, parse_context(call('ctxget', 1))) eq(with_all, parse_context(call('ctxget', 2))) call('ctxpush', {'jumps'}) eq(with_jumps, parse_context(call('ctxget'))) eq(with_jumps, parse_context(call('ctxget', 0))) - eq(with_buflist, parse_context(call('ctxget', 1))) + eq(with_bufs, parse_context(call('ctxget', 1))) eq(with_gvars, parse_context(call('ctxget', 2))) eq(with_all, parse_context(call('ctxget', 3))) @@ -340,20 +340,20 @@ describe('context functions', function() eq(with_regs, parse_context(call('ctxget'))) eq(with_regs, parse_context(call('ctxget', 0))) eq(with_jumps, parse_context(call('ctxget', 1))) - eq(with_buflist, parse_context(call('ctxget', 2))) + eq(with_bufs, parse_context(call('ctxget', 2))) eq(with_gvars, parse_context(call('ctxget', 3))) eq(with_all, parse_context(call('ctxget', 4))) call('ctxpop') eq(with_jumps, parse_context(call('ctxget'))) eq(with_jumps, parse_context(call('ctxget', 0))) - eq(with_buflist, parse_context(call('ctxget', 1))) + eq(with_bufs, parse_context(call('ctxget', 1))) eq(with_gvars, parse_context(call('ctxget', 2))) eq(with_all, parse_context(call('ctxget', 3))) call('ctxpop') - eq(with_buflist, parse_context(call('ctxget'))) - eq(with_buflist, parse_context(call('ctxget', 0))) + eq(with_bufs, parse_context(call('ctxget'))) + eq(with_bufs, parse_context(call('ctxget', 0))) eq(with_gvars, parse_context(call('ctxget', 1))) eq(with_all, parse_context(call('ctxget', 2))) diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 2cf81ed4d0..b29161e34c 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -777,12 +777,12 @@ end function module.parse_context(ctx) local parsed = {} - for _, item in ipairs({'regs', 'jumps', 'buflist', 'gvars'}) do + for _, item in ipairs({'regs', 'jumps', 'bufs', 'gvars'}) do parsed[item] = filter(function(v) return type(v) == 'table' end, module.call('msgpackparse', ctx[item])) end - parsed['buflist'] = parsed['buflist'][1] + parsed['bufs'] = parsed['bufs'][1] return map(function(v) if #v == 0 then return nil |