all repos

gopher.nvim @ 149e89eab4ccd8f47ebe518b3ebf4d54f15566e0

Minimalistic plugin for Go development
5 files changed, 100 insertions(+), 0 deletions(-)
test: add for struct_tags
Author: Smirnov Olexander ss2316544@gmail.com
Committed at: 2022-06-11 17:16:41 +0300
Parent: 04e1af2
A spec/fixtures/tags/add_input.go

@@ -0,0 +1,11 @@

+package main + +type Test struct { + ID int + Name string + Num int64 + Another struct { + First int + Second string + } +}
A spec/fixtures/tags/add_output.go

@@ -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"` +}
A spec/fixtures/tags/remove_input.go

@@ -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"` +}
A spec/fixtures/tags/remove_output.go

@@ -0,0 +1,11 @@

+package main + +type Test struct { + ID int + Name string + Num int64 + Another struct { + First int + Second string + } +}
A spec/gopher_struct_tags_spec.lua

@@ -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)