mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
test: Extend {unit,functional}.helpers with global helpers
Automatically include all "global helper" util functions in the unit.helpers and functional.helpers and modules. So tests don't need to expicitly do: local global_helpers = require('test.helpers')
This commit is contained in:
@@ -3,6 +3,7 @@ local assert = require('luassert')
|
||||
local luv = require('luv')
|
||||
local lfs = require('lfs')
|
||||
local relpath = require('pl.path').relpath
|
||||
local Paths = require('test.config.paths')
|
||||
|
||||
local quote_me = '[^.%w%+%-%@%_%/]' -- complement (needn't quote)
|
||||
local function shell_quote(str)
|
||||
@@ -420,6 +421,7 @@ local function updated(d, d2)
|
||||
return d
|
||||
end
|
||||
|
||||
-- Concat list-like tables.
|
||||
local function concat_tables(...)
|
||||
local ret = {}
|
||||
for i = 1, select('#', ...) do
|
||||
@@ -433,6 +435,34 @@ local function concat_tables(...)
|
||||
return ret
|
||||
end
|
||||
|
||||
-- Concat map-like tables.
|
||||
--
|
||||
-- behavior: Decides what to do if a key is found in more than one map:
|
||||
-- "error": raise an error
|
||||
-- "keep": skip
|
||||
-- "force": set the item again
|
||||
local function map_extend(behavior, ...)
|
||||
if (behavior ~= 'error' and behavior ~= 'keep' and behavior ~= 'force') then
|
||||
error('invalid "behavior": '..tostring(behavior))
|
||||
end
|
||||
local ret = {}
|
||||
for i = 1, select('#', ...) do
|
||||
local tbl = select(i, ...)
|
||||
if tbl then
|
||||
for k, v in pairs(tbl) do
|
||||
if behavior ~= 'force' and ret[k] ~= nil then
|
||||
if behavior == 'error' then
|
||||
error('key found in more than one map: '..k)
|
||||
end -- Else behavior is "keep".
|
||||
else
|
||||
ret[k] = v
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
local function dedent(str, leave_indent)
|
||||
-- find minimum common indent across lines
|
||||
local indent = nil
|
||||
@@ -771,6 +801,7 @@ local module = {
|
||||
intchar2lua = intchar2lua,
|
||||
isCI = isCI,
|
||||
map = map,
|
||||
map_extend = map_extend,
|
||||
matches = matches,
|
||||
mergedicts_copy = mergedicts_copy,
|
||||
near = near,
|
||||
@@ -792,5 +823,6 @@ local module = {
|
||||
which = which,
|
||||
write_file = write_file,
|
||||
}
|
||||
module = map_extend('error', module, Paths)
|
||||
|
||||
return module
|
||||
|
Reference in New Issue
Block a user