decode: fix wrong indention for tables' comments (#892)

This commit is contained in:
Mikhail f. Shiryaev
2023-08-28 19:23:11 +02:00
committed by GitHub
parent 76cc96f6d8
commit 4a5c27c299
2 changed files with 5 additions and 4 deletions
+2 -2
View File
@@ -983,12 +983,12 @@ func (enc *Encoder) encodeSliceAsArrayTable(b []byte, ctx encoderCtx, v reflect.
scratch = append(scratch, "]]\n"...)
ctx.skipTableHeader = true
b = enc.encodeComment(ctx.indent, ctx.options.comment, b)
if enc.indentTables {
ctx.indent++
}
b = enc.encodeComment(ctx.indent, ctx.options.comment, b)
for i := 0; i < v.Len(); i++ {
if i != 0 {
b = append(b, "\n"...)
+3 -2
View File
@@ -1208,7 +1208,7 @@ func TestMarhsalIssue888(t *testing.T) {
}
type Cfg struct {
Custom []Thing
Custom []Thing `comment:"custom config"`
}
buf := new(bytes.Buffer)
@@ -1223,7 +1223,8 @@ func TestMarhsalIssue888(t *testing.T) {
encoder := toml.NewEncoder(buf).SetIndentTables(true)
encoder.Encode(config)
expected := `[[Custom]]
expected := `# custom config
[[Custom]]
# my field A
FieldA = 'field a 1'
# my field B