diff --git a/c_formatter_42/formatters/hoist.py b/c_formatter_42/formatters/hoist.py index 6e23b0f..76be7ba 100644 --- a/c_formatter_42/formatters/hoist.py +++ b/c_formatter_42/formatters/hoist.py @@ -54,7 +54,7 @@ def hoist(content: str) -> str: r"(?P.+);$".format(t=helper.REGEX_TYPE, d=helper.REGEX_DECL_NAME), line, ) - if m is not None: + if m is not None and re.match(r".*\[.*\].*", m.group("name")) is None: lines.append(f"\t{m.group('type')}\t{m.group('name')};") lines.append( "{}{} = {};".format( diff --git a/tests/formatters/test_hoist.py b/tests/formatters/test_hoist.py index 90cb80f..d00b56d 100644 --- a/tests/formatters/test_hoist.py +++ b/tests/formatters/test_hoist.py @@ -197,6 +197,22 @@ def test_hoist_empty_function(): assert output == hoist(input) +def test_hoist_array_initialization(): + input = """ +void foo(void) +{ +\tint xs[4] = {1, 2, 3, 4}; +} +""" + output = """ +void foo(void) +{ +\tint xs[4] = {1, 2, 3, 4}; +} +""" + assert output == hoist(input) + + @pytest.mark.skip() def test_hoist_array(): pass