2017-10-14 21:13:38 +03:00
|
|
|
import unittest
|
|
|
|
|
|
2019-08-07 09:51:22 -04:00
|
|
|
from markdown import parse
|
2017-10-14 21:13:38 +03:00
|
|
|
|
2020-10-15 12:46:24 -04:00
|
|
|
# Tests adapted from `problem-specifications//canonical-data.json`
|
2017-10-14 21:13:38 +03:00
|
|
|
|
|
|
|
|
|
2019-08-07 09:51:22 -04:00
|
|
|
class MarkdownTest(unittest.TestCase):
|
|
|
|
|
def test_parses_normal_text_as_a_paragraph(self):
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
parse("This will be a paragraph"), "<p>This will be a paragraph</p>"
|
|
|
|
|
)
|
2017-10-14 21:13:38 +03:00
|
|
|
|
2019-08-07 09:51:22 -04:00
|
|
|
def test_parsing_italics(self):
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
parse("_This will be italic_"), "<p><em>This will be italic</em></p>"
|
|
|
|
|
)
|
2017-10-14 21:13:38 +03:00
|
|
|
|
2019-08-07 09:51:22 -04:00
|
|
|
def test_parsing_bold_text(self):
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
parse("__This will be bold__"), "<p><strong>This will be bold</strong></p>"
|
|
|
|
|
)
|
2017-10-14 21:13:38 +03:00
|
|
|
|
2019-08-07 09:51:22 -04:00
|
|
|
def test_mixed_normal_italics_and_bold_text(self):
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
parse("This will _be_ __mixed__"),
|
|
|
|
|
"<p>This will <em>be</em> <strong>mixed</strong></p>",
|
|
|
|
|
)
|
2017-10-14 21:13:38 +03:00
|
|
|
|
2019-08-07 09:51:22 -04:00
|
|
|
def test_with_h1_header_level(self):
|
|
|
|
|
self.assertEqual(parse("# This will be an h1"), "<h1>This will be an h1</h1>")
|
2017-10-14 21:13:38 +03:00
|
|
|
|
2019-08-07 09:51:22 -04:00
|
|
|
def test_with_h2_header_level(self):
|
|
|
|
|
self.assertEqual(parse("## This will be an h2"), "<h2>This will be an h2</h2>")
|
2017-10-14 21:13:38 +03:00
|
|
|
|
2019-08-07 09:51:22 -04:00
|
|
|
def test_with_h6_header_level(self):
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
parse("###### This will be an h6"), "<h6>This will be an h6</h6>"
|
|
|
|
|
)
|
2017-10-14 21:13:38 +03:00
|
|
|
|
|
|
|
|
def test_unordered_lists(self):
|
2019-08-07 09:51:22 -04:00
|
|
|
self.assertEqual(
|
|
|
|
|
parse("* Item 1\n* Item 2"), "<ul><li>Item 1</li><li>Item 2</li></ul>"
|
|
|
|
|
)
|
2017-10-14 21:13:38 +03:00
|
|
|
|
2019-08-07 09:51:22 -04:00
|
|
|
def test_with_a_little_bit_of_everything(self):
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
parse("# Header!\n* __Bold Item__\n* _Italic Item_"),
|
|
|
|
|
"<h1>Header!</h1><ul><li><strong>Bold Item</strong></li><li><em>Italic Item</em></li></ul>",
|
|
|
|
|
)
|
2017-10-14 21:13:38 +03:00
|
|
|
|
2019-08-07 09:51:22 -04:00
|
|
|
def test_with_markdown_symbols_in_the_header_text_that_should_not_be_interpreted(
|
|
|
|
|
self
|
|
|
|
|
):
|
2018-08-27 13:21:24 -04:00
|
|
|
self.assertEqual(
|
2019-08-07 09:51:22 -04:00
|
|
|
parse("# This is a header with # and * in the text"),
|
|
|
|
|
"<h1>This is a header with # and * in the text</h1>",
|
|
|
|
|
)
|
2018-08-27 13:21:24 -04:00
|
|
|
|
2019-08-07 09:51:22 -04:00
|
|
|
def test_with_markdown_symbols_in_the_list_item_text_that_should_not_be_interpreted(
|
|
|
|
|
self
|
|
|
|
|
):
|
2018-08-27 13:21:24 -04:00
|
|
|
self.assertEqual(
|
2019-08-07 09:51:22 -04:00
|
|
|
parse("* Item 1 with a # in the text\n* Item 2 with * in the text"),
|
|
|
|
|
"<ul><li>Item 1 with a # in the text</li><li>Item 2 with * in the text</li></ul>",
|
|
|
|
|
)
|
2018-08-27 13:21:24 -04:00
|
|
|
|
2019-08-07 09:51:22 -04:00
|
|
|
def test_with_markdown_symbols_in_the_paragraph_text_that_should_not_be_interpreted(
|
|
|
|
|
self
|
|
|
|
|
):
|
2018-08-27 13:21:24 -04:00
|
|
|
self.assertEqual(
|
2019-08-07 09:51:22 -04:00
|
|
|
parse("This is a paragraph with # and * in the text"),
|
|
|
|
|
"<p>This is a paragraph with # and * in the text</p>",
|
|
|
|
|
)
|
2018-08-27 13:21:24 -04:00
|
|
|
|
2019-08-07 09:51:22 -04:00
|
|
|
def test_unordered_lists_close_properly_with_preceding_and_following_lines(self):
|
2019-05-28 09:01:13 -04:00
|
|
|
self.assertEqual(
|
2019-08-07 09:51:22 -04:00
|
|
|
parse("# Start a list\n* Item 1\n* Item 2\nEnd a list"),
|
|
|
|
|
"<h1>Start a list</h1><ul><li>Item 1</li><li>Item 2</li></ul><p>End a list</p>",
|
|
|
|
|
)
|
2019-05-28 09:01:13 -04:00
|
|
|
|
2017-10-14 21:13:38 +03:00
|
|
|
|
2019-08-07 09:51:22 -04:00
|
|
|
if __name__ == "__main__":
|
2017-10-14 21:13:38 +03:00
|
|
|
unittest.main()
|