From f2c75ef9b481e6c3b65f7b37a3c8e8afc5c73be3 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 14 Sep 2019 18:13:02 -0700 Subject: API: nvim_get_context: "opts" param Since the parameter is already non-primitive, make it an `opts` map instead of just a list, in case we want to extend it later. --- test/functional/api/vim_spec.lua | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'test/functional/api/vim_spec.lua') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index c34e7a0945..77296e27f6 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', 'buflist', 'gvars'}} + eq({}, parse_context(nvim('get_context', {}))) feed('i123ddddddqahjklquuu') feed('gg') @@ -928,19 +936,21 @@ describe('API', function() ['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', 'buflist', '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') -- cgit From ffdf8c4c1227874a62b950cc7138005b40004c6a Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 14 Sep 2019 18:52:16 -0700 Subject: Context: rename "buflist" => "bufs" Given the other type names "jumps", "vars", etc., the name "buflist" is somewhat unintuitive. --- test/functional/api/vim_spec.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test/functional/api/vim_spec.lua') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 77296e27f6..8b77dbcaa6 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -903,7 +903,7 @@ describe('API', function() pcall_err(nvim, 'get_context', {types={'jumps', 'zub', 'zam',}})) end) it('returns map of current editor state', function() - local opts = {types={'regs', 'jumps', 'buflist', 'gvars'}} + local opts = {types={'regs', 'jumps', 'bufs', 'gvars'}} eq({}, parse_context(nvim('get_context', {}))) feed('i123ddddddqahjklquuu') @@ -929,7 +929,7 @@ 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)') ]]), @@ -944,7 +944,7 @@ describe('API', function() describe('nvim_load_context', function() it('sets current editor state to given context dictionary', function() - local opts = {types={'regs', 'jumps', 'buflist', 'gvars'}} + local opts = {types={'regs', 'jumps', 'bufs', 'gvars'}} eq({}, parse_context(nvim('get_context', opts))) nvim('set_var', 'one', 1) -- cgit