diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2025-02-26 14:31:03 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-26 14:31:03 -0800 |
commit | 4f42b69b4ad0d0034581d756ef9bcb0e55f3491d (patch) | |
tree | 0c40b6f8c3569e339d375cb5842820590c5f3103 /test/testutil.lua | |
parent | f4921e2b7deb4812414998a521c33f920f571c20 (diff) | |
parent | 4a997a1732fdb7a1c99cadf780b789f1ac84d990 (diff) | |
download | rneovim-4f42b69b4ad0d0034581d756ef9bcb0e55f3491d.tar.gz rneovim-4f42b69b4ad0d0034581d756ef9bcb0e55f3491d.tar.bz2 rneovim-4f42b69b4ad0d0034581d756ef9bcb0e55f3491d.zip |
Merge #32601 vim.text.indent()
Diffstat (limited to 'test/testutil.lua')
-rw-r--r-- | test/testutil.lua | 26 |
1 files changed, 4 insertions, 22 deletions
diff --git a/test/testutil.lua b/test/testutil.lua index e69dcae120..3655a87d93 100644 --- a/test/testutil.lua +++ b/test/testutil.lua @@ -148,6 +148,7 @@ end --- @param actual string --- @return boolean function M.matches(pat, actual) + assert(pat and pat ~= '', 'pat must be a non-empty string') if nil ~= string.match(actual, pat) then return true end @@ -641,28 +642,9 @@ end --- @param leave_indent? integer --- @return string function M.dedent(str, leave_indent) - -- find minimum common indent across lines - local indent --- @type string? - 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 not indent or #indent == 0 then - -- 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, left_indent) - -- strip it from the remaining lines - str = str:gsub('[\n]' .. indent, '\n' .. left_indent) - return str + -- Last blank line often has non-matching indent, so remove it. + str = str:gsub('\n[ ]+$', '\n') + return (vim.text.indent(leave_indent or 0, str)) end function M.intchar2lua(ch) |