Fix nested keys
This commit is contained in:
+2
-2
@@ -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)
|
||||
|
||||
@@ -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),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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, ".")
|
||||
|
||||
Reference in New Issue
Block a user