Completed
Branch master (883534)
by Christophe
01:22 queued 11s
created

test_listing_latex()   B

Complexity

Conditions 2

Size

Total Lines 28

Duplication

Lines 28
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 28
loc 28
rs 8.8571
1
# This Python file uses the following encoding: utf-8
2
3
from unittest import TestCase
4
from pandocfilters import Para, Str, Space, Header, BulletList, Span, Strong, Plain, Link, RawBlock
5
6
import json
7
8
import pandoc_numbering
9
10
from helper import init, createLink, createMetaList, createMetaMap, createMetaInlines, createListStr, createMetaString
11
12
def getMeta1():
13
    return {
14
        'pandoc-numbering': createMetaList([
15
            createMetaMap({
16
                'category': createMetaInlines('exercise'),
17
                'listing': createMetaInlines('Listings of exercises'),
18
                'sectioning': createMetaInlines('-.+.')
19
            })
20
        ])
21
    }
22
23
def getMeta2():
24
    return {
25
        'pandoc-numbering': createMetaList([
26
            createMetaMap({
27
                'category': createMetaInlines('exercise'),
28
                'listing': createMetaInlines('Listings of exercises'),
29
                'sectioning': createMetaInlines('-.+.'),
30
                'tab': createMetaString('2'),
31
                'space': createMetaString('4'),
32
            })
33
        ])
34
    }
35
36
def getMeta3():
37
    return {
38
        'pandoc-numbering': createMetaList([
39
            createMetaMap({
40
                'category': createMetaInlines('exercise'),
41
                'listing': createMetaInlines('Listings of exercises'),
42
                'sectioning': createMetaInlines('-.+.'),
43
                'tab': createMetaString('a'),
44
                'space': createMetaString('b'),
45
            })
46
        ])
47
    }
48
49
def test_listing_classic():
50
    init()
51
52
    meta = getMeta1()
53
54
    src = Para(createListStr('Exercise #'))
55
    pandoc_numbering.numbering(src['t'], src['c'], '', meta)
56
    src = Para(createListStr('Exercise (test) #'))
57
    pandoc_numbering.numbering(src['t'], src['c'], '', meta)
58
59
    doc = [[{'unMeta': meta}], []]
60
    pandoc_numbering.addListings(doc, '', meta)
61
62
    dest = [
63
        Header(1, ['', ['unnumbered'], []], createListStr('Listings of exercises')),
64
	    BulletList([
65
	    	[Plain([createLink(['', [], []], createListStr('0.0.1 Exercise'), ['#exercise:0.0.1', ''])])],
66
	    	[Plain([createLink(['', [], []], createListStr('0.0.2 test'), ['#exercise:0.0.2', ''])])]
67
	    ])
68
	]
69
70
    assert json.loads(json.dumps(doc[1])) == json.loads(json.dumps(dest))
71
72 View Code Duplication
def test_listing_latex():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
73
    init()
74
75
    meta = getMeta1()
76
77
    src = Para(createListStr('Exercise #'))
78
    pandoc_numbering.numbering(src['t'], src['c'], 'latex', meta)
79
    src = Para(createListStr('Exercise (test) #'))
80
    pandoc_numbering.numbering(src['t'], src['c'], 'latex', meta)
81
82
    doc = [[{'unMeta': meta}], []]
83
    pandoc_numbering.addListings(doc, 'latex', meta)
84
85
    dest = [
86
        Header(1, ['', ['unnumbered'], []], createListStr('Listings of exercises')),
87
        RawBlock(
88
            'tex',
89
            ''.join([
90
                '\\hypersetup{linkcolor=black}',
91
                '\\makeatletter',
92
                '\\newcommand*\\l@exercise{\\@dottedtocline{1}{1.5em}{3.3em}}',
93
                '\\@starttoc{exercise}',
94
                '\\makeatother'
95
            ])
96
        )
97
    ]
98
99
    assert json.loads(json.dumps(doc[1])) == json.loads(json.dumps(dest))
100
101 View Code Duplication
def test_listing_latex_color():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
102
    init()
103
104
    meta = getMeta1()
105
    meta['toccolor']= createMetaInlines('blue')
106
107
    src = Para(createListStr('Exercise #'))
108
    pandoc_numbering.numbering(src['t'], src['c'], 'latex', meta)
109
    src = Para(createListStr('Exercise (test) #'))
110
    pandoc_numbering.numbering(src['t'], src['c'], 'latex', meta)
111
112
    doc = [[{'unMeta': meta}], []]
113
    pandoc_numbering.addListings(doc, 'latex', meta)
114
115
    dest = [
116
        Header(1, ['', ['unnumbered'], []], createListStr('Listings of exercises')),
117
        RawBlock(
118
            'tex',
119
            ''.join([
120
                '\\hypersetup{linkcolor=blue}',
121
                '\\makeatletter',
122
                '\\newcommand*\\l@exercise{\\@dottedtocline{1}{1.5em}{3.3em}}',
123
                '\\@starttoc{exercise}',
124
                '\\makeatother'
125
            ])
126
        )
127
    ]
128
129
    assert json.loads(json.dumps(doc[1])) == json.loads(json.dumps(dest))
130
131 View Code Duplication
def test_listing_latex_tab_space():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
132
    init()
133
134
    meta = getMeta2()
135
136
    src = Para(createListStr('Exercise #'))
137
    pandoc_numbering.numbering(src['t'], src['c'], 'latex', meta)
138
    src = Para(createListStr('Exercise (test) #'))
139
    pandoc_numbering.numbering(src['t'], src['c'], 'latex', meta)
140
141
    doc = [[{'unMeta': meta}], []]
142
    pandoc_numbering.addListings(doc, 'latex', meta)
143
144
    dest = [
145
        Header(1, ['', ['unnumbered'], []], createListStr('Listings of exercises')),
146
        RawBlock(
147
            'tex',
148
            '\\hypersetup{linkcolor=black}\\makeatletter\\newcommand*\\l@exercise{\\@dottedtocline{1}{2.0em}{4.0em}}\\@starttoc{exercise}\\makeatother'
149
        )
150
    ]
151
152
    assert json.loads(json.dumps(doc[1])) == json.loads(json.dumps(dest))
153
154 View Code Duplication
def test_listing_latex_tab_space_error():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
155
    init()
156
157
    meta = getMeta3()
158
    src = Para(createListStr('Exercise #'))
159
    pandoc_numbering.numbering(src['t'], src['c'], 'latex', meta)
160
    src = Para(createListStr('Exercise (test) #'))
161
    pandoc_numbering.numbering(src['t'], src['c'], 'latex', meta)
162
163
    doc = [[{'unMeta': meta}], []]
164
    pandoc_numbering.addListings(doc, 'latex', meta)
165
166
    dest = [
167
        Header(1, ['', ['unnumbered'], []], createListStr('Listings of exercises')),
168
        RawBlock(
169
            'tex',
170
            '\\hypersetup{linkcolor=black}\\makeatletter\\newcommand*\\l@exercise{\\@dottedtocline{1}{1.5em}{3.3em}}\\@starttoc{exercise}\\makeatother'
171
        )
172
    ]
173
174
    assert json.loads(json.dumps(doc[1])) == json.loads(json.dumps(dest))
175
176