72 lines
2.4 KiB
Python
72 lines
2.4 KiB
Python
from gmirator.generate import (
|
|
make_paragraph,
|
|
process_heading,
|
|
process_list,
|
|
process_inline,
|
|
process_url
|
|
)
|
|
|
|
############################
|
|
### generate gmi section ###
|
|
############################
|
|
|
|
def test_make_footer():
|
|
pass
|
|
|
|
def test_find_title_date():
|
|
pass
|
|
|
|
#############################
|
|
### generate html section ###
|
|
#############################
|
|
def test_process_list_legit_item():
|
|
test_str = "* this is a list item"
|
|
assert process_list(test_str, True) == (f"<li>{test_str[2:]}</li>", True)
|
|
assert process_list(test_str, False) == (f"<ul>\n<li>{test_str[2:]}</li>", True)
|
|
|
|
def test_process_list_not_list_items():
|
|
test_str = "this is a line outside a list"
|
|
assert process_list(test_str, True) == (f"</ul>\n\n{test_str}", False)
|
|
assert process_list(test_str, False) == (test_str, False)
|
|
test_str = "*this is NOT a list item*"
|
|
assert process_list(test_str, True) == (f"</ul>\n\n{test_str}", False)
|
|
assert process_list(test_str, False) == (f"{test_str}", False)
|
|
|
|
def test_process_list_empty_line():
|
|
assert process_list("", True) == ("</ul>\n\n", False)
|
|
assert process_list("", False) == ("", False)
|
|
|
|
def test_process_inline():
|
|
assert process_inline("*Hello* ~~world~~!") == "<em>Hello</em> <s>world</s>!"
|
|
|
|
def test_process_url_external_gmi_url():
|
|
external_url = "=> gemini://domain/gempage.gmi\n"
|
|
new_url = process_url(external_url)
|
|
assert new_url == '<a href="gemini://domain/gempage.gmi">=> gemini://domain/gempage.gmi</a><br>\n'
|
|
|
|
def test_process_url_internal_gmi_url():
|
|
internal_url = "=> /gempage.gmi title\n"
|
|
new_url = process_url(internal_url)
|
|
assert new_url == '<a href="/gempage.html">=> title</a><br>\n'
|
|
|
|
def test_process_heading():
|
|
line = "# this is h1 title"
|
|
html_h1 = process_heading(line)
|
|
line = "## this is h2 title"
|
|
html_h2 = process_heading(line)
|
|
line = "### this is h3 title"
|
|
html_h3 = process_heading(line)
|
|
assert html_h1 == "<h1># this is h1 title</h1>"
|
|
assert html_h2 == "<h2>## this is h2 title</h2>"
|
|
assert html_h3 == "<h3>### this is h3 title</h3>"
|
|
|
|
def test_process_heading_h4():
|
|
line = "#### this is h4 title"
|
|
html_h4 = process_heading(line)
|
|
assert html_h4 == "<h4>#### this is h4 title</h4>"
|
|
|
|
def test_make_paragraph():
|
|
line = "hello world!"
|
|
assert make_paragraph(line) == "<p>hello world!</p>\n"
|
|
line = "*hello world!*"
|
|
assert make_paragraph(line) == "<p>*hello world!*</p>\n"
|