-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from lgrandco/fix-array_init
array initialization fix
- Loading branch information
Showing
3 changed files
with
31 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,10 @@ | |
# ::: :::::::: # | ||
# helper.py :+: :+: :+: # | ||
# +:+ +:+ +:+ # | ||
# By: kiokuless <[email protected]> +#+ +:+ +#+ # | ||
# By: root <[email protected]> +#+ +:+ +#+ # | ||
# +#+#+#+#+#+ +#+ # | ||
# 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]: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
# ############################################################################ # | ||
# **************************************************************************** # | ||
# # | ||
# ::: :::::::: # | ||
# test_align.py :+: :+: :+: # | ||
# +:+ +:+ +:+ # | ||
# By: cacharle <[email protected]> +#+ +:+ +#+ # | ||
# By: root <[email protected]> +#+ +:+ +#+ # | ||
# +#+#+#+#+#+ +#+ # | ||
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
# ############################################################################ # | ||
# **************************************************************************** # | ||
# # | ||
# ::: :::::::: # | ||
# test_hoist.py :+: :+: :+: # | ||
# +:+ +:+ +:+ # | ||
# By: cacharle <[email protected]> +#+ +:+ +#+ # | ||
# By: root <[email protected]> +#+ +:+ +#+ # | ||
# +#+#+#+#+#+ +#+ # | ||
# 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) | ||
|