Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent committed Feb 18, 2025
1 parent fa8253e commit 5592d40
Showing 1 changed file with 54 additions and 2 deletions.
56 changes: 54 additions & 2 deletions interpreter/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6916,7 +6916,7 @@ func TestInterpretClosureScopingInnerFunction(t *testing.T) {
)
}

func TestInterpretClosureScopingFunctionExpressionInCall(t *testing.T) {
func TestInterpretClosureScopingFunctionExpressionParameterConfusion(t *testing.T) {
t.Parallel()

inter := parseCheckAndInterpret(t, `
Expand All @@ -6942,7 +6942,7 @@ func TestInterpretClosureScopingFunctionExpressionInCall(t *testing.T) {
)
}

func TestInterpretClosureScopingInnerFunctionInCall(t *testing.T) {
func TestInterpretClosureScopingInnerFunctionParameterConfusion(t *testing.T) {
t.Parallel()

inter := parseCheckAndInterpret(t, `
Expand All @@ -6968,6 +6968,58 @@ func TestInterpretClosureScopingInnerFunctionInCall(t *testing.T) {
)
}

func TestInterpretClosureScopingFunctionExpressionInCall(t *testing.T) {
t.Parallel()

inter := parseCheckAndInterpret(t, `
fun foo() {
fun() {}
}
fun test(): Int {
let a = 1
foo()
return a
}
`)

actual, err := inter.Invoke("test")
require.NoError(t, err)

AssertValuesEqual(
t,
inter,
interpreter.NewUnmeteredIntValueFromInt64(1),
actual,
)
}

func TestInterpretClosureScopingInnerFunctionInCall(t *testing.T) {
t.Parallel()

inter := parseCheckAndInterpret(t, `
fun foo() {
let f = fun() {}
}
fun test(): Int {
let a = 1
foo()
return a
}
`)

actual, err := inter.Invoke("test")
require.NoError(t, err)

AssertValuesEqual(
t,
inter,
interpreter.NewUnmeteredIntValueFromInt64(1),
actual,
)
}

func TestInterpretAssignmentAfterClosureFunctionExpression(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 5592d40

Please sign in to comment.