summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Shachnev <mitya57@gmail.com>2023-05-13 21:56:33 +0300
committerWaylan Limberg <waylan.limberg@icloud.com>2023-05-16 11:42:55 -0400
commit965c06c398a394b1da06651bb4ed62be7609a946 (patch)
treeba6adcea01d010c8c2162266493c93de8f8bd975
parent1aa4c3d385a8456397c5189079c90e818fc34a06 (diff)
downloadpython-markdown-965c06c398a394b1da06651bb4ed62be7609a946.tar.gz
Port all smarty tests to the new frameworkHEADmaster
-rw-r--r--tests/extensions/smarty.html32
-rw-r--r--tests/extensions/smarty.txt40
-rw-r--r--tests/test_extensions.py34
-rw-r--r--tests/test_legacy.py5
-rw-r--r--tests/test_syntax/extensions/test_smarty.py162
5 files changed, 161 insertions, 112 deletions
diff --git a/tests/extensions/smarty.html b/tests/extensions/smarty.html
deleted file mode 100644
index e37e377..0000000
--- a/tests/extensions/smarty.html
+++ /dev/null
@@ -1,32 +0,0 @@
-<p>&rsquo;.<br />
-1440&ndash;80&rsquo;s<br />
-1440&ndash;&rsquo;80s<br />
-1440&mdash;&rsquo;80s<br />
-1960s<br />
-1960&rsquo;s<br />
-one two &rsquo;60s<br />
-&rsquo;60s</p>
-<p>It&rsquo;s fun. What&rsquo;s fun?<br />
-&ldquo;Isn&rsquo;t this fun&rdquo;? &mdash; she said&hellip;<br />
-&ldquo;&lsquo;Quoted&rsquo; words in a larger quote.&rdquo;<br />
-&lsquo;Quoted &ldquo;words&rdquo; in a larger quote.&rsquo;<br />
-&ldquo;quoted&rdquo; text and <strong>bold &ldquo;quoted&rdquo; text</strong><br />
-&lsquo;quoted&rsquo; text and <strong>bold &lsquo;quoted&rsquo; text</strong><br />
-em-dashes (&mdash;) and ellipes (&hellip;)<br />
-&ldquo;<a href="http://example.com">Link</a>&rdquo; &mdash; she said.</p>
-<p>&ldquo;Ellipsis within quotes&hellip;&rdquo;</p>
-<p>Кавычки-&laquo;ёлочки&raquo;<br />
-&laquo;hello&raquo;<br />
-Anführungszeichen-&raquo;Chevrons&laquo;</p>
-<hr />
-<p>Escaped -- ndash<br />
-'Escaped' "quotes"<br />
-Escaped ellipsis...</p>
-<p>&lsquo;Escaped "quotes" in real ones&rsquo;<br />
-'&ldquo;Real&rdquo; quotes in escaped ones'</p>
-<p>Skip <code>&lt;&lt;all&gt;&gt; "code" -- --- 'spans' ...</code>.</p>
-<pre><code>Also skip "code" 'blocks'
-foo -- bar --- baz ...
-</code></pre>
-<p>A line that &lsquo;wraps&rsquo; with
-<em>emphasis</em> at the beginning of the next line.</p> \ No newline at end of file
diff --git a/tests/extensions/smarty.txt b/tests/extensions/smarty.txt
deleted file mode 100644
index 12e5c95..0000000
--- a/tests/extensions/smarty.txt
+++ /dev/null
@@ -1,40 +0,0 @@
-'.
-1440--80's
-1440--'80s
-1440---'80s
-1960s
-1960's
-one two '60s
-'60s
-
-It's fun. What's fun?
-"Isn't this fun"? --- she said...
-"'Quoted' words in a larger quote."
-'Quoted "words" in a larger quote.'
-"quoted" text and **bold "quoted" text**
-'quoted' text and **bold 'quoted' text**
-em-dashes (---) and ellipes (...)
-"[Link](http://example.com)" --- she said.
-
-"Ellipsis within quotes..."
-
-Кавычки-<<ёлочки>>
-<<hello>>
-Anführungszeichen->>Chevrons<<
-
---- -- ---
-
-Escaped \-- ndash
-\'Escaped\' \"quotes\"
-Escaped ellipsis\...
-
-'Escaped \"quotes\" in real ones'
-\'"Real" quotes in escaped ones\'
-
-Skip `<<all>> "code" -- --- 'spans' ...`.
-
- Also skip "code" 'blocks'
- foo -- bar --- baz ...
-
-A line that 'wraps' with
-*emphasis* at the beginning of the next line.
diff --git a/tests/test_extensions.py b/tests/test_extensions.py
index ad985c3..c8cee99 100644
--- a/tests/test_extensions.py
+++ b/tests/test_extensions.py
@@ -629,37 +629,3 @@ class TestTOC(TestCaseWithAssertStartsWith):
'</div>\n' # noqa
'<h1 id="toc"><em>[TOC]</em></h1>' # noqa
)
-
-
-class TestSmarty(unittest.TestCase):
- def setUp(self):
- config = {
- 'smarty': [
- ('smart_angled_quotes', True),
- ('substitutions', {
- 'ndash': '\u2013',
- 'mdash': '\u2014',
- 'ellipsis': '\u2026',
- 'left-single-quote': '&sbquo;', # `sb` is not a typo!
- 'right-single-quote': '&lsquo;',
- 'left-double-quote': '&bdquo;',
- 'right-double-quote': '&ldquo;',
- 'left-angle-quote': '[',
- 'right-angle-quote': ']',
- }),
- ]
- }
- self.md = markdown.Markdown(
- extensions=['smarty'],
- extension_configs=config
- )
-
- def testCustomSubstitutions(self):
- text = """<< The "Unicode char of the year 2014"
-is the 'mdash': ---
-Must not be confused with 'ndash' (--) ... >>
-"""
- correct = """<p>[ The &bdquo;Unicode char of the year 2014&ldquo;
-is the &sbquo;mdash&lsquo;: \u2014
-Must not be confused with &sbquo;ndash&lsquo; (\u2013) \u2026 ]</p>"""
- self.assertEqual(self.md.convert(text), correct)
diff --git a/tests/test_legacy.py b/tests/test_legacy.py
index 30b6c18..295588b 100644
--- a/tests/test_legacy.py
+++ b/tests/test_legacy.py
@@ -156,11 +156,6 @@ class TestExtensions(LegacyTestCase):
admonition = Kwargs(extensions=['admonition'])
- smarty = Kwargs(
- extensions=['smarty'],
- extension_configs={'smarty': {'smart_angled_quotes': True}}
- )
-
class TestExtensionsExtra(LegacyTestCase):
location = os.path.join(parent_test_dir, 'extensions/extra')
diff --git a/tests/test_syntax/extensions/test_smarty.py b/tests/test_syntax/extensions/test_smarty.py
index fc635ad..f2d074d 100644
--- a/tests/test_syntax/extensions/test_smarty.py
+++ b/tests/test_syntax/extensions/test_smarty.py
@@ -27,10 +27,170 @@ class TestSmarty(TestCase):
default_kwargs = {'extensions': ['smarty']}
+ def test_basic(self):
+ self.assertMarkdownRenders(
+ "It's fun. What's fun?",
+ '<p>It&rsquo;s fun. What&rsquo;s fun?</p>'
+ )
+ self.assertMarkdownRenders(
+ '"Isn\'t this fun"? --- she said...',
+ '<p>&ldquo;Isn&rsquo;t this fun&rdquo;? &mdash; she said&hellip;</p>'
+ )
+ self.assertMarkdownRenders(
+ '"\'Quoted\' words in a larger quote."',
+ '<p>&ldquo;&lsquo;Quoted&rsquo; words in a larger quote.&rdquo;</p>'
+ )
+ self.assertMarkdownRenders(
+ '\'Quoted "words" in a larger quote.\'',
+ '<p>&lsquo;Quoted &ldquo;words&rdquo; in a larger quote.&rsquo;</p>'
+ )
+ self.assertMarkdownRenders(
+ '"quoted" text and **bold "quoted" text**',
+ '<p>&ldquo;quoted&rdquo; text and <strong>bold &ldquo;quoted&rdquo; text</strong></p>'
+ )
+ self.assertMarkdownRenders(
+ "'quoted' text and **bold 'quoted' text**",
+ '<p>&lsquo;quoted&rsquo; text and <strong>bold &lsquo;quoted&rsquo; text</strong></p>'
+ )
+ self.assertMarkdownRenders(
+ 'em-dashes (---) and ellipes (...)',
+ '<p>em-dashes (&mdash;) and ellipes (&hellip;)</p>'
+ )
+ self.assertMarkdownRenders(
+ '"[Link](http://example.com)" --- she said.',
+ '<p>&ldquo;<a href="http://example.com">Link</a>&rdquo; &mdash; she said.</p>'
+ )
+ self.assertMarkdownRenders(
+ '"Ellipsis within quotes..."',
+ '<p>&ldquo;Ellipsis within quotes&hellip;&rdquo;</p>'
+ )
+
+ def test_years(self):
+ self.assertMarkdownRenders("1440--80's", '<p>1440&ndash;80&rsquo;s</p>')
+ self.assertMarkdownRenders("1440--'80s", '<p>1440&ndash;&rsquo;80s</p>')
+ self.assertMarkdownRenders("1440---'80s", '<p>1440&mdash;&rsquo;80s</p>')
+ self.assertMarkdownRenders("1960's", '<p>1960&rsquo;s</p>')
+ self.assertMarkdownRenders("one two '60s", '<p>one two &rsquo;60s</p>')
+ self.assertMarkdownRenders("'60s", '<p>&rsquo;60s</p>')
+
+ def test_wrapping_line(self):
+ text = (
+ "A line that 'wraps' with\n"
+ "*emphasis* at the beginning of the next line."
+ )
+ html = (
+ '<p>A line that &lsquo;wraps&rsquo; with\n'
+ '<em>emphasis</em> at the beginning of the next line.</p>'
+ )
+ self.assertMarkdownRenders(text, html)
+
+ def test_escaped(self):
+ self.assertMarkdownRenders(
+ 'Escaped \\-- ndash',
+ '<p>Escaped -- ndash</p>'
+ )
+ self.assertMarkdownRenders(
+ '\\\'Escaped\\\' \\"quotes\\"',
+ '<p>\'Escaped\' "quotes"</p>'
+ )
+ self.assertMarkdownRenders(
+ 'Escaped ellipsis\\...',
+ '<p>Escaped ellipsis...</p>'
+ )
+ self.assertMarkdownRenders(
+ '\'Escaped \\"quotes\\" in real ones\'',
+ '<p>&lsquo;Escaped "quotes" in real ones&rsquo;</p>'
+ )
+ self.assertMarkdownRenders(
+ '\\\'"Real" quotes in escaped ones\\\'',
+ "<p>'&ldquo;Real&rdquo; quotes in escaped ones'</p>"
+ )
+
def test_escaped_attr(self):
self.assertMarkdownRenders(
'![x\"x](x)',
'<p><img alt="x&quot;x" src="x" /></p>'
)
- # TODO: Move rest of smarty tests here.
+ def test_code_spans(self):
+ self.assertMarkdownRenders(
+ 'Skip `"code" -- --- \'spans\' ...`.',
+ '<p>Skip <code>"code" -- --- \'spans\' ...</code>.</p>'
+ )
+
+ def test_code_blocks(self):
+ text = (
+ ' Also skip "code" \'blocks\'\n'
+ ' foo -- bar --- baz ...'
+ )
+ html = (
+ '<pre><code>Also skip "code" \'blocks\'\n'
+ 'foo -- bar --- baz ...\n'
+ '</code></pre>'
+ )
+ self.assertMarkdownRenders(text, html)
+
+ def test_horizontal_rule(self):
+ self.assertMarkdownRenders('--- -- ---', '<hr />')
+
+
+class TestSmartyAngledQuotes(TestCase):
+
+ default_kwargs = {
+ 'extensions': ['smarty'],
+ 'extension_configs': {
+ 'smarty': {
+ 'smart_angled_quotes': True,
+ },
+ },
+ }
+
+ def test_angled_quotes(self):
+ self.assertMarkdownRenders(
+ '<<hello>>',
+ '<p>&laquo;hello&raquo;</p>'
+ )
+ self.assertMarkdownRenders(
+ 'Кавычки-<<ёлочки>>',
+ '<p>Кавычки-&laquo;ёлочки&raquo;</p>'
+ )
+ self.assertMarkdownRenders(
+ 'Anführungszeichen->>Chevrons<<',
+ '<p>Anführungszeichen-&raquo;Chevrons&laquo;</p>'
+ )
+
+
+class TestSmartyCustomSubstitutions(TestCase):
+
+ default_kwargs = {
+ 'extensions': ['smarty'],
+ 'extension_configs': {
+ 'smarty': {
+ 'smart_angled_quotes': True,
+ 'substitutions': {
+ 'ndash': '\u2013',
+ 'mdash': '\u2014',
+ 'ellipsis': '\u2026',
+ 'left-single-quote': '&sbquo;', # `sb` is not a typo!
+ 'right-single-quote': '&lsquo;',
+ 'left-double-quote': '&bdquo;',
+ 'right-double-quote': '&ldquo;',
+ 'left-angle-quote': '[',
+ 'right-angle-quote': ']',
+ },
+ },
+ },
+ }
+
+ def test_custom_substitutions(self):
+ text = (
+ '<< The "Unicode char of the year 2014"\n'
+ "is the 'mdash': ---\n"
+ "Must not be confused with 'ndash' (--) ... >>"
+ )
+ html = (
+ '<p>[ The &bdquo;Unicode char of the year 2014&ldquo;\n'
+ 'is the &sbquo;mdash&lsquo;: \u2014\n'
+ 'Must not be confused with &sbquo;ndash&lsquo; (\u2013) \u2026 ]</p>'
+ )
+ self.assertMarkdownRenders(text, html)