diff options
author | Jakob Schnitzer <mail@jakobschnitzer.de> | 2017-06-28 16:52:04 +0200 |
---|---|---|
committer | Jakob Schnitzer <mail@jakobschnitzer.de> | 2017-06-28 16:52:04 +0200 |
commit | e8829710bc5f38208499e0ad38402eac24a67ac2 (patch) | |
tree | 4e1ae954c2e301adadbfa7038b823ea9ea2fb08e /test/helpers.lua | |
parent | ff8b2eb435c518f0eafd0e509afe1f5ee4a81fd1 (diff) | |
parent | f0dafa89c2b7602cfedf0bd3409858e4c212b0a2 (diff) | |
download | rneovim-e8829710bc5f38208499e0ad38402eac24a67ac2.tar.gz rneovim-e8829710bc5f38208499e0ad38402eac24a67ac2.tar.bz2 rneovim-e8829710bc5f38208499e0ad38402eac24a67ac2.zip |
Merge branch 'master' into option-fixes
Diffstat (limited to 'test/helpers.lua')
-rw-r--r-- | test/helpers.lua | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/test/helpers.lua b/test/helpers.lua index d60d5ba242..260f10002e 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -263,6 +263,14 @@ local function which(exe) end end +local function shallowcopy(orig) + local copy = {} + for orig_key, orig_value in pairs(orig) do + copy[orig_key] = orig_value + end + return copy +end + local function concat_tables(...) local ret = {} for i = 1, select('#', ...) do @@ -276,7 +284,7 @@ local function concat_tables(...) return ret end -local function dedent(str) +local function dedent(str, leave_indent) -- find minimum common indent across lines local indent = nil for line in str:gmatch('[^\n]+') do @@ -289,12 +297,13 @@ local function dedent(str) -- no minimum common indent return str end + local left_indent = (' '):rep(leave_indent or 0) -- create a pattern for the indent indent = indent:gsub('%s', '[ \t]') -- strip it from the first line - str = str:gsub('^'..indent, '') + str = str:gsub('^'..indent, left_indent) -- strip it from the remaining lines - str = str:gsub('[\n]'..indent, '\n') + str = str:gsub('[\n]'..indent, '\n' .. left_indent) return str end @@ -311,6 +320,7 @@ return { check_cores = check_cores, hasenv = hasenv, which = which, + shallowcopy = shallowcopy, concat_tables = concat_tables, dedent = dedent, } |