Harden tests for bad arrays

This commit is contained in:
Thomas Pelletier
2015-09-09 17:33:28 +01:00
parent 5753e884d0
commit 6b9002d8f9
2 changed files with 12 additions and 2 deletions
+2 -2
View File
@@ -264,7 +264,7 @@ func (p *tomlParser) parseArray() []interface{} {
} }
if follow.typ == tokenRightBracket { if follow.typ == tokenRightBracket {
p.getToken() p.getToken()
return array break
} }
val := p.parseRvalue() val := p.parseRvalue()
if arrayType == nil { if arrayType == nil {
@@ -275,7 +275,7 @@ func (p *tomlParser) parseArray() []interface{} {
} }
array = append(array, val) array = append(array, val)
follow = p.peek() follow = p.peek()
if follow == nil { if follow == nil || follow.typ == tokenEOF {
p.raiseError(follow, "unterminated array") p.raiseError(follow, "unterminated array")
} }
if follow.typ != tokenRightBracket && follow.typ != tokenComma { if follow.typ != tokenRightBracket && follow.typ != tokenComma {
+10
View File
@@ -297,6 +297,16 @@ func TestUnterminatedArray(t *testing.T) {
if err.Error() != "(1, 8): unterminated array" { if err.Error() != "(1, 8): unterminated array" {
t.Error("Bad error message:", err.Error()) t.Error("Bad error message:", err.Error())
} }
_, err = Load("a = [1")
if err.Error() != "(1, 7): unterminated array" {
t.Error("Bad error message:", err.Error())
}
_, err = Load("a = [1 2")
if err.Error() != "(1, 8): missing comma" {
t.Error("Bad error message:", err.Error())
}
} }
func TestNewlinesInArrays(t *testing.T) { func TestNewlinesInArrays(t *testing.T) {