Inline tables

This commit is contained in:
Thomas Pelletier
2021-03-13 23:06:16 -05:00
parent fbf01f7683
commit fa7ee6461a
4 changed files with 134 additions and 29 deletions
+56
View File
@@ -137,6 +137,62 @@ func TestFromAst_Table(t *testing.T) {
})
}
func TestFromAst_InlineTable(t *testing.T) {
t.Run("one level of strings", func(t *testing.T) {
// name = { first = "Tom", last = "Preston-Werner" }
root := ast.Root{
ast.Node{
Kind: ast.KeyValue,
Children: []ast.Node{
{
Kind: ast.Key,
Data: []byte(`Name`)},
{
Kind: ast.InlineTable,
Children: []ast.Node{
{
Kind: ast.KeyValue,
Children: []ast.Node{
{Kind: ast.Key, Data: []byte(`First`)},
{Kind: ast.String, Data: []byte(`Tom`)},
},
},
{
Kind: ast.KeyValue,
Children: []ast.Node{
{Kind: ast.Key, Data: []byte(`Last`)},
{Kind: ast.String, Data: []byte(`Preston-Werner`)},
},
},
},
},
},
},
}
type Name struct {
First string
Last string
}
type Doc struct {
Name Name
}
x := Doc{}
err := fromAst(root, &x)
require.NoError(t, err)
assert.Equal(t, Doc{
Name: Name{
First: "Tom",
Last: "Preston-Werner",
},
}, x)
})
}
func TestFromAst_Slice(t *testing.T) {
t.Run("slice of string", func(t *testing.T) {
root := ast.Root{