Skip to content

Commit

Permalink
[feature] added toggle favorite test in list
Browse files Browse the repository at this point in the history
  • Loading branch information
vladevelops committed Oct 11, 2024
1 parent 4d33b81 commit 6483187
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
gtestler.nvim
==============================================================================

[!NOTE]
The plugin is new and may have some bugs

**Easy-to-use Go test list system.**

Expand Down
13 changes: 10 additions & 3 deletions doc/gtestler.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ Available Commands:
:h gtestler.add_favorite_test
:h gtestler.execute_favorite_test
:h gtestler.visual_delete
:h gtestler.toggle_favorite


------------------------------------------------------------------------------
open_tests_list() *gtestler.open_tests_list()*
Opens a list of all added tests for the current project. The project's working
directory is used to locate the valid tests:
>
vim.fn.getcwd()
<
<
The last directory in the path provided by the `getcwd()` command is used as
the project directory.
If before test labal you see * (ex: * TestMyTestSample) it meens this test is
Expand All @@ -35,15 +37,15 @@ to run the test in the context of the gtestler buffer list.
add_test() *gtestler.add_test()*
Adds the test under the cursor to the list. You can run this from any line
within the test function scope:
>
>
[no]
[yes] func TestMyTestSample(t *testing.T) {
[yes] ...
[yes] ...
[yes] ...
[yes] }
[no]
<
<
The plugin will add the name of the function as a label for the test.

------------------------------------------------------------------------------
Expand Down Expand Up @@ -72,6 +74,11 @@ Pressing d will delete all the selected tests.

It will automatically refresh the buffer list.

------------------------------------------------------------------------------
toggle_favorite() *gtestler.favorite()*

In the list of tests press f to toggle betwin current test
being favorite or not


vim:tw=80:ts=8:ft=help:norl:
23 changes: 22 additions & 1 deletion lua/gtestler/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ vim.api.nvim_create_autocmd("FileType", {
pattern = pattern,
group = gtestler_autogroup,
callback = function()
vim.keymap.set("n", "f", function()
M.toggle_favorite()
end, {
buffer = true,
desc = "test is now favorite",
noremap = true,
})
vim.keymap.set("n", "<leader>tr", function()
M.run_selected_test()
end, {
Expand Down Expand Up @@ -193,6 +200,18 @@ function M.add_test()
return test_name
end

--- makes current test favorite
function M.toggle_favorite()
local command_alias = gtestler_utils.get_command_alias()
if command_alias ~= "" then
print("command_alias:", command_alias)
command_alias = command_alias:gsub("^%s+", ""):gsub("%s+$", "")
current_favorite_test = command_alias
vim.cmd("bd!")
M.open_tests_list()
end
end

--- @return string
function M.add_favorite_test()
current_favorite_test = M.add_test()
Expand Down Expand Up @@ -254,7 +273,9 @@ end

function M.execute_test()
local new_cmd = gtestler_utils.get_command_and_test_name()
M.execute_wrap(new_cmd)
if new_cmd ~= nil then
M.execute_wrap(new_cmd)
end
end

--- @param opts {split_method: string} "method: horizontal|vertical"
Expand Down
2 changes: 2 additions & 0 deletions lua/gtestler/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function M.get_command_and_test_name()

if ft ~= "go" then
print("can only run test in a .go file, not " .. ft)
return
end

local test_name = iterateLines()
Expand Down Expand Up @@ -115,6 +116,7 @@ function M.remove_star_if_exists(str)
end

--- in context of gtestler list gets the test name
--- checks the cursor current location line
---@return string
function M.get_command_alias()
local buf = vim.api.nvim_get_current_buf()
Expand Down

0 comments on commit 6483187

Please sign in to comment.