diff --git a/lua/neotest-golang/convert.lua b/lua/neotest-golang/convert.lua index e6eb1dfa..ad5e6a1b 100644 --- a/lua/neotest-golang/convert.lua +++ b/lua/neotest-golang/convert.lua @@ -12,6 +12,13 @@ function M.to_gotest_regex_pattern(test_name) "]", "{", "}", + "-", + "|", + "?", + "+", + "*", + "^", + "$", } for _, character in ipairs(special_characters) do test_name = test_name:gsub("%" .. character, "\\" .. character) @@ -38,7 +45,7 @@ function M.to_gotest_test_name(pos_id) return test_name end ---- Escape characters, for usage of string as pattern in Lua.. +--- Escape characters, for usage of string as pattern in Lua. --- - `.` (matches any character) --- - `%` (used to escape special characters) --- - `+` (matches 1 or more of the previous character or class) diff --git a/tests/go/testname_spec.lua b/tests/go/testname_spec.lua index e878f93a..71868db2 100644 --- a/tests/go/testname_spec.lua +++ b/tests/go/testname_spec.lua @@ -1,6 +1,7 @@ local nio = require("nio") local adapter = require("neotest-golang") local convert = require("neotest-golang.convert") +local _ = require("plenary") describe("Neotest position to Go test name", function() -- Arrange @@ -62,6 +63,25 @@ describe("Neotest position to Go test name", function() vim.inspect(actual_go_test_name) ) end) + + it("supports regexp characters", function() + local expected_subtest_name = + '"Regexp characters like ( ) [ ] { } - | ? + * ^ $ are ok"' + local expected_gotest_name = + "TestNames/Regexp_characters_like_(_)_[_]_{_}_-_|_?_+_*_^_$_are_ok" + + -- Act + local pos = tree:node(8):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) describe("Full Go test name conversion", function() diff --git a/tests/go/testname_test.go b/tests/go/testname_test.go index 926afecc..85d19532 100644 --- a/tests/go/testname_test.go +++ b/tests/go/testname_test.go @@ -33,4 +33,10 @@ func TestNames(t *testing.T) { t.Fail() } }) + + t.Run("Regexp characters like ( ) [ ] { } - | ? + * ^ $ are ok", func(t *testing.T) { + if Add(1, 2) != 3 { + t.Fail() + } + }) }