summaryrefslogtreecommitdiff
path: root/tests/test_document.py
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2021-09-05 22:21:48 +0200
committerDaniel Schadt <kingdread@gmx.de>2021-09-05 22:21:48 +0200
commitb018a271e714b42ed7e1049b34c25fc50c160af6 (patch)
treead815659e45263f3ef7f04790337f54f7975e3d3 /tests/test_document.py
parent0a3b5dca1fd022f0071f0fd9895e3680a23bee7a (diff)
downloadwikimini-b018a271e714b42ed7e1049b34c25fc50c160af6.tar.gz
wikimini-b018a271e714b42ed7e1049b34c25fc50c160af6.tar.bz2
wikimini-b018a271e714b42ed7e1049b34c25fc50c160af6.zip
add more tests for wikimini.document
Diffstat (limited to 'tests/test_document.py')
-rw-r--r--tests/test_document.py146
1 files changed, 145 insertions, 1 deletions
diff --git a/tests/test_document.py b/tests/test_document.py
index 35f706f..0ddce94 100644
--- a/tests/test_document.py
+++ b/tests/test_document.py
@@ -1,5 +1,11 @@
+import pytest
+
from wikimini import document
+###########################
+# Block level element tests
+###########################
+
class TestBlockLink:
@@ -47,4 +53,142 @@ class TestBlockQuote:
document.InlineLink("http://localhost", document.Plain("bar")),
]
assert (document.BlockQuote(document.Paragraph(nodes)).to_nodes()
- == nodes)
+ == nodes)
+
+
+class TestHeading:
+
+ def test_append(self):
+ heading = document.Heading(1, "foo")
+ heading.append(document.Plain("bar"))
+ assert heading.text == "foobar"
+ assert heading.level == 1
+
+ heading.append(
+ document.Style(document.Plain("bar"), True, True, False)
+ )
+ assert heading.text == "foobarbar"
+ assert heading.level == 1
+
+ def test_plain(self):
+ heading = document.Heading(1, "raboof")
+ assert heading.plain() == "raboof"
+
+ def test_to_nodes(self):
+ heading = document.Heading(1, "raboof")
+ assert heading.to_nodes() == [document.Plain("raboof")]
+
+
+class TestItemList:
+
+ def test_append(self):
+ item_list = document.ItemList([], False)
+ item_list.append(document.Plain("foo"))
+ item_list.append(document.Plain("bar"))
+ assert len(item_list.items) == 1
+
+ def test_cleanup(self):
+ item_list = document.ItemList([
+ document.Paragraph([document.Plain(" foo")]),
+ document.Paragraph([document.Plain(" ")]),
+ document.Paragraph([document.Plain(" bar")]),
+ ], False)
+ item_list.cleanup()
+ assert len(item_list.items) == 2
+ assert item_list.items[0].plain() == "foo"
+ assert item_list.items[1].plain() == "bar"
+
+ def test_new_item(self):
+ item_list = document.ItemList([], False)
+ item_list.append(document.Plain("foo"))
+ item_list.new_item()
+ item_list.append(document.Plain("bar"))
+ assert len(item_list.items) == 2
+
+ def test_plain(self):
+ item_list = document.ItemList([
+ document.Paragraph([document.Plain("foo")]),
+ document.Paragraph([document.Plain("bar")]),
+ ], False)
+ assert item_list.plain() == "foo\nbar"
+
+ def test_to_nodes(self):
+ item_list = document.ItemList([
+ document.Paragraph([document.Plain("foo")]),
+ document.Paragraph([document.Plain("bar")]),
+ ], False)
+ nodes = item_list.to_nodes()
+ assert nodes == [document.Plain("foo"), document.Plain("bar")]
+
+
+class TestParagraph:
+
+ def test_append(self):
+ par = document.Paragraph([])
+ par.append(document.Plain("foo"))
+ par.append(document.InlineLink(
+ "https://localhost", document.Plain("bar")
+ ))
+ assert len(par.nodes) == 2
+
+ def test_cleanup(self):
+ par = document.Paragraph([
+ document.Plain(" "),
+ document.Plain(" foo"),
+ document.InlineLink("https://localhost", document.Plain("bar ")),
+ ])
+ par.cleanup()
+ assert len(par.nodes) == 2
+ assert par.plain() == "foobar"
+
+ @pytest.mark.parametrize("nodes, result", [
+ ([], False),
+ ([document.Plain("foo")], False),
+ ([document.InlineLink("foo", document.Plain("bar"))], True),
+ ([
+ document.InlineLink("foo", document.Plain("bar")),
+ document.Plain("raboof")
+ ], False),
+ ])
+ def test_is_link_paragraph(self, nodes, result):
+ par = document.Paragraph(nodes)
+ assert par.is_link_paragraph() == result
+
+ @pytest.mark.parametrize("nodes, result", [
+ ([], ""),
+ ([document.Plain("foo")], "foo"),
+ ([document.Plain("foo"), document.Plain("bar")], "foobar"),
+ ([document.InlineLink("foo", document.Plain("bar"))], "bar"),
+ ])
+ def test_plain(self, nodes, result):
+ par = document.Paragraph(nodes)
+ assert par.plain() == result
+
+
+class TestVerbatim:
+
+ def test_append(self):
+ verb = document.Verbatim("")
+ verb.append(document.Plain("foo"))
+ verb.append(document.InlineLink("foo", document.Plain("bar")))
+ assert verb.text == "foobar"
+
+ def test_cleanup(self):
+ verb = document.Verbatim(" \nfoo\n bar\n ")
+ verb.cleanup()
+ assert verb.text == " \nfoo\n bar\n "
+
+#############################
+# Tests for extract_plaintext
+#############################
+
+
+class TestExtractPlaintext:
+
+ @pytest.mark.parametrize("node, plain", [
+ (document.Plain("foo"), "foo"),
+ (document.InlineLink("foo", document.Plain("bar")), "bar"),
+ (document.Style(document.Plain("foo"), True, False, False), "foo"),
+ ])
+ def test_with_node(self, node, plain):
+ assert document.extract_plaintext(node) == plain