From 4b7864ddb5f5d8fc0cf967085bbd73faf4127544 Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sun, 7 Jan 2018 03:20:38 +0000 Subject: tests: Add test_parse_block_html. * tests/data/blexer-block-html.md: New file. * tests/test_md_tw.py (TestTWBlockLexer.test_parse_block_html): New test. --- tests/data/blexer-block-html.md | 22 ++++++++++++ tests/test_md_tw.py | 74 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 tests/data/blexer-block-html.md (limited to 'tests') diff --git a/tests/data/blexer-block-html.md b/tests/data/blexer-block-html.md new file mode 100644 index 0000000..edc452d --- /dev/null +++ b/tests/data/blexer-block-html.md @@ -0,0 +1,22 @@ +This is a regular paragraph. + + + + + +
Monte Carlo
+ +This is another regular paragraph, which is followed by some HTML +fluff decorated with attributes. + +
+
+

A dispute conference; human snafu.

+
+
+ +Which is followed by a + +
+ +Ameba. diff --git a/tests/test_md_tw.py b/tests/test_md_tw.py index 6eb769f..18fb1ac 100644 --- a/tests/test_md_tw.py +++ b/tests/test_md_tw.py @@ -577,6 +577,80 @@ class TestTWBlockLexer(object): } tokens = process(tokens) + def test_parse_block_html(self): + tokens = self._parse('blexer-block-html.md') + + def process(tokens): + token = tokens.pop(0) + while token: + type_ = token['type'] + + expected_token = None + if type_ in expected: + expected_token = expected[type_].pop(0) + + validate(token, expected_token) + + if type_ in ['open_html', 'close_html']: + break + else: + token = tokens.pop(0) + + return tokens + + def validate(token, expected_token=None): + type_ = token['type'] + + if type_ == 'open_html': + assert 'tag' in token + assert 'extra' in token + assert 'text' in token + elif type_ == 'close_html': + assert 'text' in token + + if not expected_token: + return + + if 'text' in token: + assert_equal(token['text'], expected_token['text']) + if 'extra' in token: + assert_equal(token['extra'], expected_token['extra']) + if 'tag' in token: + assert_equal(token['tag'], expected_token['tag']) + return + + expected = { + 'open_html': [ + { + 'tag': 'table', + 'extra': '', + 'text': '\n \n Monte Carlo' + '\n \n' + }, + ], + } + tokens = process(tokens) + + expected = { + 'open_html': [ + { + 'tag': 'div', + 'extra': ' class="parley"', + 'text': '\n
\n ' + '

A dispute conference; human snafu.

\n ' + '
\n' + } + ], + } + tokens = process(tokens) + + expected = { + 'close_html': [ + {'text': '
\n\n'} + ] + } + tokens = process(tokens) + def teardown(self): pass -- cgit v1.2.3