Skip to content

Commit e9e1044

Browse files
committed
json: use reflect.IsZero on arrays instead of len check
1 parent 7caec6b commit e9e1044

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

encode_patch_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package json
2+
3+
import (
4+
"testing"
5+
"time"
6+
)
7+
8+
func TestMarshalPatch(t *testing.T) {
9+
type S struct{
10+
T int
11+
U string
12+
}
13+
v := struct {
14+
A [2]float64
15+
B time.Time
16+
C S
17+
18+
X [2]float64 `json:",omitempty"`
19+
Y time.Time `json:",omitempty"`
20+
Z S `json:",omitempty"`
21+
}{}
22+
want := `{"A":[0,0],"B":"0001-01-01T00:00:00Z","C":{"T":0,"U":""}}`
23+
have, _ := Marshal(v)
24+
if h, w := string(have), want; h != w {
25+
t.Fatalf("have %s, want %s", h, w)
26+
}
27+
}

0 commit comments

Comments
 (0)