Skip to content

Commit 71854c0

Browse files
committed
Add some new tests
1 parent 3cb7a64 commit 71854c0

File tree

1 file changed

+310
-0
lines changed

1 file changed

+310
-0
lines changed
Lines changed: 310 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,310 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Python Markdown
4+
5+
A Python implementation of John Gruber's Markdown.
6+
7+
Documentation: https://python-markdown.github.io/
8+
GitHub: https://github.com/Python-Markdown/markdown/
9+
PyPI: https://pypi.org/project/Markdown/
10+
11+
Started by Manfred Stienstra (http://www.dwerg.net/).
12+
Maintained for a few years by Yuri Takhteyev (http://www.freewisdom.org).
13+
Currently maintained by Waylan Limberg (https://github.com/waylan),
14+
Dmitry Shachnev (https://github.com/mitya57) and Isaac Muse (https://github.com/facelessuser).
15+
16+
Copyright 2007-2018 The Python Markdown Project (v. 1.7 and later)
17+
Copyright 2004, 2005, 2006 Yuri Takhteyev (v. 0.2-1.6b)
18+
Copyright 2004 Manfred Stienstra (the original version)
19+
20+
License: BSD (see LICENSE.md for details).
21+
"""
22+
23+
import unittest
24+
from markdown.test_tools import TestCase
25+
26+
27+
class TestHTMLBlocks(TestCase):
28+
29+
def test_raw_paragraph(self):
30+
self.assertMarkdownRenders(
31+
'<p>A raw paragraph.</p>',
32+
'<p>A raw paragraph.</p>'
33+
)
34+
35+
def test_raw_skip_inline_markdown(self):
36+
self.assertMarkdownRenders(
37+
'<p>A *raw* paragraph.</p>',
38+
'<p>A *raw* paragraph.</p>'
39+
)
40+
41+
def test_raw_indent_one_space(self):
42+
self.assertMarkdownRenders(
43+
' <p>A *raw* paragraph.</p>',
44+
# TODO: reevaluate. This matches strict rules and reference
45+
# implementation version 1.0.1 but not 1.0.2b8.
46+
'<p><p>A <em>raw</em> paragraph.</p></p>'
47+
)
48+
49+
def test_raw_indent_four_spaces(self):
50+
self.assertMarkdownRenders(
51+
' <p>code block</p>',
52+
self.dedent(
53+
"""
54+
<pre><code>&lt;p&gt;code block&lt;/p&gt;
55+
</code></pre>
56+
"""
57+
)
58+
)
59+
60+
def test_raw_span(self):
61+
self.assertMarkdownRenders(
62+
'<span>*inline*</span>',
63+
'<p><span><em>inline</em></span></p>'
64+
)
65+
66+
def test_code_span(self):
67+
self.assertMarkdownRenders(
68+
'`<em>code span</em>`',
69+
'<p><code>&lt;em&gt;code span&lt;/em&gt;</code></p>'
70+
)
71+
72+
def test_multiline_raw(self):
73+
self.assertMarkdownRenders(
74+
self.dedent(
75+
"""
76+
<p>
77+
A raw paragraph
78+
with multiple lines.
79+
</p>
80+
"""
81+
),
82+
self.dedent(
83+
"""
84+
<p>
85+
A raw paragraph
86+
with multiple lines.
87+
</p>
88+
"""
89+
)
90+
)
91+
92+
def test_blank_lines_in_raw(self):
93+
self.assertMarkdownRenders(
94+
self.dedent(
95+
"""
96+
<p>
97+
98+
A raw paragraph...
99+
100+
with many blank lines.
101+
102+
</p>
103+
"""
104+
),
105+
self.dedent(
106+
"""
107+
<p>
108+
109+
A raw paragraph...
110+
111+
with many blank lines.
112+
113+
</p>
114+
"""
115+
)
116+
)
117+
118+
def test_raw_surrounded_by_Markdown(self):
119+
self.assertMarkdownRenders(
120+
self.dedent(
121+
"""
122+
Some *Markdown* text.
123+
124+
<p>*Raw* HTML.</p>
125+
126+
More *Markdown* text.
127+
"""
128+
),
129+
self.dedent(
130+
"""
131+
<p>Some <em>Markdown</em> text.</p>
132+
<p>*Raw* HTML.</p>
133+
134+
<p>More <em>Markdown</em> text.</p>
135+
"""
136+
)
137+
)
138+
139+
def test_raw_without_blank_lines(self):
140+
self.assertMarkdownRenders(
141+
self.dedent(
142+
"""
143+
Some *Markdown* text.
144+
<p>*Raw* HTML.</p>
145+
More *Markdown* text.
146+
"""
147+
),
148+
# The raw gets treated as inline HTML. This follows the rules and this lib's
149+
# previous behavior, but not the reference implementation. TODO: Reevaluate.
150+
self.dedent(
151+
"""
152+
<p>Some <em>Markdown</em> text.
153+
<p><em>Raw</em> HTML.</p>
154+
More <em>Markdown</em> text.</p>
155+
"""
156+
)
157+
# The reference implementation does this instead:
158+
# self.dedent(
159+
# """
160+
# <p>Some <em>Markdown</em> text.</p>
161+
# <p>*Raw* HTML.</p>
162+
# <p>More <em>Markdown</em> text.</p>
163+
# """
164+
# )
165+
)
166+
167+
def test_raw_with_markdown_blocks(self):
168+
self.assertMarkdownRenders(
169+
self.dedent(
170+
"""
171+
<div>
172+
Not a Markdown paragraph.
173+
174+
* Not a list item.
175+
* Another non-list item.
176+
177+
Another non-Markdown paragraph.
178+
</div>
179+
"""
180+
),
181+
self.dedent(
182+
"""
183+
<div>
184+
Not a Markdown paragraph.
185+
186+
* Not a list item.
187+
* Another non-list item.
188+
189+
Another non-Markdown paragraph.
190+
</div>
191+
"""
192+
)
193+
)
194+
195+
# TODO: This fails. Fix it.
196+
def test_adjacent_raw_blocks(self):
197+
self.assertMarkdownRenders(
198+
self.dedent(
199+
"""
200+
<p>A raw paragraph.</p>
201+
<p>A second raw paragraph.</p>
202+
"""
203+
),
204+
self.dedent(
205+
"""
206+
<p>A raw paragraph.</p>
207+
<p>A second raw paragraph.</p>
208+
"""
209+
)
210+
)
211+
212+
def test_adjacent_raw_blocks_with_blank_lines(self):
213+
self.assertMarkdownRenders(
214+
self.dedent(
215+
"""
216+
<p>A raw paragraph.</p>
217+
218+
<p>A second raw paragraph.</p>
219+
"""
220+
),
221+
self.dedent(
222+
"""
223+
<p>A raw paragraph.</p>
224+
225+
<p>A second raw paragraph.</p>
226+
"""
227+
)
228+
)
229+
230+
def test_nested_raw_block(self):
231+
self.assertMarkdownRenders(
232+
self.dedent(
233+
"""
234+
<div>
235+
<p>A raw paragraph.</p>
236+
</div>
237+
"""
238+
),
239+
self.dedent(
240+
"""
241+
<div>
242+
<p>A raw paragraph.</p>
243+
</div>
244+
"""
245+
)
246+
)
247+
248+
def test_nested_indented_raw_block(self):
249+
self.assertMarkdownRenders(
250+
self.dedent(
251+
"""
252+
<div>
253+
<p>A raw paragraph.</p>
254+
</div>
255+
"""
256+
),
257+
self.dedent(
258+
"""
259+
<div>
260+
<p>A raw paragraph.</p>
261+
</div>
262+
"""
263+
)
264+
)
265+
266+
def test_nested_raw_blocks(self):
267+
self.assertMarkdownRenders(
268+
self.dedent(
269+
"""
270+
<div>
271+
<p>A raw paragraph.</p>
272+
<p>A second raw paragraph.</p>
273+
</div>
274+
"""
275+
),
276+
self.dedent(
277+
"""
278+
<div>
279+
<p>A raw paragraph.</p>
280+
<p>A second raw paragraph.</p>
281+
</div>
282+
"""
283+
)
284+
)
285+
286+
def test_nested_raw_blocks_with_blank_lines(self):
287+
self.assertMarkdownRenders(
288+
self.dedent(
289+
"""
290+
<div>
291+
292+
<p>A raw paragraph.</p>
293+
294+
<p>A second raw paragraph.</p>
295+
296+
</div>
297+
"""
298+
),
299+
self.dedent(
300+
"""
301+
<div>
302+
303+
<p>A raw paragraph.</p>
304+
305+
<p>A second raw paragraph.</p>
306+
307+
</div>
308+
"""
309+
)
310+
)

0 commit comments

Comments
 (0)