From 9242df367ec97093dbfce62830db020ec53def11 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Sat, 9 Dec 2023 23:50:49 +0700 Subject: all: rewrite tests for ToHTML using [test.Data] --- document_test.go | 51 ------------------ testdata/document_tohtml_test.txt | 110 ++++++++++++++++++++++++++++++++++++++ testdata/html/header.adoc | 12 ----- testdata/html/header.exp.html | 34 ------------ testdata/html/preamble.adoc | 11 ---- testdata/html/preamble.exp.html | 44 --------------- 6 files changed, 110 insertions(+), 152 deletions(-) create mode 100644 testdata/document_tohtml_test.txt delete mode 100644 testdata/html/header.adoc delete mode 100644 testdata/html/header.exp.html delete mode 100644 testdata/html/preamble.adoc delete mode 100644 testdata/html/preamble.exp.html diff --git a/document_test.go b/document_test.go index 7fc692f..a6f60e7 100644 --- a/document_test.go +++ b/document_test.go @@ -4,7 +4,6 @@ package asciidoctor import ( - "bytes" "os" "testing" @@ -95,53 +94,3 @@ func TestParse_document_title(t *testing.T) { test.Assert(t, `String`, c.expString, got.Title.String()) } } - -func TestDocument_ToHTML(t *testing.T) { - type testCase struct { - name string - fileAdoc string - fileExpHTML string - } - - var ( - cases = []testCase{{ - name: `header`, - fileAdoc: `testdata/html/header.adoc`, - fileExpHTML: `testdata/html/header.exp.html`, - }, { - name: `preamble`, - fileAdoc: `testdata/html/preamble.adoc`, - fileExpHTML: `testdata/html/preamble.exp.html`, - }} - - c testCase - doc *Document - err error - got bytes.Buffer - exp []byte - ) - - for _, c = range cases { - doc, err = Open(c.fileAdoc) - if err != nil { - t.Fatal(err) - } - - // Since we cannot overwrite the asciidoctor output for - // generator, we override ourself. - doc.Attributes[MetaNameGenerator] = `Asciidoctor 2.0.18` - - got.Reset() - - err = doc.ToHTML(&got) - if err != nil { - t.Fatal(err) - } - - exp, err = os.ReadFile(c.fileExpHTML) - if err != nil { - t.Fatal(err) - } - test.Assert(t, c.name, string(exp), got.String()) - } -} diff --git a/testdata/document_tohtml_test.txt b/testdata/document_tohtml_test.txt new file mode 100644 index 0000000..7258a3e --- /dev/null +++ b/testdata/document_tohtml_test.txt @@ -0,0 +1,110 @@ +output_call: ToHTML + +>>> header += Title +John Doe +v1.0, 15 Dec 2022 +:description: Multiline \ +description \ +with backslash +:keywords: multiline, \ +key, \ +words +:last-update-label!: + +Document body. + +<<< header + + + + + + + + + + +Title + + + +
+
+

Document body.

+
+
+ + + + +>>> preamble += Title +John Doe +v1.0, 15 Dec 2022 +:last-update-label!: +:idprefix: + +This is preamble. + +== Section 2 + +Section 2 content. + +<<< preamble + + + + + + + + +Title + + + +
+
+
+
+

This is preamble.

+
+
+
+
+

Section 2

+
+
+

Section 2 content.

+
+
+
+
+ + + diff --git a/testdata/html/header.adoc b/testdata/html/header.adoc deleted file mode 100644 index d807033..0000000 --- a/testdata/html/header.adoc +++ /dev/null @@ -1,12 +0,0 @@ -= Title -John Doe -v1.0, 15 Dec 2022 -:description: Multiline \ -description \ -with backslash -:keywords: multiline, \ -key, \ -words -:last-update-label!: - -Document body. diff --git a/testdata/html/header.exp.html b/testdata/html/header.exp.html deleted file mode 100644 index 54ebd62..0000000 --- a/testdata/html/header.exp.html +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - -Title - - - -
-
-

Document body.

-
-
- - - \ No newline at end of file diff --git a/testdata/html/preamble.adoc b/testdata/html/preamble.adoc deleted file mode 100644 index 2eaec88..0000000 --- a/testdata/html/preamble.adoc +++ /dev/null @@ -1,11 +0,0 @@ -= Title -John Doe -v1.0, 15 Dec 2022 -:last-update-label!: -:idprefix: - -This is preamble. - -== Section 2 - -Section 2 content. diff --git a/testdata/html/preamble.exp.html b/testdata/html/preamble.exp.html deleted file mode 100644 index b4b5b23..0000000 --- a/testdata/html/preamble.exp.html +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - - - -Title - - - -
-
-
-
-

This is preamble.

-
-
-
-
-

Section 2

-
-
-

Section 2 content.

-
-
-
-
- - - \ No newline at end of file -- cgit v1.3