1
|
|
|
from __future__ import unicode_literals |
2
|
|
|
|
3
|
|
|
import unittest |
4
|
|
|
|
5
|
|
|
try: |
6
|
|
|
from hypothesis import given, example |
7
|
|
|
except ImportError: |
8
|
|
|
# Mock out hypothesis stuff for python 2.6 |
9
|
|
|
def given(a): |
10
|
|
|
def func(b): |
11
|
|
|
return |
12
|
|
|
return func |
13
|
|
|
|
14
|
|
|
example = given |
15
|
|
|
|
16
|
|
|
try: |
17
|
|
|
from hypothesis.strategies import text |
18
|
|
|
except ImportError: |
19
|
|
|
def text(): |
20
|
|
|
pass |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
import CommonMark |
24
|
|
|
from CommonMark.blocks import Parser |
25
|
|
|
from CommonMark.render.html import HtmlRenderer |
26
|
|
|
from CommonMark.inlines import InlineParser |
27
|
|
|
from CommonMark.node import NodeWalker, Node |
28
|
|
|
from CommonMark.utils import to_camel_case |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
class TestCommonmark(unittest.TestCase): |
32
|
|
|
def test_output(self): |
33
|
|
|
s = CommonMark.commonmark('*hello!*') |
34
|
|
|
self.assertEqual(s, '<p><em>hello!</em></p>\n') |
35
|
|
|
|
36
|
|
|
def test_unicode(self): |
37
|
|
|
s = CommonMark.commonmark('<div>\u2020</div>\n') |
38
|
|
|
self.assertEqual(s, '<div>\u2020</div>\n', |
39
|
|
|
'Unicode works in an HTML block.') |
40
|
|
|
CommonMark.commonmark('* unicode: \u2020') |
41
|
|
|
CommonMark.commonmark('# unicode: \u2020') |
42
|
|
|
CommonMark.commonmark('```\n# unicode: \u2020\n```') |
43
|
|
|
|
44
|
|
|
def test_null_string_bug(self): |
45
|
|
|
s = CommonMark.commonmark('> sometext\n>\n\n') |
46
|
|
|
self.assertEqual( |
47
|
|
|
s, |
48
|
|
|
'<blockquote>\n<pre><code>sometext\n</code></pre>' |
49
|
|
|
'\n</blockquote>\n') |
50
|
|
|
|
51
|
|
|
def test_dumpAST_orderedlist(self): |
52
|
|
|
md = '1.' |
53
|
|
|
ast = Parser().parse(md) |
54
|
|
|
CommonMark.dumpAST(ast) |
55
|
|
|
|
56
|
|
|
@given(text()) |
57
|
|
|
def test_random_text(self, s): |
58
|
|
|
CommonMark.commonmark(s) |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
class TestHtmlRenderer(unittest.TestCase): |
62
|
|
|
def test_init(self): |
63
|
|
|
HtmlRenderer() |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
class TestInlineParser(unittest.TestCase): |
67
|
|
|
def test_init(self): |
68
|
|
|
InlineParser() |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
class TestNode(unittest.TestCase): |
72
|
|
|
def test_doc_node(self): |
73
|
|
|
Node('document', [[1, 1], [0, 0]]) |
74
|
|
|
|
75
|
|
|
|
76
|
|
|
class TestNodeWalker(unittest.TestCase): |
77
|
|
|
def test_node_walker(self): |
78
|
|
|
node = Node('document', [[1, 1], [0, 0]]) |
79
|
|
|
NodeWalker(node) |
80
|
|
|
|
81
|
|
|
def test_node_walker_iter(self): |
82
|
|
|
node = Node('document', [[1, 1], [0, 0]]) |
83
|
|
|
for subnode, entered in node.walker(): |
84
|
|
|
pass |
85
|
|
|
|
86
|
|
|
|
87
|
|
|
class TestParser(unittest.TestCase): |
88
|
|
|
def setUp(self): |
89
|
|
|
self.parser = Parser() |
90
|
|
|
|
91
|
|
|
@given(text()) |
92
|
|
|
@example('') |
93
|
|
|
@example('* unicode: \u2020') |
94
|
|
|
def test_text(self, s): |
95
|
|
|
self.parser.parse(s) |
96
|
|
|
|
97
|
|
|
|
98
|
|
|
class TestUtils(unittest.TestCase): |
99
|
|
|
def test_to_camel_case(self): |
100
|
|
|
self.assertEqual(to_camel_case('snake_case'), 'SnakeCase') |
101
|
|
|
self.assertEqual(to_camel_case(''), '') |
102
|
|
|
self.assertEqual(to_camel_case('word'), 'Word') |
103
|
|
|
|
104
|
|
|
@given(text()) |
105
|
|
|
def test_random_text(self, s): |
106
|
|
|
to_camel_case(s) |
107
|
|
|
|
108
|
|
|
|
109
|
|
|
if __name__ == '__main__': |
110
|
|
|
unittest.main() |
111
|
|
|
|