From 965c06c398a394b1da06651bb4ed62be7609a946 Mon Sep 17 00:00:00 2001 From: Dmitry Shachnev Date: Sat, 13 May 2023 21:56:33 +0300 Subject: Port all smarty tests to the new framework --- tests/extensions/smarty.html | 32 ------ tests/extensions/smarty.txt | 40 ------- tests/test_extensions.py | 34 ------ tests/test_legacy.py | 5 - tests/test_syntax/extensions/test_smarty.py | 162 +++++++++++++++++++++++++++- 5 files changed, 161 insertions(+), 112 deletions(-) delete mode 100644 tests/extensions/smarty.html delete mode 100644 tests/extensions/smarty.txt 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 @@ -

’.
-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” — 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.

\ 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..." - -Кавычки-<<ёлочки>> -<> -Anführungszeichen->>Chevrons<< - ---- -- --- - -Escaped \-- ndash -\'Escaped\' \"quotes\" -Escaped ellipsis\... - -'Escaped \"quotes\" in real ones' -\'"Real" quotes in escaped ones\' - -Skip `<> "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): '\n' # noqa '

[TOC]

' # noqa ) - - -class TestSmarty(unittest.TestCase): - def setUp(self): - config = { - 'smarty': [ - ('smart_angled_quotes', True), - ('substitutions', { - 'ndash': '\u2013', - 'mdash': '\u2014', - 'ellipsis': '\u2026', - 'left-single-quote': '‚', # `sb` is not a typo! - 'right-single-quote': '‘', - 'left-double-quote': '„', - 'right-double-quote': '“', - '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 = """

[ The „Unicode char of the year 2014“ -is the ‚mdash‘: \u2014 -Must not be confused with ‚ndash‘ (\u2013) \u2026 ]

""" - 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?", + '

It’s fun. What’s fun?

' + ) + self.assertMarkdownRenders( + '"Isn\'t this fun"? --- she said...', + '

“Isn’t this fun”? — she said…

' + ) + self.assertMarkdownRenders( + '"\'Quoted\' words in a larger quote."', + '

“‘Quoted’ words in a larger quote.”

' + ) + self.assertMarkdownRenders( + '\'Quoted "words" in a larger quote.\'', + '

‘Quoted “words” in a larger quote.’

' + ) + self.assertMarkdownRenders( + '"quoted" text and **bold "quoted" text**', + '

“quoted” text and bold “quoted” text

' + ) + self.assertMarkdownRenders( + "'quoted' text and **bold 'quoted' text**", + '

‘quoted’ text and bold ‘quoted’ text

' + ) + self.assertMarkdownRenders( + 'em-dashes (---) and ellipes (...)', + '

em-dashes (—) and ellipes (…)

' + ) + self.assertMarkdownRenders( + '"[Link](http://example.com)" --- she said.', + '

Link” — she said.

' + ) + self.assertMarkdownRenders( + '"Ellipsis within quotes..."', + '

“Ellipsis within quotes…”

' + ) + + def test_years(self): + self.assertMarkdownRenders("1440--80's", '

1440–80’s

') + self.assertMarkdownRenders("1440--'80s", '

1440–’80s

') + self.assertMarkdownRenders("1440---'80s", '

1440—’80s

') + self.assertMarkdownRenders("1960's", '

1960’s

') + self.assertMarkdownRenders("one two '60s", '

one two ’60s

') + self.assertMarkdownRenders("'60s", '

’60s

') + + def test_wrapping_line(self): + text = ( + "A line that 'wraps' with\n" + "*emphasis* at the beginning of the next line." + ) + html = ( + '

A line that ‘wraps’ with\n' + 'emphasis at the beginning of the next line.

' + ) + self.assertMarkdownRenders(text, html) + + def test_escaped(self): + self.assertMarkdownRenders( + 'Escaped \\-- ndash', + '

Escaped -- ndash

' + ) + self.assertMarkdownRenders( + '\\\'Escaped\\\' \\"quotes\\"', + '

\'Escaped\' "quotes"

' + ) + self.assertMarkdownRenders( + 'Escaped ellipsis\\...', + '

Escaped ellipsis...

' + ) + self.assertMarkdownRenders( + '\'Escaped \\"quotes\\" in real ones\'', + '

‘Escaped "quotes" in real ones’

' + ) + self.assertMarkdownRenders( + '\\\'"Real" quotes in escaped ones\\\'', + "

'“Real” quotes in escaped ones'

" + ) + def test_escaped_attr(self): self.assertMarkdownRenders( '![x\"x](x)', '

x"x

' ) - # TODO: Move rest of smarty tests here. + def test_code_spans(self): + self.assertMarkdownRenders( + 'Skip `"code" -- --- \'spans\' ...`.', + '

Skip "code" -- --- \'spans\' ....

' + ) + + def test_code_blocks(self): + text = ( + ' Also skip "code" \'blocks\'\n' + ' foo -- bar --- baz ...' + ) + html = ( + '
Also skip "code" \'blocks\'\n'
+            'foo -- bar --- baz ...\n'
+            '
' + ) + self.assertMarkdownRenders(text, html) + + def test_horizontal_rule(self): + self.assertMarkdownRenders('--- -- ---', '
') + + +class TestSmartyAngledQuotes(TestCase): + + default_kwargs = { + 'extensions': ['smarty'], + 'extension_configs': { + 'smarty': { + 'smart_angled_quotes': True, + }, + }, + } + + def test_angled_quotes(self): + self.assertMarkdownRenders( + '<>', + '

«hello»

' + ) + self.assertMarkdownRenders( + 'Кавычки-<<ёлочки>>', + '

Кавычки-«ёлочки»

' + ) + self.assertMarkdownRenders( + 'Anführungszeichen->>Chevrons<<', + '

Anführungszeichen-»Chevrons«

' + ) + + +class TestSmartyCustomSubstitutions(TestCase): + + default_kwargs = { + 'extensions': ['smarty'], + 'extension_configs': { + 'smarty': { + 'smart_angled_quotes': True, + 'substitutions': { + 'ndash': '\u2013', + 'mdash': '\u2014', + 'ellipsis': '\u2026', + 'left-single-quote': '‚', # `sb` is not a typo! + 'right-single-quote': '‘', + 'left-double-quote': '„', + 'right-double-quote': '“', + '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 = ( + '

[ The „Unicode char of the year 2014“\n' + 'is the ‚mdash‘: \u2014\n' + 'Must not be confused with ‚ndash‘ (\u2013) \u2026 ]

' + ) + self.assertMarkdownRenders(text, html) -- cgit v1.2.1