1 from unittest import TestCase, main
2 from lonk import HtmlToGmi
5 def fn_media_url(mime, img_url):
9 class TestHtmlToGmi(TestCase):
11 html = '<p>head<br>tail</p>'
12 self.assertEqual(HtmlToGmi("https://localhost/api", fn_media_url).feed(html), """\
18 def test_img_realtive(self):
19 html = '<img src="/d/xxxx.jpg" title="yyy">'
20 self.assertEqual(HtmlToGmi("https://localhost/api", fn_media_url).feed(html), "=> https://localhost/d/xxxx.jpg yyy")
22 def test_link_realtive(self):
23 html = '<p>head <a href="/sub1/1">https link</a> tail</p>'
24 self.assertEqual(HtmlToGmi("https://localhost/api", fn_media_url).feed(html), """\
25 head ↳ https link tail
26 => https://localhost/sub1/1 https link
29 def test_links_in_paragraph(self):
30 html = '<p>head <a href="https://127.0.0.1">https link</a> <a href="gemini://127.0.0.1">gemini link</a> tail</p>'
31 self.assertEqual(HtmlToGmi("", fn_media_url).feed(html), """\
32 head ↳ https link ↳ gemini link tail
33 => https://127.0.0.1 https link
34 => gemini://127.0.0.1 gemini link
37 def test_in_text_tag(self):
38 html = "<p><b>bold</b> text</p>"
39 self.assertEqual(HtmlToGmi("", fn_media_url).feed(html), "bold text\n")
41 def test_img_emu(self):
42 html = "aa <img class=\"emu\" title=\":blobcatgooglyshrug:\" src=\"/d/6ytBYw515CvqFJZ8N2.png\"> bb</p>"
43 self.assertEqual(HtmlToGmi("", fn_media_url).feed(html), "aa :blobcatgooglyshrug: bb\n")
45 def test_html2gmi_header(self):
52 self.assertEqual(HtmlToGmi("", fn_media_url).feed(html), """\
62 def test_html2gmi_pre(self):
68 return fib(n - 1) + fib(n - 1)
71 self.assertEqual(HtmlToGmi("", fn_media_url).feed(html), """\
77 return fib(n - 1) + fib(n - 1)
82 def test_html2gmi_description_list(self):
86 <dd>Black hot drink</dd>
88 <dd>White cold drink</dd>
91 self.assertEqual(HtmlToGmi("", fn_media_url).feed(html), """\
102 if __name__ == '__main__':