Skip to content

Commit

Permalink
test(compat): verify that 'demo.adoc' renders as expected (#961)
Browse files Browse the repository at this point in the history
Also, move all docs in `test/fixtures/pending` into
`test/fixtures/supported` since they all pass now! (and rename
dir to `test/compat`)
Also, refactor (X)HTML matchers to support files and improve
support for templates

Fixes #960

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon authored Mar 3, 2022
1 parent ada72a8 commit 8e3016b
Show file tree
Hide file tree
Showing 57 changed files with 2,029 additions and 804 deletions.
325 changes: 103 additions & 222 deletions libasciidoc_test.go

Large diffs are not rendered by default.

99 changes: 74 additions & 25 deletions pkg/renderer/sgml/html5/document_details_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ v1.0, March 22, 2020: Containment
{author} wrote this doc on {revdate}.
`
expected := `<!DOCTYPE html>
expectedTmpl := `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
Expand Down Expand Up @@ -51,22 +51,30 @@ v1.0, March 22, 2020: Containment
<div id="footer">
<div id="footer-text">
Version 1.0<br>
Last updated {{.LastUpdated}}
Last updated {{ .LastUpdated }}
</div>
</div>
</body>
</html>
`
now := time.Now()
Expect(RenderHTML(source, configuration.WithHeaderFooter(true), configuration.WithLastUpdated(now))).To(MatchHTMLTemplate(expected, now))
Expect(RenderHTML(source,
configuration.WithHeaderFooter(true),
configuration.WithLastUpdated(now),
)).To(MatchHTMLTemplate(expectedTmpl,
struct {
LastUpdated string
}{
LastUpdated: now.Format(configuration.LastUpdatedFormat),
}))
})

It("header with 2 authors and no revision", func() {
source := `= Document Title
John Foo Doe <[email protected]>; Jane Doe <[email protected]>`
// top-level section is not rendered per-say,
// but the section will be used to set the HTML page's <title> element
expected := `<!DOCTYPE html>
expectedTmpl := `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
Expand All @@ -90,23 +98,30 @@ John Foo Doe <[email protected]>; Jane Doe <[email protected]>`
</div>
<div id="footer">
<div id="footer-text">
Last updated {{.LastUpdated}}
Last updated {{ .LastUpdated }}
</div>
</div>
</body>
</html>
`
now := time.Now()
Expect(RenderHTML(source, configuration.WithHeaderFooter(true), configuration.WithLastUpdated(now))).
To(MatchHTMLTemplate(expected, now))
Expect(RenderHTML(source,
configuration.WithHeaderFooter(true),
configuration.WithLastUpdated(now),
)).To(MatchHTMLTemplate(expectedTmpl,
struct {
LastUpdated string
}{
LastUpdated: now.Format(configuration.LastUpdatedFormat),
}))
})

It("header with description", func() {
source := `= Document Title
:description: a description
some content`
expected := `<!DOCTYPE html>
expectedTmpl := `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
Expand All @@ -127,15 +142,22 @@ some content`
</div>
<div id="footer">
<div id="footer-text">
Last updated {{.LastUpdated}}
Last updated {{ .LastUpdated }}
</div>
</div>
</body>
</html>
`
now := time.Now()
Expect(RenderHTML(source, configuration.WithHeaderFooter(true), configuration.WithLastUpdated(now))).
To(MatchHTMLTemplate(expected, now))
Expect(RenderHTML(source,
configuration.WithHeaderFooter(true),
configuration.WithLastUpdated(now),
)).To(MatchHTMLTemplate(expectedTmpl,
struct {
LastUpdated string
}{
LastUpdated: now.Format(configuration.LastUpdatedFormat),
}))
})

It("header with sotf-wrapped description", func() {
Expand All @@ -148,7 +170,7 @@ Last updated {{.LastUpdated}}
{description}`

expected := `<!DOCTYPE html>
expectedTmpl := `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
Expand All @@ -173,15 +195,22 @@ Last updated {{.LastUpdated}}
</div>
<div id="footer">
<div id="footer-text">
Last updated {{.LastUpdated}}
Last updated {{ .LastUpdated }}
</div>
</div>
</body>
</html>
`
now := time.Now()
Expect(RenderHTML(source, configuration.WithHeaderFooter(true), configuration.WithLastUpdated(now))).
To(MatchHTMLTemplate(expected, now))
Expect(RenderHTML(source,
configuration.WithHeaderFooter(true),
configuration.WithLastUpdated(now),
)).To(MatchHTMLTemplate(expectedTmpl,
struct {
LastUpdated string
}{
LastUpdated: now.Format(configuration.LastUpdatedFormat),
}))
})
})

