diff --git a/marshaler.go b/marshaler.go index 1f3bec9..9368ecd 100644 --- a/marshaler.go +++ b/marshaler.go @@ -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"...) diff --git a/marshaler_test.go b/marshaler_test.go index b4b8e28..514c885 100644 --- a/marshaler_test.go +++ b/marshaler_test.go @@ -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