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 bytesparadise#707

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon committed Sep 28, 2020
1 parent ec1fc87 commit 862977d
Showing 1 changed file with 90 additions and 2 deletions.
92 changes: 90 additions & 2 deletions pkg/parser/document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,104 @@ 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 862977d

Please sign in to comment.