diff --git a/parse/document.go b/parse/document.go index 50504a4..22c577d 100644 --- a/parse/document.go +++ b/parse/document.go @@ -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() { diff --git a/parse/comment_test.go b/parse/document_test.go similarity index 68% rename from parse/comment_test.go rename to parse/document_test.go index 3b6a4e6..5cd49a0 100644 --- a/parse/comment_test.go +++ b/parse/document_test.go @@ -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) + } +}