Skip to content

Commit

Permalink
Fix inline table first key value whitespace (#837)
Browse files Browse the repository at this point in the history
Co-authored-by: Cuong Manh Le <cuong@windscribe.com>
  • Loading branch information
cuonglm and cuonglm authored Feb 1, 2023
1 parent 58a592b commit 090cccf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion marshaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, " = "...)

Expand Down
21 changes: 21 additions & 0 deletions marshaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 090cccf

Please sign in to comment.