Skip to content

Commit

Permalink
test: test name conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikaverpil committed May 22, 2024
1 parent ddae100 commit eb5ae3c
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/go/testname_spec.lua
Original file line number Diff line number Diff line change
@@ -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)
18 changes: 18 additions & 0 deletions tests/go/testname_test.go
Original file line number Diff line number Diff line change
@@ -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()
}
})
}

0 comments on commit eb5ae3c

Please sign in to comment.