Fix unmarshaling struct with interface field which is a pointer to a struct (part 2: test)

This commit is contained in:
dd
2016-10-14 11:46:51 +03:00
parent ef252ae407
commit 532bbefda8
2 changed files with 26 additions and 0 deletions
+12
View File
@@ -156,3 +156,15 @@ func TestUnderflowArray(t *testing.T) {
t.Errorf("Unmarshal(%v) = %+v; want %+v", arrayUnderflowString, a, arrayUnderflowValue)
}
}
func TestUnmarshalStructWithEmbeddedPtrStruct(t *testing.T) {
var s = StructWithInterface{Field2: &EmbeddedStruct{}}
var err error
err = easyjson.Unmarshal([]byte(structWithInterfaceString), &s)
if err != nil {
t.Errorf("easyjson.Unmarshal() error: %v", err)
}
if !reflect.DeepEqual(s, structWithInterfaceValueFilled) {
t.Errorf("easyjson.Unmarshal() = %#v; want %#v", s, structWithInterfaceValueFilled)
}
}
+14
View File
@@ -624,3 +624,17 @@ type RequiredOptionalStruct struct {
FirstName string `json:"first_name,required"`
Lastname string `json:"last_name"`
}
type StructWithInterface struct {
Field1 int `json:"f1"`
Field2 interface{} `json:"f2"`
Field3 string `json:"f3"`
}
type EmbeddedStruct struct {
Field1 int `json:"f1"`
Field2 string `json:"f2"`
}
var structWithInterfaceString = `{"f1":1,"f2":{"f1":11,"f2":"22"},"f3":"3"}`
var structWithInterfaceValueFilled = StructWithInterface{1, &EmbeddedStruct{11, "22"}, "3"}