MCPcopy Index your code
hub / github.com/expr-lang/expr / TestWithContext

Function TestWithContext

patcher/with_context_test.go:13–32  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

11)
12
13func TestWithContext(t *testing.T) {
14 env := map[string]any{
15 "fn": func(ctx context.Context, a int) int {
16 return ctx.Value("value").(int) + a
17 },
18 "ctx": context.TODO(),
19 }
20
21 withContext := patcher.WithContext{Name: "ctx"}
22
23 program, err := expr.Compile(`fn(40)`, expr.Env(env), expr.Patch(withContext))
24 require.NoError(t, err)
25
26 ctx := context.WithValue(context.Background(), "value", 2)
27 env["ctx"] = ctx
28
29 output, err := expr.Run(program, env)
30 require.NoError(t, err)
31 require.Equal(t, 42, output)
32}
33
34func TestWithContext_with_env_Function(t *testing.T) {
35 env := map[string]any{

Callers

nothing calls this directly

Calls 6

CompileFunction · 0.92
EnvStruct · 0.92
PatchFunction · 0.92
NoErrorFunction · 0.92
RunFunction · 0.92
EqualFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…