Slight improvement for the document-level error in case no key or table was found.

This commit is contained in:
Maurice Makaay 2019-06-27 22:54:54 +00:00
parent 5782971bde
commit b1484cb690
2 changed files with 13 additions and 2 deletions

View File

@ -21,8 +21,10 @@ func (t *parser) startDocument(p *parse.API) {
p.Handle(t.startTable)
case p.Peek(detectKey):
p.Handle(t.startKeyValuePair)
case p.Accept(a.EndOfFile):
p.Stop()
default:
p.ExpectEndOfFile()
p.Expected("key/value pair, table or array of tables")
return
}
if p.IsStoppedOrInError() {

View File

@ -6,7 +6,7 @@ import (
func TestComment(t *testing.T) {
for _, test := range []parseTest{
{``, `{}`, `unexpected end of file (expected comment) at start of file`},
{``, `{}`, ``},
{`#`, `{}`, ``},
{`# `, `{}`, ``},
{`# with data`, `{}`, ``},
@ -20,3 +20,12 @@ func TestComment(t *testing.T) {
testParse(t, p, p.startDocument, test)
}
}
func TestInvalidDocument(t *testing.T) {
for _, test := range []parseTest{
{`!false!`, `{}`, `unexpected input (expected key/value pair, table or array of tables) at start of file`},
} {
p := newParser()
testParse(t, p, p.startDocument, test)
}
}