Added arrays tests
This commit is contained in:
@@ -135,6 +135,8 @@ func parseRvalue(p *parser) interface{} {
|
||||
return parseArray(p)
|
||||
}
|
||||
|
||||
println(tok.typ)
|
||||
println(tok.val)
|
||||
panic("never reached")
|
||||
|
||||
return nil
|
||||
@@ -152,10 +154,16 @@ func parseArray(p *parser) []interface{} {
|
||||
val := parseRvalue(p)
|
||||
array = append(array, val)
|
||||
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.typ != tokenRightBracket && follow.typ != tokenComma {
|
||||
panic("missing comma")
|
||||
}
|
||||
if follow.typ == tokenComma {
|
||||
p.getToken()
|
||||
}
|
||||
}
|
||||
return array
|
||||
}
|
||||
|
||||
+21
-1
@@ -1,6 +1,7 @@
|
||||
package toml
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -8,7 +9,7 @@ import (
|
||||
|
||||
func assertTree(t *testing.T, tree *TomlTree, ref map[string]interface{}) {
|
||||
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.Fail()
|
||||
}
|
||||
@@ -76,3 +77,22 @@ func TestNestedKeys(t *testing.T) {
|
||||
"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