|
1
|
|
|
# This Python file uses the following encoding: utf-8 |
|
2
|
|
|
from unittest import TestCase |
|
3
|
|
|
from pandocfilters import Span, Str, Space, RawInline, Header |
|
4
|
|
|
|
|
5
|
|
|
import json |
|
6
|
|
|
import pandoc_listof |
|
7
|
|
|
|
|
8
|
|
|
def init(): |
|
9
|
|
|
pandoc_listof.collections = {} |
|
10
|
|
|
pandoc_listof.headers = [0, 0, 0, 0, 0, 0] |
|
11
|
|
|
|
|
12
|
|
View Code Duplication |
def test_classic(): |
|
|
|
|
|
|
13
|
|
|
init() |
|
14
|
|
|
|
|
15
|
|
|
src = json.loads(json.dumps(Span(['exercise:1', [], []], [Str(u'Exercise'), Space(), Str(u'1')]))) |
|
16
|
|
|
dest = json.loads(json.dumps(Span(['exercise:1', [], []], [Str(u'Exercise'), Space(), Str(u'1')]))) |
|
17
|
|
|
assert pandoc_listof.collect(src['t'], src['c'], '', {}) == None |
|
18
|
|
|
assert src == dest |
|
19
|
|
|
assert pandoc_listof.collections == {'exercise': [{'identifier': u'1', 'text': u'Exercise 1'}]} |
|
20
|
|
|
|
|
21
|
|
|
def test_headers(): |
|
22
|
|
|
init() |
|
23
|
|
|
|
|
24
|
|
|
src = Header(1, [u'first-chapter', [], []], [Str(u'First'), Space(), Str('chapter')]) |
|
25
|
|
|
pandoc_listof.collect(src['t'], src['c'], '', {}) |
|
26
|
|
|
|
|
27
|
|
|
src = json.loads(json.dumps(Span(['exercise:1', [], []], [Str(u'Exercise'), Space(), Str(u'1')]))) |
|
28
|
|
|
pandoc_listof.collect(src['t'], src['c'], '', {}) |
|
29
|
|
|
src = json.loads(json.dumps(Span(['exercise:2', [], []], [Str(u'Exercise'), Space(), Str(u'2')]))) |
|
30
|
|
|
pandoc_listof.collect(src['t'], src['c'], '', {}) |
|
31
|
|
|
|
|
32
|
|
|
src = Header(1, [u'second-chapter', [], []], [Str(u'Second'), Space(), Str('chapter')]) |
|
33
|
|
|
pandoc_listof.collect(src['t'], src['c'], '', {}) |
|
34
|
|
|
|
|
35
|
|
|
src = json.loads(json.dumps(Span(['exercise:3', [], []], [Str(u'Exercise'), Space(), Str(u'3')]))) |
|
36
|
|
|
pandoc_listof.collect(src['t'], src['c'], '', {}) |
|
37
|
|
|
src = json.loads(json.dumps(Span(['exercise:4', [], []], [Str(u'Exercise'), Space(), Str(u'4')]))) |
|
38
|
|
|
pandoc_listof.collect(src['t'], src['c'], '', {}) |
|
39
|
|
|
|
|
40
|
|
|
src = Header(2, [u'first-section', [], []], [Str(u'First'), Space(), Str('section')]) |
|
41
|
|
|
pandoc_listof.collect(src['t'], src['c'], '', {}) |
|
42
|
|
|
|
|
43
|
|
|
src = json.loads(json.dumps(Span(['exercise:5', [], []], [Str(u'Exercise'), Space(), Str(u'5')]))) |
|
44
|
|
|
pandoc_listof.collect(src['t'], src['c'], '', {}) |
|
45
|
|
|
src = json.loads(json.dumps(Span(['exercise:6', [], []], [Str(u'Exercise'), Space(), Str(u'6')]))) |
|
46
|
|
|
pandoc_listof.collect(src['t'], src['c'], '', {}) |
|
47
|
|
|
|
|
48
|
|
|
assert pandoc_listof.collections == { |
|
49
|
|
|
'exercise': [ |
|
50
|
|
|
{'identifier': u'1', 'text': u'Exercise 1'}, |
|
51
|
|
|
{'identifier': u'2', 'text': u'Exercise 2'}, |
|
52
|
|
|
{'identifier': u'3', 'text': u'Exercise 3'}, |
|
53
|
|
|
{'identifier': u'4', 'text': u'Exercise 4'}, |
|
54
|
|
|
{'identifier': u'5', 'text': u'Exercise 5'}, |
|
55
|
|
|
{'identifier': u'6', 'text': u'Exercise 6'}, |
|
56
|
|
|
], |
|
57
|
|
|
'exercise:1': [ |
|
58
|
|
|
{'identifier': u'1', 'text': u'Exercise 1'}, |
|
59
|
|
|
{'identifier': u'2', 'text': u'Exercise 2'} |
|
60
|
|
|
], |
|
61
|
|
|
'exercise:2': [ |
|
62
|
|
|
{'identifier': u'3', 'text': u'Exercise 3'}, |
|
63
|
|
|
{'identifier': u'4', 'text': u'Exercise 4'}, |
|
64
|
|
|
{'identifier': u'5', 'text': u'Exercise 5'}, |
|
65
|
|
|
{'identifier': u'6', 'text': u'Exercise 6'}, |
|
66
|
|
|
], |
|
67
|
|
|
'exercise:2.1': [ |
|
68
|
|
|
{'identifier': u'5', 'text': u'Exercise 5'}, |
|
69
|
|
|
{'identifier': u'6', 'text': u'Exercise 6'}, |
|
70
|
|
|
] |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
View Code Duplication |
def test_latex(): |
|
|
|
|
|
|
74
|
|
|
init() |
|
75
|
|
|
|
|
76
|
|
|
src = json.loads(json.dumps(Span(['exercise:1', [], []], [Str(u'Exercise'), Space(), Str(u'1')]))) |
|
77
|
|
|
latex = '\\phantomsection\\addcontentsline{exercise}{figure}{Exercise 1}' |
|
78
|
|
|
dest = json.loads(json.dumps(Span(['exercise:1', [], []], [RawInline('tex', latex), Str(u'Exercise'), Space(), Str(u'1')]))) |
|
79
|
|
|
assert pandoc_listof.collect(src['t'], src['c'], 'latex', {}) == None |
|
80
|
|
|
assert json.loads(json.dumps(src)) == dest |
|
81
|
|
|
assert pandoc_listof.collections == {'exercise': [{'identifier': u'1', 'text': u'Exercise 1'}]} |
|
82
|
|
|
|
|
83
|
|
|
def test_headers_latex(): |
|
84
|
|
|
init() |
|
85
|
|
|
|
|
86
|
|
|
src = Header(1, [u'first-chapter', [], []], [Str(u'First'), Space(), Str('chapter')]) |
|
87
|
|
|
pandoc_listof.collect(src['t'], src['c'], '', {}) |
|
88
|
|
|
|
|
89
|
|
|
src = json.loads(json.dumps(Span(['exercise:1', [], []], [Str(u'Exercise'), Space(), Str(u'1')]))) |
|
90
|
|
|
latex = '\\phantomsection\\addcontentsline{exercise}{figure}{Exercise 1}' \ |
|
91
|
|
|
'\\phantomsection\\addcontentsline{exercise:1}{figure}{Exercise 1}' \ |
|
92
|
|
|
'\\phantomsection\\addcontentsline{exercise:1_}{figure}{Exercise 1}' |
|
93
|
|
|
dest = json.loads(json.dumps(Span(['exercise:1', [], []], [RawInline('tex', latex), Str(u'Exercise'), Space(), Str(u'1')]))) |
|
94
|
|
|
assert pandoc_listof.collect(src['t'], src['c'], 'latex', {}) == None |
|
95
|
|
|
assert json.loads(json.dumps(src)) == dest |
|
96
|
|
|
|
|
97
|
|
|
|