Skip to content

Commit

Permalink
✨ Support toggle test
Browse files Browse the repository at this point in the history
  • Loading branch information
Nguyen-Hoang-Nam committed Mar 5, 2022
1 parent fc6b276 commit f2a3c9e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ Check [wiki](https://github.com/Nguyen-Hoang-Nam/nvim-dotfiles-kitty/wiki/Test)
| <Leader>q | Turn off search's highlight |
| <Leader>r | Rename variable |
| <Leader>s | Save file |
| <Leader>t | Run test |
| <Leader>t | Toggle test |
| <Leader>u | Toggle debug sidebar |
| <Leader>v | Run Restful API |
| <Leader>w | Delete current buffer |
Expand Down
2 changes: 1 addition & 1 deletion lua/mappings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ map(
end)
)

map('n', '<Leader>t', [[<Cmd>Ultest<CR>]], cmd_options)
map('n', '<Leader>t', [[<Cmd>Ultest<CR>]], cmd_option(utils_core.toggle_test))
map('n', ']t', '<Plug>(ultest-next-fail)', { noremap = false, silent = true })
map('n', '[t', '<Plug>(ultest-prev-fail)', { noremap = false, silent = true })

Expand Down
11 changes: 10 additions & 1 deletion lua/utils/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,16 @@ function M.rename_popup()

-- Normal to insert
api.nvim_feedkeys('A', 'n', true)
-- api.nvim_command('startinsert')
end

function M.toggle_test()
local current_test = api.nvim_eval('ultest#status()')
if current_test['tests'] > 0 then
if current_test['passed'] > 0 or current_test['failed'] > 0 or current_test['running'] > 0 then
vim.api.nvim_command('UltestClear')
else
vim.api.nvim_command('UltestNearest')
end
end
end
return M

0 comments on commit f2a3c9e

Please sign in to comment.