From 1f36abee489ed8b3421e0515fae6551db2401c73 Mon Sep 17 00:00:00 2001 From: Younes Aassila <47226184+younesaassila@users.noreply.github.com> Date: Thu, 31 Aug 2023 13:40:29 +0200 Subject: [PATCH 1/4] Fix #58 --- c_formatter_42/formatters/line_breaker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c_formatter_42/formatters/line_breaker.py b/c_formatter_42/formatters/line_breaker.py index 352db42..c42b992 100644 --- a/c_formatter_42/formatters/line_breaker.py +++ b/c_formatter_42/formatters/line_breaker.py @@ -79,7 +79,7 @@ def line_length(line: str) -> int: def indent_level(line: str) -> int: # An exceptional rule for function declaration - align_pattern = r"^(static\s+)?{type}\s+{name}\((.|\s)*?\);" + align_pattern = r"^(static\s+)?{type}\s+{name}\([^)]*?\);" align_pattern = align_pattern.format(type=helper.REGEX_TYPE, name=helper.REGEX_NAME) if re.match(align_pattern, line): last_tab_index = line.rfind("\t") From 4c6bac85f884c540e49fb8a8dc7b31ef1ee3757c Mon Sep 17 00:00:00 2001 From: Younes Aassila <47226184+younesaassila@users.noreply.github.com> Date: Thu, 31 Aug 2023 14:44:46 +0200 Subject: [PATCH 2/4] Remove useless $ sign --- c_formatter_42/formatters/line_breaker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/c_formatter_42/formatters/line_breaker.py b/c_formatter_42/formatters/line_breaker.py index fd5b799..f29fdac 100644 --- a/c_formatter_42/formatters/line_breaker.py +++ b/c_formatter_42/formatters/line_breaker.py @@ -81,7 +81,7 @@ def additional_indent_level(s: str, nest_indent_level: int = 0) -> int: def additional_nest_indent_level(line: str) -> int: # An exceptional rule for variable assignment # https://github.com/42School/norminette/blob/921b5e22d991591f385e1920f7e7ee5dcf71f3d5/norminette/rules/check_assignation_indent.py#L59 - align_pattern = r"^\s*({decl})((\.|->){decl})*\s+=\s+[^;]*?;$" + align_pattern = r"^\s*({decl})((\.|->){decl})*\s+=\s+[^;]*?;" align_pattern = align_pattern.format(decl=helper.REGEX_DECL_NAME) return 1 if re.match(align_pattern, line) is not None else 0 From c7327fa70618289927da71b4c6d4174d686204eb Mon Sep 17 00:00:00 2001 From: Younes Aassila <47226184+younesaassila@users.noreply.github.com> Date: Thu, 31 Aug 2023 14:49:09 +0200 Subject: [PATCH 3/4] Add test for #58 fix --- requirements-dev.txt | 1 + tests/test_run.py | 26 ++++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index 0e3a74b..91c9c08 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,5 +1,6 @@ pytest pytest-cov +pytest-timeout six pytest-clarity mypy diff --git a/tests/test_run.py b/tests/test_run.py index e3381f5..b214371 100644 --- a/tests/test_run.py +++ b/tests/test_run.py @@ -1,14 +1,14 @@ -# ############################################################################ # +# **************************************************************************** # # # # ::: :::::::: # # test_run.py :+: :+: :+: # # +:+ +:+ +:+ # -# By: charles +#+ +:+ +#+ # +# By: yaassila +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2021/02/08 19:56:48 by charles #+# #+# # -# Updated: 2021/02/11 20:27:07 by charles ### ########.fr # +# Updated: 2023/08/31 14:00:00 by yaassila ### ########.fr # # # -# ############################################################################ # +# **************************************************************************** # import pytest @@ -82,3 +82,21 @@ def test_basic(): } """ assert output == run_all(input) + + +@pytest.mark.timeout(15) +def test_function_call_in_comment(): + input = """ +#include "libft.h" + +/* +The bzero() function erases the data in the n bytes of the memory starting at the location pointed to by s, by writing zeros (bytes containing '\0') to that area. + +The explicit_bzero() function performs the same task as bzero(). It differs from bzero() in that it guarantees that compiler optimizations will not remove the erase operation if the compiler deduces that the operation is "un-necessary". +*/ +void bzero(void *s, size_t n) +{ + unsigned char *ptr_s; +} +""" + run_all(input) From 9127f20695b171cb8081b67761185a8642c03e71 Mon Sep 17 00:00:00 2001 From: Younes Aassila <47226184+younesaassila@users.noreply.github.com> Date: Thu, 31 Aug 2023 14:50:31 +0200 Subject: [PATCH 4/4] Fixed test string --- tests/test_run.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_run.py b/tests/test_run.py index b214371..dbae673 100644 --- a/tests/test_run.py +++ b/tests/test_run.py @@ -90,7 +90,7 @@ def test_function_call_in_comment(): #include "libft.h" /* -The bzero() function erases the data in the n bytes of the memory starting at the location pointed to by s, by writing zeros (bytes containing '\0') to that area. +The bzero() function erases the data in the n bytes of the memory starting at the location pointed to by s, by writing zeros (bytes containing '\\0') to that area. The explicit_bzero() function performs the same task as bzero(). It differs from bzero() in that it guarantees that compiler optimizations will not remove the erase operation if the compiler deduces that the operation is "un-necessary". */