| 130 | } |
| 131 | |
| 132 | func TestWithContext_issue529(t *testing.T) { |
| 133 | env := map[string]any{ |
| 134 | "ctx": context.Background(), |
| 135 | "foo": func(ctx context.Context, n int) int { |
| 136 | if ctx == nil { |
| 137 | panic("wanted a context") |
| 138 | } |
| 139 | return n + 1 |
| 140 | }, |
| 141 | } |
| 142 | options := []expr.Option{ |
| 143 | expr.Env(env), |
| 144 | expr.WithContext("ctx"), |
| 145 | } |
| 146 | |
| 147 | code := "foo(0) | foo()" |
| 148 | program, err := expr.Compile(code, options...) |
| 149 | require.NoError(t, err) |
| 150 | |
| 151 | out, err := expr.Run(program, env) |
| 152 | require.NoError(t, err) |
| 153 | require.Equal(t, 2, out) |
| 154 | } |