From e01af462a38254b4f7afda88f1f1e88cd4a2cd72 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Wed, 15 Sep 2021 22:57:44 +0200 Subject: add more tests for extract_plaintext --- tests/test_document.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) 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 -- cgit v1.2.3