From 2dfb27b967011054b186f3fc5a416b18af693a48 Mon Sep 17 00:00:00 2001 From: Krzysztof Rudnicki Date: Wed, 7 Jun 2023 03:16:28 +0200 Subject: [PATCH] feat: more easy unit tests --- .../texfilelonger.tex.html | 2 +- program/code/main.py | 5 +++- .../test_code/test_command_name_check.py | 24 +++++++++++++++++ .../test_document_class_only_checks.py | 19 +++++++++++++ .../test_code/test_generic_checks.py | 21 +++++++++++++++ .../test_code/test_generic_checks_command.py | 27 +++++++++++++++++++ 6 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 program/unit_tests/test_code/test_command_name_check.py create mode 100644 program/unit_tests/test_code/test_document_class_only_checks.py create mode 100644 program/unit_tests/test_code/test_generic_checks.py create mode 100644 program/unit_tests/test_code/test_generic_checks_command.py diff --git a/program/code/functional_tests/PASScomplicatedTable/texfilelonger.tex.html b/program/code/functional_tests/PASScomplicatedTable/texfilelonger.tex.html index 31ed8b4a..f3e4ce83 100644 --- a/program/code/functional_tests/PASScomplicatedTable/texfilelonger.tex.html +++ b/program/code/functional_tests/PASScomplicatedTable/texfilelonger.tex.html @@ -1 +1 @@ -
test 2 test
4 5 6
\ No newline at end of file +Error! \ No newline at end of file diff --git a/program/code/main.py b/program/code/main.py index 32574a20..78d3d23b 100644 --- a/program/code/main.py +++ b/program/code/main.py @@ -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) diff --git a/program/unit_tests/test_code/test_command_name_check.py b/program/unit_tests/test_code/test_command_name_check.py new file mode 100644 index 00000000..b5fe891d --- /dev/null +++ b/program/unit_tests/test_code/test_command_name_check.py @@ -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() diff --git a/program/unit_tests/test_code/test_document_class_only_checks.py b/program/unit_tests/test_code/test_document_class_only_checks.py new file mode 100644 index 00000000..ad8aa299 --- /dev/null +++ b/program/unit_tests/test_code/test_document_class_only_checks.py @@ -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() diff --git a/program/unit_tests/test_code/test_generic_checks.py b/program/unit_tests/test_code/test_generic_checks.py new file mode 100644 index 00000000..545c4d46 --- /dev/null +++ b/program/unit_tests/test_code/test_generic_checks.py @@ -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() diff --git a/program/unit_tests/test_code/test_generic_checks_command.py b/program/unit_tests/test_code/test_generic_checks_command.py new file mode 100644 index 00000000..f4793538 --- /dev/null +++ b/program/unit_tests/test_code/test_generic_checks_command.py @@ -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()