diff --git a/examples/complicated/table1.pdf b/examples/complicated/table1.pdf index 7c7c0201..68484692 100644 Binary files a/examples/complicated/table1.pdf and b/examples/complicated/table1.pdf differ diff --git a/examples/complicated/table1.tex b/examples/complicated/table1.tex index f83c1933..ad6681ff 100644 --- a/examples/complicated/table1.tex +++ b/examples/complicated/table1.tex @@ -3,7 +3,7 @@ Here is a table: -\begin{tabular}{|l|c|r|} +\begin{tabular}{|lp{1.3pt}c|r|} \hline left & center & right \\ \cline{2-3} diff --git a/program/code/main.py b/program/code/main.py index 626b4e8e..ffa5507f 100644 --- a/program/code/main.py +++ b/program/code/main.py @@ -90,6 +90,38 @@ def tabular_parameters(latex_string): return "Error!" +def only_pipes_and_space(latex_string): + """Checks if latex string only contains | or " ", if yes returns True, if no returns false""" + return all(char == '|' or char == ' ' or char == '{' or char == '}' for char in latex_string) + + +def main_tabular_parameters_loop(latex_string, simple_parameters_dictionary): + return_array = [] + i = 0 + latex_string_length = len(latex_string) + while i < latex_string_length: + character = latex_string[i] + if character in ['l', 'c', 'r', '|']: + print("entered") + return_array.append( + simple_parameters_dictionary.get(latex_string[i])) + i += 1 + continue + if character in ['p', 'm', 'b']: + closing_bracket = latex_string.find('}', i + 1) + columns_string = latex_string[i:closing_bracket + 1] + print(columns_string) + result = tabular_columns_parameters(columns_string) + if result == "Error!": + return result + return_array.append(result) + i = closing_bracket + continue + i += 1 + print(return_array) + return return_array + + def tabular_required_parameters(latex_string): if generic_checks(latex_string) == "Error!": return "Error!" @@ -102,7 +134,10 @@ def tabular_required_parameters(latex_string): "r": "align='right'", "|": "style=\"border-left: 1px solid black" } - return latex_string + if only_pipes_and_space(latex_string): + print("tabular_required_parameters, required table parameters are only pipes and spaces!:", latex_string) + return "Error!" + return main_tabular_parameters_loop(latex_string, simple_parameters_dictionary) def length_conversions(latex_length): diff --git a/program/tests/test_code/test_only_pipes_and_space.py b/program/tests/test_code/test_only_pipes_and_space.py new file mode 100644 index 00000000..c330c426 --- /dev/null +++ b/program/tests/test_code/test_only_pipes_and_space.py @@ -0,0 +1,29 @@ +from code.main import only_pipes_and_space + + +def given_empty_then_true(): + assert only_pipes_and_space("") == True + + +def given_only_pipes_then_true(): + assert only_pipes_and_space("|||||") == True + + +def given_only_space_then_true(): + assert only_pipes_and_space(" ") == True + + +def given_space_and_pipes_then_true(): + assert only_pipes_and_space("| | ||| |") == True + + +def given_not_space_nor_pipes_then_false(): + assert only_pipes_and_space(" || || a") == False + + +def test_only_pipes_and_space(): + given_empty_then_true() + given_only_pipes_then_true() + given_only_space_then_true() + given_space_and_pipes_then_true() + given_not_space_nor_pipes_then_false() diff --git a/program/tests/test_code/test_tabular_required_parameters.py b/program/tests/test_code/test_tabular_required_parameters.py index cc0cea48..2141e18f 100644 --- a/program/tests/test_code/test_tabular_required_parameters.py +++ b/program/tests/test_code/test_tabular_required_parameters.py @@ -47,7 +47,7 @@ def given_single_left_then_correct(): When: N/A Then: """ - assert tabular_required_parameters("{l}") == ['l'] + assert tabular_required_parameters("{l}") == ["align='left'"] def given_single_center_then_correct(): @@ -56,7 +56,7 @@ def given_single_center_then_correct(): When: N/A Then: """ - assert tabular_required_parameters("{c}") == ['c'] + assert tabular_required_parameters("{c}") == ["align='center'"] def given_single_right_then_correct(): @@ -65,7 +65,7 @@ def given_single_right_then_correct(): When: N/A Then: """ - assert tabular_required_parameters("{r}") == ['r'] + assert tabular_required_parameters("{r}") == ["align='right'"] def given_empty_wrap_p_then_error(): @@ -122,6 +122,28 @@ def given_empty_wrap_b_brackets_then_error(): assert tabular_required_parameters("{b{}}") == "Error!" +def given_filled_p_brackets_then_correct(): + """ + Given: {r} + When: N/A + Then: + """ + assert tabular_required_parameters("{p{1.3pt}}") == [ + "style=\"vertical-align: top; width: 1.69px;\""] + + +def given_complicated_then_correct(): + assert tabular_required_parameters("{|lp{1.3pt}c|r|}") == [ + "style=\"border-left: 1px solid black", + "align='left'", + "style=\"vertical-align: top; width: 1.69px;\"", + "align='center'", + "style=\"border-left: 1px solid black", + "align='right'", + "style=\"border-left: 1px solid black" + ] + + def test_tabular_required_parameters(): given_empty_then_error() given_empty_brackets_then_error() @@ -136,3 +158,5 @@ def test_tabular_required_parameters(): given_empty_wrap_p_brackets_then_error() given_empty_wrap_m_brackets_then_error() given_empty_wrap_b_brackets_then_error() + given_filled_p_brackets_then_correct() + given_complicated_then_correct()