Skip to content

Commit 965c06c

Browse files
mitya57waylan
authored andcommitted
Port all smarty tests to the new framework
1 parent 1aa4c3d commit 965c06c

File tree

5 files changed

+161
-112
lines changed

5 files changed

+161
-112
lines changed

tests/extensions/smarty.html

Lines changed: 0 additions & 32 deletions
This file was deleted.

tests/extensions/smarty.txt

Lines changed: 0 additions & 40 deletions
This file was deleted.

tests/test_extensions.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -629,37 +629,3 @@ def testTocInHeaders(self):
629629
'</div>\n' # noqa
630630
'<h1 id="toc"><em>[TOC]</em></h1>' # noqa
631631
)
632-
633-
634-
class TestSmarty(unittest.TestCase):
635-
def setUp(self):
636-
config = {
637-
'smarty': [
638-
('smart_angled_quotes', True),
639-
('substitutions', {
640-
'ndash': '\u2013',
641-
'mdash': '\u2014',
642-
'ellipsis': '\u2026',
643-
'left-single-quote': '&sbquo;', # `sb` is not a typo!
644-
'right-single-quote': '&lsquo;',
645-
'left-double-quote': '&bdquo;',
646-
'right-double-quote': '&ldquo;',
647-
'left-angle-quote': '[',
648-
'right-angle-quote': ']',
649-
}),
650-
]
651-
}
652-
self.md = markdown.Markdown(
653-
extensions=['smarty'],
654-
extension_configs=config
655-
)
656-
657-
def testCustomSubstitutions(self):
658-
text = """<< The "Unicode char of the year 2014"
659-
is the 'mdash': ---
660-
Must not be confused with 'ndash' (--) ... >>
661-
"""
662-
correct = """<p>[ The &bdquo;Unicode char of the year 2014&ldquo;
663-
is the &sbquo;mdash&lsquo;: \u2014
664-
Must not be confused with &sbquo;ndash&lsquo; (\u2013) \u2026 ]</p>"""
665-
self.assertEqual(self.md.convert(text), correct)

tests/test_legacy.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,6 @@ class TestExtensions(LegacyTestCase):
156156

157157
admonition = Kwargs(extensions=['admonition'])
158158

159-
smarty = Kwargs(
160-
extensions=['smarty'],
161-
extension_configs={'smarty': {'smart_angled_quotes': True}}
162-
)
163-
164159

165160
class TestExtensionsExtra(LegacyTestCase):
166161
location = os.path.join(parent_test_dir, 'extensions/extra')

tests/test_syntax/extensions/test_smarty.py

Lines changed: 161 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,170 @@ class TestSmarty(TestCase):
2727

2828
default_kwargs = {'extensions': ['smarty']}
2929

30+
def test_basic(self):
31+
self.assertMarkdownRenders(
32+
"It's fun. What's fun?",
33+
'<p>It&rsquo;s fun. What&rsquo;s fun?</p>'
34+
)
35+
self.assertMarkdownRenders(
36+
'"Isn\'t this fun"? --- she said...',
37+
'<p>&ldquo;Isn&rsquo;t this fun&rdquo;? &mdash; she said&hellip;</p>'
38+
)
39+
self.assertMarkdownRenders(
40+
'"\'Quoted\' words in a larger quote."',
41+
'<p>&ldquo;&lsquo;Quoted&rsquo; words in a larger quote.&rdquo;</p>'
42+
)
43+
self.assertMarkdownRenders(
44+
'\'Quoted "words" in a larger quote.\'',
45+
'<p>&lsquo;Quoted &ldquo;words&rdquo; in a larger quote.&rsquo;</p>'
46+
)
47+
self.assertMarkdownRenders(
48+
'"quoted" text and **bold "quoted" text**',
49+
'<p>&ldquo;quoted&rdquo; text and <strong>bold &ldquo;quoted&rdquo; text</strong></p>'
50+
)
51+
self.assertMarkdownRenders(
52+
"'quoted' text and **bold 'quoted' text**",
53+
'<p>&lsquo;quoted&rsquo; text and <strong>bold &lsquo;quoted&rsquo; text</strong></p>'
54+
)
55+
self.assertMarkdownRenders(
56+
'em-dashes (---) and ellipes (...)',
57+
'<p>em-dashes (&mdash;) and ellipes (&hellip;)</p>'
58+
)
59+
self.assertMarkdownRenders(
60+
'"[Link](http://example.com)" --- she said.',
61+
'<p>&ldquo;<a href="http://example.com">Link</a>&rdquo; &mdash; she said.</p>'
62+
)
63+
self.assertMarkdownRenders(
64+
'"Ellipsis within quotes..."',
65+
'<p>&ldquo;Ellipsis within quotes&hellip;&rdquo;</p>'
66+
)
67+
68+
def test_years(self):
69+
self.assertMarkdownRenders("1440--80's", '<p>1440&ndash;80&rsquo;s</p>')
70+
self.assertMarkdownRenders("1440--'80s", '<p>1440&ndash;&rsquo;80s</p>')
71+
self.assertMarkdownRenders("1440---'80s", '<p>1440&mdash;&rsquo;80s</p>')
72+
self.assertMarkdownRenders("1960's", '<p>1960&rsquo;s</p>')
73+
self.assertMarkdownRenders("one two '60s", '<p>one two &rsquo;60s</p>')
74+
self.assertMarkdownRenders("'60s", '<p>&rsquo;60s</p>')
75+
76+
def test_wrapping_line(self):
77+
text = (
78+
"A line that 'wraps' with\n"
79+
"*emphasis* at the beginning of the next line."
80+
)
81+
html = (
82+
'<p>A line that &lsquo;wraps&rsquo; with\n'
83+
'<em>emphasis</em> at the beginning of the next line.</p>'
84+
)
85+
self.assertMarkdownRenders(text, html)
86+
87+
def test_escaped(self):
88+
self.assertMarkdownRenders(
89+
'Escaped \\-- ndash',
90+
'<p>Escaped -- ndash</p>'
91+
)
92+
self.assertMarkdownRenders(
93+
'\\\'Escaped\\\' \\"quotes\\"',
94+
'<p>\'Escaped\' "quotes"</p>'
95+
)
96+
self.assertMarkdownRenders(
97+
'Escaped ellipsis\\...',
98+
'<p>Escaped ellipsis...</p>'
99+
)
100+
self.assertMarkdownRenders(
101+
'\'Escaped \\"quotes\\" in real ones\'',
102+
'<p>&lsquo;Escaped "quotes" in real ones&rsquo;</p>'
103+
)
104+
self.assertMarkdownRenders(
105+
'\\\'"Real" quotes in escaped ones\\\'',
106+
"<p>'&ldquo;Real&rdquo; quotes in escaped ones'</p>"
107+
)
108+
30109
def test_escaped_attr(self):
31110
self.assertMarkdownRenders(
32111
'![x\"x](x)',
33112
'<p><img alt="x&quot;x" src="x" /></p>'
34113
)
35114

