From 945f5a8ca3c5aa0a9f8275156849927373e88a12 Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Wed, 22 May 2024 19:49:27 +0200 Subject: [PATCH] fix: allow brackets --- lua/neotest-golang/convert.lua | 5 ----- tests/go/testname_spec.lua | 17 +++++++++++++++++ tests/go/testname_test.go | 6 ++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/lua/neotest-golang/convert.lua b/lua/neotest-golang/convert.lua index e3eed8c4..bf39f828 100644 --- a/lua/neotest-golang/convert.lua +++ b/lua/neotest-golang/convert.lua @@ -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(" ", "_") diff --git a/tests/go/testname_spec.lua b/tests/go/testname_spec.lua index 5c276de7..ea510e39 100644 --- a/tests/go/testname_spec.lua +++ b/tests/go/testname_spec.lua @@ -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) diff --git a/tests/go/testname_test.go b/tests/go/testname_test.go index aba15029..0d880dfe 100644 --- a/tests/go/testname_test.go +++ b/tests/go/testname_test.go @@ -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() + } + }) }