Skip to content

Commit

Permalink
Fix trimming test names
Browse files Browse the repository at this point in the history
  • Loading branch information
MisanthropicBit committed Jan 1, 2025
1 parent ddec0ac commit c9e64b2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
16 changes: 14 additions & 2 deletions lua/neotest-busted/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,23 @@ local util = {}

local lib = require("neotest.lib")

--- Strip quotes from a string
local trim_chars = { "'", '"' }

--- Trim quotes from a string
---@param value string
---@return string
function util.trim_quotes(value)
return vim.fn.trim(value, "\"'[]")
for _, trim_char in ipairs(trim_chars) do
if value:sub(1, 1) == trim_char and value:sub(#value, #value) == trim_char then
return value:sub(2, #value - 1)
end
end

if vim.startswith(value, "[[") and vim.endswith(value, "]]") then
return value:sub(3, #value - 3)
end

return value
end

---@param ... string
Expand Down
7 changes: 5 additions & 2 deletions tests/util_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ describe("util", function()
assert.are.same(util.trim_quotes('"this will be trimmed"'), "this will be trimmed")
assert.are.same(
util.trim_quotes("\"'[[this will be trimmed]]'\""),
"this will be trimmed"
"'[[this will be trimmed]]'"
)
assert.are.same(
util.trim_quotes('"[brackets will not be trimmed]"'),
"[brackets will not be trimmed]"
)

assert.are.same(
util.trim_quotes("this will not be trimmed"),
"this will not be trimmed"
Expand Down

0 comments on commit c9e64b2

Please sign in to comment.