Added arrays tests
This commit is contained in:
@@ -135,6 +135,8 @@ func parseRvalue(p *parser) interface{} {
|
|||||||
return parseArray(p)
|
return parseArray(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println(tok.typ)
|
||||||
|
println(tok.val)
|
||||||
panic("never reached")
|
panic("never reached")
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@@ -152,10 +154,16 @@ func parseArray(p *parser) []interface{} {
|
|||||||
val := parseRvalue(p)
|
val := parseRvalue(p)
|
||||||
array = append(array, val)
|
array = append(array, val)
|
||||||
follow = p.peek()
|
follow = p.peek()
|
||||||
|
fmt.Println("Added to array:", val)
|
||||||
|
fmt.Println("Follow", follow)
|
||||||
|
fmt.Println("Follow", follow.typ)
|
||||||
if follow == nil { panic("unterminated array") }
|
if follow == nil { panic("unterminated array") }
|
||||||
if follow.typ != tokenRightBracket && follow.typ != tokenComma {
|
if follow.typ != tokenRightBracket && follow.typ != tokenComma {
|
||||||
panic("missing comma")
|
panic("missing comma")
|
||||||
}
|
}
|
||||||
|
if follow.typ == tokenComma {
|
||||||
|
p.getToken()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return array
|
return array
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-1
@@ -1,6 +1,7 @@
|
|||||||
package toml
|
package toml
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -8,7 +9,7 @@ import (
|
|||||||
|
|
||||||
func assertTree(t *testing.T, tree *TomlTree, ref map[string]interface{}) {
|
func assertTree(t *testing.T, tree *TomlTree, ref map[string]interface{}) {
|
||||||
for k, v := range ref {
|
for k, v := range ref {
|
||||||
if tree.Get(k) != v {
|
if fmt.Sprintf("%v", tree.Get(k)) != fmt.Sprintf("%v", v) {
|
||||||
t.Log("was expecting", v, "at", k, "but got", tree.Get(k))
|
t.Log("was expecting", v, "at", k, "but got", tree.Get(k))
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
@@ -76,3 +77,22 @@ func TestNestedKeys(t *testing.T) {
|
|||||||
"a.b.c.d": int64(42),
|
"a.b.c.d": int64(42),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestArraySimple(t *testing.T) {
|
||||||
|
tree := Load("a = [42, 21, 10]")
|
||||||
|
assertTree(t, tree, map[string]interface{}{
|
||||||
|
"a": []int64{int64(42), int64(21), int64(10),},
|
||||||
|
})
|
||||||
|
|
||||||
|
tree = Load("a = [42, 21, 10,]")
|
||||||
|
assertTree(t, tree, map[string]interface{}{
|
||||||
|
"a": []int64{int64(42), int64(21), int64(10),},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestArrayNested(t *testing.T) {
|
||||||
|
tree := Load("a = [[42, 21], [10]]")
|
||||||
|
assertTree(t, tree, map[string]interface{}{
|
||||||
|
"a": [][]int64{[]int64{int64(42), int64(21),}, []int64{int64(10),},},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user