fix issue #406
This commit is contained in:
+2
-1
@@ -822,7 +822,8 @@ func (d *Decoder) valueFromTree(mtype reflect.Type, tval *Tree, mval1 *reflect.V
|
|||||||
if !mtypef.Anonymous {
|
if !mtypef.Anonymous {
|
||||||
tmpTval = nil
|
tmpTval = nil
|
||||||
}
|
}
|
||||||
v, err := d.valueFromTree(mtypef.Type, tmpTval, nil)
|
fval := mval.Field(i)
|
||||||
|
v, err := d.valueFromTree(mtypef.Type, tmpTval, &fval)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return v, err
|
return v, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3807,3 +3807,44 @@ func TestTextUnmarshalError(t *testing.T) {
|
|||||||
t.Fatalf("expected err, got none")
|
t.Fatalf("expected err, got none")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// issue406
|
||||||
|
func TestPreserveNotEmptyField(t *testing.T) {
|
||||||
|
toml := []byte(`Field1 = "ccc"`)
|
||||||
|
type Inner struct {
|
||||||
|
InnerField1 string
|
||||||
|
InnerField2 int
|
||||||
|
}
|
||||||
|
type TestStruct struct {
|
||||||
|
Field1 string
|
||||||
|
Field2 int
|
||||||
|
Field3 Inner
|
||||||
|
}
|
||||||
|
|
||||||
|
actual := TestStruct{
|
||||||
|
"aaa",
|
||||||
|
100,
|
||||||
|
Inner{
|
||||||
|
"bbb",
|
||||||
|
200,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := TestStruct{
|
||||||
|
"ccc",
|
||||||
|
100,
|
||||||
|
Inner{
|
||||||
|
"bbb",
|
||||||
|
200,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
err := Unmarshal(toml, &actual)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(actual, expected) {
|
||||||
|
t.Errorf("Bad unmarshal: expected %+v, got %+v", expected, actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user