aboutsummaryrefslogtreecommitdiff
path: root/test/functional/api
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2018-12-27 22:49:44 +0100
committerJustin M. Keyes <justinkz@gmail.com>2018-12-27 22:49:44 +0100
commitc1015121ec626cab6cb384f544bc0be1a1760c0e (patch)
tree6cc9a5d1899a4486a24c491e07d17a7dd01f9503 /test/functional/api
parent4f030ec24e0e148bbb83aedaef7dd629e5fef130 (diff)
parente1876c7ad1b5e30c0a9919e2c4587d11550c8507 (diff)
downloadrneovim-c1015121ec626cab6cb384f544bc0be1a1760c0e.tar.gz
rneovim-c1015121ec626cab6cb384f544bc0be1a1760c0e.tar.bz2
rneovim-c1015121ec626cab6cb384f544bc0be1a1760c0e.zip
Merge 'upstream/master' into pr-win-erw7
Diffstat (limited to 'test/functional/api')
-rw-r--r--test/functional/api/version_spec.lua84
-rw-r--r--test/functional/api/vim_spec.lua24
-rw-r--r--test/functional/api/window_spec.lua18
3 files changed, 88 insertions, 38 deletions
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)
diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua
index a9d137391e..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()
@@ -1237,7 +1247,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()
@@ -1269,4 +1279,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)
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'))