1 | # This Python file uses the following encoding: utf-8 |
||
2 | from unittest import TestCase |
||
3 | from pandocfilters import Div, Str, RawBlock |
||
4 | |||
5 | import json |
||
6 | |||
7 | import pandoc_latex_environment |
||
8 | |||
9 | def init(): |
||
10 | if hasattr(pandoc_latex_environment.getDefined, 'value'): |
||
11 | delattr(pandoc_latex_environment.getDefined, 'value') |
||
12 | |||
13 | View Code Duplication | def test_div(): |
|
0 ignored issues
–
show
Duplication
introduced
by
![]() |
|||
14 | init() |
||
15 | |||
16 | meta = { |
||
17 | 'pandoc-latex-environment': { |
||
18 | 'c': { |
||
19 | 'test': { |
||
20 | 'c': [ |
||
21 | { |
||
22 | 'c': [ |
||
23 | { |
||
24 | 'c': 'class1', |
||
25 | 't': 'Str' |
||
26 | } |
||
27 | ], |
||
28 | 't': 'MetaInlines' |
||
29 | }, |
||
30 | { |
||
31 | 'c': [ |
||
32 | { |
||
33 | 'c': 'class2', |
||
34 | 't': 'Str' |
||
35 | } |
||
36 | ], |
||
37 | 't': 'MetaInlines' |
||
38 | } |
||
39 | ], |
||
40 | 't': 'MetaList' |
||
41 | } |
||
42 | }, |
||
43 | 't': 'MetaMap' |
||
44 | } |
||
45 | } |
||
46 | |||
47 | src = json.loads(json.dumps(Div( |
||
48 | [ |
||
49 | '', |
||
50 | [ |
||
51 | 'class1', |
||
52 | 'class2' |
||
53 | ], |
||
54 | [] |
||
55 | ], |
||
56 | [ |
||
57 | { |
||
58 | 'c': [ |
||
59 | { |
||
60 | 'c': 'content', |
||
61 | 't': 'Str' |
||
62 | } |
||
63 | ], |
||
64 | 't': 'Plain' |
||
65 | } |
||
66 | ] |
||
67 | ))) |
||
68 | dest = json.loads(json.dumps(Div( |
||
69 | [ |
||
70 | '', |
||
71 | [ |
||
72 | 'class1', |
||
73 | 'class2' |
||
74 | ], |
||
75 | [] |
||
76 | ], |
||
77 | [ |
||
78 | { |
||
79 | 'c': [ |
||
80 | 'tex', |
||
81 | '\\begin{test}' |
||
82 | ], |
||
83 | 't': 'RawBlock' |
||
84 | }, |
||
85 | { |
||
86 | 'c': [ |
||
87 | { |
||
88 | 'c': 'content', |
||
89 | 't': 'Str' |
||
90 | } |
||
91 | ], |
||
92 | 't': 'Plain' |
||
93 | }, |
||
94 | { |
||
95 | 'c': [ |
||
96 | 'tex', |
||
97 | '\\end{test}' |
||
98 | ], |
||
99 | 't': 'RawBlock' |
||
100 | } |
||
101 | ] |
||
102 | ))) |
||
103 | |||
104 | pandoc_latex_environment.environment(src['t'], src['c'], 'latex', meta) |
||
105 | |||
106 | assert json.loads(json.dumps(src)) == dest |
||
107 | |||
108 | View Code Duplication | def test_empty(): |
|
0 ignored issues
–
show
|
|||
109 | init() |
||
110 | |||
111 | meta = { |
||
112 | 'pandoc-latex-environment': { |
||
113 | 'c': { |
||
114 | 'test': { |
||
115 | 'c': [ |
||
116 | { |
||
117 | 'c': [ |
||
118 | { |
||
119 | 'c': 'class1', |
||
120 | 't': 'Str' |
||
121 | } |
||
122 | ], |
||
123 | 't': 'MetaInlines' |
||
124 | }, |
||
125 | { |
||
126 | 'c': [ |
||
127 | { |
||
128 | 'c': 'class2', |
||
129 | 't': 'Str' |
||
130 | } |
||
131 | ], |
||
132 | 't': 'MetaInlines' |
||
133 | } |
||
134 | ], |
||
135 | 't': 'MetaList' |
||
136 | } |
||
137 | }, |
||
138 | 't': 'MetaMap' |
||
139 | } |
||
140 | } |
||
141 | |||
142 | src = json.loads(json.dumps(Div( |
||
143 | [ |
||
144 | '', |
||
145 | [], |
||
146 | [] |
||
147 | ], |
||
148 | [ |
||
149 | { |
||
150 | 'c': [ |
||
151 | { |
||
152 | 'c': 'content', |
||
153 | 't': 'Str' |
||
154 | } |
||
155 | ], |
||
156 | 't': 'Plain' |
||
157 | } |
||
158 | ] |
||
159 | ))) |
||
160 | dest = json.loads(json.dumps(Div( |
||
161 | [ |
||
162 | '', |
||
163 | [], |
||
164 | [] |
||
165 | ], |
||
166 | [ |
||
167 | { |
||
168 | 'c': [ |
||
169 | { |
||
170 | 'c': 'content', |
||
171 | 't': 'Str' |
||
172 | } |
||
173 | ], |
||
174 | 't': 'Plain' |
||
175 | } |
||
176 | ] |
||
177 | ))) |
||
178 | |||
179 | pandoc_latex_environment.environment(src['t'], src['c'], 'latex', meta) |
||
180 | |||
181 | assert json.loads(json.dumps(src)) == dest |
||
182 | |||
183 | |||
184 | View Code Duplication | def test_div_with_id(): |
|
0 ignored issues
–
show
|
|||
185 | init() |
||
186 | |||
187 | meta = { |
||
188 | 'pandoc-latex-environment': { |
||
189 | 'c': { |
||
190 | 'test': { |
||
191 | 'c': [ |
||
192 | { |
||
193 | 'c': [ |
||
194 | { |
||
195 | 'c': 'class1', |
||
196 | 't': 'Str' |
||
197 | } |
||
198 | ], |
||
199 | 't': 'MetaInlines' |
||
200 | }, |
||
201 | { |
||
202 | 'c': [ |
||
203 | { |
||
204 | 'c': 'class2', |
||
205 | 't': 'Str' |
||
206 | } |
||
207 | ], |
||
208 | 't': 'MetaInlines' |
||
209 | } |
||
210 | ], |
||
211 | 't': 'MetaList' |
||
212 | } |
||
213 | }, |
||
214 | 't': 'MetaMap' |
||
215 | } |
||
216 | } |
||
217 | |||
218 | src = json.loads(json.dumps(Div( |
||
219 | [ |
||
220 | 'identifier', |
||
221 | [ |
||
222 | 'class1', |
||
223 | 'class2' |
||
224 | ], |
||
225 | [] |
||
226 | ], |
||
227 | [ |
||
228 | { |
||
229 | 'c': [ |
||
230 | { |
||
231 | 'c': 'content', |
||
232 | 't': 'Str' |
||
233 | } |
||
234 | ], |
||
235 | 't': 'Plain' |
||
236 | } |
||
237 | ] |
||
238 | ))) |
||
239 | dest = json.loads(json.dumps(Div( |
||
240 | [ |
||
241 | 'identifier', |
||
242 | [ |
||
243 | 'class1', |
||
244 | 'class2' |
||
245 | ], |
||
246 | [] |
||
247 | ], |
||
248 | [ |
||
249 | { |
||
250 | 'c': [ |
||
251 | 'tex', |
||
252 | '\\begin{test} \\label{identifier}' |
||
253 | ], |
||
254 | 't': 'RawBlock' |
||
255 | }, |
||
256 | { |
||
257 | 'c': [ |
||
258 | { |
||
259 | 'c': 'content', |
||
260 | 't': 'Str' |
||
261 | } |
||
262 | ], |
||
263 | 't': 'Plain' |
||
264 | }, |
||
265 | { |
||
266 | 'c': [ |
||
267 | 'tex', |
||
268 | '\\end{test}' |
||
269 | ], |
||
270 | 't': 'RawBlock' |
||
271 | } |
||
272 | ] |
||
273 | ))) |
||
274 | |||
275 | pandoc_latex_environment.environment(src['t'], src['c'], 'latex', meta) |
||
276 | |||
277 | assert json.loads(json.dumps(src)) == dest |
||
278 | |||
279 | |||
280 | def test_div_with_title(): |
||
281 | init() |
||
282 | |||
283 | meta = { |
||
284 | 'pandoc-latex-environment': { |
||
285 | 'c': { |
||
286 | 'test': { |
||
287 | 'c': [ |
||
288 | { |
||
289 | 'c': [ |
||
290 | { |
||
291 | 'c': 'class1', |
||
292 | 't': 'Str' |
||
293 | } |
||
294 | ], |
||
295 | 't': 'MetaInlines' |
||
296 | }, |
||
297 | { |
||
298 | 'c': [ |
||
299 | { |
||
300 | 'c': 'class2', |
||
301 | 't': 'Str' |
||
302 | } |
||
303 | ], |
||
304 | 't': 'MetaInlines' |
||
305 | } |
||
306 | ], |
||
307 | 't': 'MetaList' |
||
308 | } |
||
309 | }, |
||
310 | 't': 'MetaMap' |
||
311 | } |
||
312 | } |
||
313 | |||
314 | src = json.loads(json.dumps(Div( |
||
315 | [ |
||
316 | '', |
||
317 | [ |
||
318 | 'class1', |
||
319 | 'class2' |
||
320 | ], |
||
321 | [ |
||
322 | ['title', 'theTitle'] |
||
323 | ] |
||
324 | ], |
||
325 | [ |
||
326 | { |
||
327 | 'c': [ |
||
328 | { |
||
329 | 'c': 'content', |
||
330 | 't': 'Str' |
||
331 | } |
||
332 | ], |
||
333 | 't': 'Plain' |
||
334 | } |
||
335 | ] |
||
336 | ))) |
||
337 | dest = json.loads(json.dumps(Div( |
||
338 | [ |
||
339 | '', |
||
340 | [ |
||
341 | 'class1', |
||
342 | 'class2' |
||
343 | ], |
||
344 | [ |
||
345 | ['title', 'theTitle'] |
||
346 | ] |
||
347 | ], |
||
348 | [ |
||
349 | { |
||
350 | 'c': [ |
||
351 | 'tex', |
||
352 | '\\begin{test}[theTitle]' |
||
353 | ], |
||
354 | 't': 'RawBlock' |
||
355 | }, |
||
356 | { |
||
357 | 'c': [ |
||
358 | { |
||
359 | 'c': 'content', |
||
360 | 't': 'Str' |
||
361 | } |
||
362 | ], |
||
363 | 't': 'Plain' |
||
364 | }, |
||
365 | { |
||
366 | 'c': [ |
||
367 | 'tex', |
||
368 | '\\end{test}' |
||
369 | ], |
||
370 | 't': 'RawBlock' |
||
371 | } |
||
372 | ] |
||
373 | ))) |
||
374 | |||
375 | pandoc_latex_environment.environment(src['t'], src['c'], 'latex', meta) |
||
376 | |||
377 | assert json.loads(json.dumps(src)) == dest |
||
378 |