mirror of
https://github.com/go-ini/ini.git
synced 2026-06-19 21:46:45 +02:00
file: support multiline comments
This commit is contained in:
@@ -305,6 +305,10 @@ func (f *File) writeToBuffer(indent string) (*bytes.Buffer, error) {
|
||||
} else {
|
||||
key.Comment = key.Comment[:1] + " " + strings.TrimSpace(key.Comment[1:])
|
||||
}
|
||||
|
||||
// Support multiline comments
|
||||
key.Comment = strings.Replace(key.Comment, "\n", "\n; ", -1)
|
||||
|
||||
if _, err := buf.WriteString(key.Comment + LineBreak); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -264,6 +264,22 @@ func TestFile_WriteTo(t *testing.T) {
|
||||
So(err, ShouldBeNil)
|
||||
So(buf.String(), ShouldEqual, string(expected))
|
||||
})
|
||||
|
||||
Convey("Support multiline comments", t, func() {
|
||||
f := ini.Empty()
|
||||
f.Section("").Key("test").Comment = "Multiline\nComment"
|
||||
|
||||
var buf bytes.Buffer
|
||||
_, err := f.WriteTo(&buf)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
So(buf.String(), ShouldEqual, `; Multiline
|
||||
; Comment
|
||||
test =
|
||||
|
||||
`)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
func TestFile_SaveTo(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user