diff --git a/marshaler.go b/marshaler.go index ffc99272..7f4e20c1 100644 --- a/marshaler.go +++ b/marshaler.go @@ -1025,6 +1025,10 @@ func (enc *Encoder) encodeSliceAsArrayTable(b []byte, ctx encoderCtx, v reflect. scratch = enc.commented(ctx.commented, scratch) + if enc.indentTables { + scratch = enc.indent(ctx.indent, scratch) + } + scratch = append(scratch, "[["...) for i, k := range ctx.parentKey { diff --git a/marshaler_test.go b/marshaler_test.go index 23b0efcd..b3473e38 100644 --- a/marshaler_test.go +++ b/marshaler_test.go @@ -1499,6 +1499,43 @@ func TestMarshalCommented(t *testing.T) { 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() { type MyConfig struct { Version int