test(iferr): add integration
This commit is contained in:
parent
713e5290e0
commit
4ff84c5031
3 changed files with 43 additions and 0 deletions
7
spec/fixtures/iferr/input.go
vendored
Normal file
7
spec/fixtures/iferr/input.go
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "net"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
_, err := net.Listen("tcp", ":8080")
|
||||||
|
}
|
||||||
10
spec/fixtures/iferr/output.go
vendored
Normal file
10
spec/fixtures/iferr/output.go
vendored
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "net"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
_, err := net.Listen("tcp", ":8080")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
26
spec/integration/iferr_spec.lua
Normal file
26
spec/integration/iferr_spec.lua
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
local cur_dir = vim.fn.expand "%:p:h"
|
||||||
|
|
||||||
|
describe("gopher.iferr", function()
|
||||||
|
it("can be required", function()
|
||||||
|
require "gopher.iferr"
|
||||||
|
end)
|
||||||
|
|
||||||
|
it("should be able to add iferr", function()
|
||||||
|
local temp_file = vim.fn.tempname() .. ".go"
|
||||||
|
local input_file = vim.fn.readfile(cur_dir .. "/spec/fixtures/iferr/input.go")
|
||||||
|
local output_file = vim.fn.join(vim.fn.readfile(cur_dir .. "/spec/fixtures/iferr/output.go"), "\n")
|
||||||
|
|
||||||
|
vim.fn.writefile(input_file, temp_file)
|
||||||
|
vim.bo.filetype = "go"
|
||||||
|
vim.cmd("silent exe 'e " .. temp_file .. "'")
|
||||||
|
|
||||||
|
local bufn = vim.fn.bufnr(0)
|
||||||
|
vim.fn.setpos(".", { bufn, 6, 4, 0 })
|
||||||
|
require "gopher.iferr"()
|
||||||
|
vim.cmd "w"
|
||||||
|
|
||||||
|
vim.wait(100)
|
||||||
|
assert.are.same(output_file, vim.fn.join(vim.fn.readfile(temp_file), "\n"))
|
||||||
|
vim.cmd("bd! " .. temp_file)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue