Skip to content

Commit

Permalink
Add initial 'complex_multistatement_lambdas' tests & align lambda for…
Browse files Browse the repository at this point in the history
…matter implementation
  • Loading branch information
Scony committed Sep 14, 2024
1 parent 6e6cba6 commit f1fb2a2
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 2 deletions.
13 changes: 11 additions & 2 deletions gdtoolkit/formatter/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,6 @@ def _format_lambda_to_multiple_lines(
expression_context: ExpressionContext,
context: Context,
) -> FormattedLines:
assert expression_context.suffix_string == ""
expression_context_for_header = ExpressionContext(
expression_context.prefix_string, expression_context.prefix_line, "", -1
)
Expand All @@ -788,8 +787,18 @@ def _format_lambda_to_multiple_lines(
function_statement_module.format_func_statement,
child_context,
)
last_block_line_number, last_block_line_content = block_lines[-1]

return header_lines + block_lines
return (
header_lines
+ block_lines[:-1]
+ [
(
last_block_line_number,
f"{last_block_line_content}{expression_context.suffix_string}",
)
]
)


def _format_lambda_header_to_multiple_lines(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
func foo(x):
pass
func bar(x,y):
pass
func baz():
foo(func():
var x = 1
return x)

foo(func():
var x = 1
if x > 1:
print(x))

foo(func():
var x = 1
if x > 1:
print(x)
)

bar(func():
var x = 1
return x, func():
var y = 1
return y)

bar(func():
var x = 1
return x,
func():
var y = 1
return y)

bar(func():
var x = 1
return x,

func():
var y = 1
return y)

bar(func():
var x = 1
if x > 0:
print(x), func():
var y = 1
return y)

bar(func():
var x = 1
if x > 0:
print(x),
func():
var y = 1
return y)
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
func foo(x):
pass


func bar(x, y):
pass


func baz():
foo(
func():
var x = 1
return x
)

foo(
func():
var x = 1
if x > 1:
print(x)
)

foo(
func():
var x = 1
if x > 1:
print(x)
)

bar(
func():
var x = 1
return x,
func():
var y = 1
return y
)

bar(
func():
var x = 1
return x,
func():
var y = 1
return y
)

bar(
func():
var x = 1
return x,
func():
var y = 1
return y
)

bar(
func():
var x = 1
if x > 0:
print(x),
func():
var y = 1
return y
)

bar(
func():
var x = 1
if x > 0:
print(x),
func():
var y = 1
return y
)

0 comments on commit f1fb2a2

Please sign in to comment.