From 04f2f864e270e772c6326cefdf24947f0130e492 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 3 Jan 2024 02:09:18 +0100 Subject: refactor: format test/* --- test/functional/api/version_spec.lua | 155 +++++++++++++++++++++-------------- 1 file changed, 92 insertions(+), 63 deletions(-) (limited to 'test/functional/api/version_spec.lua') diff --git a/test/functional/api/version_spec.lua b/test/functional/api/version_spec.lua index 6d466b0cc1..76cdb9cbca 100644 --- a/test/functional/api/version_spec.lua +++ b/test/functional/api/version_spec.lua @@ -19,41 +19,40 @@ end describe("api_info()['version']", function() before_each(clear) - it("returns API level", function() + it('returns API level', function() local version = call('api_info')['version'] local current = version['api_level'] - local compat = version['api_compatible'] - eq("number", type(current)) - eq("number", type(compat)) + local compat = version['api_compatible'] + eq('number', type(current)) + eq('number', type(compat)) assert(current >= compat) end) - it("returns Nvim version", function() + it('returns Nvim version', function() local version = call('api_info')['version'] - local major = version['major'] - local minor = version['minor'] - local patch = version['patch'] + local major = version['major'] + local minor = version['minor'] + local patch = version['patch'] local prerelease = version['prerelease'] - local build = version['build'] - eq("number", type(major)) - eq("number", type(minor)) - eq("number", type(patch)) - eq("boolean", type(prerelease)) - eq(1, funcs.has("nvim-"..major.."."..minor.."."..patch)) - eq(0, funcs.has("nvim-"..major.."."..minor.."."..(patch + 1))) - eq(0, funcs.has("nvim-"..major.."."..(minor + 1).."."..patch)) - eq(0, funcs.has("nvim-"..(major + 1).."."..minor.."."..patch)) + local build = version['build'] + eq('number', type(major)) + eq('number', type(minor)) + eq('number', type(patch)) + eq('boolean', type(prerelease)) + eq(1, funcs.has('nvim-' .. major .. '.' .. minor .. '.' .. patch)) + eq(0, funcs.has('nvim-' .. major .. '.' .. minor .. '.' .. (patch + 1))) + eq(0, funcs.has('nvim-' .. major .. '.' .. (minor + 1) .. '.' .. patch)) + eq(0, funcs.has('nvim-' .. (major + 1) .. '.' .. minor .. '.' .. patch)) assert(build == nil or type(build) == 'string') end) end) - -describe("api metadata", function() +describe('api metadata', function() before_each(clear) local function name_table(entries) local by_name = {} - for _,e in ipairs(entries) do + for _, e in ipairs(entries) do by_name[e.name] = e end return by_name @@ -63,10 +62,10 @@ describe("api metadata", function() local function filter_function_metadata(f) f.deprecated_since = nil for idx, _ in ipairs(f.parameters) do - f.parameters[idx][2] = '' -- Remove parameter name. + f.parameters[idx][2] = '' -- Remove parameter name. end - if string.sub(f.name, 1, 4) ~= "nvim" then + if string.sub(f.name, 1, 4) ~= 'nvim' then f.method = nil end return f @@ -76,7 +75,7 @@ describe("api metadata", function() -- check types of existing params are the same -- adding parameters is ok, but removing params is not (gives nil error) eq(old_e.since, new_e.since, old_e.name) - for i,p in ipairs(old_e.parameters) do + for i, p in ipairs(old_e.parameters) do eq(new_e.parameters[i][1], p[1], old_e.name) end end @@ -95,25 +94,27 @@ describe("api metadata", function() local api, compat, stable, api_level local old_api = {} setup(function() - clear() -- Ensure a session before requesting api_info. + clear() -- Ensure a session before requesting api_info. api = meths.get_api_info()[2] - compat = api.version.api_compatible + compat = api.version.api_compatible api_level = api.version.api_level if api.version.api_prerelease then - stable = api_level-1 + stable = api_level - 1 else stable = api_level end for level = compat, stable do - local path = ('test/functional/fixtures/api_level_'.. - tostring(level)..'.mpack') + local path = ('test/functional/fixtures/api_level_' .. tostring(level) .. '.mpack') old_api[level] = read_mpack_file(path) 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 - errstr = (errstr.."If NVIM_API_CURRENT was bumped, ".. - "don't forget to set NVIM_API_PRERELEASE to true.") + errstr = ( + errstr + .. 'If NVIM_API_CURRENT was bumped, ' + .. "don't forget to set NVIM_API_PRERELEASE to true." + ) end error(errstr) end @@ -124,60 +125,76 @@ describe("api metadata", function() end end) - it("functions are compatible with old metadata or have new level", function() + 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 + 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 '.. - f.since..' which nvim should be compatible with') + error( + 'function ' + .. f.name + .. ' was removed but exists in level ' + .. f.since + .. ' which nvim should be compatible with' + ) end else - eq(filter_function_metadata(f), - filter_function_metadata(funcs_new[f.name])) + eq(filter_function_metadata(f), filter_function_metadata(funcs_new[f.name])) end end funcs_compat[level] = name_table(old_api[level].functions) end - for _,f in ipairs(api.functions) do + for _, f in ipairs(api.functions) do if f.since <= stable then local f_old = funcs_compat[f.since][f.name] if f_old == nil then - if string.sub(f.name, 1, 4) == "nvim" then - local errstr = ("function "..f.name.." has too low since value. ".. - "For new functions set it to "..(stable+1)..".") + if string.sub(f.name, 1, 4) == 'nvim' then + local errstr = ( + 'function ' + .. f.name + .. ' has too low since value. ' + .. 'For new functions set it to ' + .. (stable + 1) + .. '.' + ) if not api.version.api_prerelease then - errstr = (errstr.." Also bump NVIM_API_CURRENT and set ".. - "NVIM_API_PRERELEASE to true in CMakeLists.txt.") + errstr = ( + errstr + .. ' Also bump NVIM_API_CURRENT and set ' + .. 'NVIM_API_PRERELEASE to true in CMakeLists.txt.' + ) end error(errstr) else - error("function name '"..f.name.."' doesn't begin with 'nvim_'") + error("function name '" .. f.name .. "' doesn't begin with 'nvim_'") end end elseif f.since > api_level then if api.version.api_prerelease then - error("New function "..f.name.." should use since value ".. - api_level) + error('New function ' .. f.name .. ' should use since value ' .. api_level) else - error("function "..f.name.." has since value > api_level. ".. - "Bump NVIM_API_CURRENT and set ".. - "NVIM_API_PRERELEASE to true in CMakeLists.txt.") + error( + 'function ' + .. f.name + .. ' has since value > api_level. ' + .. 'Bump NVIM_API_CURRENT and set ' + .. 'NVIM_API_PRERELEASE to true in CMakeLists.txt.' + ) end end end end) - it("UI events are compatible with old metadata or have new level", function() + 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 + 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) @@ -186,32 +203,44 @@ describe("api metadata", function() 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 local e_old = ui_events_compat[e.since][e.name] if e_old == nil then - local errstr = ("UI event "..e.name.." has too low since value. ".. - "For new events set it to "..(stable+1)..".") + local errstr = ( + 'UI event ' + .. e.name + .. ' has too low since value. ' + .. 'For new events set it to ' + .. (stable + 1) + .. '.' + ) if not api.version.api_prerelease then - errstr = (errstr.." Also bump NVIM_API_CURRENT and set ".. - "NVIM_API_PRERELEASE to true in CMakeLists.txt.") + errstr = ( + errstr + .. ' Also bump NVIM_API_CURRENT and set ' + .. 'NVIM_API_PRERELEASE to true in CMakeLists.txt.' + ) end error(errstr) end elseif e.since > api_level then if api.version.api_prerelease then - error("New UI event "..e.name.." should use since value ".. - api_level) + error('New UI event ' .. e.name .. ' should use since value ' .. api_level) else - error("UI event "..e.name.." has since value > api_level. ".. - "Bump NVIM_API_CURRENT and set ".. - "NVIM_API_PRERELEASE to true in CMakeLists.txt.") + error( + 'UI event ' + .. e.name + .. ' has since value > api_level. ' + .. 'Bump NVIM_API_CURRENT and set ' + .. 'NVIM_API_PRERELEASE to true in CMakeLists.txt.' + ) end end end end) - it("ui_options are preserved from older levels", function() + it('ui_options are preserved from older levels', function() local available_options = {} for _, option in ipairs(api.ui_options) do available_options[option] = true @@ -220,7 +249,7 @@ describe("api metadata", function() 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") + error('UI option ' .. option .. ' from stable metadata is missing') end end end -- cgit From 284e0ad26dd9de90c3a813dd1b357a425eca6bad Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 12:03:25 +0000 Subject: test: use vim.mpack and vim.uv directly --- test/functional/api/version_spec.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'test/functional/api/version_spec.lua') diff --git a/test/functional/api/version_spec.lua b/test/functional/api/version_spec.lua index 76cdb9cbca..41f8fccab9 100644 --- a/test/functional/api/version_spec.lua +++ b/test/functional/api/version_spec.lua @@ -1,5 +1,4 @@ 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 @@ -12,7 +11,7 @@ local function read_mpack_file(fname) local data = fd:read('*a') fd:close() - local unpack = mpack.Unpacker() + local unpack = vim.mpack.Unpacker() return unpack(data) end -- cgit From c30f2e3182e3b50e7c03932027ac55edfc8ada4a Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 12:44:54 +0000 Subject: test: typing for helpers.meths --- test/functional/api/version_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/functional/api/version_spec.lua') diff --git a/test/functional/api/version_spec.lua b/test/functional/api/version_spec.lua index 41f8fccab9..fefafb8f98 100644 --- a/test/functional/api/version_spec.lua +++ b/test/functional/api/version_spec.lua @@ -94,7 +94,7 @@ describe('api metadata', function() local old_api = {} setup(function() clear() -- Ensure a session before requesting api_info. - api = meths.get_api_info()[2] + api = meths.nvim_get_api_info()[2] compat = api.version.api_compatible api_level = api.version.api_level if api.version.api_prerelease then -- cgit From 795f896a5772d5e0795f86642bdf90c82efac45c Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 12 Jan 2024 17:59:57 +0000 Subject: test: rename (meths, funcs) -> (api, fn) --- test/functional/api/version_spec.lua | 47 ++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 24 deletions(-) (limited to 'test/functional/api/version_spec.lua') diff --git a/test/functional/api/version_spec.lua b/test/functional/api/version_spec.lua index fefafb8f98..c304f1aa88 100644 --- a/test/functional/api/version_spec.lua +++ b/test/functional/api/version_spec.lua @@ -1,7 +1,6 @@ local helpers = require('test.functional.helpers')(after_each) -local clear, funcs, eq = helpers.clear, helpers.funcs, helpers.eq -local call = helpers.call -local meths = helpers.meths +local clear, fn, eq = helpers.clear, helpers.fn, helpers.eq +local api = helpers.api local function read_mpack_file(fname) local fd = io.open(fname, 'rb') @@ -19,7 +18,7 @@ describe("api_info()['version']", function() before_each(clear) it('returns API level', function() - local version = call('api_info')['version'] + local version = fn.api_info()['version'] local current = version['api_level'] local compat = version['api_compatible'] eq('number', type(current)) @@ -28,7 +27,7 @@ describe("api_info()['version']", function() end) it('returns Nvim version', function() - local version = call('api_info')['version'] + local version = fn.api_info()['version'] local major = version['major'] local minor = version['minor'] local patch = version['patch'] @@ -38,10 +37,10 @@ describe("api_info()['version']", function() eq('number', type(minor)) eq('number', type(patch)) eq('boolean', type(prerelease)) - eq(1, funcs.has('nvim-' .. major .. '.' .. minor .. '.' .. patch)) - eq(0, funcs.has('nvim-' .. major .. '.' .. minor .. '.' .. (patch + 1))) - eq(0, funcs.has('nvim-' .. major .. '.' .. (minor + 1) .. '.' .. patch)) - eq(0, funcs.has('nvim-' .. (major + 1) .. '.' .. minor .. '.' .. patch)) + eq(1, fn.has('nvim-' .. major .. '.' .. minor .. '.' .. patch)) + eq(0, fn.has('nvim-' .. major .. '.' .. minor .. '.' .. (patch + 1))) + eq(0, fn.has('nvim-' .. major .. '.' .. (minor + 1) .. '.' .. patch)) + eq(0, fn.has('nvim-' .. (major + 1) .. '.' .. minor .. '.' .. patch)) assert(build == nil or type(build) == 'string') end) end) @@ -90,14 +89,14 @@ describe('api metadata', function() end end - local api, compat, stable, api_level + local api_info, compat, stable, api_level local old_api = {} setup(function() clear() -- Ensure a session before requesting api_info. - api = meths.nvim_get_api_info()[2] - compat = api.version.api_compatible - api_level = api.version.api_level - if api.version.api_prerelease then + api_info = api.nvim_get_api_info()[2] + compat = api_info.version.api_compatible + api_level = api_info.version.api_level + if api_info.version.api_prerelease then stable = api_level - 1 else stable = api_level @@ -108,7 +107,7 @@ describe('api metadata', function() 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 + if level == api_level and not api_info.version.api_prerelease then errstr = ( errstr .. 'If NVIM_API_CURRENT was bumped, ' @@ -125,7 +124,7 @@ describe('api metadata', function() end) it('functions are compatible with old metadata or have new level', function() - local funcs_new = name_table(api.functions) + local funcs_new = name_table(api_info.functions) local funcs_compat = {} for level = compat, stable do for _, f in ipairs(old_api[level].functions) do @@ -146,7 +145,7 @@ describe('api metadata', function() funcs_compat[level] = name_table(old_api[level].functions) end - for _, f in ipairs(api.functions) do + for _, f in ipairs(api_info.functions) do if f.since <= stable then local f_old = funcs_compat[f.since][f.name] if f_old == nil then @@ -159,7 +158,7 @@ describe('api metadata', function() .. (stable + 1) .. '.' ) - if not api.version.api_prerelease then + if not api_info.version.api_prerelease then errstr = ( errstr .. ' Also bump NVIM_API_CURRENT and set ' @@ -172,7 +171,7 @@ describe('api metadata', function() end end elseif f.since > api_level then - if api.version.api_prerelease then + if api_info.version.api_prerelease then error('New function ' .. f.name .. ' should use since value ' .. api_level) else error( @@ -188,7 +187,7 @@ describe('api metadata', function() 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_new = name_table(api_info.ui_events) local ui_events_compat = {} -- UI events were formalized in level 3 @@ -202,7 +201,7 @@ describe('api metadata', function() 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_info.ui_events) do if e.since <= stable then local e_old = ui_events_compat[e.since][e.name] if e_old == nil then @@ -214,7 +213,7 @@ describe('api metadata', function() .. (stable + 1) .. '.' ) - if not api.version.api_prerelease then + if not api_info.version.api_prerelease then errstr = ( errstr .. ' Also bump NVIM_API_CURRENT and set ' @@ -224,7 +223,7 @@ describe('api metadata', function() error(errstr) end elseif e.since > api_level then - if api.version.api_prerelease then + if api_info.version.api_prerelease then error('New UI event ' .. e.name .. ' should use since value ' .. api_level) else error( @@ -241,7 +240,7 @@ describe('api metadata', function() it('ui_options are preserved from older levels', function() local available_options = {} - for _, option in ipairs(api.ui_options) do + for _, option in ipairs(api_info.ui_options) do available_options[option] = true end -- UI options were versioned from level 4 -- cgit