test: add for struct_tags
This commit is contained in:
parent
04e1af228b
commit
149e89eab4
5 changed files with 100 additions and 0 deletions
11
spec/fixtures/tags/add_input.go
vendored
Normal file
11
spec/fixtures/tags/add_input.go
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package main
|
||||
|
||||
type Test struct {
|
||||
ID int
|
||||
Name string
|
||||
Num int64
|
||||
Another struct {
|
||||
First int
|
||||
Second string
|
||||
}
|
||||
}
|
||||
11
spec/fixtures/tags/add_output.go
vendored
Normal file
11
spec/fixtures/tags/add_output.go
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package main
|
||||
|
||||
type Test struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Num int64 `json:"num"`
|
||||
Another struct {
|
||||
First int `json:"first"`
|
||||
Second string `json:"second"`
|
||||
} `json:"another"`
|
||||
}
|
||||
11
spec/fixtures/tags/remove_input.go
vendored
Normal file
11
spec/fixtures/tags/remove_input.go
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package main
|
||||
|
||||
type Test struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Num int64 `json:"num"`
|
||||
Another struct {
|
||||
First int `json:"first"`
|
||||
Second string `json:"second"`
|
||||
} `json:"another"`
|
||||
}
|
||||
11
spec/fixtures/tags/remove_output.go
vendored
Normal file
11
spec/fixtures/tags/remove_output.go
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package main
|
||||
|
||||
type Test struct {
|
||||
ID int
|
||||
Name string
|
||||
Num int64
|
||||
Another struct {
|
||||
First int
|
||||
Second string
|
||||
}
|
||||
}
|
||||
56
spec/gopher_struct_tags_spec.lua
Normal file
56
spec/gopher_struct_tags_spec.lua
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
local cur_dir = vim.fn.expand "%:p:h"
|
||||
|
||||
describe("gopher.struct_tags", function()
|
||||
it("can be required", function()
|
||||
require "gopher.struct_tags"
|
||||
end)
|
||||
|
||||
it("can add json tag to struct", function()
|
||||
local add = require("gopher.struct_tags").add
|
||||
local name = vim.fn.tempname() .. ".go"
|
||||
local input_file = vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/add_input.go")
|
||||
local output_file = vim.fn.join(
|
||||
vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/add_output.go"),
|
||||
"\n"
|
||||
)
|
||||
|
||||
vim.fn.writefile(input_file, name)
|
||||
vim.cmd("silent exe 'e " .. name .. "'")
|
||||
|
||||
local bufn = vim.fn.bufnr ""
|
||||
vim.bo.filetype = "go"
|
||||
vim.fn.setpos(".", { bufn, 3, 6, 0 })
|
||||
add()
|
||||
|
||||
vim.wait(100, function() end)
|
||||
local fmt = vim.fn.join(vim.fn.readfile(name), "\n")
|
||||
assert.are.same(output_file, fmt)
|
||||
|
||||
vim.cmd("bd! " .. name)
|
||||
end)
|
||||
|
||||
it("can remove json tag from struct", function()
|
||||
local remove = require("gopher.struct_tags").remove
|
||||
local name = vim.fn.tempname() .. ".go"
|
||||
local input_file = vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/remove_input.go")
|
||||
local output_file = vim.fn.join(
|
||||
vim.fn.readfile(cur_dir .. "/spec/fixtures/tags/remove_output.go"),
|
||||
"\n"
|
||||
)
|
||||
|
||||
vim.fn.writefile(input_file, name)
|
||||
vim.cmd("silent exe 'e " .. name .. "'")
|
||||
|
||||
local bufn = vim.fn.bufnr ""
|
||||
vim.bo.filetype = "go"
|
||||
vim.fn.setpos(".", { bufn, 3, 6, 0 })
|
||||
remove()
|
||||
|
||||
vim.wait(100, function() end)
|
||||
|
||||
local fmt = vim.fn.join(vim.fn.readfile(name), "\n")
|
||||
assert.are.same(output_file, fmt)
|
||||
|
||||
vim.cmd("bd! " .. name)
|
||||
end)
|
||||
end)
|
||||
Loading…
Add table
Add a link
Reference in a new issue