Skip to content

Commit

Permalink
test(parser): verify document with leading empty line
Browse files Browse the repository at this point in the history
verify that document metadata are recognized when the
content starts with an empty line

Fixes #707

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon committed Sep 28, 2020
1 parent ec1fc87 commit 8bc27f1
Showing 1 changed file with 89 additions and 2 deletions.
91 changes: 89 additions & 2 deletions pkg/parser/document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}{},
Expand Down

0 comments on commit 8bc27f1

Please sign in to comment.