Unmarshal slices of strings

This commit is contained in:
Thomas Pelletier
2021-03-13 22:07:36 -05:00
parent 1fafb71fd9
commit a0548e793c
6 changed files with 286 additions and 139 deletions
+66 -1
View File
@@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/require"
)
func TestParser_Simple(t *testing.T) {
func TestParser_AST(t *testing.T) {
examples := []struct {
desc string
input string
@@ -33,6 +33,71 @@ func TestParser_Simple(t *testing.T) {
},
},
},
{
desc: "array of strings",
input: `A = ["hello", ["world", "again"]]`,
ast: ast.Root{
ast.Node{
Kind: ast.KeyValue,
Children: []ast.Node{
{
Kind: ast.Key,
Data: []byte(`A`),
},
{
Kind: ast.Array,
Children: []ast.Node{
{
Kind: ast.String,
Data: []byte(`hello`),
},
{
Kind: ast.Array,
Children: []ast.Node{
{
Kind: ast.String,
Data: []byte(`world`),
},
{
Kind: ast.String,
Data: []byte(`again`),
},
},
},
},
},
},
},
},
},
{
desc: "array of arrays of strings",
input: `A = ["hello", "world"]`,
ast: ast.Root{
ast.Node{
Kind: ast.KeyValue,
Children: []ast.Node{
{
Kind: ast.Key,
Data: []byte(`A`),
},
{
Kind: ast.Array,
Children: []ast.Node{
{
Kind: ast.String,
Data: []byte(`hello`),
},
{
Kind: ast.String,
Data: []byte(`world`),
},
},
},
},
},
},
},
}
for _, e := range examples {