decode: fix wrong indention for tables' comments (#892)
This commit is contained in:
committed by
GitHub
parent
76cc96f6d8
commit
4a5c27c299
+2
-2
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user