refactor: move thing out to utils

This commit is contained in:
Oleksandr Smirnov 2025-03-22 23:00:14 +02:00
parent 0c0584edbd
commit 74d7afcc01
No known key found for this signature in database
3 changed files with 15 additions and 10 deletions

View file

@ -30,4 +30,11 @@ function utils.remove_empty_lines(t)
return res return res
end end
---@param s string
---@return string
function utils.trimend(s)
local r, _ = string.gsub(s, "%s+$", "")
return r
end
return utils return utils

View file

@ -33,6 +33,7 @@
local ts = require "gopher._utils.ts" local ts = require "gopher._utils.ts"
local r = require "gopher._utils.runner" local r = require "gopher._utils.runner"
local c = require "gopher.config" local c = require "gopher.config"
local u = require "gopher._utils"
local log = require "gopher._utils.log" local log = require "gopher._utils.log"
local struct_tags = {} local struct_tags = {}
@ -77,7 +78,7 @@ local function handle_tags(fpath, bufnr, user_args)
end end
for i, v in ipairs(res["lines"]) do for i, v in ipairs(res["lines"]) do
res["lines"][i] = string.gsub(v, "%s+$", "") res["lines"][i] = u.trimend(v)
end end
vim.api.nvim_buf_set_lines( vim.api.nvim_buf_set_lines(

View file

@ -1,13 +1,5 @@
local t = require "spec.testutils" local t = require "spec.testutils"
local child = MiniTest.new_child_neovim() local _, T = t.setup "utils"
local T = MiniTest.new_set {
hooks = {
post_once = child.stop,
pre_case = function()
child.restart { "-u", t.mininit_path }
end,
},
}
T["utils"] = MiniTest.new_set() T["utils"] = MiniTest.new_set()
T["utils"]["should .remove_empty_lines()"] = function() T["utils"]["should .remove_empty_lines()"] = function()
@ -26,4 +18,9 @@ T["utils"]["should .readfile_joined()"] = function()
t.eq(u.readfile_joined(tmp), data) t.eq(u.readfile_joined(tmp), data)
end end
T["utils"]["should .trimend()"] = function()
local u = require "gopher._utils"
t.eq(u.trimend " hi ", " hi")
end
return T return T