-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocument_test.go
97 lines (85 loc) · 1.83 KB
/
document_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// SPDX-FileCopyrightText: 2020 M. Shulhan <[email protected]>
// SPDX-License-Identifier: GPL-3.0-or-later
package asciidoctor
import (
"os"
"testing"
"git.sr.ht/~shulhan/pakakeh.go/lib/test"
)
func TestOpen(t *testing.T) {
var (
doc *Document
fout *os.File
err error
)
doc, err = Open(`testdata/test.adoc`)
if err != nil {
t.Fatal(err)
}
// Since we cannot overwrite the asciidoctor output for
// generator, we override ourself.
doc.Attributes.Entry[DocAttrGenerator] = `Asciidoctor 2.0.18`
fout, err = os.OpenFile(`testdata/test.got.html`, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
t.Fatal(err)
}
err = doc.ToHTML(fout)
if err != nil {
t.Fatal(err)
}
}
func TestParse_document_title(t *testing.T) {
type testCase struct {
content string
expString string
exp DocumentTitle
}
var cases = []testCase{{
content: `= Main: sub`,
exp: DocumentTitle{
Main: `Main`,
Sub: `sub`,
sep: defTitleSeparator,
},
expString: `Main: sub`,
}, {
// Without space after separator
content: `= Main:sub`,
exp: DocumentTitle{
Main: `Main:sub`,
sep: defTitleSeparator,
},
expString: `Main:sub`,
}, {
// With multiple separator after separator
content: `= a: b: c`,
exp: DocumentTitle{
Main: `a: b`,
Sub: `c`,
sep: defTitleSeparator,
},
expString: `a: b: c`,
}, {
// With custom separator.
content: `
= Mainx sub
:title-separator: x`,
exp: DocumentTitle{
Main: `Main`,
Sub: `sub`,
sep: 'x',
},
expString: `Mainx sub`,
}}
var (
c testCase
got *Document
)
for _, c = range cases {
got = Parse([]byte(c.content))
test.Assert(t, `Main`, c.exp.Main, got.Title.Main)
test.Assert(t, `Sub`, c.exp.Sub, got.Title.Sub)
test.Assert(t, `sep`, c.exp.sep, got.Title.sep)
test.Assert(t, `String`, c.expString, got.Title.String())
}
}