feat: more easy unit tests

This commit is contained in:
Krzysztof Rudnicki 2023-06-07 03:16:28 +02:00
parent 87523aabe2
commit a52cef8dbc
6 changed files with 96 additions and 2 deletions

View File

@ -1 +1 @@
<!DOCTYPE html><html><html> <table><tr><td align='left'>test </td><td style='border-left: 1px solid black'align='center'> 2 </td><td style='border-left: 1px solid black'align='right'> test </td></tr><tr><td align='left'></td></tr><tr><td align='left'>4 </td><td style='border-left: 1px solid black'align='center'> 5 </td><td style='border-left: 1px solid black'align='right'> 6 </td></tr><tr><td align='left'></td></tr><tr><td align='left'></td></tr> </table> </html>
<!DOCTYPE html><html>Error!</tr></table>

View File

@ -44,6 +44,9 @@ def document_class_only_checks(latex_string):
"""
Checks only errors connected to document class
"""
if len(latex_string) < len("\\documentclass{"):
print(latex_string + "Error! latex string to short to be document class!")
return "Error!"
if latex_string[len("\\documentclass{") - 1] != "{":
print(latex_string + "Error! curly bracket not opened!")
return "Error!"
@ -355,7 +358,7 @@ def handle_single_column(column, column_style,
f"""Error! column_number index: {column_number}
is out of length of column_style: {column_style}"""
)
return "Error!"
return "Error!", column_number
return_string, column_number = handle_line_strings(
line_string, column_style, column_number, return_string)

View File

@ -0,0 +1,24 @@
from code.main import command_name_check
def given_valid_then_empty():
assert command_name_check("{documentclass}", "documentclass") == ""
def given_valid_begin_then_empty():
assert command_name_check("{begin}", "begin") == ""
def given_invalid_then_error():
assert command_name_check("{documentclasS}", "documentclass") == "Error!"
def given_invalid_begin_then_error():
assert command_name_check("{begIn}", "begin") == "Error!"
def test_command_name_check():
given_valid_then_empty()
given_valid_begin_then_empty()
given_invalid_then_error()
given_invalid_begin_then_error()

View File

@ -0,0 +1,19 @@
from code.main import document_class_only_checks
def test_missing_curly_bracket():
assert document_class_only_checks("\\documentclass") == "Error!"
def test_missing_command_name():
assert document_class_only_checks("\\otherclass{}") == "Error!"
def test_correct_input():
assert document_class_only_checks("\\documentclass{}") == ""
def test_document_class_only_checks():
test_missing_curly_bracket()
test_missing_command_name()
test_correct_input()

View File

@ -0,0 +1,21 @@
from code.main import generic_checks
def test_empty_string():
assert generic_checks("") == "Error!"
def test_no_curly_bracket():
assert generic_checks(
"latex_string_without_curly_bracket") == "Error!"
def test_with_curly_bracket_at_end():
assert generic_checks(
"latex_string_with_curly_bracket}") == ""
def test_generic_checks():
test_empty_string()
test_no_curly_bracket()
test_with_curly_bracket_at_end()

View File

@ -0,0 +1,27 @@
from code.main import generic_checks_command
def test_empty_string():
assert (generic_checks_command("")) == "Error!"
def test_no_curly_bracket():
assert (generic_checks_command(
"latex_string_without_curly_bracket")) == "Error!"
def test_no_slash_at_beginning():
assert (generic_checks_command(
"latex_string_without_slash_at_beginning}")) == "Error!"
def test_with_slash_and_curly_bracket():
assert (generic_checks_command(
"\\latex_string_with_slash_and_curly_bracket}")) == ""
def test_generic_checks_command():
test_empty_string()
test_no_curly_bracket()
test_no_slash_at_beginning()
test_with_slash_and_curly_bracket()