-
Notifications
You must be signed in to change notification settings - Fork 0
/
inline_parser_test.go
184 lines (150 loc) · 3.64 KB
/
inline_parser_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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// SPDX-FileCopyrightText: 2020 M. Shulhan <[email protected]>
// SPDX-License-Identifier: GPL-3.0-or-later
package asciidoctor
import (
"bytes"
"fmt"
"strings"
"testing"
"git.sr.ht/~shulhan/pakakeh.go/lib/test"
)
func TestInlineParser(t *testing.T) {
var (
_testDoc = &Document{
Attributes: DocumentAttribute{
Entry: map[string]string{
`x`: `https://kilabit.info`,
},
},
anchors: map[string]*anchor{
`x`: &anchor{
label: `X y`,
},
},
titleID: map[string]string{
`X y`: `x`,
},
}
buf bytes.Buffer
tdata *test.Data
container *element
err error
name string
lineNum string
vbytes []byte
exps [][]byte
lines [][]byte
x int
)
tdata, err = test.LoadData(`testdata/inline_parser/inline_parser_test.txt`)
if err != nil {
t.Fatal(err)
}
for name, vbytes = range tdata.Input {
t.Run(name, func(t *testing.T) {
lines = bytes.Split(vbytes, []byte("\n"))
exps = bytes.Split(tdata.Output[name], []byte("\n"))
for x, vbytes = range lines {
buf.Reset()
container = parseInlineMarkup(_testDoc, vbytes)
container.toHTML(_testDoc, &buf)
lineNum = fmt.Sprintf("#%d", x)
test.Assert(t, lineNum, string(exps[x]), buf.String())
}
})
}
}
func TestInlineParser_parseInlineID_isForToC(t *testing.T) {
type testCase struct {
content string
exp string
}
var _testDoc = &Document{
anchors: make(map[string]*anchor),
titleID: make(map[string]string),
isForToC: true,
}
var cases = []testCase{{
content: `[[A]] B`,
exp: ` B`,
}}
var (
buf bytes.Buffer
c testCase
container *element
got string
)
for _, c = range cases {
buf.Reset()
container = parseInlineMarkup(_testDoc, []byte(c.content))
container.toHTML(_testDoc, &buf)
got = buf.String()
test.Assert(t, c.content, c.exp, got)
}
}
func TestInlineParser_macro_footnote(t *testing.T) {
var (
testFiles = []string{
`testdata/inline_parser/macro_footnote_test.txt`,
`testdata/inline_parser/macro_footnote_externalized_test.txt`,
}
testFile string
got bytes.Buffer
tdata *test.Data
doc *Document
exp []byte
err error
)
for _, testFile = range testFiles {
tdata, err = test.LoadData(testFile)
if err != nil {
t.Fatalf(`%s: %s`, testFile, err)
}
doc = Parse(tdata.Input[`input.adoc`])
err = doc.ToHTMLEmbedded(&got)
if err != nil {
t.Fatalf(`%s: %s`, testFile, err)
}
exp = tdata.Output[`output.html`]
test.Assert(t, testFile, string(exp), got.String())
got.Reset()
}
}
func TestInlineParser_macro_pass(t *testing.T) {
var (
testFiles = []string{
`testdata/inline_parser/macro_pass_none_test.txt`,
`testdata/inline_parser/macro_pass_c_test.txt`,
`testdata/inline_parser/macro_pass_q_test.txt`,
`testdata/inline_parser/macro_pass_a_test.txt`,
`testdata/inline_parser/macro_pass_r_test.txt`,
`testdata/inline_parser/macro_pass_m_test.txt`,
}
testFile string
inputName string
outputName string
got bytes.Buffer
tdata *test.Data
doc *Document
exp []byte
err error
)
for _, testFile = range testFiles {
tdata, err = test.LoadData(testFile)
if err != nil {
t.Fatalf(`%s: %s`, testFile, err)
}
for inputName = range tdata.Input {
t.Logf(`%s: %s`, testFile, inputName)
outputName = strings.Replace(inputName, `.adoc`, `.html`, 1)
doc = Parse(tdata.Input[inputName])
got.Reset()
err = doc.ToHTMLEmbedded(&got)
if err != nil {
t.Fatalf(`%s: %s`, inputName, err)
}
exp = tdata.Output[outputName]
test.Assert(t, inputName, string(exp), got.String())
}
}
}