MCPcopy Create free account
hub / github.com/cel-expr/cel-go / program

Function program

interpreter/interpreter_test.go:2237–2326  ·  view source on GitHub ↗
(t testing.TB, tst *testCase, opts ...PlannerOption)

Source from the content-addressed store, hash-verified

2235}
2236
2237func program(t testing.TB, tst *testCase, opts ...PlannerOption) (InterpretableV2, *ExecutionFrame, error) {
2238 // Configure the package.
2239 cont := containers.DefaultContainer
2240 if tst.container != "" {
2241 cont = testContainer(tst.container)
2242 }
2243 var err error
2244 if tst.abbrevs != nil {
2245 cont, err = containers.NewContainer(
2246 containers.Name(cont.Name()),
2247 containers.Abbrevs(tst.abbrevs...))
2248 if err != nil {
2249 return nil, nil, err
2250 }
2251 }
2252 var reg *types.Registry
2253 var env *checker.Env
2254 reg = newTestRegistry(t)
2255 if tst.typeOpts != nil {
2256 reg = newTestRegistry(t, tst.typeOpts...)
2257 }
2258 env = newTestEnv(t, cont, reg)
2259 attrs := NewAttributeFactory(cont, reg, reg)
2260 if tst.attrs != nil {
2261 attrs = tst.attrs
2262 }
2263 if tst.vars != nil {
2264 err = env.AddIdents(tst.vars...)
2265 if err != nil {
2266 return nil, nil, fmt.Errorf("env.Add(%v) failed: %v", tst.vars, err)
2267 }
2268 }
2269 // Configure the program input.
2270 vars := EmptyActivation()
2271 if tst.in != nil {
2272 vars, err = NewActivation(tst.in)
2273 if err != nil {
2274 t.Fatalf("NewActivation(%v) failed: %v", tst.in, err)
2275 }
2276 }
2277 // Adapt the test output, if needed.
2278 if tst.out != nil {
2279 tst.out = reg.NativeToValue(tst.out)
2280 }
2281
2282 disp := NewDispatcher()
2283 addFunctionBindings(t, disp)
2284 if tst.funcs != nil {
2285 err = env.AddFunctions(tst.funcs...)
2286 if err != nil {
2287 return nil, nil, fmt.Errorf("env.Add(%v) failed: %v", tst.funcs, err)
2288 }
2289 disp.Add(funcBindings(t, tst.funcs...)...)
2290 }
2291 interp := NewInterpreter(disp, cont, reg, reg, attrs)
2292
2293 // Parse the expression.
2294 s := common.NewTextSource(tst.expr)

Callers 5

BenchmarkInterpreterFunction · 0.85
TestInterpreterFunction · 0.85

Calls 15

AddIdentsMethod · 0.95
NativeToValueMethod · 0.95
AddFunctionsMethod · 0.95
AddMethod · 0.95
ParseMethod · 0.95
NewInterpretableMethod · 0.95
NewContainerFunction · 0.92
NameFunction · 0.92
AbbrevsFunction · 0.92
NewTextSourceFunction · 0.92
NewParserFunction · 0.92
MacrosFunction · 0.92

Tested by

no test coverage detected