Fix nested keys

This commit is contained in:
Thomas Pelletier
2013-02-24 22:45:44 +01:00
parent a94cae08c3
commit 820938471d
3 changed files with 9 additions and 4 deletions
+2 -2
View File
@@ -84,8 +84,8 @@ func parseStart(p *parser) parserStateFn {
func parseGroup(p *parser) parserStateFn {
p.getToken() // discard the [
key := p.getToken()
if key.typ != tokenKey {
panic(fmt.Sprintf("unexpected token %s, was expecting a key", key))
if key.typ != tokenKeyGroup {
panic(fmt.Sprintf("unexpected token %s, was expecting a key group", key))
}
p.tree.createSubTree(key.val)
p.assume(tokenRightBracket)
+7
View File
@@ -69,3 +69,10 @@ func TestBools(t *testing.T) {
"b": false,
})
}
func TestNestedKeys(t *testing.T) {
tree := Load("[a.b.c]\nd = 42")
assertTree(t, tree, map[string]interface{}{
"a.b.c.d": int64(42),
})
}
-2
View File
@@ -20,8 +20,6 @@ func (t *TomlTree) Keys() []string {
return keys
}
// Get an element from the tree.
// If the path described by the key does not exist, nil is returned.
func (t *TomlTree) Get(key string) interface{} {
subtree := t
keys := strings.Split(key, ".")