Array values
This commit is contained in:
+9
-1
@@ -141,7 +141,15 @@ func (u *unmarshaler) StringValue(v []byte) {
|
|||||||
if u.err != nil {
|
if u.err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
u.top().SetString(string(v))
|
|
||||||
|
t := u.top()
|
||||||
|
if t.Type().Kind() == reflect.Slice {
|
||||||
|
s := reflect.ValueOf(string(v))
|
||||||
|
n := reflect.Append(t, s)
|
||||||
|
t.Set(n)
|
||||||
|
} else {
|
||||||
|
u.top().SetString(string(v))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *unmarshaler) SimpleKey(v []byte) {
|
func (u *unmarshaler) SimpleKey(v []byte) {
|
||||||
|
|||||||
@@ -234,3 +234,13 @@ Name = "plantain"
|
|||||||
|
|
||||||
assert.Equal(t, expected, x)
|
assert.Equal(t, expected, x)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestArraySimple(t *testing.T) {
|
||||||
|
x := struct {
|
||||||
|
Foo []string
|
||||||
|
}{}
|
||||||
|
doc := `Foo = ["hello", "world"]`
|
||||||
|
err := toml.Unmarshal([]byte(doc), &x)
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.Equal(t, []string{"hello", "world"}, x.Foo)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user