diff --git a/c_formatter_42/formatters/helper.py b/c_formatter_42/formatters/helper.py index 107bf16..bc22278 100644 --- a/c_formatter_42/formatters/helper.py +++ b/c_formatter_42/formatters/helper.py @@ -3,10 +3,10 @@ # ::: :::::::: # # helper.py :+: :+: :+: # # +:+ +:+ +:+ # -# By: kiokuless +#+ +:+ +#+ # +# By: root +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/10/04 11:38:00 by cacharle #+# #+# # -# Updated: 2023/07/17 02:28:52 by kiokuless ### ########.fr # +# Updated: 2023/09/03 11:05:57 by root ### ########.fr # # # # **************************************************************************** # from __future__ import annotations @@ -22,7 +22,9 @@ # regex for a c variable/function name REGEX_NAME = r"\**[a-zA-Z_*()]\w*" # regex for a name in a declaration context (with array and function ptr) -REGEX_DECL_NAME = r"\(?{name}(\[.*\])*(\)\(.*\))?".format(name=REGEX_NAME) +REGEX_DECL_NAME = r"\(?{name}(\[.*\])*(\s\=\s{{.*}})?(\)\(.*\))?".format( + name=REGEX_NAME +) def locally_scoped(func: Callable[[str], str]) -> Callable[[str], str]: diff --git a/tests/formatters/test_align.py b/tests/formatters/test_align.py index 047e170..b9274be 100644 --- a/tests/formatters/test_align.py +++ b/tests/formatters/test_align.py @@ -1,14 +1,14 @@ -# ############################################################################ # +# **************************************************************************** # # # # ::: :::::::: # # test_align.py :+: :+: :+: # # +:+ +:+ +:+ # -# By: cacharle +#+ +:+ +#+ # +# By: root +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/10/04 12:19:45 by cacharle #+# #+# # -# Updated: 2021/02/11 20:35:54 by charles ### ########.fr # +# Updated: 2023/09/02 20:26:16 by root ### ########.fr # # # -# ############################################################################ # +# **************************************************************************** # import pytest @@ -791,3 +791,15 @@ def test_align_func_typedef(): int\t\t\t\t\t\tbar(); """ assert output == align(input) + + +def test_align_array_initialization(): + input = """ +int\ta; +static int\txs[4] = {1, 2, 3, 4}; +""" + output = """ +int\t\t\ta; +static int\txs[4] = {1, 2, 3, 4}; +""" + assert output == align(input) diff --git a/tests/formatters/test_hoist.py b/tests/formatters/test_hoist.py index d00b56d..b682cea 100644 --- a/tests/formatters/test_hoist.py +++ b/tests/formatters/test_hoist.py @@ -1,14 +1,14 @@ -# ############################################################################ # +# **************************************************************************** # # # # ::: :::::::: # # test_hoist.py :+: :+: :+: # # +:+ +:+ +:+ # -# By: cacharle +#+ +:+ +#+ # +# By: root +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/10/04 12:29:07 by cacharle #+# #+# # -# Updated: 2021/02/11 22:16:57 by charles ### ########.fr # +# Updated: 2023/09/02 22:43:13 by root ### ########.fr # # # -# ############################################################################ # +# **************************************************************************** # import pytest @@ -201,13 +201,17 @@ def test_hoist_array_initialization(): input = """ void foo(void) { -\tint xs[4] = {1, 2, 3, 4}; +\tint a = 2; +\tstatic int\txs[4] = {1, 2, 3, 4}; } """ output = """ void foo(void) { -\tint xs[4] = {1, 2, 3, 4}; +\tint\ta; +\tstatic int\txs[4] = {1, 2, 3, 4}; + +\ta = 2; } """ assert output == hoist(input)