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

Function program

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

Source from the content-addressed store, hash-verified

2488}
2489
2490func program(t testing.TB, tst *testCase, opts ...PlannerOption) (InterpretableV2, *ExecutionFrame, error) {
2491 // Configure the package.
2492 cont := containers.DefaultContainer
2493 if tst.container != "" {
2494 cont = testContainer(tst.container)
2495 }
2496 var err error
2497 if tst.abbrevs != nil {
2498 cont, err = containers.NewContainer(
2499 containers.Name(cont.Name()),
2500 containers.Abbrevs(tst.abbrevs...))
2501 if err != nil {
2502 return nil, nil, err
2503 }
2504 }
2505 var reg *types.Registry
2506 var env *checker.Env
2507 reg = newTestRegistry(t)
2508 if tst.typeOpts != nil {
2509 reg = newTestRegistry(t, tst.typeOpts...)
2510 }
2511 env = newTestEnv(t, cont, reg)
2512 attrs := NewAttributeFactory(cont, reg, reg)
2513 if tst.attrs != nil {
2514 attrs = tst.attrs
2515 }
2516 if tst.vars != nil {
2517 err = env.AddIdents(tst.vars...)
2518 if err != nil {
2519 return nil, nil, fmt.Errorf("env.Add(%v) failed: %v", tst.vars, err)
2520 }
2521 }
2522 // Configure the program input.
2523 vars := EmptyActivation()
2524 if tst.in != nil {
2525 vars, err = NewActivation(tst.in)
2526 if err != nil {
2527 t.Fatalf("NewActivation(%v) failed: %v", tst.in, err)
2528 }
2529 }
2530 // Adapt the test output, if needed.
2531 if tst.out != nil {
2532 tst.out = reg.NativeToValue(tst.out)
2533 }
2534
2535 disp := NewDispatcher()
2536 addFunctionBindings(t, disp)
2537 if tst.funcs != nil {
2538 err = env.AddFunctions(tst.funcs...)
2539 if err != nil {
2540 return nil, nil, fmt.Errorf("env.Add(%v) failed: %v", tst.funcs, err)
2541 }
2542 disp.Add(funcBindings(t, tst.funcs...)...)
2543 }
2544 interp := NewInterpreter(disp, cont, reg, reg, attrs)
2545
2546 // Parse the expression.
2547 s := common.NewTextSource(tst.expr)

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