markdown-textwrap

text wrap markdown documents
git clone git://git.ricketyspace.net/markdown-textwrap.git
Log | Files | Refs

commit 4b7864ddb5f5d8fc0cf967085bbd73faf4127544
parent fc9b789240fbed2cf55255dd2b2e8d233e961de1
Author: rsiddharth <s@ricketyspace.net>
Date:   Sun,  7 Jan 2018 03:20:38 +0000

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.

Diffstat:
tests/data/blexer-block-html.md | 22++++++++++++++++++++++
tests/test_md_tw.py | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 96 insertions(+), 0 deletions(-)

diff --git a/tests/data/blexer-block-html.md b/tests/data/blexer-block-html.md @@ -0,0 +1,22 @@ +This is a regular paragraph. + +<table> + <tr> + <td>Monte Carlo</td> + </tr> +</table> + +This is another regular paragraph, which is followed by some HTML +fluff decorated with attributes. + +<div class="parley"> + <article> + <p>A dispute conference; human snafu.</p> + </article> +</div> + +Which is followed by a + +<hr /> + +Ameba. diff --git 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 <tr>\n <td>Monte Carlo</td>' + '\n </tr>\n' + }, + ], + } + tokens = process(tokens) + + expected = { + 'open_html': [ + { + 'tag': 'div', + 'extra': ' class="parley"', + 'text': '\n <article>\n ' + '<p>A dispute conference; human snafu.</p>\n ' + '</article>\n' + } + ], + } + tokens = process(tokens) + + expected = { + 'close_html': [ + {'text': '<hr />\n\n'} + ] + } + tokens = process(tokens) + def teardown(self): pass