Fix []*Toml.Tree being wrapped in *Toml.Value (#110)
Nodes can be either *Toml.Tree, []*Toml.Tree, or *Toml.Value. Arrays of trees were incorrectly wrapped in a *Toml.Value, making the conversion functions think they were leaf nodes.
This commit is contained in:
@@ -211,7 +211,7 @@ func (p *tomlParser) parseAssign() tomlParserStateFn {
|
|||||||
var toInsert interface{}
|
var toInsert interface{}
|
||||||
|
|
||||||
switch value.(type) {
|
switch value.(type) {
|
||||||
case *TomlTree:
|
case *TomlTree, []*TomlTree:
|
||||||
toInsert = value
|
toInsert = value
|
||||||
default:
|
default:
|
||||||
toInsert = &tomlValue{value, key.Position}
|
toInsert = &tomlValue{value, key.Position}
|
||||||
|
|||||||
@@ -101,3 +101,35 @@ func TestTomlTreeConversionToMapWithTablesInMultipleChunks(t *testing.T) {
|
|||||||
|
|
||||||
testMaps(t, treeMap, expected)
|
testMaps(t, treeMap, expected)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTomlTreeConversionToMapWithArrayOfInlineTables(t *testing.T) {
|
||||||
|
tree, _ := Load(`
|
||||||
|
[params]
|
||||||
|
language_tabs = [
|
||||||
|
{ key = "shell", name = "Shell" },
|
||||||
|
{ key = "ruby", name = "Ruby" },
|
||||||
|
{ key = "python", name = "Python" }
|
||||||
|
]`)
|
||||||
|
|
||||||
|
expected := map[string]interface{}{
|
||||||
|
"params": map[string]interface{}{
|
||||||
|
"language_tabs": []interface{}{
|
||||||
|
map[string]interface{}{
|
||||||
|
"key": "shell",
|
||||||
|
"name": "Shell",
|
||||||
|
},
|
||||||
|
map[string]interface{}{
|
||||||
|
"key": "ruby",
|
||||||
|
"name": "Ruby",
|
||||||
|
},
|
||||||
|
map[string]interface{}{
|
||||||
|
"key": "python",
|
||||||
|
"name": "Python",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
treeMap := tree.ToMap()
|
||||||
|
testMaps(t, treeMap, expected)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user