From 01dbf0951b25d582451a8e656731dcf3d9295a71 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Fri, 23 Jun 2017 09:56:35 +0200 Subject: api: implement object namespaces Namespaces is a lightweight concept that should be used to group objects for purposes of bulk operations and introspection. This is initially used for highlights and virtual text in buffers, and is planned to also be used for extended marks. There is no plan use them for privileges or isolation, neither to introduce nanespace-level options. --- test/functional/api/vim_spec.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index a9d137391e..dde4dab7ac 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1269,4 +1269,16 @@ describe('API', function() end) end) + describe('nvim_create_namespace', function() + it('works', function() + eq({}, meths.get_namespaces()) + eq(1, meths.create_namespace("ns-1")) + eq(2, meths.create_namespace("ns-2")) + eq(1, meths.create_namespace("ns-1")) + eq({["ns-1"]=1, ["ns-2"]=2}, meths.get_namespaces()) + eq(3, meths.create_namespace("")) + eq(4, meths.create_namespace("")) + eq({["ns-1"]=1, ["ns-2"]=2}, meths.get_namespaces()) + end) + end) end) -- cgit From b1aaa0a881ef36676ddd71e7308ae7461c62896d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 25 Nov 2018 16:27:10 +0100 Subject: API: Implement nvim_win_set_buf() #9100 closes #9100 --- test/functional/api/window_spec.lua | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index 27d7aa11b4..4496e1f644 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -11,6 +11,7 @@ local NIL = helpers.NIL local meth_pcall = helpers.meth_pcall local meths = helpers.meths local command = helpers.command +local expect_err = helpers.expect_err -- check if str is visible at the beginning of some line local function is_visible(str) @@ -31,7 +32,7 @@ local function is_visible(str) return false end -describe('api/win', function() +describe('API/win', function() before_each(clear) describe('get_buf', function() @@ -45,6 +46,21 @@ describe('api/win', function() end) end) + describe('set_buf', function() + it('works', function() + nvim('command', 'new') + local windows = nvim('list_wins') + neq(window('get_buf', windows[2]), window('get_buf', windows[1])) + window('set_buf', windows[2], window('get_buf', windows[1])) + eq(window('get_buf', windows[2]), window('get_buf', windows[1])) + end) + + it('validates args', function() + expect_err('Invalid buffer id$', window, 'set_buf', nvim('get_current_win'), 23) + expect_err('Invalid window id$', window, 'set_buf', 23, nvim('get_current_buf')) + end) + end) + describe('{get,set}_cursor', function() it('works', function() eq({1, 0}, curwin('get_cursor')) -- cgit From 30857030e848e4a727a889e51d4618ab9b30651f Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 16 Nov 2018 02:00:04 +0100 Subject: doc - develop.txt is for design/guidelines; architecture/concepts should live elsewhere (currently src/nvim/README.md) - move dev-jargon to intro.txt - replace https://neovim.io/community (deprecated) with https://neovim.io/#chat - avoids CmdlineEnter/Leave https://github.com/vim/vim/issues/2889 --- test/functional/api/vim_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index dde4dab7ac..6261458f2a 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1237,7 +1237,7 @@ describe('API', function() describe('nvim_list_uis', function() it('returns empty if --headless', function() - -- --embed implies --headless. + -- Test runner defaults to --headless. eq({}, nvim("list_uis")) end) it('returns attached UIs', function() -- cgit From 8b42249cddf6b257e2eee808a41f3d6dd5af6846 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Sat, 1 Dec 2018 16:44:36 +0100 Subject: RPC: turn errors from async calls into notifications Previously, nvim sent a response with invalid request id (UINT64_MAX). In functionaltests, catch unexpected error notifications in after_each(). --- test/functional/api/vim_spec.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index 6261458f2a..ddf5575e31 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -14,6 +14,7 @@ local ok, nvim_async, feed = helpers.ok, helpers.nvim_async, helpers.feed local os_name = helpers.os_name local request = helpers.request local source = helpers.source +local next_msg = helpers.next_msg local expect_err = global_helpers.expect_err local format_string = global_helpers.format_string @@ -46,6 +47,15 @@ describe('API', function() request, nil) end) + it('handles errors in async requests', function() + local error_types = meths.get_api_info()[2].error_types + nvim_async("bogus") + eq({'notification', 'nvim_error_event', + {error_types.Exception.id, 'Invalid method: nvim_bogus'}}, next_msg()) + -- error didn't close channel. + eq(2, eval('1+1')) + end) + describe('nvim_command', function() it('works', function() local fname = helpers.tmpname() -- cgit From 8b41f429bb6d590979c839052b3b5722b13c2664 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Fri, 21 Dec 2018 10:44:27 +0100 Subject: test/api: verify that UI options from stable metadata are preserved --- test/functional/api/version_spec.lua | 84 ++++++++++++++++++++---------------- 1 file changed, 48 insertions(+), 36 deletions(-) (limited to 'test/functional/api') diff --git a/test/functional/api/version_spec.lua b/test/functional/api/version_spec.lua index b4ae17d963..bf67d4788b 100644 --- a/test/functional/api/version_spec.lua +++ b/test/functional/api/version_spec.lua @@ -2,6 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local mpack = require('mpack') local clear, funcs, eq = helpers.clear, helpers.funcs, helpers.eq local call = helpers.call +local meths = helpers.meths local function read_mpack_file(fname) local fd = io.open(fname, 'rb') @@ -43,7 +44,7 @@ describe("api_info()['version']", function() end) -describe("api functions", function() +describe("api metadata", function() before_each(clear) local function name_table(entries) @@ -87,26 +88,23 @@ describe("api functions", function() end end - it("are compatible with old metadata or have new level", function() - local api = helpers.call('api_info') - local compat = api.version.api_compatible - local api_level = api.version.api_level - local stable + local api, compat, stable, api_level + local old_api = {} + setup(function() + api = meths.get_api_info()[2] + compat = api.version.api_compatible + api_level = api.version.api_level if api.version.api_prerelease then stable = api_level-1 else stable = api_level end - local funcs_new = name_table(api.functions) - local ui_events_new = name_table(api.ui_events) - local funcs_compat = {} - local ui_events_compat = {} for level = compat, stable do local path = ('test/functional/fixtures/api_level_'.. tostring(level)..'.mpack') - local old_api = read_mpack_file(path) - if old_api == nil then + old_api[level] = read_mpack_file(path) + if old_api[level] == nil then local errstr = "missing metadata fixture for stable level "..level..". " if level == api_level and not api.version.api_prerelease then errstr = (errstr.."If NVIM_API_CURRENT was bumped, ".. @@ -116,10 +114,16 @@ describe("api functions", function() end if level == 0 then - clean_level_0(old_api) + clean_level_0(old_api[level]) end + end + end) - for _,f in ipairs(old_api.functions) do + it("functions are compatible with old metadata or have new level", function() + local funcs_new = name_table(api.functions) + local funcs_compat = {} + for level = compat, stable do + for _,f in ipairs(old_api[level].functions) do if funcs_new[f.name] == nil then if f.since >= compat then error('function '..f.name..' was removed but exists in level '.. @@ -130,18 +134,7 @@ describe("api functions", function() filter_function_metadata(funcs_new[f.name])) end end - funcs_compat[level] = name_table(old_api.functions) - - -- UI events were formalized in level 3 - if level >= 3 then - for _,e in ipairs(old_api.ui_events) do - local new_e = ui_events_new[e.name] - if new_e ~= nil then - check_ui_event_compatible(e, new_e) - end - end - ui_events_compat[level] = name_table(old_api.ui_events) - end + funcs_compat[level] = name_table(old_api[level].functions) end for _,f in ipairs(api.functions) do @@ -171,6 +164,22 @@ describe("api functions", function() end end end + end) + + it("UI events are compatible with old metadata or have new level", function() + local ui_events_new = name_table(api.ui_events) + local ui_events_compat = {} + + -- UI events were formalized in level 3 + for level = 3, stable do + for _,e in ipairs(old_api[level].ui_events) do + local new_e = ui_events_new[e.name] + if new_e ~= nil then + check_ui_event_compatible(e, new_e) + end + end + ui_events_compat[level] = name_table(old_api[level].ui_events) + end for _,e in ipairs(api.ui_events) do if e.since <= stable then @@ -197,15 +206,18 @@ describe("api functions", function() end end) -end) - -describe("ui_options in metadata", function() - it('are correct', function() - -- TODO(bfredl) once a release freezes this into metadata, - -- instead check that all old options are present - local api = helpers.call('api_info') - local options = api.ui_options - eq({'rgb', 'ext_cmdline', 'ext_popupmenu', - 'ext_tabline', 'ext_wildmenu', 'ext_linegrid', 'ext_hlstate'}, options) + it("ui_options are preserved from older levels", function() + local available_options = {} + for _, option in ipairs(api.ui_options) do + available_options[option] = true + end + -- UI options were versioned from level 4 + for level = 4, stable do + for _, option in ipairs(old_api[level].ui_options) do + if not available_options[option] then + error("UI option "..option.." from stable metadata is missing") + end + end + end end) end) -- cgit