diff --git a/CHANGELOG.md b/CHANGELOG.md index b5f3a325..e0ed0d58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/gdtoolkit/gd2py/__init__.py b/gdtoolkit/gd2py/__init__.py index 6a78ed80..e2e19541 100644 --- a/gdtoolkit/gd2py/__init__.py +++ b/gdtoolkit/gd2py/__init__.py @@ -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" ], @@ -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: [ @@ -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"), @@ -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) diff --git a/tests/gd2py/test_conversion.py b/tests/gd2py/test_conversion.py new file mode 100644 index 00000000..1645e109 --- /dev/null +++ b/tests/gd2py/test_conversion.py @@ -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)