refactor: move thing out to utils
This commit is contained in:
parent
0c0584edbd
commit
74d7afcc01
3 changed files with 15 additions and 10 deletions
|
|
@ -30,4 +30,11 @@ function utils.remove_empty_lines(t)
|
|||
return res
|
||||
end
|
||||
|
||||
---@param s string
|
||||
---@return string
|
||||
function utils.trimend(s)
|
||||
local r, _ = string.gsub(s, "%s+$", "")
|
||||
return r
|
||||
end
|
||||
|
||||
return utils
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
local ts = require "gopher._utils.ts"
|
||||
local r = require "gopher._utils.runner"
|
||||
local c = require "gopher.config"
|
||||
local u = require "gopher._utils"
|
||||
local log = require "gopher._utils.log"
|
||||
local struct_tags = {}
|
||||
|
||||
|
|
@ -77,7 +78,7 @@ local function handle_tags(fpath, bufnr, user_args)
|
|||
end
|
||||
|
||||
for i, v in ipairs(res["lines"]) do
|
||||
res["lines"][i] = string.gsub(v, "%s+$", "")
|
||||
res["lines"][i] = u.trimend(v)
|
||||
end
|
||||
|
||||
vim.api.nvim_buf_set_lines(
|
||||
|
|
|
|||
|
|
@ -1,13 +1,5 @@
|
|||
local t = require "spec.testutils"
|
||||
local child = MiniTest.new_child_neovim()
|
||||
local T = MiniTest.new_set {
|
||||
hooks = {
|
||||
post_once = child.stop,
|
||||
pre_case = function()
|
||||
child.restart { "-u", t.mininit_path }
|
||||
end,
|
||||
},
|
||||
}
|
||||
local _, T = t.setup "utils"
|
||||
|
||||
T["utils"] = MiniTest.new_set()
|
||||
T["utils"]["should .remove_empty_lines()"] = function()
|
||||
|
|
@ -26,4 +18,9 @@ T["utils"]["should .readfile_joined()"] = function()
|
|||
t.eq(u.readfile_joined(tmp), data)
|
||||
end
|
||||
|
||||
T["utils"]["should .trimend()"] = function()
|
||||
local u = require "gopher._utils"
|
||||
t.eq(u.trimend " hi ", " hi")
|
||||
end
|
||||
|
||||
return T
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue