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

Function TestWithContext_issue529

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

Source from the content-addressed store, hash-verified

130}
131
132func 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}

Callers

nothing calls this directly

Calls 6

EnvStruct · 0.92
WithContextFunction · 0.92
CompileFunction · 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…