commit - 11eb9ffae8b7af8e9474e4d3e3149de0246e5017
commit + 6e3768be317a2aaa642cdee5f694c0d2395e955a
blob - 1421ebd352620245cec8ef55ee9c7bc465266d83
blob + 82b65b146819d13416f37b7f0be522f51fceaeda
--- tests.py
+++ tests.py
+from unittest import TestCase, main
from lonk import HtmlToGmi
-def test_html2gmi_header():
- html = """\
-<h1>Header 1</h1>
-<p>Paragraph 1</p>
-<h2>Header 1.1</h2>
-<p>Paragraph 1.1</p>
-"""
- gmi = HtmlToGmi().feed(html)
- assert gmi == """\
+class TestHtmlToGmi(TestCase):
+ def test_in_text_tag(self):
+ html = "<p><b>bold</b> text</p>"
+ self.assertEqual(HtmlToGmi().feed(html), "bold text\n")
+
+
+ def test_img_emu(self):
+ html = "aa <img class=\"emu\" title=\":blobcatgooglyshrug:\" src=\"/d/6ytBYw515CvqFJZ8N2.png\"> bb</p>"
+ self.assertEqual(HtmlToGmi().feed(html), "aa :blobcatgooglyshrug: bb\n")
+
+ def test_html2gmi_header(self):
+ html = """\
+ <h1>Header 1</h1>
+ <p>Paragraph 1</p>
+ <h2>Header 1.1</h2>
+ <p>Paragraph 1.1</p>
+ """
+ self.assertEqual(HtmlToGmi().feed(html), """\
# Header 1
Paragraph 1
## Header 1.1
Paragraph 1.1
-""", gmi
+""")
-def test_html2gmi_pre():
- html = """\
+ def test_html2gmi_pre(self):
+ html = """\
<pre>
def fib(n):
if n == 1 or n == 2:
return 1
return fib(n - 1) + fib(n - 1)
</pre>
-"""
- gmi = HtmlToGmi().feed(html)
- assert gmi == """\
+ """
+ self.assertEqual(HtmlToGmi().feed(html), """\
```
def fib(n):
return fib(n - 1) + fib(n - 1)
```
-""", gmi
+""")
-def test_html2gmi_description_list():
- html = """\
-<dl>
- <dt>Coffee</dt>
- <dd>Black hot drink</dd>
- <dt>Milk</dt>
- <dd>White cold drink</dd>
-</dl>
-"""
- gmi = HtmlToGmi().feed(html)
- assert gmi == """\
+ def test_html2gmi_description_list(self):
+ html = """
+ <dl>
+ <dt>Coffee</dt>
+ <dd>Black hot drink</dd>
+ <dt>Milk</dt>
+ <dd>White cold drink</dd>
+ </dl>
+ """
+ self.assertEqual(HtmlToGmi().feed(html), """\
* Coffee
Black hot drink
* Milk
White cold drink
-""", gmi
+""")
if __name__ == '__main__':
- TESTS = (
- test_html2gmi_header,
- test_html2gmi_pre,
- test_html2gmi_description_list,
- )
- for func in TESTS:
- print(f"{func.__name__} ... ", end="")
- func()
- print("PASSED")
+ main()