Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(parser): rearranging lists with delimited blocks afterwards #789

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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