aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2023-12-09 23:50:49 +0700
committerShulhan <ms@kilabit.info>2023-12-09 23:56:48 +0700
commit9242df367ec97093dbfce62830db020ec53def11 (patch)
treed68b08fac6dd77130c1d759e8e548dfc9e2d0f3c
parentf016620361024bb3f5c9709bfdf1e48691439ad4 (diff)
downloadasciidoctor-go-9242df367ec97093dbfce62830db020ec53def11.tar.xz
all: rewrite tests for ToHTML using [test.Data]
-rw-r--r--document_test.go51
-rw-r--r--testdata/document_tohtml_test.txt110
-rw-r--r--testdata/html/header.adoc12
-rw-r--r--testdata/html/header.exp.html34
-rw-r--r--testdata/html/preamble.adoc11
-rw-r--r--testdata/html/preamble.exp.html44
6 files changed, 110 insertions, 152 deletions
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 <john@doe.tld>
+v1.0, 15 Dec 2022
+:description: Multiline \
+description \
+with backslash
+:keywords: multiline, \
+key, \
+words
+:last-update-label!:
+
+Document body.
+
+<<< header
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="UTF-8">
+<meta http-equiv="X-UA-Compatible" content="IE=edge">
+<meta name="viewport" content="width=device-width, initial-scale=1.0">
+<meta name="generator" content="asciidoctor-go 0.5.0">
+<meta name="description" content="Multiline description with backslash">
+<meta name="keywords" content="multiline, key, words">
+<meta name="author" content="John Doe">
+<title>Title</title>
+</head>
+<body class="article">
+<div id="header">
+<h1>Title</h1>
+<div class="details">
+<span id="author" class="author">John Doe</span><br>
+<span id="email" class="email"><a href="mailto:john@doe.tld">john@doe.tld</a></span><br>
+<span id="revnumber">version 1.0,</span>
+<span id="revdate">15 Dec 2022</span>
+</div>
+</div>
+<div id="content">
+<div class="paragraph">
+<p>Document body.</p>
+</div>
+</div>
+<div id="footer">
+<div id="footer-text">
+Version 1.0<br>
+</div>
+</div>
+</body>
+</html>
+
+>>> preamble
+= Title
+John Doe <john@doe.tld>
+v1.0, 15 Dec 2022
+:last-update-label!:
+:idprefix:
+
+This is preamble.
+
+== Section 2
+
+Section 2 content.
+
+<<< preamble
+<!DOCTYPE html>
+<html lang="en">
+<head>
+<meta charset="UTF-8">
+<meta http-equiv="X-UA-Compatible" content="IE=edge">
+<meta name="viewport" content="width=device-width, initial-scale=1.0">
+<meta name="generator" content="asciidoctor-go 0.5.0">
+<meta name="author" content="John Doe">
+<title>Title</title>
+</head>
+<body class="article">
+<div id="header">
+<h1>Title</h1>
+<div class="details">
+<span id="author" class="author">John Doe</span><br>
+<span id="email" class="email"><a href="mailto:john@doe.tld">john@doe.tld</a></span><br>
+<span id="revnumber">version 1.0,</span>
+<span id="revdate">15 Dec 2022</span>
+</div>
+</div>
+<div id="content">
+<div id="preamble">
+<div class="sectionbody">
+<div class="paragraph">
+<p>This is preamble.</p>
+</div>
+</div>
+</div>
+<div class="sect1">
+<h2 id="section_2">Section 2</h2>
+<div class="sectionbody">
+<div class="paragraph">
+<p>Section 2 content.</p>
+</div>
+</div>
+</div>
+</div>
+<div id="footer">
+<div id="footer-text">
+Version 1.0<br>
+</div>
+</div>
+</body>
+</html>
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 <john@doe.tld>
-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 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
-<meta charset="UTF-8">
-<meta http-equiv="X-UA-Compatible" content="IE=edge">
-<meta name="viewport" content="width=device-width, initial-scale=1.0">
-<meta name="generator" content="Asciidoctor 2.0.18">
-<meta name="description" content="Multiline description with backslash">
-<meta name="keywords" content="multiline, key, words">
-<meta name="author" content="John Doe">
-<title>Title</title>
-</head>
-<body class="article">
-<div id="header">
-<h1>Title</h1>
-<div class="details">
-<span id="author" class="author">John Doe</span><br>
-<span id="email" class="email"><a href="mailto:john@doe.tld">john@doe.tld</a></span><br>
-<span id="revnumber">version 1.0,</span>
-<span id="revdate">15 Dec 2022</span>
-</div>
-</div>
-<div id="content">
-<div class="paragraph">
-<p>Document body.</p>
-</div>
-</div>
-<div id="footer">
-<div id="footer-text">
-Version 1.0<br>
-</div>
-</div>
-</body>
-</html> \ 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 <john@doe.tld>
-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 @@
-<!DOCTYPE html>
-<html lang="en">
-<head>
-<meta charset="UTF-8">
-<meta http-equiv="X-UA-Compatible" content="IE=edge">
-<meta name="viewport" content="width=device-width, initial-scale=1.0">
-<meta name="generator" content="Asciidoctor 2.0.18">
-<meta name="author" content="John Doe">
-<title>Title</title>
-</head>
-<body class="article">
-<div id="header">
-<h1>Title</h1>
-<div class="details">
-<span id="author" class="author">John Doe</span><br>
-<span id="email" class="email"><a href="mailto:john@doe.tld">john@doe.tld</a></span><br>
-<span id="revnumber">version 1.0,</span>
-<span id="revdate">15 Dec 2022</span>
-</div>
-</div>
-<div id="content">
-<div id="preamble">
-<div class="sectionbody">
-<div class="paragraph">
-<p>This is preamble.</p>
-</div>
-</div>
-</div>
-<div class="sect1">
-<h2 id="section_2">Section 2</h2>
-<div class="sectionbody">
-<div class="paragraph">
-<p>Section 2 content.</p>
-</div>
-</div>
-</div>
-</div>
-<div id="footer">
-<div id="footer-text">
-Version 1.0<br>
-</div>
-</div>
-</body>
-</html> \ No newline at end of file