diff --git a/preliminaryReport/tests/simpletable.css b/preliminaryReport/tests/simpletable.css deleted file mode 100644 index 31314dd1..00000000 --- a/preliminaryReport/tests/simpletable.css +++ /dev/null @@ -1,99 +0,0 @@ - -/* start css.sty */ -.cmtt-10{font-family: monospace,monospace;} -p{margin-top:0;margin-bottom:0} -p.indent{text-indent:0;} -p + p{margin-top:1em;} -p + div, p + pre {margin-top:1em;} -div + p, pre + p {margin-top:1em;} -a { overflow-wrap: break-word; word-wrap: break-word; word-break: break-word; hyphens: auto; } -@media print {div.crosslinks {visibility:hidden;}} -table.tabular{border-collapse: collapse; border-spacing: 0;} -a img { border-top: 0; border-left: 0; border-right: 0; } -center { margin-top:1em; margin-bottom:1em; } -td center { margin-top:0em; margin-bottom:0em; } -.Canvas { position:relative; } -img.math{vertical-align:middle;} -div.par-math-display, div.math-display{text-align:center;} -li p.indent { text-indent: 0em } -li p:first-child{ margin-top:0em; } -li p:last-child, li div:last-child { margin-bottom:0.5em; } -li p:first-child{ margin-bottom:0; } -li p~ul:last-child, li p~ol:last-child{ margin-bottom:0.5em; } -.enumerate1 {list-style-type:decimal;} -.enumerate2 {list-style-type:lower-alpha;} -.enumerate3 {list-style-type:lower-roman;} -.enumerate4 {list-style-type:upper-alpha;} -div.newtheorem { margin-bottom: 2em; margin-top: 2em;} -div.newtheorem .head{font-weight: bold;} -.obeylines-h,.obeylines-v {white-space: nowrap; } -div.obeylines-v p { margin-top:0; margin-bottom:0; } -.overline{ text-decoration:overline; } -.overline img{ border-top: 1px solid black; } -td.displaylines {text-align:center; white-space:nowrap;} -.centerline {text-align:center;} -.rightline {text-align:right;} -pre.verbatim {font-family: monospace,monospace; text-align:left; clear:both; } -.fbox {padding-left:3.0pt; padding-right:3.0pt; text-indent:0pt; border:solid black 0.4pt; } -div.fbox {display:table} -div.center div.fbox {text-align:center; clear:both; padding-left:3.0pt; padding-right:3.0pt; text-indent:0pt; border:solid black 0.4pt; } -div.minipage{width:100%;} -div.center, div.center div.center {text-align: center; margin-left:1em; margin-right:1em;} -div.center div {text-align: left;} -div.flushright, div.flushright div.flushright {text-align: right;} -div.flushright div {text-align: left;} -div.flushleft {text-align: left;} -.underline{ text-decoration:underline; } -.underline img{ border-bottom: 1px solid black; margin-bottom:1pt; } -.framebox-c, .framebox-l, .framebox-r { padding-left:3.0pt; padding-right:3.0pt; text-indent:0pt; border:solid black 0.4pt; } -.framebox-c {text-align:center;} -.framebox-l {text-align:left;} -.framebox-r {text-align:right;} -span.thank-mark{ vertical-align: super } -span.footnote-mark sup.textsuperscript, span.footnote-mark a sup.textsuperscript{ font-size:80%; } -div.tabular, div.center div.tabular {text-align: center; margin-top:0.5em; margin-bottom:0.5em; } -table.tabular td p{margin-top:0em;} -table.tabular {margin-left: auto; margin-right: auto;} -td p:first-child{ margin-top:0em; } -td p:last-child{ margin-bottom:0em; } -div.td00{ margin-left:0pt; margin-right:0pt; } -div.td01{ margin-left:0pt; margin-right:5pt; } -div.td10{ margin-left:5pt; margin-right:0pt; } -div.td11{ margin-left:5pt; margin-right:5pt; } -table[rules] {border-left:solid black 0.4pt; border-right:solid black 0.4pt; } -td.td00{ padding-left:0pt; padding-right:0pt; } -td.td01{ padding-left:0pt; padding-right:5pt; } -td.td10{ padding-left:5pt; padding-right:0pt; } -td.td11{ padding-left:5pt; padding-right:5pt; } -table[rules] {border-left:solid black 0.4pt; border-right:solid black 0.4pt; } -.hline hr, .cline hr{ height : 0px; margin:0px; } -.hline td, .cline td{ padding: 0; } -.hline hr, .cline hr{border:none;border-top:1px solid black;} -.hline {border-top: 1px solid black;} -.hline + .vspace:last-child{display:none;} -.hline:first-child{border-bottom:1px solid black;border-top:none;} -.tabbing-right {text-align:right;} -div.float, div.figure {margin-left: auto; margin-right: auto;} -div.float img {text-align:center;} -div.figure img {text-align:center;} -.marginpar,.reversemarginpar {width:20%; float:right; text-align:left; margin-left:auto; margin-top:0.5em; font-size:85%; text-decoration:underline;} -.marginpar p,.reversemarginpar p{margin-top:0.4em; margin-bottom:0.4em;} -.reversemarginpar{float:left;} -table.equation {width:100%;} -.equation td{text-align:center; } -td.equation { margin-top:1em; margin-bottom:1em; } -td.equation-label { width:5%; text-align:center; } -td.eqnarray4 { width:5%; white-space: normal; } -td.eqnarray2 { width:5%; } -table.eqnarray-star, table.eqnarray {width:100%;} -div.eqnarray{text-align:center;} -div.array {text-align:center;} -div.pmatrix {text-align:center;} -table.pmatrix {width:100%;} -span.pmatrix img{vertical-align:middle;} -div.pmatrix {text-align:center;} -table.pmatrix {width:100%;} -span.bar-css {text-decoration:overline;} -img.cdots{vertical-align:middle;} -/* end css.sty */ - diff --git a/preliminaryReport/tests/simpletable.html b/preliminaryReport/tests/simpletable.html deleted file mode 100644 index 5ba6db64..00000000 --- a/preliminaryReport/tests/simpletable.html +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - -
-
123
4 5 6
7 89
- - - - - diff --git a/preliminaryReport/tests/simpletable.pdf b/preliminaryReport/tests/simpletable.pdf index e301984a..7a16d85b 100644 Binary files a/preliminaryReport/tests/simpletable.pdf and b/preliminaryReport/tests/simpletable.pdf differ diff --git a/preliminaryReport/tests/simpletable.tex b/preliminaryReport/tests/simpletable.tex index 56b29a66..c92e959c 100644 --- a/preliminaryReport/tests/simpletable.tex +++ b/preliminaryReport/tests/simpletable.tex @@ -1,8 +1,7 @@ \documentclass{article} \begin{document} -\begin{tabular}{ l | c | r } -test & 2 & test \\ -4 & 5 & 6 \\ -7 & 8 & 9 \\ + +\begin{tabular}{c} \end{tabular} + \end{document} \ No newline at end of file diff --git a/preliminaryReport/tests/simpletable.tmp b/preliminaryReport/tests/simpletable.tmp deleted file mode 100644 index 41b58e2c..00000000 --- a/preliminaryReport/tests/simpletable.tmp +++ /dev/null @@ -1,2 +0,0 @@ - -/* css.sty */ \ No newline at end of file diff --git a/program/code/main.py b/program/code/main.py index 2106a09b..6993d578 100644 --- a/program/code/main.py +++ b/program/code/main.py @@ -5,6 +5,13 @@ from code.latex_classes.latex_classes import return_latex_classes from code.error_messages.error_arrays import return_error_arrays +def command_name_check(latex_string, command_name): + error_arrays = return_error_arrays() + if latex_string[1 : (len(command_name) + 1)] != command_name: + print(latex_string + error_arrays[4]) + return "Error!" + return + def generic_checks(latex_string): error_arrays = return_error_arrays() if latex_string == "": @@ -16,6 +23,8 @@ def generic_checks(latex_string): if latex_string[0] != "\\": print(latex_string + error_arrays[6]) return "Error!" + return + def document_class(latex_string): @@ -29,8 +38,7 @@ def document_class(latex_string): if latex_string[len("\\documentclass{") - 1] != "{": print(latex_string + error_arrays[3]) return "Error!" - if latex_string[1 : (len("documentclass") + 1)] != "documentclass": - print(latex_string + error_arrays[4]) + if command_name_check(latex_string, "documentclass") == "Error!": return "Error!" document_type = latex_string[len("\\documentclass{") : (len(latex_string) - 1)] latex_classes = return_latex_classes() @@ -46,12 +54,30 @@ def begin_document(latex_string): """ if generic_checks(latex_string) == "Error!": return "Error!" - error_arrays = return_error_arrays() - if latex_string[1 : (len("begin") + 1)] != "begin": - print(latex_string + error_arrays[4]) + if command_name_check(latex_string, "begin") == "Error!": return "Error!" return "" +def begin_tabular(latex_string): + r""" + Checks if LaTeX begin tabular method is correct + """ + if generic_checks(latex_string) == "Error!": + return "Error!" + if command_name_check(latex_string, "begin") == "Error!": + return "Error!" + return "" + +def tabular_parameters(latex_string): + r""" + Checks if LaTeX tabular environment has any parameters + """ + if latex_string == "": + return "" + if latex_string == "[]": + return "" + return "Error!" + if __name__ == "__main__": document_class("") diff --git a/program/tests/conftest.py b/program/tests/conftest.py deleted file mode 100644 index e69de29b..00000000 diff --git a/program/tests/test_code/test_begin_document.py b/program/tests/test_code/test_begin_document.py index 0a1f8528..12c21341 100644 --- a/program/tests/test_code/test_begin_document.py +++ b/program/tests/test_code/test_begin_document.py @@ -19,7 +19,7 @@ def given_not_closed_then_error(): When: N/A Then: Error message """ - assert begin_document(r"\begin{document") == "Error!" + assert begin_document(r"\\begin{document") == "Error!" def given_no_opening_then_error(): diff --git a/program/tests/test_code/test_begin_tabular.py b/program/tests/test_code/test_begin_tabular.py new file mode 100644 index 00000000..551f1b23 --- /dev/null +++ b/program/tests/test_code/test_begin_tabular.py @@ -0,0 +1,67 @@ +""" + Tests begin document function +""" +from code.main import begin_tabular + +# Write python tests for a function translating LaTeX documentclass to html +def given_empty_then_error(): + """ + Given: "" + When: N/A + Then: Error message + """ + assert begin_tabular("") == "Error!" + + +def given_not_closed_then_error(): + r""" + Given: command not closed + When: N/A + Then: Error message + """ + assert begin_tabular(r"\\begin{tabular") == "Error!" + + +def given_no_opening_then_error(): + """ + Given: No opening curly bracket + When: N/A + Then: Error message + """ + assert begin_tabular(r"\\begintabular}") == "Error!" + + +def given_misspeled_then_error(): + """ + Given: misspelled begin tabular + When: N/A + Then: Error message + """ + assert begin_tabular(r"\\begim{tabular}") == "Error!" + + +def given_no_slash_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(): + """ + Given: \begin{tabular} + When: N/A + Then: + """ + assert begin_tabular(r"\begin{tabular}") == "
" + + +def test_begin_tabular(): + given_correct_then_html() + given_empty_then_error() + given_misspeled_then_error() + given_no_opening_then_error() + given_not_closed_then_error() + given_no_slash_then_error() diff --git a/program/tests/test_code/test_tabular_parameters.py b/program/tests/test_code/test_tabular_parameters.py new file mode 100644 index 00000000..eade0793 --- /dev/null +++ b/program/tests/test_code/test_tabular_parameters.py @@ -0,0 +1,36 @@ +""" + Tests tabular_parameters function +""" + +from code.main import tabular_parameters + +def given_empty_then_empty(): + """ + Given: + When: N/A + Then: + """ + assert tabular_parameters("") == "" + +def given_empty_brackets_then_empty(): + """ + Given: [] + When: N/A + Then: + """ + assert tabular_parameters("[]") == "" + +def given_non_empty_then_error(): + """ + Given: [c] + When: N/A + Then: + """ + assert tabular_parameters("[c]") == "Error!" + + + +def test_tabular_parameters(): + given_empty_then_empty() + given_empty_brackets_then_empty() + given_non_empty_then_error()