mirror of
https://github.com/kuhyx/WUT_Computer_Science.git
synced 2026-07-04 18:23:15 +02:00
feat: length conversion
This commit is contained in:
parent
69825d5b51
commit
b20714fe29
Binary file not shown.
10
examples/paragraphs/table.tex
Normal file
10
examples/paragraphs/table.tex
Normal file
@ -0,0 +1,10 @@
|
||||
\documentclass{article}
|
||||
\begin{document}
|
||||
|
||||
Here is a table:
|
||||
|
||||
\begin{tabular}{p[5cm]}
|
||||
test
|
||||
\end{tabular}
|
||||
|
||||
\end{document}
|
||||
@ -20,11 +20,16 @@ def generic_checks(latex_string):
|
||||
if "}" not in latex_string:
|
||||
print(latex_string + error_arrays[1])
|
||||
return "Error!"
|
||||
return
|
||||
|
||||
def generic_checks_command(latex_string):
|
||||
error_arrays = return_error_arrays()
|
||||
if generic_checks(latex_string) == "Error!":
|
||||
return "Error!"
|
||||
if latex_string[0] != "\\":
|
||||
print(latex_string + error_arrays[6])
|
||||
return "Error!"
|
||||
return
|
||||
|
||||
|
||||
|
||||
def document_class(latex_string):
|
||||
@ -33,7 +38,7 @@ def document_class(latex_string):
|
||||
\documentclass{article}
|
||||
"""
|
||||
error_arrays = return_error_arrays()
|
||||
if generic_checks(latex_string) == "Error!":
|
||||
if generic_checks_command(latex_string) == "Error!":
|
||||
return "Error!"
|
||||
if latex_string[len("\\documentclass{") - 1] != "{":
|
||||
print(latex_string + error_arrays[3])
|
||||
@ -52,7 +57,7 @@ def begin_document(latex_string):
|
||||
Converts LaTeX begin document method to html
|
||||
\begin{document}
|
||||
"""
|
||||
if generic_checks(latex_string) == "Error!":
|
||||
if generic_checks_command(latex_string) == "Error!":
|
||||
return "Error!"
|
||||
if command_name_check(latex_string, "begin") == "Error!":
|
||||
return "Error!"
|
||||
@ -62,7 +67,7 @@ def begin_tabular(latex_string):
|
||||
r"""
|
||||
Checks if LaTeX begin tabular method is correct
|
||||
"""
|
||||
if generic_checks(latex_string) == "Error!":
|
||||
if generic_checks_command(latex_string) == "Error!":
|
||||
return "Error!"
|
||||
if command_name_check(latex_string, "begin") == "Error!":
|
||||
return "Error!"
|
||||
@ -78,6 +83,29 @@ def tabular_parameters(latex_string):
|
||||
return ""
|
||||
return "Error!"
|
||||
|
||||
def tabular_columns_parameters(latex_string):
|
||||
if generic_checks(latex_string) == "Error!":
|
||||
return "Error!"
|
||||
return latex_string
|
||||
|
||||
def length_conversions(latex_length):
|
||||
length_dictionary = {
|
||||
"pt": [1.3, "px"],
|
||||
|
||||
"mm": [1, "mm"],
|
||||
|
||||
"cm": [1, "cm"],
|
||||
|
||||
"in": [1, "in"],
|
||||
|
||||
"ex": [1, "ex"],
|
||||
|
||||
"em": [1, "em"],
|
||||
}
|
||||
return length_dictionary.get(latex_length, "Error!")
|
||||
|
||||
def parameter_arguments(latex_string):
|
||||
return latex_string
|
||||
|
||||
if __name__ == "__main__":
|
||||
document_class("")
|
||||
|
||||
@ -48,6 +48,14 @@ def given_no_slash_then_error():
|
||||
"""
|
||||
assert begin_tabular(r"begin{tabular}") == "Error!"
|
||||
|
||||
def given_tabular_star_then_error():
|
||||
"""
|
||||
Given: no backslash at start
|
||||
When: N/A
|
||||
Then: Error message
|
||||
"""
|
||||
assert begin_tabular(r"begin{tabular*}") == "Error!"
|
||||
|
||||
|
||||
def given_correct_then_html():
|
||||
"""
|
||||
|
||||
98
program/tests/test_code/test_length_conversions.py
Normal file
98
program/tests/test_code/test_length_conversions.py
Normal file
@ -0,0 +1,98 @@
|
||||
"""
|
||||
Tests begin document function
|
||||
"""
|
||||
from code.main import length_conversions
|
||||
|
||||
# Write python tests for a function translating LaTeX documentclass to html
|
||||
def given_empty_then_error():
|
||||
"""
|
||||
Given: ""
|
||||
When: N/A
|
||||
Then: Error message
|
||||
"""
|
||||
assert length_conversions("") == "Error!"
|
||||
|
||||
def given_pt_then_px():
|
||||
"""
|
||||
Given: ""
|
||||
When: N/A
|
||||
Then: Error message
|
||||
"""
|
||||
assert length_conversions("pt") == [1.3, "px"]
|
||||
|
||||
def given_mm_then_mm():
|
||||
"""
|
||||
Given: ""
|
||||
When: N/A
|
||||
Then: Error message
|
||||
"""
|
||||
assert length_conversions("mm") == [1, "mm"]
|
||||
|
||||
def given_cm_then_cm():
|
||||
"""
|
||||
Given: ""
|
||||
When: N/A
|
||||
Then: Error message
|
||||
"""
|
||||
assert length_conversions("cm") == [1, "cm"]
|
||||
|
||||
def given_in_then_in():
|
||||
"""
|
||||
Given: ""
|
||||
When: N/A
|
||||
Then: Error message
|
||||
"""
|
||||
assert length_conversions("in") == [1, "in"]
|
||||
|
||||
def given_ex_then_ex():
|
||||
"""
|
||||
Given: ""
|
||||
When: N/A
|
||||
Then: Error message
|
||||
"""
|
||||
assert length_conversions("ex") == [1, "ex"]
|
||||
|
||||
def given_em_then_em():
|
||||
"""
|
||||
Given: ""
|
||||
When: N/A
|
||||
Then: Error message
|
||||
"""
|
||||
assert length_conversions("em") == [1, "em"]
|
||||
|
||||
def given_mu_then_error():
|
||||
"""
|
||||
Given: ""
|
||||
When: N/A
|
||||
Then: Error message
|
||||
"""
|
||||
assert length_conversions("mu") == "Error!"
|
||||
|
||||
def given_sp_then_error():
|
||||
"""
|
||||
Given: ""
|
||||
When: N/A
|
||||
Then: Error message
|
||||
"""
|
||||
assert length_conversions("sp") == "Error!"
|
||||
|
||||
def given_unknown_then_error():
|
||||
"""
|
||||
Given: ""
|
||||
When: N/A
|
||||
Then: Error message
|
||||
"""
|
||||
assert length_conversions("unknown") == "Error!"
|
||||
|
||||
def test_begin_tabular():
|
||||
given_empty_then_error()
|
||||
given_pt_then_px()
|
||||
given_mm_then_mm()
|
||||
given_cm_then_cm()
|
||||
given_in_then_in()
|
||||
given_ex_then_ex()
|
||||
given_em_then_em()
|
||||
given_mu_then_error()
|
||||
given_sp_then_error()
|
||||
given_unknown_then_error()
|
||||
|
||||
31
program/tests/test_code/test_parameter_argument.py
Normal file
31
program/tests/test_code/test_parameter_argument.py
Normal file
@ -0,0 +1,31 @@
|
||||
from code.main import parameter_arguments
|
||||
|
||||
def given_empty_then_error():
|
||||
"""
|
||||
Given:
|
||||
When: N/A
|
||||
Then: <!DOCTYPE html><html>
|
||||
"""
|
||||
assert tabular_columns_parameters("") == "Error!"
|
||||
|
||||
def given_unknown_then_error():
|
||||
"""
|
||||
Given:
|
||||
When: N/A
|
||||
Then: <!DOCTYPE html><html>
|
||||
"""
|
||||
assert tabular_columns_parameters("l{5cm}") == "Error!"
|
||||
|
||||
def given_p_then_array():
|
||||
"""
|
||||
Given:
|
||||
When: N/A
|
||||
Then: <!DOCTYPE html><html>
|
||||
"""
|
||||
assert tabular_columns_parameters("p{5cm}") == ["p", 5, [5, "cm"]]
|
||||
|
||||
|
||||
def test_parameter_arguments():
|
||||
given_empty_then_empty()
|
||||
given_empty_brackets_then_empty()
|
||||
given_c_then_array()
|
||||
108
program/tests/test_code/test_tabular_columns_parameters.py
Normal file
108
program/tests/test_code/test_tabular_columns_parameters.py
Normal file
@ -0,0 +1,108 @@
|
||||
"""
|
||||
Tests tabular_parameters function
|
||||
"""
|
||||
|
||||
from code.main import tabular_columns_parameters
|
||||
|
||||
def given_empty_then_empty():
|
||||
"""
|
||||
Given:
|
||||
When: N/A
|
||||
Then: <!DOCTYPE html><html>
|
||||
"""
|
||||
assert tabular_columns_parameters("") == "Error!"
|
||||
|
||||
def given_empty_brackets_then_empty():
|
||||
"""
|
||||
Given: {}
|
||||
When: N/A
|
||||
Then: <!DOCTYPE html><html>
|
||||
"""
|
||||
assert tabular_columns_parameters("{}") == "Error!"
|
||||
|
||||
def given_c_then_array():
|
||||
"""
|
||||
Given: [c]
|
||||
When: N/A
|
||||
Then: <!DOCTYPE html><html>
|
||||
"""
|
||||
assert tabular_columns_parameters("{c}") == ["align='center'"]
|
||||
|
||||
def given_l_then_array():
|
||||
"""
|
||||
Given: [c]
|
||||
When: N/A
|
||||
Then: <!DOCTYPE html><html>
|
||||
"""
|
||||
assert tabular_columns_parameters("{l}") == ["align='left'"]
|
||||
|
||||
def given_r_then_array():
|
||||
"""
|
||||
Given: [c]
|
||||
When: N/A
|
||||
Then: <!DOCTYPE html><html>
|
||||
"""
|
||||
assert tabular_columns_parameters("{r}") == ["align='right'"]
|
||||
|
||||
def given_line_then_array():
|
||||
"""
|
||||
Given: [c]
|
||||
When: N/A
|
||||
Then: <!DOCTYPE html><html>
|
||||
"""
|
||||
assert tabular_columns_parameters("|") == ["{style=\"border-left: 1px solid black;\"}"]
|
||||
|
||||
def given_double_line_then_array():
|
||||
"""
|
||||
Given: [c]
|
||||
When: N/A
|
||||
Then: <!DOCTYPE html><html>
|
||||
"""
|
||||
assert tabular_columns_parameters("||") == ["{style=\"border-left: 1px solid black;\"}", "{style=\"border-left: 1px solid black;\"}"]
|
||||
|
||||
def given_c_then_array():
|
||||
"""
|
||||
Given: [c]
|
||||
When: N/A
|
||||
Then: <!DOCTYPE html><html>
|
||||
"""
|
||||
assert tabular_columns_parameters("{c}") == ["c"]
|
||||
|
||||
def given_c_then_array():
|
||||
"""
|
||||
Given: [c]
|
||||
When: N/A
|
||||
Then: <!DOCTYPE html><html>
|
||||
"""
|
||||
assert tabular_columns_parameters("{c}") == ["c"]
|
||||
|
||||
def given_c_then_array():
|
||||
"""
|
||||
Given: [c]
|
||||
When: N/A
|
||||
Then: <!DOCTYPE html><html>
|
||||
"""
|
||||
assert tabular_columns_parameters("{c}") == ["c"]
|
||||
|
||||
def given_c_then_array():
|
||||
"""
|
||||
Given: [c]
|
||||
When: N/A
|
||||
Then: <!DOCTYPE html><html>
|
||||
"""
|
||||
assert tabular_columns_parameters("{c}") == ["c"]
|
||||
|
||||
def given_c_then_array():
|
||||
"""
|
||||
Given: [c]
|
||||
When: N/A
|
||||
Then: <!DOCTYPE html><html>
|
||||
"""
|
||||
assert tabular_columns_parameters("{c}") == ["c"]
|
||||
|
||||
|
||||
|
||||
def test_tabular_columns_parameters():
|
||||
given_empty_then_empty()
|
||||
given_empty_brackets_then_empty()
|
||||
given_c_then_array()
|
||||
Loading…
Reference in New Issue
Block a user