test(struct_tags): add support for multiple structs

This commit is contained in:
Oleksandr Smirnov 2025-03-18 21:21:14 +02:00
parent 59169df030
commit 59a0e961c4
No known key found for this signature in database
4 changed files with 49 additions and 1 deletions

View file

@ -45,7 +45,7 @@ function ts.get_struct_node_at_pos(bufnr)
end end
local res = {} local res = {}
local r = get_parrent_node("type_declaration", node) local r = get_parrent_node("type_spec", node)
if not r then if not r then
error "No struct found under cursor" error "No struct found under cursor"
end end

18
spec/fixtures/tags/many_input.go vendored Normal file
View file

@ -0,0 +1,18 @@
package main
type (
TestOne struct {
Asdf string
ID int
}
TestTwo struct {
Fesa int
A bool
}
TestThree struct {
Asufj int
Fs string
}
)

18
spec/fixtures/tags/many_output.go vendored Normal file
View file

@ -0,0 +1,18 @@
package main
type (
TestOne struct {
Asdf string
ID int
}
TestTwo struct {
Fesa int `testing:"fesa"`
A bool `testing:"a"`
}
TestThree struct {
Asufj int
Fs string
}
)

View file

@ -34,4 +34,16 @@ T["struct_tags"]["works remove"] = function()
t.eq(t.readfile(tmp), fixtures.output) t.eq(t.readfile(tmp), fixtures.output)
end end
T["struct_tags"]["works many structs"] = function()
local tmp = t.tmpfile()
local fixtures = t.get_fixtures "tags/many"
t.writefile(tmp, fixtures.input)
child.cmd("silent edit " .. tmp)
child.fn.setpos(".", { child.fn.bufnr "%", 10, 3, 0 })
child.cmd "GoTagAdd testing"
t.eq(t.readfile(tmp), fixtures.output)
end
return T return T