Add tests for errors (fixes #5)
This commit is contained in:
@@ -106,7 +106,7 @@ func parseAssign(p *parser) parserStateFn {
|
||||
|
||||
func parseRvalue(p *parser) interface{} {
|
||||
tok := p.getToken()
|
||||
if tok == nil {
|
||||
if tok == nil || tok.typ == tokenEOF {
|
||||
panic("expecting a value")
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ func parseArray(p *parser) []interface{} {
|
||||
array := make([]interface{}, 0)
|
||||
for {
|
||||
follow := p.peek()
|
||||
if follow == nil {
|
||||
if follow == nil || follow.typ == tokenEOF {
|
||||
panic("unterminated array")
|
||||
}
|
||||
if follow.typ == tokenRightBracket {
|
||||
|
||||
@@ -101,3 +101,17 @@ func TestArrayNested(t *testing.T) {
|
||||
"a": [][]int64{[]int64{int64(42), int64(21)}, []int64{int64(10)}},
|
||||
})
|
||||
}
|
||||
|
||||
func TestMissingValue(t *testing.T) {
|
||||
_, err := Load("a = ")
|
||||
if (err.Error() != "expecting a value") {
|
||||
t.Error("Bad error message:", err.Error());
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnterminatedArray(t *testing.T) {
|
||||
_, err := Load("a = [1,")
|
||||
if (err.Error() != "unterminated array") {
|
||||
t.Error("Bad error message:", err.Error());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user