1
|
|
|
import io |
2
|
|
|
from contextlib import redirect_stderr |
3
|
|
|
from unittest import TestCase |
4
|
|
|
|
5
|
|
|
from panflute import convert_text |
6
|
|
|
|
7
|
|
|
import pandoc_beamer_arrow |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
def conversion(markdown, fmt="markdown"): |
11
|
|
|
doc = convert_text(markdown, standalone=True) |
12
|
|
|
doc.format = fmt |
13
|
|
|
pandoc_beamer_arrow.main(doc) |
14
|
|
|
return doc |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
class NodeTest(TestCase): |
18
|
|
|
def test_simple(self): |
19
|
|
|
doc = conversion("[**abc**]{.beamer-arrow-node #id1}", fmt="beamer") |
20
|
|
|
text = convert_text( |
21
|
|
|
doc, |
22
|
|
|
input_format="panflute", |
23
|
|
|
output_format="latex", |
24
|
|
|
extra_args=["--wrap=none"], |
25
|
|
|
) |
26
|
|
|
self.assertEqual( |
27
|
|
|
text, r"\tikz[baseline]{{\node[anchor=base] (id1) {\textbf{abc}};}}" |
28
|
|
|
) |
29
|
|
|
|
30
|
|
|
def test_color(self): |
31
|
|
|
doc = conversion('[**abc**]{.beamer-arrow-node #id1 color="red"}', fmt="beamer") |
32
|
|
|
text = convert_text( |
33
|
|
|
doc, |
34
|
|
|
input_format="panflute", |
35
|
|
|
output_format="latex", |
36
|
|
|
extra_args=["--wrap=none"], |
37
|
|
|
) |
38
|
|
|
self.assertEqual( |
39
|
|
|
text, |
40
|
|
|
r"\tikz[baseline]{{\node[anchor=base,fill=red] (id1) {\textbf{abc}};}}", |
41
|
|
|
) |
42
|
|
|
|
43
|
|
|
def test_bad_color(self): |
44
|
|
|
stream = io.StringIO() |
45
|
|
|
with redirect_stderr(stream): |
46
|
|
|
doc = conversion( |
47
|
|
|
'[**abc**]{.beamer-arrow-node #id1 color="unknown"}', fmt="beamer" |
48
|
|
|
) |
49
|
|
|
text = convert_text( |
50
|
|
|
doc, |
51
|
|
|
input_format="panflute", |
52
|
|
|
output_format="latex", |
53
|
|
|
extra_args=["--wrap=none"], |
54
|
|
|
) |
55
|
|
|
self.assertEqual( |
56
|
|
|
text, r"\tikz[baseline]{{\node[anchor=base] (id1) {\textbf{abc}};}}" |
57
|
|
|
) |
58
|
|
|
self.assertEqual( |
59
|
|
|
stream.getvalue(), |
60
|
|
|
"pandoc-beamer-arrow: color 'unknown' is not correct\n", |
61
|
|
|
) |
62
|
|
|
|
63
|
|
|
def test_from(self): |
64
|
|
|
doc = conversion('[**abc**]{.beamer-arrow-node #id1 from="2"}', fmt="beamer") |
65
|
|
|
text = convert_text( |
66
|
|
|
doc, |
67
|
|
|
input_format="panflute", |
68
|
|
|
output_format="latex", |
69
|
|
|
extra_args=["--wrap=none"], |
70
|
|
|
) |
71
|
|
|
self.assertEqual( |
72
|
|
|
text, |
73
|
|
|
r"\tikz[baseline]{\only<2->{\node[anchor=base] (id1) {\textbf{abc}};}}", |
74
|
|
|
) |
75
|
|
|
|
76
|
|
|
def test_bad_from(self): |
77
|
|
|
stream = io.StringIO() |
78
|
|
|
with redirect_stderr(stream): |
79
|
|
|
doc = conversion( |
80
|
|
|
'[**abc**]{.beamer-arrow-node #id1 from="bad"}', fmt="beamer" |
81
|
|
|
) |
82
|
|
|
text = convert_text( |
83
|
|
|
doc, |
84
|
|
|
input_format="panflute", |
85
|
|
|
output_format="latex", |
86
|
|
|
extra_args=["--wrap=none"], |
87
|
|
|
) |
88
|
|
|
self.assertEqual( |
89
|
|
|
text, r"\tikz[baseline]{{\node[anchor=base] (id1) {\textbf{abc}};}}" |
90
|
|
|
) |
91
|
|
|
self.assertEqual( |
92
|
|
|
stream.getvalue(), |
93
|
|
|
"pandoc-beamer-arrow: from value 'bad' is not correct\n", |
94
|
|
|
) |
95
|
|
|
|
96
|
|
|
def test_to(self): |
97
|
|
|
doc = conversion('[**abc**]{.beamer-arrow-node #id1 to="2"}', fmt="beamer") |
98
|
|
|
text = convert_text( |
99
|
|
|
doc, |
100
|
|
|
input_format="panflute", |
101
|
|
|
output_format="latex", |
102
|
|
|
extra_args=["--wrap=none"], |
103
|
|
|
) |
104
|
|
|
self.assertEqual( |
105
|
|
|
text, |
106
|
|
|
r"\tikz[baseline]{\only<-2>{\node[anchor=base] (id1) {\textbf{abc}};}}", |
107
|
|
|
) |
108
|
|
|
|
109
|
|
|
def test_bad_to(self): |
110
|
|
|
stream = io.StringIO() |
111
|
|
|
with redirect_stderr(stream): |
112
|
|
|
doc = conversion( |
113
|
|
|
'[**abc**]{.beamer-arrow-node #id1 to="bad"}', fmt="beamer" |
114
|
|
|
) |
115
|
|
|
text = convert_text( |
116
|
|
|
doc, |
117
|
|
|
input_format="panflute", |
118
|
|
|
output_format="latex", |
119
|
|
|
extra_args=["--wrap=none"], |
120
|
|
|
) |
121
|
|
|
self.assertEqual( |
122
|
|
|
text, r"\tikz[baseline]{{\node[anchor=base] (id1) {\textbf{abc}};}}" |
123
|
|
|
) |
124
|
|
|
self.assertEqual( |
125
|
|
|
stream.getvalue(), |
126
|
|
|
"pandoc-beamer-arrow: to value 'bad' is not correct\n", |
127
|
|
|
) |
128
|
|
|
|
129
|
|
|
def test_incompatible_from_to(self): |
130
|
|
|
stream = io.StringIO() |
131
|
|
|
with redirect_stderr(stream): |
132
|
|
|
doc = conversion( |
133
|
|
|
'[**abc**]{.beamer-arrow-node #id1 from="2" to="1"}', fmt="beamer" |
134
|
|
|
) |
135
|
|
|
text = convert_text( |
136
|
|
|
doc, |
137
|
|
|
input_format="panflute", |
138
|
|
|
output_format="latex", |
139
|
|
|
extra_args=["--wrap=none"], |
140
|
|
|
) |
141
|
|
|
self.assertEqual( |
142
|
|
|
text, r"\tikz[baseline]{{\node[anchor=base] (id1) {\textbf{abc}};}}" |
143
|
|
|
) |
144
|
|
|
self.assertEqual( |
145
|
|
|
stream.getvalue(), |
146
|
|
|
"pandoc-beamer-arrow: from value '2' and to value '1' are incompatible\n", |
147
|
|
|
) |
148
|
|
|
|
149
|
|
|
|
150
|
|
|
class ArrowTest(TestCase): |
151
|
|
|
def test_simple(self): |
152
|
|
|
doc = conversion( |
153
|
|
|
'[**abc**]{.beamer-arrow-edge src="id1" dest="id2"}', fmt="beamer" |
154
|
|
|
) |
155
|
|
|
text = convert_text( |
156
|
|
|
doc, |
157
|
|
|
input_format="panflute", |
158
|
|
|
output_format="latex", |
159
|
|
|
extra_args=["--wrap=none"], |
160
|
|
|
) |
161
|
|
|
self.assertEqual( |
162
|
|
|
text, |
163
|
|
|
r"\begin{tikzpicture}" |
164
|
|
|
r"[overlay]\path[->] (id1) edge [] (id2);" |
165
|
|
|
r"\end{tikzpicture}", |
166
|
|
|
) |
167
|
|
|
|
168
|
|
|
def test_angle_src(self): |
169
|
|
|
doc = conversion( |
170
|
|
|
'[**abc**]{.beamer-arrow-edge src="id1" dest="id2" angle_src="90"}', |
171
|
|
|
fmt="beamer", |
172
|
|
|
) |
173
|
|
|
text = convert_text( |
174
|
|
|
doc, |
175
|
|
|
input_format="panflute", |
176
|
|
|
output_format="latex", |
177
|
|
|
extra_args=["--wrap=none"], |
178
|
|
|
) |
179
|
|
|
self.assertEqual( |
180
|
|
|
text, |
181
|
|
|
r"\begin{tikzpicture}" |
182
|
|
|
r"[overlay]\path[->] (id1) edge [out=90] (id2);" |
183
|
|
|
r"\end{tikzpicture}", |
184
|
|
|
) |
185
|
|
|
|
186
|
|
|
def test_bad_angle_src(self): |
187
|
|
|
stream = io.StringIO() |
188
|
|
|
with redirect_stderr(stream): |
189
|
|
|
doc = conversion( |
190
|
|
|
'[**abc**]{.beamer-arrow-edge src="id1" dest="id2" angle_src="bad"}', |
191
|
|
|
fmt="beamer", |
192
|
|
|
) |
193
|
|
|
text = convert_text( |
194
|
|
|
doc, |
195
|
|
|
input_format="panflute", |
196
|
|
|
output_format="latex", |
197
|
|
|
extra_args=["--wrap=none"], |
198
|
|
|
) |
199
|
|
|
self.assertEqual( |
200
|
|
|
text, |
201
|
|
|
r"\begin{tikzpicture}" |
202
|
|
|
r"[overlay]\path[->] (id1) edge [] (id2);" |
203
|
|
|
r"\end{tikzpicture}", |
204
|
|
|
) |
205
|
|
|
self.assertEqual( |
206
|
|
|
stream.getvalue(), |
207
|
|
|
"pandoc-beamer-arrow: angle_src 'bad' is not correct\n", |
208
|
|
|
) |
209
|
|
|
|
210
|
|
|
def test_angle_dest(self): |
211
|
|
|
doc = conversion( |
212
|
|
|
'[**abc**]{.beamer-arrow-edge src="id1" dest="id2" angle_dest="90"}', |
213
|
|
|
fmt="beamer", |
214
|
|
|
) |
215
|
|
|
text = convert_text( |
216
|
|
|
doc, |
217
|
|
|
input_format="panflute", |
218
|
|
|
output_format="latex", |
219
|
|
|
extra_args=["--wrap=none"], |
220
|
|
|
) |
221
|
|
|
self.assertEqual( |
222
|
|
|
text, |
223
|
|
|
r"\begin{tikzpicture}" |
224
|
|
|
r"[overlay]\path[->] (id1) edge [in=90] (id2);" |
225
|
|
|
r"\end{tikzpicture}", |
226
|
|
|
) |
227
|
|
|
|
228
|
|
|
def test_bad_angle_dest(self): |
229
|
|
|
stream = io.StringIO() |
230
|
|
|
with redirect_stderr(stream): |
231
|
|
|
doc = conversion( |
232
|
|
|
'[**abc**]{.beamer-arrow-edge src="id1" dest="id2" angle_dest="bad"}', |
233
|
|
|
fmt="beamer", |
234
|
|
|
) |
235
|
|
|
text = convert_text( |
236
|
|
|
doc, |
237
|
|
|
input_format="panflute", |
238
|
|
|
output_format="latex", |
239
|
|
|
extra_args=["--wrap=none"], |
240
|
|
|
) |
241
|
|
|
self.assertEqual( |
242
|
|
|
text, |
243
|
|
|
r"\begin{tikzpicture}" |
244
|
|
|
r"[overlay]\path[->] (id1) edge [] (id2);" |
245
|
|
|
r"\end{tikzpicture}", |
246
|
|
|
) |
247
|
|
|
self.assertEqual( |
248
|
|
|
stream.getvalue(), |
249
|
|
|
"pandoc-beamer-arrow: angle_dest 'bad' is not correct\n", |
250
|
|
|
) |
251
|
|
|
|
252
|
|
|
def test_color(self): |
253
|
|
|
doc = conversion( |
254
|
|
|
'[**abc**]{.beamer-arrow-edge src="id1" dest="id2" color="red"}', |
255
|
|
|
fmt="beamer", |
256
|
|
|
) |
257
|
|
|
text = convert_text( |
258
|
|
|
doc, |
259
|
|
|
input_format="panflute", |
260
|
|
|
output_format="latex", |
261
|
|
|
extra_args=["--wrap=none"], |
262
|
|
|
) |
263
|
|
|
self.assertEqual( |
264
|
|
|
text, |
265
|
|
|
r"\begin{tikzpicture}" |
266
|
|
|
r"[overlay]\path[->,red] (id1) edge [] (id2);" |
267
|
|
|
r"\end{tikzpicture}", |
268
|
|
|
) |
269
|
|
|
|
270
|
|
|
def test_linewidth(self): |
271
|
|
|
doc = conversion( |
272
|
|
|
'[**abc**]{.beamer-arrow-edge src="id1" dest="id2" linewidth="3"}', |
273
|
|
|
fmt="beamer", |
274
|
|
|
) |
275
|
|
|
text = convert_text( |
276
|
|
|
doc, |
277
|
|
|
input_format="panflute", |
278
|
|
|
output_format="latex", |
279
|
|
|
extra_args=["--wrap=none"], |
280
|
|
|
) |
281
|
|
|
self.assertEqual( |
282
|
|
|
text, |
283
|
|
|
r"\begin{tikzpicture}" |
284
|
|
|
r"[overlay]\path[->,line width=3pt] (id1) edge [] (id2);" |
285
|
|
|
r"\end{tikzpicture}", |
286
|
|
|
) |
287
|
|
|
|
288
|
|
|
def test_bad_linewidth(self): |
289
|
|
|
stream = io.StringIO() |
290
|
|
|
with redirect_stderr(stream): |
291
|
|
|
doc = conversion( |
292
|
|
|
'[**abc**]{.beamer-arrow-edge src="id1" dest="id2" linewidth="bad"}', |
293
|
|
|
fmt="beamer", |
294
|
|
|
) |
295
|
|
|
text = convert_text( |
296
|
|
|
doc, |
297
|
|
|
input_format="panflute", |
298
|
|
|
output_format="latex", |
299
|
|
|
extra_args=["--wrap=none"], |
300
|
|
|
) |
301
|
|
|
self.assertEqual( |
302
|
|
|
text, |
303
|
|
|
r"\begin{tikzpicture}" |
304
|
|
|
r"[overlay]\path[->] (id1) edge [] (id2);" |
305
|
|
|
r"\end{tikzpicture}", |
306
|
|
|
) |
307
|
|
|
self.assertEqual( |
308
|
|
|
stream.getvalue(), |
309
|
|
|
"pandoc-beamer-arrow: linewidth 'bad' is not correct\n", |
310
|
|
|
) |
311
|
|
|
|
312
|
|
|
def test_range(self): |
313
|
|
|
doc = conversion( |
314
|
|
|
'[**abc**]{.beamer-arrow-edge src="id1" dest="id2" to="3" from="2"}', |
315
|
|
|
fmt="beamer", |
316
|
|
|
) |
317
|
|
|
text = convert_text( |
318
|
|
|
doc, |
319
|
|
|
input_format="panflute", |
320
|
|
|
output_format="latex", |
321
|
|
|
extra_args=["--wrap=none"], |
322
|
|
|
) |
323
|
|
|
self.assertEqual( |
324
|
|
|
text, |
325
|
|
|
r"\begin{tikzpicture}[overlay]\path[->]<2-3> (id1) edge [] (id2);\end{" |
326
|
|
|
r"tikzpicture}", |
327
|
|
|
) |
328
|
|
|
|