Skip to content

Commit

Permalink
refactor(parser): simplify grammar rules for list elements (#1033)
Browse files Browse the repository at this point in the history
Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
  • Loading branch information
xcoulon authored Jun 3, 2022
1 parent dbd31ea commit cd41d73
Show file tree
Hide file tree
Showing 4 changed files with 51,232 additions and 62,323 deletions.
130 changes: 130 additions & 0 deletions pkg/parser/labeled_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,45 @@ a description`
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

It("with 2 descritptions as single line comment after blanklines", func() {
source := `term 1::
// a comment
term 2::
// another comment`

expected := &types.Document{
Elements: []interface{}{
&types.List{
Kind: types.LabeledListKind,
Elements: []types.ListElement{
&types.LabeledListElement{
Style: types.DoubleColons,
Term: []interface{}{
&types.StringElement{
Content: "term 1",
},
},
},
&types.LabeledListElement{
Style: types.DoubleColons,
Term: []interface{}{
&types.StringElement{
Content: "term 2",
},
},
},
},
},
},
}
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

It("with descritption as comment block attached", func() {
source := `term::
////
Expand All @@ -1442,6 +1481,49 @@ a comment
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

It("distinct lists with descritption as comment block attached", func() {
source := `term 1::
////
a comment
////
term 2::
////
another comment
////`

expected := &types.Document{
Elements: []interface{}{
&types.List{
Kind: types.LabeledListKind,
Elements: []types.ListElement{
&types.LabeledListElement{
Style: types.DoubleColons,
Term: []interface{}{
&types.StringElement{
Content: "term 1",
},
},
},
},
},
&types.List{
Kind: types.LabeledListKind,
Elements: []types.ListElement{
&types.LabeledListElement{
Style: types.DoubleColons,
Term: []interface{}{
&types.StringElement{
Content: "term 2",
},
},
},
},
},
},
}
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

It("with descritption as comment block after blanklines", func() {
source := `term::
Expand Down Expand Up @@ -1470,6 +1552,54 @@ a comment
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

It("distinct lists with descritption as comment block after blanklines", func() {
source := `term 1::
////
a comment
////
term 2::
////
a comment
////`

expected := &types.Document{
Elements: []interface{}{
&types.List{
Kind: types.LabeledListKind,
Elements: []types.ListElement{
&types.LabeledListElement{
Style: types.DoubleColons,
Term: []interface{}{
&types.StringElement{
Content: "term 1",
},
},
},
},
},
&types.List{
Kind: types.LabeledListKind,
Elements: []types.ListElement{
&types.LabeledListElement{
Style: types.DoubleColons,
Term: []interface{}{
&types.StringElement{
Content: "term 2",
},
},
},
},
},
},
}
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

})

})
Loading

0 comments on commit cd41d73

Please sign in to comment.