Skip to content

Commit 19f639d

Browse files
committed
Add tests for pandoc.inlines
1 parent 7773ecd commit 19f639d

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import pytest
2+
3+
from quartodoc.pandoc.inlines import (
4+
Code,
5+
Emph,
6+
Image,
7+
Inline,
8+
Inlines,
9+
Link,
10+
Span,
11+
Str,
12+
Strong,
13+
)
14+
from quartodoc.pandoc.components import Attr
15+
16+
# NOTE:
17+
# To make it easy to cross-check what the generated html code will be,
18+
# it should be possible to copy the markdown code on the right-hand side
19+
# of the assert statements and paste it at
20+
# https://pandoc.org/try/
21+
22+
23+
def test_code():
24+
s = "a = 1"
25+
26+
c = Code(s)
27+
assert str(c) == "`a = 1`"
28+
assert c.html == "<code>a = 1</code>"
29+
30+
c = Code(s, Attr("code-id", ["c1", "c2"]))
31+
assert str(c) == "`a = 1`{#code-id .c1 .c2}"
32+
assert c.html == '<code id="code-id" class="c1 c2">a = 1</code>'
33+
34+
35+
def test_emph():
36+
e = Emph("a")
37+
assert str(e) == "*a*"
38+
39+
e = Emph("")
40+
assert str(e) == ""
41+
42+
43+
def test_image():
44+
img = Image("Image Caption", "path/to/image.png", "Image Title")
45+
assert str(img) == '![Image Caption](path/to/image.png "Image Title")'
46+
47+
img = Image(
48+
src="image.png",
49+
attr=Attr(classes=["c1"], attributes={"width": "50%", "height": "60%"})
50+
)
51+
assert str(img) == '![](image.png){.c1 width="50%" height="60%"}'
52+
53+
54+
def test_inline():
55+
i = Inline()
56+
57+
with pytest.raises(NotImplementedError):
58+
str(i)
59+
60+
with pytest.raises(NotImplementedError):
61+
i.html
62+
63+
64+
def test_inlines():
65+
i = Inlines(["a", Span("b"), Emph("c")])
66+
assert str(i) == "a [b]{} *c*"
67+
68+
i = Inlines(["a", Span("b"), Emph("c"), Inlines(["d", Strong("e")])])
69+
assert str(i) == "a [b]{} *c* d **e**"
70+
71+
72+
def test_link():
73+
l = Link("Link Text", "https://abc.com")
74+
assert str(l) == "[Link Text](https://abc.com)"
75+
76+
l = Link("Link Text", "https://abc.com", "Link Title")
77+
assert str(l) == '[Link Text](https://abc.com "Link Title")'
78+
79+
80+
def test_span():
81+
s = Span("a")
82+
assert str(s) == "[a]{}"
83+
84+
s = Span(
85+
"a",
86+
Attr("span-id", classes=["c1", "c2"], attributes={"data-value": "1"})
87+
)
88+
assert str(s) == '[a]{#span-id .c1 .c2 data-value="1"}'
89+
90+
91+
def test_str():
92+
s = Str("a")
93+
assert str(s) == "a"
94+
95+
s = Str()
96+
assert str(s) == ""
97+
98+
99+
def test_strong():
100+
s = Strong("a")
101+
assert str(s) == "**a**"
102+
103+
s = Strong("")
104+
assert str(s) == ""
105+
106+
107+
def test_seq_inlinecontent():
108+
s = Span(
109+
[Str("a"), Emph("b"), Code("c = 3", Attr(classes=["py"]))],
110+
Attr(classes=["c1", "c2"])
111+
)
112+
assert str(s) == "[a *b* `c = 3`{.py}]{.c1 .c2}"

0 commit comments

Comments
 (0)