Playing with an AST

Idea would be to build a light AST as a first pass, then have the
unmarshaler and Document parser do what they need with it.
This commit is contained in:
Thomas Pelletier
2021-03-13 11:38:09 -05:00
parent 93a74fca35
commit 21d3e85fcc
11 changed files with 2009 additions and 59 deletions
@@ -1855,16 +1855,19 @@ func TestUnmarshalMixedTypeArray(t *testing.T) {
ArrayField []interface{}
}
doc := []byte(`ArrayField = [3.14,100,true,"hello world",{Field = "inner1"},[{Field = "inner2"},{Field = "inner3"}]]
//doc := []byte(`ArrayField = [3.14,100,true,"hello world",{Field = "inner1"},[{Field = "inner2"},{Field = "inner3"}]]
//`)
doc := []byte(`ArrayField = [{Field = "inner1"},[{Field = "inner2"},{Field = "inner3"}]]
`)
actual := TestStruct{}
expected := TestStruct{
ArrayField: []interface{}{
3.14,
int64(100),
true,
"hello world",
//3.14,
//int64(100),
//true,
//"hello world",
map[string]interface{}{
"Field": "inner1",
},
@@ -1874,14 +1877,9 @@ func TestUnmarshalMixedTypeArray(t *testing.T) {
},
},
}
if err := toml.Unmarshal(doc, &actual); err == nil {
if !reflect.DeepEqual(actual, expected) {
t.Errorf("Bad unmarshal: expected %#v, got %#v", expected, actual)
}
} else {
t.Fatal(err)
}
err := toml.Unmarshal(doc, &actual)
require.NoError(t, err)
assert.Equal(t, expected, actual)
}
func TestUnmarshalArray(t *testing.T) {