Skip to content

Commit

Permalink
fix(parser): rearranging lists with delimited blocks afterwards
Browse files Browse the repository at this point in the history
refactor the logic to rearrange list items in list, using
a 'listArranger' type (until we have a better name)

Fixes #785

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon committed Oct 25, 2020
1 parent ad8fee6 commit ece5702
Show file tree
Hide file tree
Showing 6 changed files with 895 additions and 166 deletions.
137 changes: 136 additions & 1 deletion pkg/parser/delimited_block_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
. "github.com/onsi/gomega" //nolint golint
)

const cookies = "life"

var _ = Describe("source blocks", func() {

Context("draft documents", func() {
Expand Down Expand Up @@ -143,12 +145,77 @@ type Foo struct{
}
Expect(ParseDraftDocument(source)).To(MatchDraftDocument(expected))
})

It("with callout and admonition block afterwards", func() {
source := `[source]
----
const cookies = "cookies" <1>
----
<1> a constant
[NOTE]
====
a note
====`

expected := types.DraftDocument{
Elements: []interface{}{
types.ListingBlock{
Attributes: types.Attributes{
types.AttrBlockKind: types.Source,
},
Lines: [][]interface{}{
{
types.StringElement{
Content: `const cookies = "cookies" `,
},
types.Callout{
Ref: 1,
},
},
},
},
types.CalloutListItem{
Ref: 1,
Elements: []interface{}{
types.Paragraph{
Lines: [][]interface{}{
{
types.StringElement{
Content: "a constant",
},
},
},
},
},
},
types.BlankLine{},
types.ExampleBlock{
Attributes: types.Attributes{
types.AttrAdmonitionKind: types.Note,
},
Elements: []interface{}{
types.Paragraph{
Lines: [][]interface{}{
{
types.StringElement{
Content: "a note",
},
},
},
},
},
},
},
}
Expect(ParseDraftDocument(source)).To(MatchDraftDocument(expected))
})
})
})

Context("final documents", func() {

Context("source block", func() {
Context("delimited block", func() {

It("with source attribute only", func() {
source := `[source]
Expand Down Expand Up @@ -290,6 +357,74 @@ end
}
Expect(ParseDocument(source)).To(MatchDocument(expected))
})

It("with callout and admonition block afterwards", func() {
source := `[source]
----
const cookies = "cookies" <1>
----
<1> a constant
[NOTE]
====
a note
====`

expected := types.Document{
Elements: []interface{}{
types.ListingBlock{
Attributes: types.Attributes{
types.AttrBlockKind: types.Source,
},
Lines: [][]interface{}{
{
types.StringElement{
Content: `const cookies = "cookies" `,
},
types.Callout{
Ref: 1,
},
},
},
},
types.CalloutList{
Items: []types.CalloutListItem{
{
Ref: 1,
Elements: []interface{}{
types.Paragraph{
Lines: [][]interface{}{
{
types.StringElement{
Content: "a constant",
},
},
},
},
},
},
},
},
types.ExampleBlock{
Attributes: types.Attributes{
types.AttrAdmonitionKind: types.Note,
},
Elements: []interface{}{
types.Paragraph{
Lines: [][]interface{}{
{
types.StringElement{
Content: "a note",
},
},
},
},
},
},
},
}
Expect(ParseDocument(source)).To(MatchDocument(expected))
})
})
})
})
Loading

0 comments on commit ece5702

Please sign in to comment.