Handle simple string slice

This commit is contained in:
Thomas Pelletier
2021-03-13 18:45:03 -05:00
parent 21d3e85fcc
commit d8be04d4a8
4 changed files with 145 additions and 33 deletions
+36 -1
View File
@@ -11,7 +11,6 @@ import (
)
func TestFromAst_KV(t *testing.T) {
t.Skipf("later")
root := ast.Root{
ast.Node{
Kind: ast.KeyValue,
@@ -37,3 +36,39 @@ func TestFromAst_KV(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, Doc{Foo: "hello"}, x)
}
func TestFromAst_Slice(t *testing.T) {
root := ast.Root{
ast.Node{
Kind: ast.KeyValue,
Children: []ast.Node{
{
Kind: ast.Key,
Data: []byte(`Foo`),
},
{
Kind: ast.Array,
Children: []ast.Node{
{
Kind: ast.String,
Data: []byte(`hello`),
},
{
Kind: ast.String,
Data: []byte(`world`),
},
},
},
},
},
}
type Doc struct {
Foo []string
}
x := Doc{}
err := unmarshaler.FromAst(root, &x)
require.NoError(t, err)
assert.Equal(t, Doc{Foo: []string{"hello", "world"}}, x)
}