mirror of
https://github.com/neovim/neovim.git
synced 2025-12-08 07:32:40 +00:00
Merge pull request #9384 from bfredl/ui_option_check
test/api: verify that UI options from stable metadata are preserved
This commit is contained in:
@@ -2,6 +2,7 @@ local helpers = require('test.functional.helpers')(after_each)
|
|||||||
local mpack = require('mpack')
|
local mpack = require('mpack')
|
||||||
local clear, funcs, eq = helpers.clear, helpers.funcs, helpers.eq
|
local clear, funcs, eq = helpers.clear, helpers.funcs, helpers.eq
|
||||||
local call = helpers.call
|
local call = helpers.call
|
||||||
|
local meths = helpers.meths
|
||||||
|
|
||||||
local function read_mpack_file(fname)
|
local function read_mpack_file(fname)
|
||||||
local fd = io.open(fname, 'rb')
|
local fd = io.open(fname, 'rb')
|
||||||
@@ -43,7 +44,7 @@ describe("api_info()['version']", function()
|
|||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
describe("api functions", function()
|
describe("api metadata", function()
|
||||||
before_each(clear)
|
before_each(clear)
|
||||||
|
|
||||||
local function name_table(entries)
|
local function name_table(entries)
|
||||||
@@ -87,26 +88,23 @@ describe("api functions", function()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it("are compatible with old metadata or have new level", function()
|
local api, compat, stable, api_level
|
||||||
local api = helpers.call('api_info')
|
local old_api = {}
|
||||||
local compat = api.version.api_compatible
|
setup(function()
|
||||||
local api_level = api.version.api_level
|
api = meths.get_api_info()[2]
|
||||||
local stable
|
compat = api.version.api_compatible
|
||||||
|
api_level = api.version.api_level
|
||||||
if api.version.api_prerelease then
|
if api.version.api_prerelease then
|
||||||
stable = api_level-1
|
stable = api_level-1
|
||||||
else
|
else
|
||||||
stable = api_level
|
stable = api_level
|
||||||
end
|
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
|
for level = compat, stable do
|
||||||
local path = ('test/functional/fixtures/api_level_'..
|
local path = ('test/functional/fixtures/api_level_'..
|
||||||
tostring(level)..'.mpack')
|
tostring(level)..'.mpack')
|
||||||
local old_api = read_mpack_file(path)
|
old_api[level] = read_mpack_file(path)
|
||||||
if old_api == nil then
|
if old_api[level] == nil then
|
||||||
local errstr = "missing metadata fixture for stable level "..level..". "
|
local errstr = "missing metadata fixture for stable level "..level..". "
|
||||||
if level == api_level and not api.version.api_prerelease then
|
if level == api_level and not api.version.api_prerelease then
|
||||||
errstr = (errstr.."If NVIM_API_CURRENT was bumped, "..
|
errstr = (errstr.."If NVIM_API_CURRENT was bumped, "..
|
||||||
@@ -116,10 +114,16 @@ describe("api functions", function()
|
|||||||
end
|
end
|
||||||
|
|
||||||
if level == 0 then
|
if level == 0 then
|
||||||
clean_level_0(old_api)
|
clean_level_0(old_api[level])
|
||||||
end
|
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 funcs_new[f.name] == nil then
|
||||||
if f.since >= compat then
|
if f.since >= compat then
|
||||||
error('function '..f.name..' was removed but exists in level '..
|
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]))
|
filter_function_metadata(funcs_new[f.name]))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
funcs_compat[level] = name_table(old_api.functions)
|
funcs_compat[level] = name_table(old_api[level].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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
for _,f in ipairs(api.functions) do
|
for _,f in ipairs(api.functions) do
|
||||||
@@ -171,6 +164,22 @@ describe("api functions", function()
|
|||||||
end
|
end
|
||||||
end
|
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
|
for _,e in ipairs(api.ui_events) do
|
||||||
if e.since <= stable then
|
if e.since <= stable then
|
||||||
@@ -197,15 +206,18 @@ describe("api functions", function()
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
end)
|
it("ui_options are preserved from older levels", function()
|
||||||
|
local available_options = {}
|
||||||
describe("ui_options in metadata", function()
|
for _, option in ipairs(api.ui_options) do
|
||||||
it('are correct', function()
|
available_options[option] = true
|
||||||
-- TODO(bfredl) once a release freezes this into metadata,
|
end
|
||||||
-- instead check that all old options are present
|
-- UI options were versioned from level 4
|
||||||
local api = helpers.call('api_info')
|
for level = 4, stable do
|
||||||
local options = api.ui_options
|
for _, option in ipairs(old_api[level].ui_options) do
|
||||||
eq({'rgb', 'ext_cmdline', 'ext_popupmenu',
|
if not available_options[option] then
|
||||||
'ext_tabline', 'ext_wildmenu', 'ext_linegrid', 'ext_hlstate'}, options)
|
error("UI option "..option.." from stable metadata is missing")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user