feat(struct-tag): add default option
This commit is contained in:
parent
848a9dbe97
commit
3ad6f73b57
11 changed files with 122 additions and 7 deletions
8
spec/fixtures/tags/overwrite_default_option_input.go
vendored
Normal file
8
spec/fixtures/tags/overwrite_default_option_input.go
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
package main
|
||||
|
||||
type Test struct {
|
||||
ID int
|
||||
Another struct {
|
||||
Second string
|
||||
}
|
||||
}
|
||||
8
spec/fixtures/tags/overwrite_default_option_output.go
vendored
Normal file
8
spec/fixtures/tags/overwrite_default_option_output.go
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
package main
|
||||
|
||||
type Test struct {
|
||||
ID int `xml:"id,otheroption"`
|
||||
Another struct {
|
||||
Second string `xml:"second,otheroption"`
|
||||
} `xml:"another,otheroption"`
|
||||
}
|
||||
11
spec/fixtures/tags/remove_with_option_input.go
vendored
Normal file
11
spec/fixtures/tags/remove_with_option_input.go
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package main
|
||||
|
||||
type Test struct {
|
||||
ID int `json:"id,omitempty" xml:"id,someoption"`
|
||||
Name string `json:"name,omitempty" xml:"name,someoption"`
|
||||
Num int64 `json:"num,omitempty" xml:"num,someoption"`
|
||||
Another struct {
|
||||
First int `json:"first,omitempty" xml:"first,someoption"`
|
||||
Second string `json:"second,omitempty" xml:"second,someoption"`
|
||||
} `json:"another,omitempty" xml:"another,someoption"`
|
||||
}
|
||||
11
spec/fixtures/tags/remove_with_option_output.go
vendored
Normal file
11
spec/fixtures/tags/remove_with_option_output.go
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
package main
|
||||
|
||||
type Test struct {
|
||||
ID int `xml:"id,someoption"`
|
||||
Name string `xml:"name,someoption"`
|
||||
Num int64 `xml:"num,someoption"`
|
||||
Another struct {
|
||||
First int `xml:"first,someoption"`
|
||||
Second string `xml:"second,someoption"`
|
||||
} `xml:"another,someoption"`
|
||||
}
|
||||
8
spec/fixtures/tags/with_default_option_input.go
vendored
Normal file
8
spec/fixtures/tags/with_default_option_input.go
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
package main
|
||||
|
||||
type Test struct {
|
||||
ID int
|
||||
Another struct {
|
||||
Second string
|
||||
}
|
||||
}
|
||||
8
spec/fixtures/tags/with_default_option_output.go
vendored
Normal file
8
spec/fixtures/tags/with_default_option_output.go
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
package main
|
||||
|
||||
type Test struct {
|
||||
ID int `xml:"id,theoption"`
|
||||
Another struct {
|
||||
Second string `xml:"second,theoption"`
|
||||
} `xml:"another,theoption"`
|
||||
}
|
||||
|
|
@ -105,4 +105,43 @@ struct_tags["should add tags with option"] = function()
|
|||
t.cleanup(rs)
|
||||
end
|
||||
|
||||
struct_tags["should add tags with default option"] = function()
|
||||
child.lua [[
|
||||
require("gopher").setup {
|
||||
gotag = { option = "xml=theoption" },
|
||||
}
|
||||
]]
|
||||
|
||||
local rs = t.setup_test("tags/with_default_option", child, { 3, 6 })
|
||||
child.cmd "GoTagAdd xml"
|
||||
child.cmd "write"
|
||||
|
||||
t.eq(t.readfile(rs.tmp), rs.fixtures.output)
|
||||
t.cleanup(rs)
|
||||
end
|
||||
|
||||
struct_tags["should add tags and overwrite default option"] = function()
|
||||
child.lua [[
|
||||
require("gopher").setup {
|
||||
gotag = { option = "xml=theoption" },
|
||||
}
|
||||
]]
|
||||
|
||||
local rs = t.setup_test("tags/overwrite_default_option", child, { 3, 6 })
|
||||
child.cmd "GoTagAdd xml=otheroption"
|
||||
child.cmd "write"
|
||||
|
||||
t.eq(t.readfile(rs.tmp), rs.fixtures.output)
|
||||
t.cleanup(rs)
|
||||
end
|
||||
|
||||
struct_tags["should remove tag with specified option"] = function()
|
||||
local rs = t.setup_test("tags/remove_with_option", child, { 3, 6 })
|
||||
child.cmd "GoTagRm json=omitempty"
|
||||
child.cmd "write"
|
||||
|
||||
t.eq(t.readfile(rs.tmp), rs.fixtures.output)
|
||||
t.cleanup(rs)
|
||||
end
|
||||
|
||||
return T
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue