зеркало из https://github.com/go-gitea/yaml.git
Unbreak goyaml after interface mutability fix in reflect.
R=rog CC= https://codereview.appspot.com/5784060
This commit is contained in:
Коммит
5515099aac
|
@ -0,0 +1 @@
|
|||
propose -cr -for=lp:goyaml
|
|
@ -375,11 +375,11 @@ func (d *decoder) sequence(n *node, out reflect.Value) (good bool) {
|
|||
if set := d.setter("!!seq", &out, &good); set != nil {
|
||||
defer set()
|
||||
}
|
||||
var iface reflect.Value
|
||||
if out.Kind() == reflect.Interface {
|
||||
// No type hints. Will have to use a generic sequence.
|
||||
iface := out
|
||||
iface = out
|
||||
out = settableValueOf(make([]interface{}, 0))
|
||||
iface.Set(out)
|
||||
}
|
||||
|
||||
if out.Kind() != reflect.Slice {
|
||||
|
@ -394,6 +394,9 @@ func (d *decoder) sequence(n *node, out reflect.Value) (good bool) {
|
|||
out.Set(reflect.Append(out, e))
|
||||
}
|
||||
}
|
||||
if iface.IsValid() {
|
||||
iface.Set(out)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ var unmarshalTests = []struct {
|
|||
{"fixed: 685_230.15", map[string]interface{}{"fixed": 685230.15}},
|
||||
//{"sexa: 190:20:30.15", map[string]interface{}{"sexa": 0}}, // Unsupported
|
||||
{"neginf: -.inf", map[string]interface{}{"neginf": math.Inf(-1)}},
|
||||
{"notanum: .NaN", map[string]interface{}{"notanum": math.NaN()}},
|
||||
//{"notanum: .NaN", map[string]interface{}{"notanum": math.NaN()}}, // Equality of NaN fails.
|
||||
{"fixed: 685_230.15", map[string]float64{"fixed": 685230.15}},
|
||||
|
||||
// Bools from spec
|
||||
|
@ -136,11 +136,18 @@ func (s *S) TestUnmarshal(c *C) {
|
|||
value = pv.Interface()
|
||||
}
|
||||
err := goyaml.Unmarshal([]byte(item.data), value)
|
||||
c.Assert(err, IsNil, Bug("Item #%d", i))
|
||||
c.Assert(value, Equals, item.value)
|
||||
c.Assert(err, IsNil, Commentf("Item #%d", i))
|
||||
c.Assert(value, DeepEquals, item.value)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *S) TestUnmarshalNaN(c *C) {
|
||||
value := map[string]interface{}{}
|
||||
err := goyaml.Unmarshal([]byte("notanum: .NaN"), &value)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(math.IsNaN(value["notanum"].(float64)), Equals, true)
|
||||
}
|
||||
|
||||
var unmarshalErrorTests = []struct {
|
||||
data, error string
|
||||
}{
|
||||
|
@ -155,7 +162,7 @@ func (s *S) TestUnmarshalErrors(c *C) {
|
|||
for _, item := range unmarshalErrorTests {
|
||||
var value interface{}
|
||||
err := goyaml.Unmarshal([]byte(item.data), &value)
|
||||
c.Assert(err, ErrorMatches, item.error, Bug("Partial unmarshal: %#v", value))
|
||||
c.Assert(err, ErrorMatches, item.error, Commentf("Partial unmarshal: %#v", value))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -198,9 +205,9 @@ func (s *S) TestUnmarshalWithSetter(c *C) {
|
|||
err := goyaml.Unmarshal([]byte(item.data), obj)
|
||||
c.Assert(err, IsNil)
|
||||
c.Assert(obj.Field, NotNil,
|
||||
Bug("Pointer not initialized (%#v)", item.value))
|
||||
Commentf("Pointer not initialized (%#v)", item.value))
|
||||
c.Assert(obj.Field.tag, Equals, item.tag)
|
||||
c.Assert(obj.Field.value, Equals, item.value)
|
||||
c.Assert(obj.Field.value, DeepEquals, item.value)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -211,7 +218,7 @@ func (s *S) TestUnmarshalWholeDocumentWithSetter(c *C) {
|
|||
c.Assert(obj.tag, Equals, setterTests[0].tag)
|
||||
value, ok := obj.value.(map[interface{}]interface{})
|
||||
c.Assert(ok, Equals, true)
|
||||
c.Assert(value["_"], Equals, setterTests[0].value)
|
||||
c.Assert(value["_"], DeepEquals, setterTests[0].value)
|
||||
}
|
||||
|
||||
func (s *S) TestUnmarshalWithFalseSetterIgnoresValue(c *C) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче