mirror of https://github.com/ray-x/go.nvim
quick gen return #170
parent
4f01936c00
commit
28bcaa1f44
@ -1,43 +1,41 @@
|
||||
local _ = require("plenary/busted")
|
||||
|
||||
local _ = require('plenary/busted')
|
||||
print('aaa')
|
||||
local eq = assert.are.same
|
||||
local cur_dir = vim.fn.expand("%:p:h")
|
||||
local cur_dir = vim.fn.expand('%:p:h')
|
||||
-- local status = require("plenary.reload").reload_module("go.nvim")
|
||||
-- status = require("plenary.reload").reload_module("nvim-treesitter")
|
||||
|
||||
-- local ulog = require('go.utils').log
|
||||
describe("should run fixplurals", function()
|
||||
describe('should run fixplurals', function()
|
||||
-- vim.fn.readfile('minimal.vim')
|
||||
-- vim.fn.writefile(vim.fn.readfile('fixtures/fmt/hello.go'), name)
|
||||
-- status = require("plenary.reload").reload_module("go.nvim")
|
||||
it("should run fixplurals", function()
|
||||
it('should run fixplurals', function()
|
||||
--
|
||||
local name = vim.fn.tempname() .. ".go"
|
||||
local path = cur_dir .. "/lua/tests/fixtures/fixplurals/fixp_input.go" -- %:p:h ? %:p
|
||||
local name = vim.fn.tempname() .. '.go'
|
||||
local path = cur_dir .. '/lua/tests/fixtures/fixplurals/fixp_input.go' -- %:p:h ? %:p
|
||||
local lines = vim.fn.readfile(path)
|
||||
vim.fn.writefile(lines, name)
|
||||
local expected = vim.fn.join(vim.fn.readfile(cur_dir
|
||||
.. "/lua/tests/fixtures/fixplurals/fixp_golden.go"),
|
||||
"\n")
|
||||
local expected = vim.fn.join(vim.fn.readfile(cur_dir .. '/lua/tests/fixtures/fixplurals/fixp_golden.go'), '\n')
|
||||
local cmd = " silent exe 'e " .. name .. "'"
|
||||
vim.cmd(cmd)
|
||||
local bufn = vim.fn.bufnr("")
|
||||
local bufn = vim.fn.bufnr('')
|
||||
|
||||
vim.fn.setpos(".", {bufn, 2, 11, 0})
|
||||
vim.fn.setpos('.', { bufn, 2, 11, 0 })
|
||||
|
||||
-- local l = vim.api.nvim_buf_get_lines(0, 0, -1, true)
|
||||
|
||||
vim.bo.filetype = "go"
|
||||
vim.bo.filetype = 'go'
|
||||
|
||||
local gofixp = require("go.fixplurals")
|
||||
local gofixp = require('go.fixplurals')
|
||||
gofixp.fixplurals()
|
||||
vim.wait(100, function()
|
||||
vim.cmd('w')
|
||||
vim.cmd('w')
|
||||
end)
|
||||
local fmt = vim.fn.join(vim.fn.readfile(name), "\n")
|
||||
local fmt = vim.fn.join(vim.fn.readfile(name), '\n')
|
||||
vim.fn.assert_equal(fmt, expected)
|
||||
eq(expected, fmt)
|
||||
cmd = "bd! " .. name
|
||||
cmd = 'bd! ' .. name
|
||||
vim.cmd(cmd)
|
||||
end)
|
||||
end)
|
||||
|
@ -0,0 +1,91 @@
|
||||
local eq = assert.are.same
|
||||
local cur_dir = vim.fn.expand('%:p:h')
|
||||
-- func Println(a ...any) (n int, err error)
|
||||
-- func fmt.Println(a ...any) (n int, err error)
|
||||
-- func fmt.inner.Println(a ...any) (n int, err error)
|
||||
-- func fmt.inner2.Println3(a ...any) (n int, err error)
|
||||
-- func fmt.inner2.Println3(a any, par int) (n int, err error)
|
||||
-- func fmt.inner2.Println3(a any, par int) int
|
||||
-- func fmt.inner2.Println3(par int) int
|
||||
-- func fmt.inner2.Println3(par int)
|
||||
-- func fmt.inner2.Println3(par *[]int)
|
||||
-- func fmt.inner2.Println3(par struct mnt{})
|
||||
-- /(\%(\w\|\_s\|[*\.\[\],\{\}<>-]\)*)/
|
||||
-- /\v\((\w|\_s|[*\.\[\],{}<>-])*\)
|
||||
local busted = require('plenary/busted')
|
||||
|
||||
describe('regex should work', function()
|
||||
-- vim.fn.readfile('minimal.vim')
|
||||
-- vim.fn.writefile(vim.fn.readfile('fixtures/fmt/hello.go'), name)
|
||||
require('plenary.reload').reload_module('go.nvim')
|
||||
|
||||
require('go').setup({
|
||||
trace = true,
|
||||
log_path = vim.fn.expand('$HOME') .. '/tmp/gonvim.log',
|
||||
})
|
||||
|
||||
print(vim.fn.expand('$HOME') .. '/tmp/gonvim.log')
|
||||
it('should find return', function()
|
||||
local str = [[func Println(a ...any) (n int, err error)]]
|
||||
local ret = require('go.lsp').find_ret(str)
|
||||
print(vim.inspect(ret))
|
||||
eq({'n', 'err'}, ret)
|
||||
end)
|
||||
|
||||
it('should find return', function()
|
||||
local str = [[func fmt.Println(a ...any) (int, error)]]
|
||||
local ret, e = require('go.lsp').find_ret(str)
|
||||
print(vim.inspect(ret))
|
||||
eq({'i', 'err'}, ret)
|
||||
eq(true, e)
|
||||
end)
|
||||
it('should find return', function()
|
||||
local str = [[func fmt.Println(a, b int) (int, error)]]
|
||||
local ret, e = require('go.lsp').find_ret(str)
|
||||
print(vim.inspect(ret))
|
||||
eq({'i', 'err'}, ret)
|
||||
eq(true, e)
|
||||
end)
|
||||
|
||||
it('should find return', function()
|
||||
local str = [[func fmt.Println(a, b int) int]]
|
||||
local ret, e = require('go.lsp').find_ret(str)
|
||||
print(vim.inspect(ret))
|
||||
eq({'i'}, ret)
|
||||
eq(false, e)
|
||||
end)
|
||||
|
||||
it('should find return', function()
|
||||
local str = [[func fmt.Println(a, b int) MyType]]
|
||||
local ret, e = require('go.lsp').find_ret(str)
|
||||
print(vim.inspect(ret))
|
||||
eq({'myType'}, ret)
|
||||
eq(false, e)
|
||||
end)
|
||||
|
||||
it('should find return', function()
|
||||
local str = [[func fmt.Println(a, b int) (MyType, error)]]
|
||||
local ret, e = require('go.lsp').find_ret(str)
|
||||
print(vim.inspect(ret))
|
||||
eq({'myType', 'err'}, ret)
|
||||
eq(true, e)
|
||||
end)
|
||||
end)
|
||||
describe('should run hover', function()
|
||||
-- vim.fn.readfile('minimal.vim')
|
||||
-- vim.fn.writefile(vim.fn.readfile('fixtures/fmt/hello.go'), name)
|
||||
require('plenary.reload').reload_module('go.nvim')
|
||||
it('should run hover', function()
|
||||
local result = {
|
||||
contents = {
|
||||
kind = 'markdown',
|
||||
value = [[```go\nfunc fmt.Println(a ...any) (n int, err error)(\%(\w\|\_s\|[*\.\[\],\{\}<>-]\)*)\n```\n\nPrintln formats using the default formats for its operands and writes to standard output\\.\nSpaces are always added between operands and a newline is appended\\.\nIt returns the number of bytes written and any write error encountered\\.\n\n\n[`fmt.Println` on pkg.go.dev](https://pkg.go.dev/fmt?utm_source=gopls#Println)]],
|
||||
},
|
||||
range = {},
|
||||
}
|
||||
|
||||
local ret = require('go.lsp').gen_return(result)
|
||||
print(vim.inspect(ret))
|
||||
|
||||
end)
|
||||
end)
|
@ -1,4 +0,0 @@
|
||||
[
|
||||
(composite_literal)
|
||||
(literal_element)
|
||||
] @fold
|
Loading…
Reference in New Issue