Skip to content

Commit

Permalink
[FEATURE] added: visully delete selected and multivle tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vladevelops committed Oct 10, 2024
1 parent 67c9b66 commit ac31914
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 11 deletions.
7 changes: 5 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
- [x] BUG: isolate tests based on project
- [x] delete tests from list
- [x] add user action split option
- [x] BUG: after quiting tests list buffer esc and CR effect remains on main buffer
- [x] BUG: after quitting tests list buffer esc and CR effect remains on main buffer
- [x] delete all relative tests, user callable
- [x] documentation
- [x] delete visually selected tests
- [ ] make a already added test in the list favorite
- [ ] consider test name change, so delete test if not found
- [ ] run tests by numbers
- [ ] add test file location, and search test location in that file
- [ ] add line to the floating buffer with fields to explain
- [ ] add all tests in buffer to gtester list
- [ ] add all tests in buffer to gtester list
- [ ] run test in float window
- [ ] highlight tests already in list
- [ ] consider telescope integration

54 changes: 45 additions & 9 deletions lua/gtestler/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,29 @@ vim.api.nvim_create_autocmd("FileType", {
pattern = pattern,
group = gtestler_autogroup,
callback = function()
vim.keymap.set("n", "<leader>tr", function()
M.run_selected_test()
end, {
buffer = true,
desc = "run selected test",
noremap = true,
})

vim.keymap.set("n", "<CR>", function()
M.run_selected_test()
end, { buffer = true, desc = "run selected test" })

vim.keymap.set("v", "d", function()
M.delete_selected_tests()
end, { buffer = true, desc = "run selected test" })

vim.keymap.set(
"n",
"v",
"V",
{ buffer = true, desc = "run selected test", noremap = true }
)

vim.keymap.set(
"n",
"<Esc>",
Expand Down Expand Up @@ -85,15 +104,6 @@ end, {
function M.open_tests_list()
local floating_buffer, win_id = gtestler_ui.create_buffer()
gtestler_win_id = win_id

vim.api.nvim_buf_set_keymap(
floating_buffer,
"n",
"<leader>tr",
"<Cmd>lua require('gtestler').run_selected_test()<CR>",
{ silent = true }
)

local tests_list = {}

local count = 1
Expand Down Expand Up @@ -216,6 +226,32 @@ function M.delete_all_tests()
gtestler_utils.save_json_to_file(tests_commands)
end

--- thanks to adoyle-h on https://github.com/nvim-telescope/telescope.nvim/issues/1923#issuecomment-1122642431
--- for easy visul selection hint
local function get_visual_selection()
vim.cmd('noau normal! "vy"')
local text = vim.fn.getreg("v")
vim.fn.setreg("v", {})
text = string.gsub(text, "\n", " ")
local result = vim.split(text, " ")
for _, command_alias in pairs(result) do
if command_alias ~= "" then
if tests_commands[wd] ~= nil then
tests_commands[wd][command_alias] = nil
end
end
end

vim.cmd("bd!")
M.open_tests_list()

gtestler_utils.save_json_to_file(tests_commands)
end

function M.delete_selected_tests()
get_visual_selection()
end

function M.execute_test()
local new_cmd = gtestler_utils.get_command_and_test_name()
M.execute_wrap(new_cmd)
Expand Down

0 comments on commit ac31914

Please sign in to comment.