break down functions into smaller blocks
This commit is contained in:
parent
961e9bc1e3
commit
e3b5feb09b
2 changed files with 92 additions and 53 deletions
|
@ -1,16 +1,24 @@
|
|||
import re
|
||||
from gmirator.generate import (
|
||||
process_file,
|
||||
make_paragraph,
|
||||
process_heading,
|
||||
process_list,
|
||||
process_inline,
|
||||
repl_url,
|
||||
repl_heading
|
||||
process_url
|
||||
)
|
||||
|
||||
############################
|
||||
### generate gmi section ###
|
||||
############################
|
||||
|
||||
def test_process_file():
|
||||
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)
|
||||
|
@ -31,28 +39,34 @@ def test_process_list_empty_line():
|
|||
def test_process_inline():
|
||||
assert process_inline("*Hello* ~~world~~!") == "<em>Hello</em> <s>world</s>!"
|
||||
|
||||
def test_repl_url_external_gmi_url():
|
||||
def test_process_url_external_gmi_url():
|
||||
external_url = "=> gemini://domain/gempage.gmi\n"
|
||||
new_url = re.sub(r'^=> (?P<url>[^ ]*) ?(?P<text>.*)\n', repl_url, external_url)
|
||||
new_url = process_url(external_url)
|
||||
assert new_url == '<a href="gemini://domain/gempage.gmi">=> gemini://domain/gempage.gmi</a><br>\n'
|
||||
|
||||
def test_repl_url_internal_gmi_url():
|
||||
external_url = "=> /gempage.gmi title\n"
|
||||
new_url = re.sub(r'^=> (?P<url>[^ ]*) ?(?P<text>.*)\n', repl_url, external_url)
|
||||
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_repl_heading():
|
||||
def test_process_heading():
|
||||
line = "# this is h1 title"
|
||||
html_h1 = re.sub(r'^(#+) (.*)', repl_heading, line)
|
||||
html_h1 = process_heading(line)
|
||||
line = "## this is h2 title"
|
||||
html_h2 = re.sub(r'^(#+) (.*)', repl_heading, line)
|
||||
html_h2 = process_heading(line)
|
||||
line = "### this is h3 title"
|
||||
html_h3 = re.sub(r'^(#+) (.*)', repl_heading, line)
|
||||
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_repl_heading_h4():
|
||||
def test_process_heading_h4():
|
||||
line = "#### this is h4 title"
|
||||
html_h4 = re.sub(r'^(#+) (.*)', repl_heading, line)
|
||||
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"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue