Skip to content

Commit

Permalink
Merge pull request #57 from dawnbeen/56-hoisting-breaks-array-initial…
Browse files Browse the repository at this point in the history
…ization

Fixing #56
  • Loading branch information
cacharle authored Aug 9, 2023
2 parents 8d72dfc + e861f5e commit 24960b5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion c_formatter_42/formatters/hoist.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def hoist(content: str) -> str:
r"(?P<value>.+);$".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(
Expand Down
16 changes: 16 additions & 0 deletions tests/formatters/test_hoist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 24960b5

Please sign in to comment.