diff options
author | Daniel Schadt <kingdread@gmx.de> | 2021-09-15 22:57:44 +0200 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2021-09-15 22:57:44 +0200 |
commit | e01af462a38254b4f7afda88f1f1e88cd4a2cd72 (patch) | |
tree | d7b3643afd6a78b6bf4ffe6ef478b4e7314cdaa4 /tests/test_document.py | |
parent | b018a271e714b42ed7e1049b34c25fc50c160af6 (diff) | |
download | wikimini-e01af462a38254b4f7afda88f1f1e88cd4a2cd72.tar.gz wikimini-e01af462a38254b4f7afda88f1f1e88cd4a2cd72.tar.bz2 wikimini-e01af462a38254b4f7afda88f1f1e88cd4a2cd72.zip |
add more tests for extract_plaintext
Diffstat (limited to 'tests/test_document.py')
-rw-r--r-- | tests/test_document.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tests/test_document.py b/tests/test_document.py index 0ddce94..4f0a911 100644 --- a/tests/test_document.py +++ b/tests/test_document.py @@ -192,3 +192,46 @@ class TestExtractPlaintext: ]) def test_with_node(self, node, plain): assert document.extract_plaintext(node) == plain + + def test_with_nodelist(self): + nodes = [ + document.Plain("foo"), + document.Plain("bar "), + document.Style(document.Plain("qux"), False, True, True), + ] + expected = "foobar qux" + assert document.extract_plaintext(nodes) == expected + + # Most of those just defer to Block.plain() which is tested above + @pytest.mark.parametrize("block, plain", [ + (document.Paragraph([document.Plain("foo"), document.Plain("bar")]), + "foobar"), + (document.Verbatim("foo bar"), "foo bar"), + ]) + def test_with_block(self, block, plain): + assert document.extract_plaintext(block) == plain + + def test_with_blocklist(self): + blocks = [ + document.Paragraph([document.Plain("foo")]), + document.Verbatim("bar"), + document.ItemList([ + document.Paragraph([document.Plain("qux")]), + document.Paragraph([document.Plain("baz")]), + ], False), + ] + expected = "foo\n\nbar\n\nqux\nbaz" + assert document.extract_plaintext(blocks) == expected + + def test_with_document(self): + blocks = [ + document.Paragraph([document.Plain("foo")]), + document.Verbatim("bar"), + document.ItemList([ + document.Paragraph([document.Plain("qux")]), + document.Paragraph([document.Plain("baz")]), + ], False), + ] + doc = document.Document(blocks) + expected = "foo\n\nbar\n\nqux\nbaz" + assert document.extract_plaintext(doc) == expected |