Skip to content

Commit

Permalink
fix(parser): rearranging lists with delimited blocks afterwards (#789)
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)

also, updates on dependencies via `go mod tidy`

Fixes #785

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon authored Oct 25, 2020
1 parent ad8fee6 commit d547fd0
Show file tree
Hide file tree
Showing 7 changed files with 1,062 additions and 197 deletions.
10 changes: 4 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@ require (
github.com/onsi/gomega v1.10.1
github.com/pkg/errors v0.9.1
github.com/sergi/go-diff v1.0.0
github.com/sirupsen/logrus v1.6.0
github.com/sirupsen/logrus v1.7.0
github.com/sozorogami/gover v0.0.0-20171022184752-b58185e213c5
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/cobra v1.1.1
github.com/stretchr/testify v1.6.1
golang.org/x/sys v0.0.0-20200602225109-6fdc65e7d980 // indirect
golang.org/x/tools v0.0.0-20200812195022-5ae4c3c160a0 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
golang.org/x/sys v0.0.0-20201009025420-dfb3f7c4e634 // indirect
golang.org/x/tools v0.0.0-20201013201025-64a9e34f3752 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/yaml.v2 v2.3.0
)
195 changes: 170 additions & 25 deletions go.sum

Large diffs are not rendered by default.

135 changes: 134 additions & 1 deletion pkg/parser/delimited_block_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,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 +355,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 d547fd0

Please sign in to comment.