From 3ddb37c9445773dd46f5c17f1d7769114899b4f9 Mon Sep 17 00:00:00 2001 From: Thomas Pelletier Date: Wed, 23 Nov 2016 15:48:39 +0100 Subject: [PATCH] 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. --- parser.go | 2 +- tomltree_conversions_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/parser.go b/parser.go index 25932d7a..0b59b6f0 100644 --- a/parser.go +++ b/parser.go @@ -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} diff --git a/tomltree_conversions_test.go b/tomltree_conversions_test.go index 1822dcb9..58dbf4e0 100644 --- a/tomltree_conversions_test.go +++ b/tomltree_conversions_test.go @@ -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) +}