Added arrays tests
diff --git a/src/toml/parser.go b/src/toml/parser.go index 0045e31..469dfab 100644 --- a/src/toml/parser.go +++ b/src/toml/parser.go
@@ -135,6 +135,8 @@ return parseArray(p) } + println(tok.typ) + println(tok.val) panic("never reached") return nil @@ -152,10 +154,16 @@ 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 }
diff --git a/src/toml/parser_test.go b/src/toml/parser_test.go index f5ad742..7c4fcbd 100644 --- a/src/toml/parser_test.go +++ b/src/toml/parser_test.go
@@ -1,6 +1,7 @@ package toml import ( + "fmt" "testing" "time" ) @@ -8,7 +9,7 @@ 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 @@ "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),},}, + }) +}