aboutsummaryrefslogtreecommitdiff
path: root/test/helpers.lua
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2017-11-05 21:06:12 +0300
committerZyX <kp-pav@yandex.ru>2017-11-06 01:17:39 +0300
commit7849070f998902bb6aae5d6f9147d4daf5421b36 (patch)
tree60ce9e21300fa954b476347bb4f96b074a9095c8 /test/helpers.lua
parent7bc6de75263f58c6c4f999bc86a6454ae9f28b80 (diff)
downloadrneovim-7849070f998902bb6aae5d6f9147d4daf5421b36.tar.gz
rneovim-7849070f998902bb6aae5d6f9147d4daf5421b36.tar.bz2
rneovim-7849070f998902bb6aae5d6f9147d4daf5421b36.zip
tests: Add missing test cases
Diffstat (limited to 'test/helpers.lua')
-rw-r--r--test/helpers.lua42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/helpers.lua b/test/helpers.lua
index 67ac82e6fd..20fe23821f 100644
--- a/test/helpers.lua
+++ b/test/helpers.lua
@@ -271,6 +271,45 @@ local function shallowcopy(orig)
return copy
end
+local deepcopy
+
+local function id(v)
+ return v
+end
+
+local deepcopy_funcs = {
+ table = function(orig)
+ local copy = {}
+ for k, v in pairs(orig) do
+ copy[deepcopy(k)] = deepcopy(v)
+ end
+ end,
+ number = id,
+ string = id,
+ ['nil'] = id,
+ boolean = id,
+}
+
+deepcopy = function(orig)
+ return deepcopy_funcs[type(orig)](orig)
+end
+
+local REMOVE_THIS = {}
+
+local function mergedicts_copy(d1, d2)
+ local ret = shallowcopy(d1)
+ for k, v in pairs(d2) do
+ if d2[k] == REMOVE_THIS then
+ ret[k] = nil
+ elseif type(d1[k]) == 'table' and type(d2[k]) == 'table' then
+ ret[k] = mergedicts_copy(d1[k], d2[k])
+ else
+ ret[k] = d2[k]
+ end
+ end
+ return ret
+end
+
local function concat_tables(...)
local ret = {}
for i = 1, select('#', ...) do
@@ -413,6 +452,9 @@ return {
hasenv = hasenv,
which = which,
shallowcopy = shallowcopy,
+ deepcopy = deepcopy,
+ mergedicts_copy = mergedicts_copy,
+ REMOVE_THIS = REMOVE_THIS,
concat_tables = concat_tables,
dedent = dedent,
format_luav = format_luav,