Fix indentation of custom type arrays (#944)
Signed-off-by: Daniel Weiße <dw@edgeless.systems>
This commit is contained in:
@@ -1025,6 +1025,10 @@ func (enc *Encoder) encodeSliceAsArrayTable(b []byte, ctx encoderCtx, v reflect.
|
|||||||
|
|
||||||
scratch = enc.commented(ctx.commented, scratch)
|
scratch = enc.commented(ctx.commented, scratch)
|
||||||
|
|
||||||
|
if enc.indentTables {
|
||||||
|
scratch = enc.indent(ctx.indent, scratch)
|
||||||
|
}
|
||||||
|
|
||||||
scratch = append(scratch, "[["...)
|
scratch = append(scratch, "[["...)
|
||||||
|
|
||||||
for i, k := range ctx.parentKey {
|
for i, k := range ctx.parentKey {
|
||||||
|
|||||||
@@ -1499,6 +1499,43 @@ func TestMarshalCommented(t *testing.T) {
|
|||||||
require.Equal(t, expected, string(out))
|
require.Equal(t, expected, string(out))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMarshalIndentedCustomTypeArray(t *testing.T) {
|
||||||
|
c := struct {
|
||||||
|
Nested struct {
|
||||||
|
NestedArray []struct {
|
||||||
|
Value int
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
Nested: struct {
|
||||||
|
NestedArray []struct {
|
||||||
|
Value int
|
||||||
|
}
|
||||||
|
}{
|
||||||
|
NestedArray: []struct {
|
||||||
|
Value int
|
||||||
|
}{
|
||||||
|
{Value: 1},
|
||||||
|
{Value: 2},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := `[Nested]
|
||||||
|
[[Nested.NestedArray]]
|
||||||
|
Value = 1
|
||||||
|
|
||||||
|
[[Nested.NestedArray]]
|
||||||
|
Value = 2
|
||||||
|
`
|
||||||
|
|
||||||
|
var buf bytes.Buffer
|
||||||
|
enc := toml.NewEncoder(&buf)
|
||||||
|
enc.SetIndentTables(true)
|
||||||
|
require.NoError(t, enc.Encode(c))
|
||||||
|
require.Equal(t, expected, buf.String())
|
||||||
|
}
|
||||||
|
|
||||||
func ExampleMarshal() {
|
func ExampleMarshal() {
|
||||||
type MyConfig struct {
|
type MyConfig struct {
|
||||||
Version int
|
Version int
|
||||||
|
|||||||
Reference in New Issue
Block a user