Skip to content

Commit

Permalink
test(parser): verify configuration attributes
Browse files Browse the repository at this point in the history
Adding test to verify that custom attributes
passed in the configuration work as expected

Updates #509

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon committed Mar 18, 2020
1 parent 1b574d6 commit f35ca56
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 10 deletions.
13 changes: 13 additions & 0 deletions libasciidoc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,19 @@ a paragraph with _italic content_`
</div>`
Expect(RenderHTML5Body(source, configuration.WithFilename("tmp/foo.adoc"))).To(Equal(expectedContent))
})

It("document with custom icon attribute", func() {
// given
attrs := map[string]string{
"icons": "font",
"source-highlighter": "pygments",
}
source := `{icons}`
expected := `<div class="paragraph">
<p>font</p>
</div>`
Expect(RenderHTML5Body(source, configuration.WithAttributes(attrs))).To(Equal(expected))
})
})

Context("complete Document ", func() {
Expand Down
30 changes: 30 additions & 0 deletions pkg/parser/document_attributes_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package parser_test

import (
"github.com/bytesparadise/libasciidoc/pkg/configuration"
"github.com/bytesparadise/libasciidoc/pkg/types"
. "github.com/bytesparadise/libasciidoc/testsupport"

Expand Down Expand Up @@ -1272,4 +1273,33 @@ a paragraph written by {author}.`
Expect(ParseDocument(source)).To(Equal(expected))
})
})

Context("document with attribute overrides", func() {

It("custom icon attribute", func() {
// given
attrs := map[string]string{
"icons": "font",
"source-highlighter": "pygments",
}
source := `{icons}`
expected := types.Document{
Attributes: types.DocumentAttributes{},
ElementReferences: types.ElementReferences{},
Footnotes: types.Footnotes{},
FootnoteReferences: types.FootnoteReferences{},
Elements: []interface{}{
types.Paragraph{
Attributes: types.ElementAttributes{},
Lines: [][]interface{}{
{
types.StringElement{Content: "font"},
},
},
},
},
}
Expect(ParseDocument(source, configuration.WithAttributes(attrs))).To(Equal(expected))
})
})
})
4 changes: 1 addition & 3 deletions pkg/types/document_attributes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,4 @@ var _ = DescribeTable("document attribute overrides with default",
Entry("foo", "foo", "cheesecake"),
Entry("!bar", "bar", "default"), // entry is reset, default is returned
Entry("baz", "baz", ""), // entry exists but its value is empty
)

//
)
4 changes: 2 additions & 2 deletions testsupport/parse_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

// ParseDocument parses the actual value into a Document
func ParseDocument(actual string) (types.Document, error) {
func ParseDocument(actual string, settings ...configuration.Setting) (types.Document, error) {
r := strings.NewReader(actual)
return parser.ParseDocument(r, configuration.NewConfiguration()) //, parser.Debug(true))
return parser.ParseDocument(r, configuration.NewConfiguration(settings...))
}
7 changes: 2 additions & 5 deletions testsupport/render_html5.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ import (
)

// RenderHTML5Body renders the HTML body using the given source
func RenderHTML5Body(actual string, options ...configuration.Setting) (string, error) {
config := configuration.NewConfiguration()
for _, set := range options {
set(&config)
}
func RenderHTML5Body(actual string, settings ...configuration.Setting) (string, error) {
config := configuration.NewConfiguration(settings...)
contentReader := strings.NewReader(actual)
resultWriter := bytes.NewBuffer(nil)
_, err := libasciidoc.ConvertToHTML(contentReader, resultWriter, config)
Expand Down

0 comments on commit f35ca56

Please sign in to comment.