36-
# TODO: Move rest of smarty tests here.
115+
def test_code_spans(self):
116+
self.assertMarkdownRenders(
117+
'Skip `"code" -- --- \'spans\' ...`.',
118+
'<p>Skip <code>"code" -- --- \'spans\' ...</code>.</p>'
119+
)
120+
121+
def test_code_blocks(self):
122+
text = (
123+
' Also skip "code" \'blocks\'\n'
124+
' foo -- bar --- baz ...'
125+
)
126+
html = (
127+
'<pre><code>Also skip "code" \'blocks\'\n'
128+
'foo -- bar --- baz ...\n'
129+
'</code></pre>'
130+
)
131+
self.assertMarkdownRenders(text, html)
132+
133+
def test_horizontal_rule(self):
134+
self.assertMarkdownRenders('--- -- ---', '<hr />')
135+
136+
137+
class TestSmartyAngledQuotes(TestCase):
138+
139+
default_kwargs = {
140+
'extensions': ['smarty'],
141+
'extension_configs': {
142+
'smarty': {
143+
'smart_angled_quotes': True,
144+
},
145+
},
146+
}
147+
148+
def test_angled_quotes(self):
149+
self.assertMarkdownRenders(
150+
'<<hello>>',
151+
'<p>&laquo;hello&raquo;</p>'
152+
)
153+
self.assertMarkdownRenders(
154+
'Кавычки-<<ёлочки>>',
155+
'<p>Кавычки-&laquo;ёлочки&raquo;</p>'
156+
)
157+
self.assertMarkdownRenders(
158+
'Anführungszeichen->>Chevrons<<',
159+
'<p>Anführungszeichen-&raquo;Chevrons&laquo;</p>'
160+
)
161+
162+
163+
class TestSmartyCustomSubstitutions(TestCase):
164+
165+
default_kwargs = {
166+
'extensions': ['smarty'],
167+
'extension_configs': {
168+
'smarty': {
169+
'smart_angled_quotes': True,
170+
'substitutions': {
171+
'ndash': '\u2013',
172+
'mdash': '\u2014',
173+
'ellipsis': '\u2026',
174+
'left-single-quote': '&sbquo;', # `sb` is not a typo!
175+
'right-single-quote': '&lsquo;',
176+
'left-double-quote': '&bdquo;',
177+
'right-double-quote': '&ldquo;',
178+
'left-angle-quote': '[',
179+
'right-angle-quote': ']',
180+
},
181+
},
182+
},
183+
}
184+
185+
def test_custom_substitutions(self):
186+
text = (
187+
'<< The "Unicode char of the year 2014"\n'
188+
"is the 'mdash': ---\n"
189+
"Must not be confused with 'ndash' (--) ... >>"
190+
)
191+
html = (
192+
'<p>[ The &bdquo;Unicode char of the year 2014&ldquo;\n'
193+
'is the &sbquo;mdash&lsquo;: \u2014\n'
194+
'Must not be confused with &sbquo;ndash&lsquo; (\u2013) \u2026 ]</p>'
195+
)
196+
self.assertMarkdownRenders(text, html)

0 commit comments

Comments
 (0)