test_latex()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 16

Duplication

Lines 16
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
c 2
b 0
f 0
dl 16
loc 16
rs 9.4285
1
# This Python file uses the following encoding: utf-8    
2
from unittest import TestCase
3
from pandocfilters import Span, Str, Space, Para, BulletList, Plain, Link, 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
def createLink(attributes, text, reference_title):
13
    if pandoc_listof.pandocVersion() < '1.16':
14
        return Link(text, reference_title)
15
    else:
16
        return Link(attributes, text, reference_title)
17
18
def test_simple():
19
    init()
20
21
    src = json.loads(json.dumps(Span(['exercise:1', [], []], [Str(u'Exercise'), Space(), Str(u'1')])))
22
    pandoc_listof.collect(src['t'], src['c'], '', {})
23
24
    src = json.loads(json.dumps(Span(['exercise:2', [], []], [Str(u'Exercise'), Space(), Str(u'2')])))
25
    pandoc_listof.collect(src['t'], src['c'], '', {})
26
27
    src = json.loads(json.dumps(Para([Str(u'{exercise}')])))
28
    dest = json.loads(json.dumps(BulletList([
29
        [Plain([createLink(['', [], []], [Str(u'Exercise 1')], ['#exercise:1', ''])])],
30
        [Plain([createLink(['', [], []], [Str(u'Exercise 2')], ['#exercise:2', ''])])]
31
    ])))
32
33
    assert json.loads(json.dumps(pandoc_listof.listof(src['t'], src['c'], '', {}))) == dest
34
35 View Code Duplication
def test_latex():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
36
    init()
37
38
    src = json.loads(json.dumps(Span(['exercise:1', [], []], [Str(u'Exercise'), Space(), Str(u'1')])))
39
    pandoc_listof.collect(src['t'], src['c'], 'latex', {})
40
41
    src = json.loads(json.dumps(Span(['exercise:2', [], []], [Str(u'Exercise'), Space(), Str(u'2')])))
42
    pandoc_listof.collect(src['t'], src['c'], 'latex', {})
43
44
    src = json.loads(json.dumps(Para([Str(u'{exercise}')])))
45
    dest = json.loads(json.dumps(Para([RawInline(
46
        'tex',
47
        '\\hypersetup{linkcolor=black}\\makeatletter\\@starttoc{exercise}\\makeatother'
48
    )])))
49
50
    assert json.loads(json.dumps(pandoc_listof.listof(src['t'], src['c'], 'latex', {}))) == dest
51
52 View Code Duplication
def test_toccolor():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
53
    init()
54
55
    meta = {'toccolor': {'t': 'MetaInlines', 'c': [{'t': 'Str', 'c': 'red'}]}}
56
    src = json.loads(json.dumps(Span(['exercise:1', [], []], [Str(u'Exercise'), Space(), Str(u'1')])))
57
    pandoc_listof.collect(src['t'], src['c'], 'latex', meta)
58
59
    src = json.loads(json.dumps(Span(['exercise:2', [], []], [Str(u'Exercise'), Space(), Str(u'2')])))
60
    pandoc_listof.collect(src['t'], src['c'], 'latex', meta)
61
62
    src = json.loads(json.dumps(Para([Str(u'{exercise}')])))
63
    dest = json.loads(json.dumps(Para([RawInline(
64
        'tex',
65
        '\\hypersetup{linkcolor=red}\\makeatletter\\@starttoc{exercise}\\makeatother'
66
    )])))
67
68
    assert json.loads(json.dumps(pandoc_listof.listof(src['t'], src['c'], 'latex', meta))) == dest
69
70
def test_double_curly_bracket():
71
    init()
72
73
    src = json.loads(json.dumps(Para([Str(u'{{exercise}')])))
74
    dest = json.loads(json.dumps(Para([Str(u'{exercise}')])))
75
76
    pandoc_listof.listof(src['t'], src['c'], '', {})
77
78
    assert src == dest
79
80
def test_with_number():
81
    init()
82
83
    src = Header(1, [u'first-chapter', [], []], [Str(u'First'), Space(), Str('chapter')])
84
    pandoc_listof.collect(src['t'], src['c'], '', {})
85
86
    src = json.loads(json.dumps(Span(['exercise:1', [], []], [Str(u'Exercise'), Space(), Str(u'1')])))
87
    pandoc_listof.collect(src['t'], src['c'], '', {})
88
    src = json.loads(json.dumps(Span(['exercise:2', [], []], [Str(u'Exercise'), Space(), Str(u'2')])))
89
    pandoc_listof.collect(src['t'], src['c'], '', {})
90
91
    src = Header(1, [u'second-chapter', [], []], [Str(u'Second'), Space(), Str('chapter')])
92
    pandoc_listof.collect(src['t'], src['c'], '', {})
93
94
    src = json.loads(json.dumps(Span(['exercise:3', [], []], [Str(u'Exercise'), Space(), Str(u'3')])))
95
    pandoc_listof.collect(src['t'], src['c'], '', {})
96
    src = json.loads(json.dumps(Span(['exercise:4', [], []], [Str(u'Exercise'), Space(), Str(u'4')])))
97
    pandoc_listof.collect(src['t'], src['c'], '', {})
98
99
    src = json.loads(json.dumps(Para([Str(u'{exercise}')])))
