MCPcopy
hub / github.com/go-yaml/yaml / TestUnmarshalKnownFields

Method TestUnmarshalKnownFields

decode_test.go:1684–1704  ·  view source on GitHub ↗
(c *C)

Source from the content-addressed store, hash-verified

1682}}
1683
1684func (s *S) TestUnmarshalKnownFields(c *C) {
1685 for i, item := range unmarshalStrictTests {
1686 c.Logf("test %d: %q", i, item.data)
1687 // First test that normal Unmarshal unmarshals to the expected value.
1688 if !item.unique {
1689 t := reflect.ValueOf(item.value).Type()
1690 value := reflect.New(t)
1691 err := yaml.Unmarshal([]byte(item.data), value.Interface())
1692 c.Assert(err, Equals, nil)
1693 c.Assert(value.Elem().Interface(), DeepEquals, item.value)
1694 }
1695
1696 // Then test that it fails on the same thing with KnownFields on.
1697 t := reflect.ValueOf(item.value).Type()
1698 value := reflect.New(t)
1699 dec := yaml.NewDecoder(bytes.NewBuffer([]byte(item.data)))
1700 dec.KnownFields(item.known)
1701 err := dec.Decode(value.Interface())
1702 c.Assert(err, ErrorMatches, item.error)
1703 }
1704}
1705
1706type textUnmarshaler struct {
1707 S string

Callers

nothing calls this directly

Calls 2

KnownFieldsMethod · 0.95
DecodeMethod · 0.95

Tested by

no test coverage detected