(c *C)
| 1682 | }} |
| 1683 | |
| 1684 | func (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 | |
| 1706 | type textUnmarshaler struct { |
| 1707 | S string |
nothing calls this directly
no test coverage detected