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

Function program

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

Source from the content-addressed store, hash-verified

2422}
2423
2424func program(t testing.TB, tst *testCase, opts ...PlannerOption) (InterpretableV2, *ExecutionFrame, error) {
2425 // Configure the package.
2426 cont := containers.DefaultContainer
2427 if tst.container != "" {
2428 cont = testContainer(tst.container)
2429 }
2430 var err error
2431 if tst.abbrevs != nil {
2432 cont, err = containers.NewContainer(
2433 containers.Name(cont.Name()),
2434 containers.Abbrevs(tst.abbrevs...))
2435 if err != nil {
2436 return nil, nil, err
2437 }
2438 }
2439 var reg *types.Registry
2440 var env *checker.Env
2441 reg = newTestRegistry(t)
2442 if tst.typeOpts != nil {
2443 reg = newTestRegistry(t, tst.typeOpts...)
2444 }
2445 env = newTestEnv(t, cont, reg)
2446 attrs := NewAttributeFactory(cont, reg, reg)
2447 if tst.attrs != nil {
2448 attrs = tst.attrs
2449 }
2450 if tst.vars != nil {
2451 err = env.AddIdents(tst.vars...)
2452 if err != nil {
2453 return nil, nil, fmt.Errorf("env.Add(%v) failed: %v", tst.vars, err)
2454 }
2455 }
2456 // Configure the program input.
2457 vars := EmptyActivation()
2458 if tst.in != nil {
2459 vars, err = NewActivation(tst.in)
2460 if err != nil {
2461 t.Fatalf("NewActivation(%v) failed: %v", tst.in, err)
2462 }
2463 }
2464 // Adapt the test output, if needed.
2465 if tst.out != nil {
2466 tst.out = reg.NativeToValue(tst.out)
2467 }
2468
2469 disp := NewDispatcher()
2470 addFunctionBindings(t, disp)
2471 if tst.funcs != nil {
2472 err = env.AddFunctions(tst.funcs...)
2473 if err != nil {
2474 return nil, nil, fmt.Errorf("env.Add(%v) failed: %v", tst.funcs, err)
2475 }
2476 disp.Add(funcBindings(t, tst.funcs...)...)
2477 }
2478 interp := NewInterpreter(disp, cont, reg, reg, attrs)
2479
2480 // Parse the expression.
2481 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