Skip to content

Commit

Permalink
fix(parser): verify document with leading empty line (#757)
Browse files Browse the repository at this point in the history
ignore heading blank lines after the front-matter

Fixes #707

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon authored Sep 29, 2020
1 parent ec1fc87 commit 921565a
Show file tree
Hide file tree
Showing 4 changed files with 3,928 additions and 3,833 deletions.
4 changes: 2 additions & 2 deletions pkg/parser/document_processing_include_files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,7 @@ include::../../test/includes/chapter-a.adoc[]
source := `include::../../test/includes/tag-include-unclosed.adoc[tag=unclosed]`
expected := types.RawDocument{
Blocks: []interface{}{
types.BlankLine{},
// leading blanklines are ignored
types.Paragraph{
Lines: []interface{}{
types.RawLine{
Expand Down Expand Up @@ -1936,7 +1936,7 @@ include::../../test/includes/chapter-a.adoc[]
source := `include::../../test/includes/tag-include.adoc[tag=**;!*]` // includes all sections
expected := types.RawDocument{
Blocks: []interface{}{
types.BlankLine{},
// leading blanklines are ignored
types.Paragraph{
Lines: []interface{}{
types.RawLine{
Expand Down
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
Loading

0 comments on commit 921565a

Please sign in to comment.