Skip to content

Commit

Permalink
Fix 'gd2py' amd 'gdradon' to support latest GDScript
Browse files Browse the repository at this point in the history
  • Loading branch information
Scony committed Sep 26, 2024
1 parent c2340f8 commit 34d4ee6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Changed
- Removed `private-method-call` linter check due to false positives when calling `super._foo()`
- Fixed support for `get_node` syntax to accommodate for `$/(...)`
- Fixed `gd2py` and `gdradon` to support latest GDScript
- Changed formatting of some uni-statement lambdas
- Changed formatting of multi-statement, inline lambdas
- Changed formatting of dot-chains containing a lambda(s)
Expand Down
4 changes: 4 additions & 0 deletions gdtoolkit/gd2py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def _convert_statement(statement: Tree, context: Context) -> List[str]:
"annotation": _ignore,
"pass_stmt": lambda s, c: [f"{c.indent_string}pass"],
"class_var_stmt": _convert_first_child_as_statement,
"static_class_var_stmt": _convert_first_child_as_statement,
"class_var_empty": lambda s, c: [
f"{c.indent_string}{s.children[0].value} = None"
],
Expand All @@ -63,6 +64,7 @@ def _convert_statement(statement: Tree, context: Context) -> List[str]:
)
],
"static_func_def": _convert_first_child_as_statement,
"docstr_stmt": _pass,
# func statements:
"func_var_stmt": _convert_first_child_as_statement,
"func_var_empty": lambda s, c: [
Expand All @@ -87,6 +89,7 @@ def _convert_statement(statement: Tree, context: Context) -> List[str]:
)
],
"break_stmt": lambda s, c: [f"{c.indent_string}break"],
"breakpoint_stmt": lambda s, c: [f"{c.indent_string}breakpoint"],
"continue_stmt": lambda s, c: [f"{c.indent_string}continue"],
"if_stmt": lambda s, c: _convert_block(s.children, c),
"if_branch": partial(_convert_branch_with_expression, "if"),
Expand All @@ -112,6 +115,7 @@ def _convert_statement(statement: Tree, context: Context) -> List[str]:
+ _convert_block(s.children[3:], c.create_child_context(-2)),
"match_stmt": _convert_match_statement,
"match_branch": partial(_convert_branch_with_expression, "elif"),
"guarded_match_branch": partial(_convert_branch_with_expression, "elif"),
} # type: Dict[str, Callable]
return handlers[statement.data](statement, context)

Expand Down
38 changes: 38 additions & 0 deletions tests/gd2py/test_conversion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import os

from gdtoolkit.gd2py import convert_code


VALID_SCRIPT_DIRS = [
"../formatter/big-input-files",
"../formatter/input-output-pairs",
"../valid-gd-scripts",
]
EXCEPTIONS = [
"bug_326_multistatement_lambda_corner_case.out.gd",
]


def pytest_generate_tests(metafunc):
this_directory = os.path.dirname(os.path.abspath(__file__))
if "gdscript_path" in metafunc.fixturenames:
valid_script_paths = set()
for directory_relative_path in VALID_SCRIPT_DIRS:
directory_absolute_path = os.path.join(
this_directory, directory_relative_path
)
valid_script_paths = valid_script_paths.union(
set(
os.path.join(directory_absolute_path, f)
for f in os.listdir(directory_absolute_path)
)
)
metafunc.parametrize("gdscript_path", valid_script_paths)


def test_conversion_success(gdscript_path):
if any(exception in gdscript_path for exception in EXCEPTIONS):
return
with open(gdscript_path, "r", encoding="utf-8") as file_handle:
code = file_handle.read()
convert_code(code)

0 comments on commit 34d4ee6

Please sign in to comment.