From a2fe53c3871eb5e0b2bf1d801a0deb78912d0fdd Mon Sep 17 00:00:00 2001 From: Yvonnick Esnault Date: Tue, 12 Sep 2017 10:21:15 +0200 Subject: [PATCH] feat: multiline comment Signed-off-by: Yvonnick Esnault --- marshal_test.go | 5 +++-- tomltree_write.go | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/marshal_test.go b/marshal_test.go index a44490e3..befd04a5 100644 --- a/marshal_test.go +++ b/marshal_test.go @@ -605,7 +605,8 @@ var commentTestToml = []byte(` # isCommented = "dvalue" noComment = "cvalue" - # A comment on AttrB + # A comment on AttrB with a + # break line password = "bvalue" # A comment on AttrA @@ -623,7 +624,7 @@ func TestMarshalComment(t *testing.T) { } type TypeB struct { AttrA string `toml:"user" comment:"A comment on AttrA"` - AttrB string `toml:"password" comment:"A comment on AttrB"` + AttrB string `toml:"password" comment:"A comment on AttrB with a\n break line"` AttrC string `toml:"noComment"` AttrD string `toml:"isCommented" commented:"true"` My []TypeC `comment:"a comment on My"` diff --git a/tomltree_write.go b/tomltree_write.go index 85568907..8a5e7e49 100644 --- a/tomltree_write.go +++ b/tomltree_write.go @@ -119,7 +119,7 @@ func (t *Tree) writeTo(w io.Writer, indent, keyspace string, bytesCount int64) ( } if v.comment != nil { - comment := strings.Replace(*v.comment, "\n", "\n"+indent, -1) + comment := strings.Replace(*v.comment, "\n", "\n"+indent+"#", -1) writtenBytesCountComment, errc := writeStrings(w, "\n", indent, "# ", comment, "\n") bytesCount += int64(writtenBytesCountComment) if errc != nil { @@ -151,7 +151,7 @@ func (t *Tree) writeTo(w io.Writer, indent, keyspace string, bytesCount int64) ( } if t.comment != nil { - comment := strings.Replace(*t.comment, "\n", "\n"+indent, -1) + comment := strings.Replace(*t.comment, "\n", "\n"+indent+"#", -1) writtenBytesCountComment, errc := writeStrings(w, "\n", indent, "# ", comment) bytesCount += int64(writtenBytesCountComment) if errc != nil {