Expand All @@ -193,7 +222,7 @@ Last updated {{.LastUpdated}}
source := `= Document Title
a paragraph`
expected := `<!DOCTYPE html>
expectedTmpl := `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
Expand All @@ -213,7 +242,7 @@ a paragraph`
</div>
<div id="footer">
<div id="footer-text">
Last updated {{.LastUpdated}}
Last updated {{ .LastUpdated }}
</div>
</div>
</body>
Expand All @@ -223,14 +252,19 @@ Last updated {{.LastUpdated}}
configuration.WithHeaderFooter(true),
configuration.WithLastUpdated(now),
configuration.WithAttributes(map[string]interface{}{}),
)).To(MatchHTMLTemplate(expected, now))
)).To(MatchHTMLTemplate(expectedTmpl,
struct {
LastUpdated string
}{
LastUpdated: now.Format(configuration.LastUpdatedFormat),
}))
})

It("with header and without footer", func() {
source := `= Document Title
a paragraph`
expected := `<!DOCTYPE html>
expectedTmpl := `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
Expand All @@ -257,14 +291,19 @@ a paragraph`
configuration.WithAttributes(map[string]interface{}{
types.AttrNoFooter: "",
}),
)).To(MatchHTMLTemplate(expected, now))
)).To(MatchHTMLTemplate(expectedTmpl,
struct {
LastUpdated string
}{
LastUpdated: now.Format(configuration.LastUpdatedFormat),
}))
})

It("without header and with footer", func() {
source := `= Document Title
a paragraph`
expected := `<!DOCTYPE html>
expectedTmpl := `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
Expand All @@ -281,7 +320,7 @@ a paragraph`
</div>
<div id="footer">
<div id="footer-text">
Last updated {{.LastUpdated}}
Last updated {{ .LastUpdated }}
</div>
</div>
</body>
Expand All @@ -293,14 +332,19 @@ Last updated {{.LastUpdated}}
configuration.WithAttributes(map[string]interface{}{
types.AttrNoHeader: "",
}),
)).To(MatchHTMLTemplate(expected, now))
)).To(MatchHTMLTemplate(expectedTmpl,
struct {
LastUpdated string
}{
LastUpdated: now.Format(configuration.LastUpdatedFormat),
}))
})

It("without header and without footer", func() {
source := `= Document Title
a paragraph`
expected := `<!DOCTYPE html>
expectedTmpl := `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
Expand All @@ -325,7 +369,12 @@ a paragraph`
types.AttrNoHeader: "",
types.AttrNoFooter: "",
}),
)).To(MatchHTMLTemplate(expected, now))
)).To(MatchHTMLTemplate(expectedTmpl,
struct {
LastUpdated string
}{
LastUpdated: now.Format(configuration.LastUpdatedFormat),
}))
})

})
Expand Down
25 changes: 15 additions & 10 deletions pkg/renderer/sgml/html5/file_inclusion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ var _ = Describe("file inclusions", func() {
</div>
</div>
`
Expect(RenderHTML(source, configuration.WithLastUpdated(lastUpdated))).To(Equal(expected))
Expect(DocumentMetadata(source, lastUpdated)).To(Equal(types.Metadata{

output, metadata, err := RenderHTMLWithMetadata(source,
configuration.WithLastUpdated(lastUpdated),
)
Expect(err).NotTo(HaveOccurred())
Expect(output).To(MatchHTML(expected))
Expect(metadata).To(MatchMetadata(types.Metadata{
Title: "",
LastUpdated: lastUpdated.Format(configuration.LastUpdatedFormat),
TableOfContents: &types.TableOfContents{
Expand Down Expand Up @@ -68,7 +73,9 @@ var _ = Describe("file inclusions", func() {
</div>
</div>
`
Expect(RenderHTML(source, configuration.WithFilename("tmp/foo.adoc"))).To(Equal(expected))
Expect(RenderHTML(source,
configuration.WithFilename("tmp/foo.adoc"),
)).To(MatchHTML(expected))
// verify no error/warning in logs
Expect(logs).ToNot(ContainAnyMessageWithLevels(log.ErrorLevel, log.WarnLevel))
})
Expand All @@ -85,7 +92,7 @@ var _ = Describe("file inclusions", func() {
</div>
</div>
`
Expect(RenderHTML(source)).To(Equal(expected))
Expect(RenderHTML(source)).To(MatchHTML(expected))
})

It("should include grandchild content with absolute offset", func() {
Expand All @@ -102,7 +109,7 @@ var _ = Describe("file inclusions", func() {
</div>
</div>
`
Expect(RenderHTML(source)).To(Equal(expected))
Expect(RenderHTML(source)).To(MatchHTML(expected))
})

It("should include child and grandchild content with relative level offset", func() {
Expand Down Expand Up @@ -143,7 +150,7 @@ var _ = Describe("file inclusions", func() {
</div>
</div>
`
Expect(RenderHTML(source)).To(Equal(expected))
Expect(RenderHTML(source)).To(MatchHTML(expected))
})

It("should include child and grandchild content with relative then absolute level offset", func() {
Expand Down Expand Up @@ -184,7 +191,7 @@ var _ = Describe("file inclusions", func() {
</div>
</div>
`
Expect(RenderHTML(source)).To(Equal(expected))
Expect(RenderHTML(source)).To(MatchHTML(expected))
})

It("include adoc file with leveloffset attribute", func() {
Expand Down Expand Up @@ -414,9 +421,7 @@ ____`
</blockquote>
</div>
`
result, err := RenderHTML(source)
Expect(err).NotTo(HaveOccurred())
Expect(result).To(MatchHTML(expected))
Expect(RenderHTML(source)).To(MatchHTML(expected))
})

It("should include adoc file within verse block", func() {
Expand Down
Loading

0 comments on commit 8e3016b

Please sign in to comment.