Skip to content

Commit

Permalink
Also marshal Node by value
Browse files Browse the repository at this point in the history
  • Loading branch information
niemeyer committed May 4, 2020
1 parent ae27a74 commit a81ed60
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ func (e *encoder) marshal(tag string, in reflect.Value) {
case *Node:
e.nodev(in)
return
case Node:
e.nodev(in.Addr())
return
case time.Time:
e.timev(tag, in)
return
Expand Down
15 changes: 15 additions & 0 deletions encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,21 @@ var marshalTests = []struct {
map[string]string{"a": "\tB\n\tC\n"},
"a: |\n \tB\n \tC\n",
},

// yaml.Node
{
&struct {
Value yaml.Node
}{
yaml.Node{
Kind: yaml.ScalarNode,
Tag: "!!str",
Value: "foo",
Style: yaml.SingleQuotedStyle,
},
},
"value: 'foo'\n",
},
}

func (s *S) TestMarshal(c *C) {
Expand Down

0 comments on commit a81ed60

Please sign in to comment.