From 0b62f3b419f807a52a2ec80c68eac25c5fac5500 Mon Sep 17 00:00:00 2001 From: Oleksandr Smirnov Date: Wed, 19 Mar 2025 17:59:14 +0200 Subject: [PATCH] test(struct_tags): test both possible inputs --- spec/fixtures/tags/add_many_input.go | 11 +++++++++ spec/fixtures/tags/add_many_output.go | 11 +++++++++ spec/integration/struct_tags_test.lua | 32 +++++++++++++++++++++++---- 3 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 spec/fixtures/tags/add_many_input.go create mode 100644 spec/fixtures/tags/add_many_output.go diff --git a/spec/fixtures/tags/add_many_input.go b/spec/fixtures/tags/add_many_input.go new file mode 100644 index 0000000..7e27a27 --- /dev/null +++ b/spec/fixtures/tags/add_many_input.go @@ -0,0 +1,11 @@ +package main + +type Test struct { + ID int + Name string + Num int64 + Another struct { + First int + Second string + } +} diff --git a/spec/fixtures/tags/add_many_output.go b/spec/fixtures/tags/add_many_output.go new file mode 100644 index 0000000..9a43e62 --- /dev/null +++ b/spec/fixtures/tags/add_many_output.go @@ -0,0 +1,11 @@ +package main + +type Test struct { + ID int `test4:"id" test5:"id" test1:"id" test2:"id"` + Name string `test4:"name" test5:"name" test1:"name" test2:"name"` + Num int64 `test4:"num" test5:"num" test1:"num" test2:"num"` + Another struct { + First int `test4:"first" test5:"first" test1:"first" test2:"first"` + Second string `test4:"second" test5:"second" test1:"second" test2:"second"` + } `test4:"another" test5:"another" test1:"another" test2:"another"` +} diff --git a/spec/integration/struct_tags_test.lua b/spec/integration/struct_tags_test.lua index e821192..4ac245b 100644 --- a/spec/integration/struct_tags_test.lua +++ b/spec/integration/struct_tags_test.lua @@ -16,8 +16,9 @@ T["struct_tags"]["should add tag"] = function() t.writefile(tmp, fixtures.input) child.cmd("silent edit " .. tmp) - child.fn.setpos(".", { child.fn.bufnr "%", 3, 6, 0 }) + child.fn.setpos(".", { child.fn.bufnr(tmp), 3, 6, 0 }) child.cmd "GoTagAdd json" + child.cmd "write" t.eq(t.readfile(tmp), fixtures.output) end @@ -28,8 +29,9 @@ T["struct_tags"]["should remove tag"] = function() t.writefile(tmp, fixtures.input) child.cmd("silent edit " .. tmp) - child.fn.setpos(".", { child.fn.bufnr "%", 4, 6, 0 }) + child.fn.setpos(".", { child.fn.bufnr(tmp), 4, 6, 0 }) child.cmd "GoTagRm json" + child.cmd "write" t.eq(t.readfile(tmp), fixtures.output) end @@ -40,8 +42,9 @@ T["struct_tags"]["should be able to handle many structs"] = function() t.writefile(tmp, fixtures.input) child.cmd("silent edit " .. tmp) - child.fn.setpos(".", { child.fn.bufnr "%", 10, 3, 0 }) + child.fn.setpos(".", { child.fn.bufnr(tmp), 10, 3, 0 }) child.cmd "GoTagAdd testing" + child.cmd "write" t.eq(t.readfile(tmp), fixtures.output) end @@ -52,8 +55,29 @@ T["struct_tags"]["should clear struct"] = function() t.writefile(tmp, fixtures.input) child.cmd("silent edit " .. tmp) - child.fn.setpos(".", { child.fn.bufnr "%", 3, 1, 0 }) + child.fn.setpos(".", { child.fn.bufnr(tmp), 3, 1, 0 }) child.cmd "GoTagClear" + child.cmd "write" + + t.eq(t.readfile(tmp), fixtures.output) +end + +T["struct_tags"]["should add more than one tag"] = function() + local tmp = t.tmpfile() + local fixtures = t.get_fixtures "tags/add_many" + t.writefile(tmp, fixtures.input) + + --- with comma, like gomodifytags + child.cmd("silent edit " .. tmp) + child.fn.setpos(".", { child.fn.bufnr(tmp), 3, 1 }) + child.cmd "GoTagAdd test4,test5" + child.cmd "write" + + -- without comma + child.cmd("silent edit " .. tmp) + child.fn.setpos(".", { child.fn.bufnr(tmp), 3, 1 }) + child.cmd "GoTagAdd test1 test2" + child.cmd "write" t.eq(t.readfile(tmp), fixtures.output) end