-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: break out conversion into its own file
- Loading branch information
1 parent
8e9bf4d
commit d78508f
Showing
2 changed files
with
30 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
local M = {} | ||
|
||
-- Converts the AST-detected test name into the 'go test' command test name format. | ||
---@param pos_id string | ||
---@return string | ||
function M.to_gotest_test_name(pos_id) | ||
-- construct the test name | ||
local test_name = pos_id | ||
-- Remove the path before :: | ||
test_name = test_name:match("::(.*)$") | ||
-- Replace :: with / | ||
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(" ", "_") | ||
|
||
return test_name | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters