diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2017-04-01 20:48:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-01 20:48:03 +0200 |
commit | 0f6608d039ef30fe4910f78d236c4f893e95c389 (patch) | |
tree | cfb61e4a5db0a68f9d15a45f46bd7e4775e21902 /test/helpers.lua | |
parent | 33ff29fc740fd437f1600d8ccc60b7b484d78d19 (diff) | |
parent | ac22238b6af1d37fab09fc2173d5ed2019652c41 (diff) | |
download | rneovim-0f6608d039ef30fe4910f78d236c4f893e95c389.tar.gz rneovim-0f6608d039ef30fe4910f78d236c4f893e95c389.tar.bz2 rneovim-0f6608d039ef30fe4910f78d236c4f893e95c389.zip |
Merge #6418 from ZyX-I/better-unittests
Diffstat (limited to 'test/helpers.lua')
-rw-r--r-- | test/helpers.lua | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/helpers.lua b/test/helpers.lua index 82451bc61d..3fc10e9e30 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -251,6 +251,28 @@ local function concat_tables(...) return ret end +local function dedent(str) + -- find minimum common indent across lines + local indent = nil + for line in str:gmatch('[^\n]+') do + local line_indent = line:match('^%s+') or '' + if indent == nil or #line_indent < #indent then + indent = line_indent + end + end + if indent == nil or #indent == 0 then + -- no minimum common indent + return str + end + -- create a pattern for the indent + indent = indent:gsub('%s', '[ \t]') + -- strip it from the first line + str = str:gsub('^'..indent, '') + -- strip it from the remaining lines + str = str:gsub('[\n]'..indent, '\n') + return str +end + return { eq = eq, neq = neq, @@ -265,4 +287,5 @@ return { hasenv = hasenv, which = which, concat_tables = concat_tables, + dedent = dedent, } |