Fix inline table first key value whitespace (#837)
Co-authored-by: Cuong Manh Le <cuong@windscribe.com>
This commit is contained in:
+1
-1
@@ -357,9 +357,9 @@ func (enc *Encoder) encodeKv(b []byte, ctx encoderCtx, options valueOptions, v r
|
||||
|
||||
if !ctx.inline {
|
||||
b = enc.encodeComment(ctx.indent, options.comment, b)
|
||||
b = enc.indent(ctx.indent, b)
|
||||
}
|
||||
|
||||
b = enc.indent(ctx.indent, b)
|
||||
b = enc.encodeKey(b, ctx.key)
|
||||
b = append(b, " = "...)
|
||||
|
||||
|
||||
@@ -1190,6 +1190,27 @@ func TestMarshalUint64Overflow(t *testing.T) {
|
||||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestIndentWithInlineTable(t *testing.T) {
|
||||
x := map[string][]map[string]string{
|
||||
"one": []map[string]string{
|
||||
{"0": "0"},
|
||||
{"1": "1"},
|
||||
},
|
||||
}
|
||||
expected := `one = [
|
||||
{0 = '0'},
|
||||
{1 = '1'}
|
||||
]
|
||||
`
|
||||
var buf bytes.Buffer
|
||||
enc := toml.NewEncoder(&buf)
|
||||
enc.SetIndentTables(true)
|
||||
enc.SetTablesInline(true)
|
||||
enc.SetArraysMultiline(true)
|
||||
require.NoError(t, enc.Encode(x))
|
||||
assert.Equal(t, expected, buf.String())
|
||||
}
|
||||
|
||||
func ExampleMarshal() {
|
||||
type MyConfig struct {
|
||||
Version int
|
||||
|
||||
Reference in New Issue
Block a user