Skip to content

Commit

Permalink
decode: fix wrong indention for tables' comments (#892)
Browse files Browse the repository at this point in the history
  • Loading branch information
Felixoid authored Aug 28, 2023
1 parent 76cc96f commit 4a5c27c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions marshaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"...)
Expand Down
5 changes: 3 additions & 2 deletions marshaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,7 @@ func TestMarhsalIssue888(t *testing.T) {
}

type Cfg struct {
Custom []Thing
Custom []Thing `comment:"custom config"`
}

buf := new(bytes.Buffer)
Expand All @@ -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
Expand Down

0 comments on commit 4a5c27c

Please sign in to comment.