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

Method TestNodeZeroEncodeDecode

node_test.go:2814–2834  ·  view source on GitHub ↗
(c *C)

Source from the content-addressed store, hash-verified

2812}
2813
2814func (s *S) TestNodeZeroEncodeDecode(c *C) {
2815 // Zero node value behaves as nil when encoding...
2816 var n yaml.Node
2817 data, err := yaml.Marshal(&n)
2818 c.Assert(err, IsNil)
2819 c.Assert(string(data), Equals, "null\n")
2820
2821 // ... and decoding.
2822 var v *struct{} = &struct{}{}
2823 c.Assert(n.Decode(&v), IsNil)
2824 c.Assert(v, IsNil)
2825
2826 // ... and even when looking for its tag.
2827 c.Assert(n.ShortTag(), Equals, "!!null")
2828
2829 // Kind zero is still unknown, though.
2830 n.Line = 1
2831 _, err = yaml.Marshal(&n)
2832 c.Assert(err, ErrorMatches, "yaml: cannot encode node with unknown kind 0")
2833 c.Assert(n.Decode(&v), ErrorMatches, "yaml: cannot decode node with unknown kind 0")
2834}
2835
2836func (s *S) TestNodeOmitEmpty(c *C) {
2837 var v struct {

Callers

nothing calls this directly

Calls 2

DecodeMethod · 0.95
ShortTagMethod · 0.95

Tested by

no test coverage detected