From 8bc27f12c6c760fb3c1bcdeb5a697692d74faa88 Mon Sep 17 00:00:00 2001 From: Xavier Coulon Date: Mon, 28 Sep 2020 23:03:08 +0200 Subject: [PATCH] test(parser): verify document with leading empty line verify that document metadata are recognized when the content starts with an empty line Fixes #707 Signed-off-by: Xavier Coulon --- pkg/parser/document_test.go | 91 ++++++++++++++++++++++++++++++++++++- 1 file changed, 89 insertions(+), 2 deletions(-) diff --git a/pkg/parser/document_test.go b/pkg/parser/document_test.go index b5620e76..d3cdd78d 100644 --- a/pkg/parser/document_test.go +++ b/pkg/parser/document_test.go @@ -12,16 +12,103 @@ var _ = Describe("documents", func() { Context("draft document", func() { - It("empty document", func() { + It("should parse empty document", func() { source := `` expected := types.DraftDocument{} Expect(ParseDraftDocument(source)).To(MatchDraftDocument(expected)) }) + + It("should parse header without empty first line", func() { + source := `= My title +Garrett D'Amore +1.0, July 4, 2020 +` + expected := types.DraftDocument{ + Attributes: types.Attributes{ + "revnumber": "1.0", + "revdate": "July 4, 2020", + "author": "Garrett D'Amore", + "authorinitials": "GD", + "authors": []types.DocumentAuthor{ + { + FullName: "Garrett D'Amore", + Email: "", + }, + }, + "firstname": "Garrett", + "lastname": "D'Amore", + "revision": types.DocumentRevision{ + Revnumber: "1.0", + Revdate: "July 4, 2020", + Revremark: "", + }, + }, + Blocks: []interface{}{ + types.Section{ + Level: 0, + Attributes: types.Attributes{ + "id": "_my_title", + }, + Title: []interface{}{ + types.StringElement{ + Content: "My title", + }, + }, + Elements: []interface{}{}, + }, + }, + } + Expect(ParseDraftDocument(source)).To(MatchDraftDocument(expected)) + + }) + + It("should parse header with empty first line", func() { + source := `= My title +Garrett D'Amore +1.0, July 4, 2020` + expected := types.DraftDocument{ + Attributes: types.Attributes{ + "revnumber": "1.0", + "revdate": "July 4, 2020", + "author": "Garrett D'Amore", + "authorinitials": "GD", + "authors": []types.DocumentAuthor{ + { + FullName: "Garrett D'Amore", + Email: "", + }, + }, + "firstname": "Garrett", + "lastname": "D'Amore", + "revision": types.DocumentRevision{ + Revnumber: "1.0", + Revdate: "July 4, 2020", + Revremark: "", + }, + }, + Blocks: []interface{}{ + types.Section{ + Level: 0, + Attributes: types.Attributes{ + "id": "_my_title", + }, + Title: []interface{}{ + types.StringElement{ + Content: "My title", + }, + }, + Elements: []interface{}{}, + }, + }, + } + Expect(ParseDraftDocument(source)).To(MatchDraftDocument(expected)) + + }) }) Context("final document", func() { - It("empty document", func() { + It("should parse empty document", func() { source := `` expected := types.Document{ Elements: []interface{}{},