diff --git a/tests/go/testname_spec.lua b/tests/go/testname_spec.lua new file mode 100644 index 00000000..7dc3c614 --- /dev/null +++ b/tests/go/testname_spec.lua @@ -0,0 +1,46 @@ +local nio = require("nio") +local adapter = require("neotest-golang") +local convert = require("neotest-golang.convert") + +describe("Test names conversion", function() + -- Arrange + local test_filepath = vim.loop.cwd() .. "/tests/go/testname_test.go" + + ---@type neotest.Tree + local tree = + nio.tests.with_async_context(adapter.discover_positions, test_filepath) + + it("Mixed case with space", function() + local expected_test_name = '"Mixed case with space"' + local expected_go_test_name = "TestNames/Mixed_case_with_space" + + -- Act + local pos = tree:node(3):data() + local actual_go_test_name = convert.to_gotest_test_name(pos.id) + + -- Assert + local actual_name = pos.name + assert.are.same(expected_test_name, actual_name) + assert.are.same( + vim.inspect(expected_go_test_name), + vim.inspect(actual_go_test_name) + ) + end) + + it("Special characters", function() + local expected_test_name = '"Comma , and \' are ok to use"' + local expected_go_test_name = "TestNames/Comma_,_and_'_are_ok_to_use" + + -- Act + local pos = tree:node(4):data() + local actual_go_test_name = convert.to_gotest_test_name(pos.id) + + -- Assert + local actual_name = pos.name + assert.are.same(expected_test_name, actual_name) + assert.are.same( + vim.inspect(expected_go_test_name), + vim.inspect(actual_go_test_name) + ) + end) +end) diff --git a/tests/go/testname_test.go b/tests/go/testname_test.go new file mode 100644 index 00000000..aba15029 --- /dev/null +++ b/tests/go/testname_test.go @@ -0,0 +1,18 @@ +package main + +import "testing" + +// A dummy test, just to assert that Go tests can run. +func TestNames(t *testing.T) { + t.Run("Mixed case with space", func(t *testing.T) { + if Add(1, 2) != 3 { + t.Fail() + } + }) + + t.Run("Comma , and ' are ok to use", func(t *testing.T) { + if Add(1, 2) != 3 { + t.Fail() + } + }) +}