|
1
|
|
|
# This Python file uses the following encoding: utf-8 |
|
2
|
|
|
|
|
3
|
|
|
from unittest import TestCase |
|
4
|
|
|
from pandocfilters import Para, Str, Space, Span, Strong, RawInline, Emph, Header |
|
5
|
|
|
|
|
6
|
|
|
import json |
|
7
|
|
|
|
|
8
|
|
|
import pandoc_numbering |
|
9
|
|
|
|
|
10
|
|
|
from helper import init, createMetaList, createMetaMap, createMetaInlines, createListStr, createMetaString, createMetaBool |
|
11
|
|
|
|
|
12
|
|
|
def getMeta1(): |
|
13
|
|
|
return { |
|
14
|
|
|
'pandoc-numbering': createMetaList([ |
|
15
|
|
|
createMetaMap({ |
|
16
|
|
|
'category': createMetaInlines('exercise'), |
|
17
|
|
|
'first': createMetaString('2'), |
|
18
|
|
|
'last': createMetaString('2'), |
|
19
|
|
|
}) |
|
20
|
|
|
]) |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
def getMeta2(): |
|
24
|
|
|
return { |
|
25
|
|
|
'pandoc-numbering': createMetaList([ |
|
26
|
|
|
createMetaMap({ |
|
27
|
|
|
'category': createMetaInlines('exercise'), |
|
28
|
|
|
'first': createMetaString('a'), |
|
29
|
|
|
'last': createMetaString('b'), |
|
30
|
|
|
}) |
|
31
|
|
|
]) |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
def getMeta3(): |
|
35
|
|
|
return { |
|
36
|
|
|
'pandoc-numbering': createMetaList([ |
|
37
|
|
|
createMetaMap({ |
|
38
|
|
|
'category': createMetaInlines('exercise'), |
|
39
|
|
|
'classes': createMetaList([createMetaInlines('my-class')]) |
|
40
|
|
|
}) |
|
41
|
|
|
]) |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
def getMeta4(): |
|
45
|
|
|
return { |
|
46
|
|
|
'pandoc-numbering': createMetaList([ |
|
47
|
|
|
createMetaMap({ |
|
48
|
|
|
'category': createMetaInlines('exercise'), |
|
49
|
|
|
'format': createMetaBool(False) |
|
50
|
|
|
}) |
|
51
|
|
|
]) |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
def test_numbering(): |
|
55
|
|
|
init() |
|
56
|
|
|
|
|
57
|
|
|
src = Para(createListStr('Exercise #')) |
|
58
|
|
|
dest = Para([ |
|
59
|
|
|
Span( |
|
60
|
|
|
[u'exercise:1', ['pandoc-numbering-text', 'exercise'], []], |
|
61
|
|
|
[Strong(createListStr('Exercise 1'))] |
|
62
|
|
|
) |
|
63
|
|
|
]) |
|
64
|
|
|
|
|
65
|
|
|
assert pandoc_numbering.numbering(src['t'], src['c'], '', {}) == dest |
|
66
|
|
|
|
|
67
|
|
|
def test_numbering_prefix_single(): |
|
68
|
|
|
init() |
|
69
|
|
|
|
|
70
|
|
|
src = Para(createListStr('Exercise #ex:')) |
|
71
|
|
|
dest = Para([ |
|
72
|
|
|
Span( |
|
73
|
|
|
[u'ex:1', ['pandoc-numbering-text', 'ex'], []], |
|
74
|
|
|
[Strong(createListStr('Exercise 1'))] |
|
75
|
|
|
) |
|
76
|
|
|
]) |
|
77
|
|
|
|
|
78
|
|
|
assert pandoc_numbering.numbering(src['t'], src['c'], '', {}) == dest |
|
79
|
|
|
|
|
80
|
|
|
src = Para(createListStr('Exercise #')) |
|
81
|
|
|
dest = Para([ |
|
82
|
|
|
Span( |
|
83
|
|
|
[u'exercise:1', ['pandoc-numbering-text', 'exercise'], []], |
|
84
|
|
|
[Strong(createListStr('Exercise 1'))] |
|
85
|
|
|
) |
|
86
|
|
|
]) |
|
87
|
|
|
|
|
88
|
|
|
assert pandoc_numbering.numbering(src['t'], src['c'], '', {}) == dest |
|
89
|
|
|
|
|
90
|
|
|
def test_numbering_latex(): |
|
91
|
|
|
init() |
|
92
|
|
|
|
|
93
|
|
|
src = Para(createListStr('Exercise #')) |
|
94
|
|
|
dest = Para([ |
|
95
|
|
|
RawInline(u'tex', u'\\phantomsection\\addcontentsline{exercise}{exercise}{\\protect\\numberline {1}{\\ignorespaces Exercise}}'), |
|
96
|
|
|
Span( |
|
97
|
|
|
[u'exercise:1', ['pandoc-numbering-text', 'exercise'], []], |
|
98
|
|
|
[Strong(createListStr('Exercise 1'))] |
|
99
|
|
|
) |
|
100
|
|
|
]) |
|
101
|
|
|
|
|
102
|
|
|
assert pandoc_numbering.numbering(src['t'], src['c'], 'latex', {}) == dest |
|
103
|
|
|
|
|
104
|
|
|
init() |
|
105
|
|
|
|
|
106
|
|
|
src = Para(createListStr('Exercise (The title) #')) |
|
107
|
|
|
dest = Para([ |
|
108
|
|
|
RawInline(u'tex', u'\\phantomsection\\addcontentsline{exercise}{exercise}{\\protect\\numberline {1}{\\ignorespaces The title}}'), |
|
109
|
|
|
Span( |
|
110
|
|
|
[u'exercise:1', ['pandoc-numbering-text', 'exercise'], []], |
|
111
|
|
|
[ |
|
112
|
|
|
Strong(createListStr('Exercise 1')), |
|
113
|
|
|
Space(), |
|
114
|
|
|
Emph(createListStr('(') + createListStr('The title') + createListStr(')')) |
|
115
|
|
|
] |
|
116
|
|
|
) |
|
117
|
|
|
]) |
|
118
|
|
|
|
|
119
|
|
|
assert pandoc_numbering.numbering(src['t'], src['c'], 'latex', {}) == dest |
|
120
|
|
|
|
|
121
|
|
View Code Duplication |
def test_numbering_double(): |
|
|
|
|
|
|
122
|
|
|
init() |
|
123
|
|
|
|
|
124
|
|
|
src = Para(createListStr('Exercise #')) |
|
125
|
|
|
pandoc_numbering.numbering(src['t'], src['c'], '', {}) |
|
126
|
|
|
|
|
127
|
|
|
src = Para(createListStr('Exercise #')) |
|
128
|
|
|
dest = Para([ |
|
129
|
|
|
Span( |
|
130
|
|
|
[u'exercise:2', ['pandoc-numbering-text', 'exercise'], []], |
|
131
|
|
|
[Strong(createListStr('Exercise 2'))] |
|
132
|
|
|
) |
|
133
|
|
|
]) |
|
134
|
|
|
|
|
135
|
|
|
assert pandoc_numbering.numbering(src['t'], src['c'], '', {}) == dest |
|
136
|
|
|
|
|
137
|
|
|
def test_numbering_title(): |
|
138
|
|
|
init() |
|
139
|
|
|
|
|
140
|
|
|
src = Para(createListStr('Exercise (The title) #')) |
|
141
|
|
|
dest = Para([ |
|
142
|
|
|
Span( |
|
143
|
|
|
[u'exercise:1', ['pandoc-numbering-text', 'exercise'], []], |
|
144
|
|
|
[ |
|
145
|
|
|
Strong(createListStr('Exercise 1')), |
|
146
|
|
|
Space(), |
|
147
|
|
|
Emph(createListStr('(') + createListStr('The title') + createListStr(')')) |
|
148
|
|
|
] |
|
149
|
|
|
) |
|
150
|
|
|
]) |
|
151
|
|
|
|
|
152
|
|
|
assert pandoc_numbering.numbering(src['t'], src['c'], '', {}) == dest |
|
153
|
|
|
|
|
154
|
|
|
def test_numbering_level(): |
|
155
|
|
|
init() |
|
156
|
|
|
|
|
157
|
|
|
src = Para(createListStr('Exercise +.+.#')) |
|
158
|
|
|
dest = Para([ |
|
159
|
|
|
Span( |
|
160
|
|
|
[u'exercise:0.0.1', ['pandoc-numbering-text', 'exercise'], []], |
|
161
|
|
|
[Strong(createListStr('Exercise 0.0.1'))] |
|
162
|
|
|
) |
|
163
|
|
|
]) |
|
164
|
|
|
|
|
165
|
|
|
assert pandoc_numbering.numbering(src['t'], src['c'], '', {}) == dest |
|
166
|
|
|
|
|
167
|
|
|
src = Header(1, [u'first-chapter', [], []], createListStr('First chapter')) |
|
168
|
|
|
pandoc_numbering.numbering(src['t'], src['c'], '', {}) |
|
169
|
|
|
|
|
170
|
|
|
src = Header(2, [u'first-section', [], []], createListStr('First section')) |
|
171
|
|
|
pandoc_numbering.numbering(src['t'], src['c'], '', {}) |
|
172
|
|
|
|
|
173
|
|
|
src = Para(createListStr('Exercise +.+.#')) |
|
174
|
|
|
dest = Para([ |
|
175
|
|
|
Span( |
|
176
|
|
|
[u'exercise:1.1.1', ['pandoc-numbering-text', 'exercise'], []], |
|
177
|
|
|
[Strong(createListStr('Exercise 1.1.1'))] |
|
178
|
|
|
) |
|
179
|
|
|
]) |
|
180
|
|
|
|
|
181
|
|
|
assert pandoc_numbering.numbering(src['t'], src['c'], '', {}) == dest |
|
182
|
|
|
|
|
183
|
|
|
src = Para(createListStr('Exercise +.+.#')) |
|
184
|
|
|
dest = Para([ |
|
185
|
|
|
Span( |
|
186
|
|
|
[u'exercise:1.1.2', ['pandoc-numbering-text', 'exercise'], []], |
|
187
|
|
|
[Strong(createListStr('Exercise 1.1.2'))] |
|
188
|
|
|
) |
|
189
|
|
|
]) |
|
190
|
|
|
|
|
191
|
|
|
assert pandoc_numbering.numbering(src['t'], src['c'], '', {}) == dest |
|
192
|
|
|
|
|
193
|
|
|
src = Header(2, [u'second-section', [], []], createListStr('Second section')) |
|
194
|
|
|
pandoc_numbering.numbering(src['t'], src['c'], '', {}) |
|
195
|
|
|
|
|
196
|
|
|
src = Para(createListStr('Exercise +.+.#')) |
|
197
|
|
|
dest = Para([ |
|
198
|
|
|
Span( |
|
199
|
|
|
[u'exercise:1.2.1', ['pandoc-numbering-text', 'exercise'], []], |
|
200
|
|
|
[Strong(createListStr('Exercise 1.2.1'))] |
|
201
|
|
|
) |
|
202
|
|
|
]) |
|
203
|
|
|
|
|
204
|
|
|
assert pandoc_numbering.numbering(src['t'], src['c'], '', {}) == dest |
|
205
|
|
|
|
|
206
|
|
View Code Duplication |
def test_numbering_unnumbered(): |
|
|
|
|
|
|
207
|
|
|
init() |
|
208
|
|
|
|
|
209
|
|
|
src = Header(1, [u'unnumbered-chapter', [u'unnumbered'], []], createListStr('Unnumbered chapter')) |
|
210
|
|
|
pandoc_numbering.numbering(src['t'], src['c'], '', {}) |
|
211
|
|
|
|
|
212
|
|
|
src = Para(createListStr('Exercise +.#')) |
|
213
|
|
|
dest = Para([ |
|
214
|
|
|
Span( |
|
215
|
|
|
[u'exercise:0.1', ['pandoc-numbering-text', 'exercise'], []], |
|
216
|
|
|
[Strong(createListStr('Exercise 0.1'))] |
|
217
|
|
|
) |
|
218
|
|
|
]) |
|
219
|
|
|
|
|
220
|
|
|
assert pandoc_numbering.numbering(src['t'], src['c'], '', {}) == dest |
|
221
|
|
|
|
|
222
|
|
|
def test_numbering_hidden(): |
|
223
|
|
|
init() |
|
224
|
|
|
|
|
225
|
|
|
src = Header(1, [u'first-chapter', [], []], createListStr('First chapter')) |
|
226
|
|
|
pandoc_numbering.numbering(src['t'], src['c'], '', {}) |
|
227
|
|
|
|
|
228
|
|
|
src = Para(createListStr('Exercise -.#exercise:one')) |
|
229
|
|
|
dest = Para([ |
|
230
|
|
|
Span( |
|
231
|
|
|
[u'exercise:one', ['pandoc-numbering-text', 'exercise'], []], |
|
232
|
|
|
[ |
|
233
|
|
|
Strong(createListStr('Exercise 1')) |
|
234
|
|
|
] |
|
235
|
|
|
) |
|
236
|
|
|
]) |
|
237
|
|
|
|
|
238
|
|
|
assert pandoc_numbering.numbering(src['t'], src['c'], '', {}) == dest |
|
239
|
|
|
|
|
240
|
|
|
src = Para(createListStr('Exercise -.#')) |
|
241
|
|
|
dest = Para([ |
|
242
|
|
|
Span( |
|
243
|
|
|
[u'exercise:1.2', ['pandoc-numbering-text', 'exercise'], []], |
|
244
|
|
|
[Strong(createListStr('Exercise 2'))] |
|
245
|
|
|
) |
|
246
|
|
|
]) |
|
247
|
|
|
|
|
248
|
|
|
assert pandoc_numbering.numbering(src['t'], src['c'], '', {}) == dest |
|
249
|
|
|
|
|
250
|
|
|
src = Header(1, [u'second-chapter', [], []], createListStr('Second chapter')) |
|
251
|
|
|
pandoc_numbering.numbering(src['t'], src['c'], '', {}) |
|
252
|
|
|
|
|
253
|
|
|
src = Para(createListStr('Exercise -.#')) |
|
254
|
|
|
dest = Para([ |
|
255
|
|
|
Span( |
|
256
|
|
|
[u'exercise:2.1', ['pandoc-numbering-text', 'exercise'], []], |
|
257
|
|
|
[Strong(createListStr('Exercise 1'))] |
|
258
|
|
|
) |
|
259
|
|
|
]) |
|
260
|
|
|
|
|
261
|
|
|
assert pandoc_numbering.numbering(src['t'], src['c'], '', {}) == dest |
|
262
|
|
|
|
|
263
|
|
|
src = Para(createListStr('Exercise +.#')) |
|
264
|
|
|
dest = Para([ |
|
265
|
|
|
Span( |
|
266
|
|
|
[u'exercise:2.2', ['pandoc-numbering-text', 'exercise'], []], |
|
267
|
|
|
[Strong(createListStr('Exercise 2.2'))] |
|
268
|
|
|
) |
|
269
|
|
|
]) |
|
270
|
|
|
|
|
271
|
|
|
assert pandoc_numbering.numbering(src['t'], src['c'], '', {}) == dest |
|
272
|
|
|
|
|
273
|
|
|
src = Para([Str(u'Exercise'), Space(), Str(u'#')]) |
|
274
|
|
|
dest = Para([ |
|
275
|
|
|
Span( |
|
276
|
|
|
[u'exercise:1', ['pandoc-numbering-text', 'exercise'], []], |
|
277
|
|
|
[Strong(createListStr('Exercise 1'))] |
|
278
|
|
|
) |
|
279
|
|
|
]) |
|
280
|
|
|
|
|
281
|
|
|
assert pandoc_numbering.numbering(src['t'], src['c'], '', {}) == dest |
|
282
|
|
|
|
|
283
|
|
|
def test_numbering_sharp_sharp(): |
|
284
|
|
|
init() |
|
285
|
|
|
|
|
286
|
|
|
src = Para(createListStr('Exercise ##')) |
|
287
|
|
|
dest = Para(createListStr('Exercise #')) |
|
288
|
|
|
pandoc_numbering.numbering(src['t'], src['c'], '', {}) |
|
289
|
|
|
|
|
290
|
|
|
assert src == dest |
|
291
|
|
|
|
|
292
|
|
|
def test_numbering_sectioning_string(): |
|
293
|
|
|
init() |
|
294
|
|
|
|
|
295
|
|
|
meta = { |
|
296
|
|
|
'pandoc-numbering': { |
|
297
|
|
|
't': 'MetaList', |
|
298
|
|
|
'c': [ |
|
299
|
|
|
{ |
|
300
|
|
|
't': 'MetaMap', |
|
301
|
|
|
'c': { |
|
302
|
|
|
'category': { |
|
303
|
|
|
't': 'MetaInlines', |
|
304
|
|
|
'c': [Str('exercise')] |
|
305
|
|
|
}, |
|
306
|
|
|
'sectioning': { |
|
307
|
|
|
't': 'MetaInlines', |
|
308
|
|
|
'c': [Str('-.+.')] |
|
309
|
|
|
} |
|
310
|
|
|
} |
|
311
|
|
|
} |
|
312
|
|
|
] |
|
313
|
|
|
} |
|
314
|
|
|
} |
|
315
|
|
|
|
|
316
|
|
|
src = Header(1, [u'first-chapter', [], []], createListStr('First chapter')) |
|
317
|
|
|
pandoc_numbering.numbering(src['t'], src['c'], '', meta) |
|
318
|
|
|
|
|
319
|
|
|
src = Header(1, [u'second-chapter', [], []], createListStr('Second chapter')) |
|
320
|
|
|
pandoc_numbering.numbering(src['t'], src['c'], '', meta) |
|
321
|
|
|
|
|
322
|
|
|
src = Header(2, [u'first-section', [], []], createListStr('First section')) |
|
323
|
|
|
pandoc_numbering.numbering(src['t'], src['c'], '', meta) |
|
324
|
|
|
|
|
325
|
|
|
src = Header(2, [u'second-section', [], []], createListStr('Second section')) |
|
326
|
|
|
pandoc_numbering.numbering(src['t'], src['c'], '', meta) |
|
327
|
|
|
|
|
328
|
|
|
src = Para(createListStr('Exercise #')) |
|
329
|
|
|
dest = Para([ |
|
330
|
|
|
Span( |
|
331
|
|
|
[u'exercise:2.2.1', ['pandoc-numbering-text', 'exercise'], []], |
|
332
|
|
|
[Strong(createListStr('Exercise 2.1'))] |
|
333
|
|
|
) |
|
334
|
|
|
]) |
|
335
|
|
|
|
|
336
|
|
|
assert pandoc_numbering.numbering(src['t'], src['c'], '', meta) == dest |
|
337
|
|
|
|
|
338
|
|
View Code Duplication |
def test_numbering_sectioning_map(): |
|
|
|
|
|
|
339
|
|
|
init() |
|
340
|
|
|
|
|
341
|
|
|
meta = getMeta1() |
|
342
|
|
|
|
|
343
|
|
|
src = Header(1, [u'first-chapter', [], []], createListStr('First chapter')) |
|
344
|
|
|
pandoc_numbering.numbering(src['t'], src['c'], '', meta) |
|
345
|
|
|
|
|
346
|
|
|
src = Header(1, [u'second-chapter', [], []], createListStr('Second chapter')) |
|
347
|
|
|
pandoc_numbering.numbering(src['t'], src['c'], '', meta) |
|
348
|
|
|
|
|
349
|
|
|
src = Header(2, [u'first-section', [], []], createListStr('First section')) |
|
350
|
|
|
pandoc_numbering.numbering(src['t'], src['c'], '', meta) |
|
351
|
|
|
|
|
352
|
|
|
src = Header(2, [u'second-section', [], []], createListStr('Second section')) |
|
353
|
|
|
pandoc_numbering.numbering(src['t'], src['c'], '', meta) |
|
354
|
|
|
|
|
355
|
|
|
src = Para([Str(u'Exercise'), Space(), Str(u'#')]) |
|
356
|
|
|
dest = Para([ |
|
357
|
|
|
Span( |
|
358
|
|
|
[u'exercise:2.2.1', ['pandoc-numbering-text', 'exercise'], []], |
|
359
|
|
|
[Strong(createListStr('Exercise 2.1'))] |
|
360
|
|
|
) |
|
361
|
|
|
]) |
|
362
|
|
|
|
|
363
|
|
|
assert pandoc_numbering.numbering(src['t'], src['c'], '', meta) == dest |
|
364
|
|
|
|
|
365
|
|
View Code Duplication |
def test_numbering_sectioning_map_error(): |
|
|
|
|
|
|
366
|
|
|
init() |
|
367
|
|
|
|
|
368
|
|
|
meta = getMeta2() |
|
369
|
|
|
|
|
370
|
|
|
src = Header(1, [u'first-chapter', [], []], createListStr('First chapter')) |
|
371
|
|
|
pandoc_numbering.numbering(src['t'], src['c'], '', meta) |
|
372
|
|
|
|
|
373
|
|
|
src = Header(1, [u'second-chapter', [], []], createListStr('Second chapter')) |
|
374
|
|
|
pandoc_numbering.numbering(src['t'], src['c'], '', meta) |
|
375
|
|
|
|
|
376
|
|
|
src = Header(2, [u'first-section', [], []], createListStr('First section')) |
|
377
|
|
|
pandoc_numbering.numbering(src['t'], src['c'], '', meta) |
|
378
|
|
|
|
|
379
|
|
|
src = Header(2, [u'second-section', [], []], createListStr('Second section')) |
|
380
|
|
|
pandoc_numbering.numbering(src['t'], src['c'], '', meta) |
|
381
|
|
|
|
|
382
|
|
|
src = Para([Str(u'Exercise'), Space(), Str(u'#')]) |
|
383
|
|
|
dest = Para([ |
|
384
|
|
|
Span( |
|
385
|
|
|
[u'exercise:1', ['pandoc-numbering-text', 'exercise'], []], |
|
386
|
|
|
[Strong(createListStr('Exercise 1'))] |
|
387
|
|
|
) |
|
388
|
|
|
]) |
|
389
|
|
|
|
|
390
|
|
|
assert pandoc_numbering.numbering(src['t'], src['c'], '', meta) == dest |
|
391
|
|
|
|
|
392
|
|
|
def test_classes(): |
|
393
|
|
|
init() |
|
394
|
|
|
|
|
395
|
|
|
meta = getMeta3() |
|
396
|
|
|
|
|
397
|
|
|
src = Para(createListStr('Exercise #')) |
|
398
|
|
|
dest = Para([ |
|
399
|
|
|
Span( |
|
400
|
|
|
[u'exercise:1', ['pandoc-numbering-text', 'my-class'], []], |
|
401
|
|
|
[Strong(createListStr('Exercise 1'))] |
|
402
|
|
|
) |
|
403
|
|
|
]) |
|
404
|
|
|
|
|
405
|
|
|
assert pandoc_numbering.numbering(src['t'], src['c'], '', meta) == dest |
|
406
|
|
|
|
|
407
|
|
|
def test_format(): |
|
408
|
|
|
init() |
|
409
|
|
|
|
|
410
|
|
|
meta = getMeta4() |
|
411
|
|
|
|
|
412
|
|
|
src = Para(createListStr('Exercise #')) |
|
413
|
|
|
dest = json.loads(json.dumps(Para([ |
|
414
|
|
|
Span( |
|
415
|
|
|
[u'exercise:1', ['pandoc-numbering-text', 'exercice'], []], |
|
416
|
|
|
[ |
|
417
|
|
|
Span(['', ['description'], []], createListStr('Exercise')), |
|
418
|
|
|
Span(['', ['number'], []], createListStr('1')), |
|
419
|
|
|
Span(['', ['title'], []], []) |
|
420
|
|
|
] |
|
421
|
|
|
) |
|
422
|
|
|
]))) |
|
423
|
|
|
|
|
424
|
|
|
json.loads(json.dumps(pandoc_numbering.numbering(src['t'], src['c'], '', meta))) == dest |
|
425
|
|
|
|
|
426
|
|
|
|