Completed
Push — master ( cf398c...d6b46b )
by Christophe
01:07
created

test_listing_latex()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
c 3
b 0
f 0
dl 0
loc 2
rs 10
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(u'exercise'),
17
                'listing': createMetaInlines(u'Listings of exercises'),
18
                'sectioning': createMetaInlines(u'-.+.')
19
            })
20
        ])
21
    }
22
23
def getMeta2():
24
    return {
25
        'pandoc-numbering': createMetaList([
26
            createMetaMap({
27
                'category': createMetaInlines(u'exercise'),
28
                'listing': createMetaInlines(u'Listings of exercises'),
29
                'sectioning': createMetaInlines(u'-.+.'),
30
                'tab': createMetaString(u'2'),
31
                'space': createMetaString(u'4'),
32
            })
33
        ])
34
    }
35
36
def getMeta3():
37
    return {
38
        'pandoc-numbering': createMetaList([
39
            createMetaMap({
40
                'category': createMetaInlines(u'exercise'),
41
                'listing': createMetaInlines(u'Listings of exercises'),
42
                'sectioning': createMetaInlines(u'-.+.'),
43
                'tab': createMetaString(u'a'),
44
                'space': createMetaString(u'b'),
45
            })
46
        ])
47
    }
48
49
def test_listing_classic():
50
    init()
51
52
    meta = getMeta1()
53
54
    src = Para(createListStr(u'Exercise #'))
55
    pandoc_numbering.numbering(src['t'], src['c'], '', meta)
56
    src = Para(createListStr(u'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(u'Listings of exercises')),
64
	    BulletList([
65
	    	[Plain([createLink(['', [], []], createListStr(u'0.0.1 Exercise'), ['#exercise:0.0.1', ''])])],
66
	    	[Plain([createLink(['', [], []], createListStr(u'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
73 View Code Duplication
def listing_latex(meta, color, tab, space):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
74
    init()
75
76
    src = Para(createListStr(u'Exercise #'))
77
    pandoc_numbering.numbering(src['t'], src['c'], 'latex', meta)
78
    src = Para(createListStr(u'Exercise (test) #'))
79
    pandoc_numbering.numbering(src['t'], src['c'], 'latex', meta)
80
81
    doc = [[{'unMeta': meta}], []]
82
    pandoc_numbering.addListings(doc, 'latex', meta)
83
84
    dest = [
85
        Header(1, ['', ['unnumbered'], []], createListStr(u'Listings of exercises')),
86
        RawBlock(
87
            'tex',
88
            ''.join([
89
                '\\hypersetup{linkcolor=' + color + '}',
90
                '\\makeatletter',
91
                '\\newcommand*\\l@exercise{\\@dottedtocline{1}{' + tab + 'em}{' + space + 'em}}',
92
                '\\@starttoc{exercise}',
93
                '\\makeatother'
94
            ])
95
        )
96
    ]
97
98
    assert json.loads(json.dumps(doc[1])) == json.loads(json.dumps(dest))
99
100
101
def test_listing_latex():
102
    listing_latex(getMeta1(), 'black', '1.5', '3.3')
103
104
def test_listing_latex_color():
105
    meta = getMeta1()
106
    meta['toccolor'] = createMetaInlines(u'blue')
107
    listing_latex(meta, 'blue', '1.5', '3.3')
108
109
def test_listing_latex_tab_space():
110
	listing_latex(getMeta2(), 'black', '2.0', '4.0')
111
112
def test_listing_latex_tab_space_error():
113
	listing_latex(getMeta3(), 'black', '1.5', '3.3')
114
115