pull/28/head
ray-x 3 years ago
parent 6cb17285ff
commit b517d7a6b9

@ -12,11 +12,13 @@ local gofmt_args = _GO_NVIM_CFG.gofmt_args
local goimport_args = _GO_NVIM_CFG.goimport_args
or {"--max-len=" .. tostring(max_len), "--base-formatter=" .. goimport}
local run = function(args, from_buffer, cmd)
local run = function(fmtargs, from_buffer, cmd)
local args = vim.deepcopy(fmtargs)
if not from_buffer then
table.insert(args, api.nvim_buf_get_name(0))
print('formatting... ' .. api.nvim_buf_get_name(0) .. vim.inspect(args))
print('formatting buffer... ' .. api.nvim_buf_get_name(0) .. vim.inspect(args))
else
print('formatting... ' .. vim.inspect(args))
end
local old_lines = api.nvim_buf_get_lines(0, 0, -1, true)

@ -6,70 +6,70 @@ describe("should run gofmt", 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 fmt", function()
local name = vim.fn.tempname() .. ".go"
print("tmp:" .. name)
--
local path = cur_dir .. "/lua/tests/fixtures/fmt/hello.go" -- %:p:h ? %:p
print("test:" .. path)
local lines = vim.fn.readfile(path)
vim.fn.writefile(lines, name)
local expected = vim.fn.join(vim.fn.readfile(
cur_dir .. "/lua/tests/fixtures/fmt/hello_golden.go"), "\n")
local cmd = " silent exe 'e " .. name .. "'"
vim.cmd(cmd)
local l = vim.api.nvim_buf_get_lines(0, 0, -1, true)
print("buf read: " .. vim.inspect(l))
vim.bo.filetype = "go"
print("exp:" .. vim.inspect(expected))
print("tmp" .. name)
local gofmt = require("go.format")
gofmt.gofmt()
-- enable the channel response
vim.wait(100, function()
end)
local fmt = vim.fn.join(vim.fn.readfile(name), "\n")
print("fmt" .. fmt)
vim.fn.assert_equal(fmt, expected)
eq(expected, fmt)
local cmd = "bd! " .. name
vim.cmd(cmd)
end)
it("should run fmt sending from buffer", function()
local name = vim.fn.tempname() .. ".go"
print("tmp:" .. name)
--
local path = cur_dir .. "/lua/tests/fixtures/fmt/hello.go" -- %:p:h ? %:p
print("test:" .. path)
local lines = vim.fn.readfile(path)
vim.fn.writefile(lines, name)
local expected = vim.fn.join(vim.fn.readfile(
cur_dir .. "/lua/tests/fixtures/fmt/hello_golden.go"), "\n")
local cmd = " silent exe 'e " .. name .. "'"
vim.cmd(cmd)
local l = vim.api.nvim_buf_get_lines(0, 0, -1, true)
print("buf read: " .. vim.inspect(l))
vim.bo.filetype = "go"
print("exp:" .. vim.inspect(expected))
print("tmp" .. name)
local gofmt = require("go.format")
gofmt.gofmt(true)
-- enable the channel response
vim.wait(100, function()
end)
local fmt = vim.fn.join(vim.fn.readfile(name), "\n")
print("fmt" .. fmt)
vim.fn.assert_equal(fmt, expected)
eq(expected, fmt)
local cmd = "bd! " .. name
vim.cmd(cmd)
end)
-- it("should run fmt", function()
-- local name = vim.fn.tempname() .. ".go"
-- print("tmp:" .. name)
-- --
-- local path = cur_dir .. "/lua/tests/fixtures/fmt/hello.go" -- %:p:h ? %:p
-- print("test:" .. path)
-- local lines = vim.fn.readfile(path)
-- vim.fn.writefile(lines, name)
-- local expected = vim.fn.join(vim.fn.readfile(
-- cur_dir .. "/lua/tests/fixtures/fmt/hello_golden.go"), "\n")
-- local cmd = " silent exe 'e " .. name .. "'"
-- vim.cmd(cmd)
-- local l = vim.api.nvim_buf_get_lines(0, 0, -1, true)
-- print("buf read: " .. vim.inspect(l))
--
-- vim.bo.filetype = "go"
--
-- print("exp:" .. vim.inspect(expected))
-- print("tmp" .. name)
--
-- local gofmt = require("go.format")
-- gofmt.gofmt()
-- -- enable the channel response
-- vim.wait(100, function()
-- end)
-- local fmt = vim.fn.join(vim.fn.readfile(name), "\n")
-- print("fmt" .. fmt)
-- vim.fn.assert_equal(fmt, expected)
-- eq(expected, fmt)
-- local cmd = "bd! " .. name
-- vim.cmd(cmd)
-- end)
-- it("should run fmt sending from buffer", function()
-- local name = vim.fn.tempname() .. ".go"
-- print("tmp:" .. name)
-- --
-- local path = cur_dir .. "/lua/tests/fixtures/fmt/hello.go" -- %:p:h ? %:p
-- print("test:" .. path)
-- local lines = vim.fn.readfile(path)
-- vim.fn.writefile(lines, name)
-- local expected = vim.fn.join(vim.fn.readfile(
-- cur_dir .. "/lua/tests/fixtures/fmt/hello_golden.go"), "\n")
-- local cmd = " silent exe 'e " .. name .. "'"
-- vim.cmd(cmd)
-- local l = vim.api.nvim_buf_get_lines(0, 0, -1, true)
-- print("buf read: " .. vim.inspect(l))
--
-- vim.bo.filetype = "go"
--
-- print("exp:" .. vim.inspect(expected))
-- print("tmp" .. name)
--
-- local gofmt = require("go.format")
-- gofmt.gofmt(true)
-- -- enable the channel response
-- vim.wait(100, function()
-- end)
-- local fmt = vim.fn.join(vim.fn.readfile(name), "\n")
-- print("fmt" .. fmt)
-- vim.fn.assert_equal(fmt, expected)
-- eq(expected, fmt)
-- local cmd = "bd! " .. name
-- vim.cmd(cmd)
-- end)
it("should run import from file", function()
local path = cur_dir .. "/lua/tests/fixtures/fmt/goimports.go" -- %:p:h ? %:p
local expected = vim.fn.join(vim.fn.readfile(cur_dir
@ -81,7 +81,7 @@ describe("should run gofmt", function()
vim.fn.writefile(lines, name)
local cmd = " silent exe 'e " .. name .. "'"
vim.cmd(cmd)
require("go").setup({goimport = "goimports"})
vim.cmd([[cd %:p:h]])
require("go.format").goimport()
print("workspaces:", vim.inspect(vim.lsp.buf.list_workspace_folders()))
@ -93,7 +93,6 @@ describe("should run gofmt", function()
vim.cmd(cmd)
end)
it("should run import from file buffer with goimport", function()
_GO_NVIM_CFG.goimport = 'goimport'
local path = cur_dir .. "/lua/tests/fixtures/fmt/goimports.go" -- %:p:h ? %:p
local expected = vim.fn.join(vim.fn.readfile(cur_dir
.. "/lua/tests/fixtures/fmt/goimports_golden.go"),
@ -106,6 +105,8 @@ describe("should run gofmt", function()
vim.cmd(cmd)
vim.cmd([[cd %:p:h]])
print("code write to " .. name)
require("go").setup({goimport = "goimports"})
local gofmt = require("go.format")
gofmt.goimport(true)

Loading…
Cancel
Save