Skip to content

Commit

Permalink
fix(parser): support comment between doc title and author
Browse files Browse the repository at this point in the history
support comments (single lines and blocks) before the author
and between the author and the revision

Fixes bytesparadise#481

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon committed Jan 25, 2020
1 parent cdccf6f commit 74d47a9
Show file tree
Hide file tree
Showing 3 changed files with 3,262 additions and 3,030 deletions.
198 changes: 198 additions & 0 deletions pkg/parser/document_attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,120 @@ Chameleon`

It("2 authors only", func() {
source := `= title
Kismet Rainbow Chameleon <[email protected]>; Lazarus het_Draeke <[email protected]>`
title := []interface{}{
types.StringElement{
Content: "title",
},
}
expected := types.Document{
Attributes: types.DocumentAttributes{},
ElementReferences: types.ElementReferences{
"_title": title,
},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
types.Section{
Level: 0,
Attributes: types.ElementAttributes{
types.AttrID: "_title",
types.AttrAuthors: []types.DocumentAuthor{
{
FullName: "Kismet Rainbow Chameleon ",
Email: "[email protected]",
},
{
FullName: "Lazarus het_Draeke ",
Email: "[email protected]",
},
},
},
Title: title,
Elements: []interface{}{},
},
},
}
Expect(source).To(BecomeDocument(expected))
})
})

Context("authors and comments", func() {

It("authors commented out", func() {
source := `= title
// Kismet Rainbow Chameleon <[email protected]>; Lazarus het_Draeke <[email protected]>`
title := []interface{}{
types.StringElement{
Content: "title",
},
}
expected := types.Document{
Attributes: types.DocumentAttributes{},
ElementReferences: types.ElementReferences{
"_title": title,
},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
types.Section{
Level: 0,
Attributes: types.ElementAttributes{
types.AttrID: "_title",
},
Title: title,
Elements: []interface{}{},
},
},
}
Expect(source).To(BecomeDocument(expected))
})

It("authors after a single comment line", func() {
source := `= title
// a comment
Kismet Rainbow Chameleon <[email protected]>; Lazarus het_Draeke <[email protected]>`
title := []interface{}{
types.StringElement{
Content: "title",
},
}
expected := types.Document{
Attributes: types.DocumentAttributes{},
ElementReferences: types.ElementReferences{
"_title": title,
},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
types.Section{
Level: 0,
Attributes: types.ElementAttributes{
types.AttrID: "_title",
types.AttrAuthors: []types.DocumentAuthor{
{
FullName: "Kismet Rainbow Chameleon ",
Email: "[email protected]",
},
{
FullName: "Lazarus het_Draeke ",
Email: "[email protected]",
},
},
},
Title: title,
Elements: []interface{}{},
},
},
}
Expect(source).To(BecomeDocument(expected))
})

It("authors after a comment block", func() {
source := `= title
////
a comment
////
Kismet Rainbow Chameleon <[email protected]>; Lazarus het_Draeke <[email protected]>`
title := []interface{}{
types.StringElement{
Expand Down Expand Up @@ -316,6 +430,90 @@ Kismet Rainbow Chameleon <[email protected]>; Lazarus het_Draeke <lazarus
Expect(source).To(BecomeDocument(expected))
})

It("full document revision with a comment before author", func() {
source := `= title
// a comment
john doe
v1.0, June 19, 2017: First incarnation`
title := []interface{}{
types.StringElement{
Content: "title",
},
}
expected := types.Document{
Attributes: types.DocumentAttributes{},
ElementReferences: types.ElementReferences{
"_title": title,
},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
types.Section{
Level: 0,
Attributes: types.ElementAttributes{
types.AttrID: "_title",
types.AttrAuthors: []types.DocumentAuthor{
{
FullName: "john doe",
Email: "",
},
},
types.AttrRevision: types.DocumentRevision{
Revnumber: "1.0",
Revdate: "June 19, 2017",
Revremark: "First incarnation",
},
},
Title: title,
Elements: []interface{}{},
},
},
}
Expect(source).To(BecomeDocument(expected))
})

It("full document revision with a comment before revision", func() {
source := `= title
john doe
// a comment
v1.0, June 19, 2017: First incarnation`
title := []interface{}{
types.StringElement{
Content: "title",
},
}
expected := types.Document{
Attributes: types.DocumentAttributes{},
ElementReferences: types.ElementReferences{
"_title": title,
},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
types.Section{
Level: 0,
Attributes: types.ElementAttributes{
types.AttrID: "_title",
types.AttrAuthors: []types.DocumentAuthor{
{
FullName: "john doe",
Email: "",
},
},
types.AttrRevision: types.DocumentRevision{
Revnumber: "1.0",
Revdate: "June 19, 2017",
Revremark: "First incarnation",
},
},
Title: title,
Elements: []interface{}{},
},
},
}
Expect(source).To(BecomeDocument(expected))
})

It("revision with revnumber and revdate only", func() {
source := `= title
john doe
Expand Down
Loading

0 comments on commit 74d47a9

Please sign in to comment.