go.nvim/lua/tests/go_fixplurals_spec.lua

42 lines
1.4 KiB
Lua
Raw Normal View History

2022-08-23 09:31:13 +00:00
local _ = require('plenary/busted')
print('aaa')
2022-05-22 10:11:14 +00:00
local eq = assert.are.same
2022-08-23 09:31:13 +00:00
local cur_dir = vim.fn.expand('%:p:h')
2022-05-22 10:11:14 +00:00
-- local status = require("plenary.reload").reload_module("go.nvim")
-- status = require("plenary.reload").reload_module("nvim-treesitter")
-- local ulog = require('go.utils').log
2022-08-23 09:31:13 +00:00
describe('should run fixplurals', function()
2022-05-22 10:11:14 +00:00
-- vim.fn.readfile('minimal.vim')
-- vim.fn.writefile(vim.fn.readfile('fixtures/fmt/hello.go'), name)
-- status = require("plenary.reload").reload_module("go.nvim")
2022-08-23 09:31:13 +00:00
it('should run fixplurals', function()
2022-05-22 10:11:14 +00:00
--
2022-08-23 09:31:13 +00:00
local name = vim.fn.tempname() .. '.go'
local path = cur_dir .. '/lua/tests/fixtures/fixplurals/fixp_input.go' -- %:p:h ? %:p
2022-05-22 10:11:14 +00:00
local lines = vim.fn.readfile(path)
vim.fn.writefile(lines, name)
2022-08-23 09:31:13 +00:00
local expected = vim.fn.join(vim.fn.readfile(cur_dir .. '/lua/tests/fixtures/fixplurals/fixp_golden.go'), '\n')
2022-05-22 10:11:14 +00:00
local cmd = " silent exe 'e " .. name .. "'"
vim.cmd(cmd)
2022-08-23 09:31:13 +00:00
local bufn = vim.fn.bufnr('')
2022-05-22 10:11:14 +00:00
2022-08-23 09:31:13 +00:00
vim.fn.setpos('.', { bufn, 2, 11, 0 })
2022-05-22 10:11:14 +00:00
-- local l = vim.api.nvim_buf_get_lines(0, 0, -1, true)
2022-08-23 09:31:13 +00:00
vim.bo.filetype = 'go'
2022-05-22 10:11:14 +00:00
2022-08-23 09:31:13 +00:00
local gofixp = require('go.fixplurals')
2022-05-22 10:11:14 +00:00
gofixp.fixplurals()
vim.wait(100, function()
2022-08-23 09:31:13 +00:00
vim.cmd('w')
2022-05-22 10:11:14 +00:00
end)
2022-08-23 09:31:13 +00:00
local fmt = vim.fn.join(vim.fn.readfile(name), '\n')
2022-05-22 10:11:14 +00:00
vim.fn.assert_equal(fmt, expected)
eq(expected, fmt)
2022-08-23 09:31:13 +00:00
cmd = 'bd! ' .. name
2022-05-22 10:11:14 +00:00
vim.cmd(cmd)
end)
end)