file: support multiline comments

This commit is contained in:
Unknwon
2018-04-02 20:54:27 -04:00
parent 6ecc596bd7
commit 5e9692864e
3 changed files with 21 additions and 1 deletions
+4
View File
@@ -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
}
+16
View File
@@ -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) {
+1 -1
View File
@@ -32,7 +32,7 @@ const (
// Maximum allowed depth when recursively substituing variable names.
_DEPTH_VALUES = 99
_VERSION = "1.33.0"
_VERSION = "1.34.0"
)
// Version returns current package version literal.