Skip to content

Commit

Permalink
test: additional coverage of omitempty
Browse files Browse the repository at this point in the history
  • Loading branch information
blgm committed May 21, 2020
1 parent 9d2bf6a commit ef62926
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ var _ = Describe("Marshal", func() {
})

Describe("omitempty", func() {
It("omits zero values", func() {
It("omits zero values of basic types", func() {
s := struct {
A string `json:",omitempty"`
B string `json:"bee,omitempty"`
Expand All @@ -215,6 +215,30 @@ var _ = Describe("Marshal", func() {
expectToMarshal(s, `{"E":""}`)
})

It("omits zero value structs", func() {
type t struct{ A string }
s := struct {
B t `jsonry:",omitempty"`
}{}
expectToMarshal(s, `{}`)
})

It("omits empty lists", func() {
s := struct {
A []string `jsonry:",omitempty"`
D [0]string `jsonry:",omitempty"`
}{}
expectToMarshal(s, `{}`)
})

It("omits empty maps", func() {
s := struct {
A map[interface{}]interface{} `jsonry:",omitempty"`
D map[int]int `jsonry:",omitempty"`
}{}
expectToMarshal(s, `{}`)
})

It("omits nil pointers", func() {
s := struct {
A *string `json:",omitempty"`
Expand Down

0 comments on commit ef62926

Please sign in to comment.