100
    dest = json.loads(json.dumps(BulletList([
101
        [Plain([createLink(['', [], []], [Str(u'Exercise 1')], ['#exercise:1', ''])])],
102
        [Plain([createLink(['', [], []], [Str(u'Exercise 2')], ['#exercise:2', ''])])],
103
        [Plain([createLink(['', [], []], [Str(u'Exercise 3')], ['#exercise:3', ''])])],
104
        [Plain([createLink(['', [], []], [Str(u'Exercise 4')], ['#exercise:4', ''])])],
105
    ])))
106
107
    assert json.loads(json.dumps(pandoc_listof.listof(src['t'], src['c'], '', {}))) == dest
108
109
    src = json.loads(json.dumps(Para([Str(u'{exercise:1}')])))
110
    dest = json.loads(json.dumps(BulletList([
111
        [Plain([createLink(['', [], []], [Str(u'Exercise 1')], ['#exercise:1', ''])])],
112
        [Plain([createLink(['', [], []], [Str(u'Exercise 2')], ['#exercise:2', ''])])],
113
    ])))
114
115
    assert json.loads(json.dumps(pandoc_listof.listof(src['t'], src['c'], '', {}))) == dest
116
117
    src = json.loads(json.dumps(Para([Str(u'{exercise:2}')])))
118
    dest = json.loads(json.dumps(BulletList([
119
        [Plain([createLink(['', [], []], [Str(u'Exercise 3')], ['#exercise:3', ''])])],
120
        [Plain([createLink(['', [], []], [Str(u'Exercise 4')], ['#exercise:4', ''])])],
121
    ])))
122
123
    assert json.loads(json.dumps(pandoc_listof.listof(src['t'], src['c'], '', {}))) == dest
124
125
def test_with_number_latex():
126
    init()
127
128
    src = Header(1, [u'first-chapter', [], []], [Str(u'First'), Space(), Str('chapter')])
129
    pandoc_listof.collect(src['t'], src['c'], '', {})
130
131
    src = json.loads(json.dumps(Span(['exercise:1', [], []], [Str(u'Exercise'), Space(), Str(u'1')])))
132
    pandoc_listof.collect(src['t'], src['c'], '', {})
133
    src = json.loads(json.dumps(Span(['exercise:2', [], []], [Str(u'Exercise'), Space(), Str(u'2')])))
134
    pandoc_listof.collect(src['t'], src['c'], '', {})
135
136
    src = Header(1, [u'second-chapter', [], []], [Str(u'Second'), Space(), Str('chapter')])
137
    pandoc_listof.collect(src['t'], src['c'], '', {})
138
139
    src = json.loads(json.dumps(Span(['exercise:3', [], []], [Str(u'Exercise'), Space(), Str(u'3')])))
140
    pandoc_listof.collect(src['t'], src['c'], '', {})
141
    src = json.loads(json.dumps(Span(['exercise:4', [], []], [Str(u'Exercise'), Space(), Str(u'4')])))
142
    pandoc_listof.collect(src['t'], src['c'], '', {})
143
144
    src = json.loads(json.dumps(Para([Str(u'{exercise}')])))
145
    dest = json.loads(json.dumps(Para([RawInline(
146
        'tex',
147
        '\\hypersetup{linkcolor=black}\\makeatletter\\@starttoc{exercise}\\makeatother'
148
    )])))
149
150
    assert json.loads(json.dumps(pandoc_listof.listof(src['t'], src['c'], 'latex', {}))) == dest
151
152
    src = json.loads(json.dumps(Para([Str(u'{exercise:1}')])))
153
    dest = json.loads(json.dumps(Para([RawInline(
154
        'tex',
155
        '\\hypersetup{linkcolor=black}\\makeatletter\\@starttoc{exercise:1}\\makeatother'
156
    )])))
157
158
    assert json.loads(json.dumps(pandoc_listof.listof(src['t'], src['c'], 'latex', {}))) == dest
159
160
def test_sharp():
161
    init()
162
163
    src = Header(1, [u'first-chapter', [], []], [Str(u'First'), Space(), Str('chapter')])
164
    pandoc_listof.collect(src['t'], src['c'], '', {})
165
166
    src = json.loads(json.dumps(Span(['exercise:1', [], []], [Str(u'Exercise'), Space(), Str(u'1')])))
167
    pandoc_listof.collect(src['t'], src['c'], '', {})
168
    src = json.loads(json.dumps(Span(['exercise:2', [], []], [Str(u'Exercise'), Space(), Str(u'2')])))
169
    pandoc_listof.collect(src['t'], src['c'], '', {})
170
171
    src = Header(1, [u'first-chapter', [], []], [Str(u'First'), Space(), Str('chapter')])
172
    pandoc_listof.listof(src['t'], src['c'], '', {})
173
174
    src = json.loads(json.dumps(Para([Str(u'{exercise:#}')])))
175
    dest = json.loads(json.dumps(Para([RawInline(
176
        'tex',
177
        '\\hypersetup{linkcolor=black}\\makeatletter\\@starttoc{exercise:1_}\\makeatother'
178
    )])))
179
180
    assert json.loads(json.dumps(pandoc_listof.listof(src['t'], src['c'], 'latex', {}))) == dest
181
182