Skip to content

Commit

Permalink
fix: allow brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed May 22, 2024
1 parent c0a34a5 commit 945f5a8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
5 changes: 0 additions & 5 deletions lua/neotest-golang/convert.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ function M.to_gotest_test_name(pos_id)
test_name = test_name:gsub("::", "/")
-- Remove double quotes (single quotes are supported)
test_name = test_name:gsub('"', "")
-- Replace any special characters with . so to avoid breaking regexp
test_name = test_name:gsub("%[", ".")
test_name = test_name:gsub("%]", ".")
test_name = test_name:gsub("%(", ".")
test_name = test_name:gsub("%)", ".")
-- Replace any spaces with _
test_name = test_name:gsub(" ", "_")

Expand Down
17 changes: 17 additions & 0 deletions tests/go/testname_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,21 @@ describe("Subtest name conversion", function()
vim.inspect(actual_go_test_name)
)
end)

it("Brackets", function()
local expected_subtest_name = '"Brackets [1] (2) {3} are ok"'
local expected_gotest_name = "TestNames/Brackets_[1]_(2)_{3}_are_ok"

-- Act
local pos = tree:node(5):data()
local actual_go_test_name = convert.to_gotest_test_name(pos.id)

-- Assert
local actual_name = pos.name
assert.are.same(expected_subtest_name, actual_name)
assert.are.same(
vim.inspect(expected_gotest_name),
vim.inspect(actual_go_test_name)
)
end)
end)
6 changes: 6 additions & 0 deletions tests/go/testname_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ func TestNames(t *testing.T) {
t.Fail()
}
})

t.Run("Brackets [1] (2) {3} are ok", func(t *testing.T) {
if Add(1, 2) != 3 {
t.Fail()
}
})
}

0 comments on commit 945f5a8

Please sign in to comment.