Support dotted-keys (#260)
Implement dotted keys as sequence of bare and quoted keys. Introduced in TOML 0.5.0. Fixes #230
This commit is contained in:
+31
-2
@@ -79,7 +79,7 @@ zyx = 42`)
|
||||
if err == nil {
|
||||
t.Error("Error should have been returned.")
|
||||
}
|
||||
if err.Error() != "(1, 4): unexpected token" {
|
||||
if err.Error() != "(1, 4): parsing error: keys cannot contain ] character" {
|
||||
t.Error("Bad error message:", err.Error())
|
||||
}
|
||||
}
|
||||
@@ -581,7 +581,7 @@ func TestDuplicateKeys(t *testing.T) {
|
||||
|
||||
func TestEmptyIntermediateTable(t *testing.T) {
|
||||
_, err := Load("[foo..bar]")
|
||||
if err.Error() != "(1, 2): invalid table array key: empty table key" {
|
||||
if err.Error() != "(1, 2): invalid table array key: expecting key part after dot" {
|
||||
t.Error("Bad error message:", err.Error())
|
||||
}
|
||||
}
|
||||
@@ -908,3 +908,32 @@ func TestMapKeyIsNum(t *testing.T) {
|
||||
t.Error("should be passed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDottedKeys(t *testing.T) {
|
||||
tree, err := Load(`
|
||||
name = "Orange"
|
||||
physical.color = "orange"
|
||||
physical.shape = "round"
|
||||
site."google.com" = true`)
|
||||
|
||||
assertTree(t, tree, err, map[string]interface{}{
|
||||
"name": "Orange",
|
||||
"physical": map[string]interface{}{
|
||||
"color": "orange",
|
||||
"shape": "round",
|
||||
},
|
||||
"site": map[string]interface{}{
|
||||
"google.com": true,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestInvalidDottedKeyEmptyGroup(t *testing.T) {
|
||||
_, err := Load(`a..b = true`)
|
||||
if err == nil {
|
||||
t.Fatal("should return an error")
|
||||
}
|
||||
if err.Error() != "(1, 1): invalid key: expecting key part after dot" {
|
||||
t.Fatalf("invalid error message: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user