mirror of
https://github.com/neovim/neovim.git
synced 2025-10-26 12:27:24 +00:00
unittests: Add trace description right to the error message
This commit is contained in:
@@ -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,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user