Skip to content

Commit

Permalink
Fix []*Toml.Tree being wrapped in *Toml.Value (#110)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
pelletier authored Nov 23, 2016
1 parent f7f1498 commit 3ddb37c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func (p *tomlParser) parseAssign() tomlParserStateFn {
var toInsert interface{}

switch value.(type) {
case *TomlTree:
case *TomlTree, []*TomlTree:
toInsert = value
default:
toInsert = &tomlValue{value, key.Position}
Expand Down
32 changes: 32 additions & 0 deletions tomltree_conversions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,35 @@ func TestTomlTreeConversionToMapWithTablesInMultipleChunks(t *testing.T) {

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)
}

0 comments on commit 3ddb37c

Please sign in to comment.