Skip to content

Commit

Permalink
feat: multiline comment
Browse files Browse the repository at this point in the history
Signed-off-by: Yvonnick Esnault <[email protected]>
  • Loading branch information
yesnault committed Sep 12, 2017
1 parent a421401 commit a2fe53c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"`
Expand Down
4 changes: 2 additions & 2 deletions tomltree_write.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit a2fe53c

Please sign in to comment.