some tests refactoring and sep by type
This commit is contained in:
parent
de37564c79
commit
ab874c6c4f
8 changed files with 46 additions and 87 deletions
|
|
@ -47,10 +47,7 @@ local function modify(...)
|
||||||
args = cmd_args,
|
args = cmd_args,
|
||||||
on_exit = function(data, retval)
|
on_exit = function(data, retval)
|
||||||
if retval ~= 0 then
|
if retval ~= 0 then
|
||||||
u.notify(
|
u.notify("command 'gomodifytags " .. unpack(cmd_args) .. "' exited with code " .. retval, "error")
|
||||||
"command 'gomodifytags " .. unpack(cmd_args) .. "' exited with code " .. retval,
|
|
||||||
"error"
|
|
||||||
)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -60,12 +57,7 @@ local function modify(...)
|
||||||
|
|
||||||
-- decode goted value
|
-- decode goted value
|
||||||
local tagged = vim.json.decode(table.concat(res_data))
|
local tagged = vim.json.decode(table.concat(res_data))
|
||||||
if
|
if tagged.errors ~= nil or tagged.lines == nil or tagged["start"] == nil or tagged["start"] == 0 then
|
||||||
tagged.errors ~= nil
|
|
||||||
or tagged.lines == nil
|
|
||||||
or tagged["start"] == nil
|
|
||||||
or tagged["start"] == 0
|
|
||||||
then
|
|
||||||
u.notify("failed to set tags " .. vim.inspect(tagged), "error")
|
u.notify("failed to set tags " .. vim.inspect(tagged), "error")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -74,13 +66,7 @@ local function modify(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- write goted tags
|
-- write goted tags
|
||||||
vim.api.nvim_buf_set_lines(
|
vim.api.nvim_buf_set_lines(0, tagged.start - 1, tagged.start - 1 + #tagged.lines, false, tagged.lines)
|
||||||
0,
|
|
||||||
tagged.start - 1,
|
|
||||||
tagged.start - 1 + #tagged.lines,
|
|
||||||
false,
|
|
||||||
tagged.lines
|
|
||||||
)
|
|
||||||
vim.cmd "write"
|
vim.cmd "write"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
describe("gopher.config", function()
|
|
||||||
it("can be required", function()
|
|
||||||
require "gopher.config"
|
|
||||||
end)
|
|
||||||
|
|
||||||
it(".setup() when gets empty table not edit config", function()
|
|
||||||
local c = require "gopher.config"
|
|
||||||
c.setup {}
|
|
||||||
|
|
||||||
assert.are.same(c.config.commands.go, "go")
|
|
||||||
assert.are.same(c.config.commands.gomodifytags, "gomodifytags")
|
|
||||||
assert.are.same(c.config.commands.gotests, "gotests")
|
|
||||||
assert.are.same(c.config.commands.impl, "impl")
|
|
||||||
end)
|
|
||||||
|
|
||||||
it(".setup() when get one custom value sets that", function()
|
|
||||||
local c = require "gopher.config"
|
|
||||||
c.setup { commands = {
|
|
||||||
go = "custom_go",
|
|
||||||
} }
|
|
||||||
|
|
||||||
assert.are.same(c.config.commands.go, "custom_go")
|
|
||||||
end)
|
|
||||||
|
|
||||||
it(".setup() when get all custom values sets it", function()
|
|
||||||
local c = require "gopher.config"
|
|
||||||
c.setup {
|
|
||||||
commands = {
|
|
||||||
go = "go1.18",
|
|
||||||
gomodifytags = "user-gomodifytags",
|
|
||||||
gotests = "gotests",
|
|
||||||
impl = "goimpl",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.are.same(c.config.commands.go, "go1.18")
|
|
||||||
assert.are.same(c.config.commands.gomodifytags, "user-gomodifytags")
|
|
||||||
assert.are.same(c.config.commands.gotests, "gotests")
|
|
||||||
assert.are.same(c.config.commands.impl, "goimpl")
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
describe("gopher", function()
|
|
||||||
it("can be required", function()
|
|
||||||
require "gopher"
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
describe("gopher._utils", function()
|
|
||||||
it("can be requried", function()
|
|
||||||
require "gopher._utils"
|
|
||||||
end)
|
|
||||||
|
|
||||||
it(".empty() with non-empty talbe", function()
|
|
||||||
local empty = require("gopher._utils").empty
|
|
||||||
local res = empty { first = "1", second = 2 }
|
|
||||||
|
|
||||||
assert.are.same(res, false)
|
|
||||||
end)
|
|
||||||
|
|
||||||
it(".empty() with empty talbe", function()
|
|
||||||
local empty = require("gopher._utils").empty
|
|
||||||
local res = empty {}
|
|
||||||
|
|
||||||
assert.are.same(res, true)
|
|
||||||
end)
|
|
||||||
end)
|
|
||||||
|
|
@ -9,8 +9,7 @@ describe("gopher.struct_tags", function()
|
||||||
local tag = require "gopher.struct_tags"
|
local tag = require "gopher.struct_tags"
|
||||||
local temp_file = vim.fn.tempname() .. ".go"
|
local temp_file = vim.fn.tempname() .. ".go"
|
||||||
local input_file = vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/add_input.go")
|
local input_file = vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/add_input.go")
|
||||||
local output_file =
|
local output_file = vim.fn.join(vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/add_output.go"), "\n")
|
||||||
vim.fn.join(vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/add_output.go"), "\n")
|
|
||||||
|
|
||||||
vim.fn.writefile(input_file, temp_file)
|
vim.fn.writefile(input_file, temp_file)
|
||||||
vim.cmd("silent exe 'e " .. temp_file .. "'")
|
vim.cmd("silent exe 'e " .. temp_file .. "'")
|
||||||
|
|
@ -30,8 +29,7 @@ describe("gopher.struct_tags", function()
|
||||||
local tag = require "gopher.struct_tags"
|
local tag = require "gopher.struct_tags"
|
||||||
local temp_file = vim.fn.tempname() .. ".go"
|
local temp_file = vim.fn.tempname() .. ".go"
|
||||||
local input_file = vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/remove_input.go")
|
local input_file = vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/remove_input.go")
|
||||||
local output_file =
|
local output_file = vim.fn.join(vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/remove_output.go"), "\n")
|
||||||
vim.fn.join(vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/remove_output.go"), "\n")
|
|
||||||
|
|
||||||
vim.fn.writefile(input_file, temp_file)
|
vim.fn.writefile(input_file, temp_file)
|
||||||
vim.cmd("silent exe 'e " .. temp_file .. "'")
|
vim.cmd("silent exe 'e " .. temp_file .. "'")
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
local function root(p)
|
local function root(p)
|
||||||
local f = debug.getinfo(1, "S").source:sub(2)
|
local f = debug.getinfo(1, "S").source:sub(2)
|
||||||
return vim.fn.fnamemodify(f, ":p:h:h") .. "/" .. (p or "")
|
return vim.fn.fnamemodify(f, ":p:h:h") .. "/" .. (p or "")
|
||||||
|
|
|
||||||
22
spec/unit/config_spec.lua
Normal file
22
spec/unit/config_spec.lua
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
describe("unit.gopher.config", function()
|
||||||
|
it("can be required", function()
|
||||||
|
require "gopher.config"
|
||||||
|
end)
|
||||||
|
|
||||||
|
describe(".setup()", function()
|
||||||
|
local c = require "gopher.config"
|
||||||
|
|
||||||
|
it("returns defaults when gets empty table", function()
|
||||||
|
c.setup {}
|
||||||
|
assert.are.same(c.config.commands.go, "go")
|
||||||
|
assert.are.same(c.config.commands.gomodifytags, "gomodifytags")
|
||||||
|
assert.are.same(c.config.commands.gotests, "gotests")
|
||||||
|
assert.are.same(c.config.commands.impl, "impl")
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("can set user opts", function()
|
||||||
|
c.setup { commands = { go = "custom_go" } }
|
||||||
|
assert.are.same(c.config.commands.go, "custom_go")
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
19
spec/unit/utils_spec.lua
Normal file
19
spec/unit/utils_spec.lua
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
describe("gopher._utils", function()
|
||||||
|
it("can be requried", function()
|
||||||
|
require "gopher._utils"
|
||||||
|
end)
|
||||||
|
|
||||||
|
describe(".empty()", function()
|
||||||
|
local empty = require("gopher._utils").empty
|
||||||
|
|
||||||
|
it("with non-empty talbe", function()
|
||||||
|
local res = empty { first = "1", second = 2 }
|
||||||
|
assert.are.same(res, false)
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("with empty talbe", function()
|
||||||
|
local res = empty {}
|
||||||
|
assert.are.same(res, true)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue