docs(gotests): add docs
This commit is contained in:
parent
de17bcac04
commit
3f07f03117
4 changed files with 94 additions and 21 deletions
20
README.md
20
README.md
|
|
@ -64,24 +64,6 @@ require("gopher").setup {
|
|||
}
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>
|
||||
For named tests to work you have to install gotests from develop branch. Next code snippets could be placed into the build step in the Lazy plugin declaration
|
||||
</summary>
|
||||
|
||||
```lua
|
||||
-- using mason-tool-installer
|
||||
require("mason-tool-installer").setup {
|
||||
ensure_installed = {
|
||||
{ "gotests", version = "develop" },
|
||||
}
|
||||
}
|
||||
|
||||
-- using `vim.fn.jobstart`
|
||||
vim.fn.jobstart("go install github.com/cweill/gotests/...@develop")
|
||||
```
|
||||
</details>
|
||||
|
||||
## Features
|
||||
|
||||
<!-- markdownlint-disable -->
|
||||
|
|
@ -148,6 +130,8 @@ require("gopher").setup {
|
|||
require("gopher").test.exported()
|
||||
require("gopher").test.all()
|
||||
```
|
||||
|
||||
For named tests see `:h gopher.nvim-gotests-named`
|
||||
</details>
|
||||
|
||||
<details>
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ Table of Contents
|
|||
Configuration...........................................|gopher.nvim-config|
|
||||
Modifty struct tags................................|gopher.nvim-struct-tags|
|
||||
Auto implementation of interface methods..................|gopher.nvim-impl|
|
||||
Generating unit tests boilerplate......................|gopher.nvim-gotests|
|
||||
Setup `nvim-dap` for Go......................................|gopher.nvim-dap|
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
|
|
@ -145,6 +146,51 @@ simple example:
|
|||
<
|
||||
|
||||
|
||||
==============================================================================
|
||||
------------------------------------------------------------------------------
|
||||
*gopher.nvim-gotests*
|
||||
gotests is utilizing the `gotests` tool to generate unit tests boilerplate.
|
||||
Usage ~
|
||||
|
||||
- generate unit test for spesisfic function/method
|
||||
- to specift the function/method put your cursor on it
|
||||
- run `:GoTestAdd`
|
||||
|
||||
- generate unit tests for all functions/methods in current file
|
||||
- run `:GoTestsAll`
|
||||
|
||||
- generate unit tests only for exported(public) functions/methods
|
||||
- run `:GoTestsExp`
|
||||
|
||||
you can also specify the template to use for generating the tests. see |gopher.nvim-config|
|
||||
more details about templates can be found at: https://github.com/cweill/gotests
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*gopher.nvim-gotests-named*
|
||||
|
||||
if you prefare using named tests, you can enable it in the config.
|
||||
but you would need to install `gotests@develop` because stable version doesn't support this feature.
|
||||
you can do it with:
|
||||
>lua
|
||||
-- simply run go get in your shell:
|
||||
go install github.com/cweill/gotests/...@develop
|
||||
|
||||
-- if you want to install it within neovim, you can use one of this:
|
||||
|
||||
vim.fn.jobstart("go install github.com/cweill/gotests/...@develop")
|
||||
|
||||
-- or if you want to use mason:
|
||||
require("mason-tool-installer").setup {
|
||||
ensure_installed = {
|
||||
{ "gotests", version = "develop" },
|
||||
}
|
||||
}
|
||||
<
|
||||
|
||||
if you choose to install `gotests` within neovim, i recommend adding it to your `build` section in your |lazy.nvim|
|
||||
|
||||
|
||||
==============================================================================
|
||||
------------------------------------------------------------------------------
|
||||
*gopher.nvim-dap*
|
||||
|
|
|
|||
|
|
@ -1,3 +1,44 @@
|
|||
---@toc_entry Generating unit tests boilerplate
|
||||
---@tag gopher.nvim-gotests
|
||||
---@text gotests is utilizing the `gotests` tool to generate unit tests boilerplate.
|
||||
---@usage
|
||||
--- - generate unit test for spesisfic function/method
|
||||
--- - to specift the function/method put your cursor on it
|
||||
--- - run `:GoTestAdd`
|
||||
---
|
||||
--- - generate unit tests for all functions/methods in current file
|
||||
--- - run `:GoTestsAll`
|
||||
---
|
||||
--- - generate unit tests only for exported(public) functions/methods
|
||||
--- - run `:GoTestsExp`
|
||||
---
|
||||
--- you can also specify the template to use for generating the tests. see |gopher.nvim-config|
|
||||
--- more details about templates can be found at: https://github.com/cweill/gotests
|
||||
---
|
||||
|
||||
---@tag gopher.nvim-gotests-named
|
||||
---@text
|
||||
--- if you prefare using named tests, you can enable it in the config.
|
||||
--- but you would need to install `gotests@develop` because stable version doesn't support this feature.
|
||||
--- you can do it with:
|
||||
--- >lua
|
||||
--- -- simply run go get in your shell:
|
||||
--- go install github.com/cweill/gotests/...@develop
|
||||
---
|
||||
--- -- if you want to install it within neovim, you can use one of this:
|
||||
---
|
||||
--- vim.fn.jobstart("go install github.com/cweill/gotests/...@develop")
|
||||
---
|
||||
--- -- or if you want to use mason:
|
||||
--- require("mason-tool-installer").setup {
|
||||
--- ensure_installed = {
|
||||
--- { "gotests", version = "develop" },
|
||||
--- }
|
||||
--- }
|
||||
--- <
|
||||
---
|
||||
--- if you choose to install `gotests` within neovim, i recommend adding it to your `build` section in your |lazy.nvim|
|
||||
|
||||
local c = require "gopher.config"
|
||||
local ts_utils = require "gopher._utils.ts"
|
||||
local r = require "gopher._utils.runner"
|
||||
|
|
@ -5,6 +46,7 @@ local u = require "gopher._utils"
|
|||
local gotests = {}
|
||||
|
||||
---@param args table
|
||||
---@private
|
||||
local function add_test(args)
|
||||
if c.gotests.named then
|
||||
table.insert(args, "-named")
|
||||
|
|
@ -35,7 +77,7 @@ local function add_test(args)
|
|||
})
|
||||
end
|
||||
|
||||
---generate unit test for one function
|
||||
-- generate unit test for one function
|
||||
function gotests.func_test()
|
||||
local ns = ts_utils.get_func_method_node_at_pos(unpack(vim.api.nvim_win_get_cursor(0)))
|
||||
if ns == nil or ns.name == nil then
|
||||
|
|
@ -46,12 +88,12 @@ function gotests.func_test()
|
|||
add_test { "-only", ns.name }
|
||||
end
|
||||
|
||||
---generate unit tests for all functions in current file
|
||||
-- generate unit tests for all functions in current file
|
||||
function gotests.all_tests()
|
||||
add_test { "-all" }
|
||||
end
|
||||
|
||||
---generate unit tests for all exported functions
|
||||
-- generate unit tests for all exported functions
|
||||
function gotests.all_exported_tests()
|
||||
add_test { "-exported" }
|
||||
end
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ local files = {
|
|||
"lua/gopher/config.lua",
|
||||
"lua/gopher/struct_tags.lua",
|
||||
"lua/gopher/impl.lua",
|
||||
"lua/gopher/gotests.lua",
|
||||
"lua/gopher/dap.lua",
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue