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

Function program

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

Source from the content-addressed store, hash-verified

2654}
2655
2656func program(t testing.TB, tst *testCase, opts ...PlannerOption) (InterpretableV2, *ExecutionFrame, error) {
2657 // Configure the package.
2658 cont := containers.DefaultContainer
2659 if tst.container != "" {
2660 cont = testContainer(tst.container)
2661 }
2662 var err error
2663 if tst.abbrevs != nil {
2664 cont, err = containers.NewContainer(
2665 containers.Name(cont.Name()),
2666 containers.Abbrevs(tst.abbrevs...))
2667 if err != nil {
2668 return nil, nil, err
2669 }
2670 }
2671 var reg *types.Registry
2672 var env *checker.Env
2673 reg = newTestRegistry(t)
2674 if tst.typeOpts != nil {
2675 reg = newTestRegistry(t, tst.typeOpts...)
2676 }
2677 env = newTestEnv(t, cont, reg)
2678 attrs := NewAttributeFactory(cont, reg, reg)
2679 if tst.attrs != nil {
2680 attrs = tst.attrs
2681 }
2682 if tst.vars != nil {
2683 err = env.AddIdents(tst.vars...)
2684 if err != nil {
2685 return nil, nil, fmt.Errorf("env.Add(%v) failed: %v", tst.vars, err)
2686 }
2687 }
2688 // Configure the program input.
2689 vars := EmptyActivation()
2690 if tst.in != nil {
2691 vars, err = NewActivation(tst.in)
2692 if err != nil {
2693 t.Fatalf("NewActivation(%v) failed: %v", tst.in, err)
2694 }
2695 }
2696 // Adapt the test output, if needed.
2697 if tst.out != nil {
2698 tst.out = reg.NativeToValue(tst.out)
2699 }
2700
2701 disp := NewDispatcher()
2702 addFunctionBindings(t, disp)
2703 if tst.funcs != nil {
2704 err = env.AddFunctions(tst.funcs...)
2705 if err != nil {
2706 return nil, nil, fmt.Errorf("env.Add(%v) failed: %v", tst.funcs, err)
2707 }
2708 disp.Add(funcBindings(t, tst.funcs...)...)
2709 }
2710 interp := NewInterpreter(disp, cont, reg, reg, attrs)
2711
2712 // Parse the expression.
2713 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