summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/test_doctests.txt22
-rw-r--r--tests/test_document.py50
2 files changed, 72 insertions, 0 deletions
diff --git a/tests/test_doctests.txt b/tests/test_doctests.txt
new file mode 100644
index 0000000..692690b
--- /dev/null
+++ b/tests/test_doctests.txt
@@ -0,0 +1,22 @@
+Document #1:
+
+>>> from wikimini.document import *
+>>> blocks = []
+>>> insert_into(blocks, Plain("Paragraph "))
+>>> insert_into(blocks, Plain("1\n\nParagraph 2"))
+>>> # blocks == [Paragraph(...), Paragraph(...)]
+>>> assert len(blocks) == 2
+
+Document #2:
+
+>>> from wikimini.document import *
+>>> verbatim = Verbatim("")
+>>> verbatim.append(InlineLink("http://localhost", Plain("Visit here!")))
+>>> assert verbatim.text == "Visit here!"
+
+Format #1:
+
+>>> from wikimini.document import Heading
+>>> from wikimini.formats import gemtext, as_string
+>>> as_string(gemtext.Gemtext(None), Heading(1, "Coffee"))
+'# Coffee\n'
diff --git a/tests/test_document.py b/tests/test_document.py
new file mode 100644
index 0000000..35f706f
--- /dev/null
+++ b/tests/test_document.py
@@ -0,0 +1,50 @@
+from wikimini import document
+
+
+class TestBlockLink:
+
+ def test_append(self):
+ link = document.BlockLink("https://localhost", "foo ")
+ link.append(document.Plain("bar"))
+ assert link.title == "foo bar"
+
+ link.append(document.Style(document.Plain("qux"), False, True, False))
+ assert link.title == "foo barqux"
+
+ def test_plain(self):
+ link = document.BlockLink("https://localhost", "foo ")
+ assert link.plain() == "foo "
+
+ def test_to_nodes(self):
+ link = document.BlockLink("https://localhost", "foo ")
+ assert link.to_nodes() == [
+ document.Plain("foo ")
+ ]
+
+
+class TestBlockQuote:
+
+ def test_append(self):
+ quote = document.BlockQuote(document.Paragraph([]))
+ quote.append(document.Plain("Foo"))
+ assert quote.plain() == "Foo"
+ assert len(quote.content.nodes) == 1
+
+ quote.append(document.Style(document.Plain("bar"), True, True, False))
+ assert quote.plain() == "Foobar"
+ assert len(quote.content.nodes) == 2
+
+ def test_plain(self):
+ quote = document.BlockQuote(document.Paragraph([
+ document.Plain("Foo"),
+ document.InlineLink("http://localhost", document.Plain("bar")),
+ ]))
+ assert quote.plain() == "Foobar"
+
+ def test_to_nodes(self):
+ nodes = [
+ document.Plain("Foo"),
+ document.InlineLink("http://localhost", document.Plain("bar")),
+ ]
+ assert (document.BlockQuote(document.Paragraph(nodes)).to_nodes()
+ == nodes)