Skip to content

Commit f9b164a

Browse files
committed
test(json): add test case for #63
1 parent 496d327 commit f9b164a

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

json/json_test.go

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1578,7 +1578,6 @@ func TestGithubIssue41(t *testing.T) {
15781578
"expected: ", expectedString,
15791579
)
15801580
}
1581-
15821581
}
15831582

15841583
func TestGithubIssue44(t *testing.T) {
@@ -1602,6 +1601,35 @@ func (r *rawJsonString) UnmarshalJSON(b []byte) error {
16021601
return nil
16031602
}
16041603

1604+
func TestGithubIssue63(t *testing.T) {
1605+
expectedString := `{"my_field":"test","code":0}`
1606+
1607+
type MyStruct struct {
1608+
MyField string `json:"my_field,omitempty"`
1609+
}
1610+
1611+
type MyStruct2 struct {
1612+
*MyStruct
1613+
Code int `json:"code"`
1614+
}
1615+
1616+
input := MyStruct2{
1617+
MyStruct: &MyStruct{
1618+
MyField: "test",
1619+
},
1620+
Code: 0,
1621+
}
1622+
1623+
if b, err := Marshal(input); err != nil {
1624+
t.Error(err)
1625+
} else if string(b) != expectedString {
1626+
t.Error(
1627+
"got: ", string(b),
1628+
"expected: ", expectedString,
1629+
)
1630+
}
1631+
}
1632+
16051633
func TestSetTrustRawMessage(t *testing.T) {
16061634
buf := &bytes.Buffer{}
16071635
enc := NewEncoder(buf)

0 commit comments

Comments
 (0)