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

Function mustProgram

cel/program_async_test.go:931–965  ·  view source on GitHub ↗

mustProgram compiles an expression and constructs a Program, separating EnvOptions and ProgramOptions.

(t *testing.T, expr string, opts ...any)

Source from the content-addressed store, hash-verified

929
930// mustProgram compiles an expression and constructs a Program, separating EnvOptions and ProgramOptions.
931func mustProgram(t *testing.T, expr string, opts ...any) cel.Program {
932 t.Helper()
933 var envOpts []cel.EnvOption
934 var prgOpts []cel.ProgramOption
935 var deferredPrgOpts []func(int64) cel.ProgramOption
936 for _, opt := range opts {
937 switch o := opt.(type) {
938 case cel.EnvOption:
939 envOpts = append(envOpts, o)
940 case cel.ProgramOption:
941 prgOpts = append(prgOpts, o)
942 case func(int64) cel.ProgramOption:
943 deferredPrgOpts = append(deferredPrgOpts, o)
944 default:
945 t.Fatalf("unsupported option type %T", opt)
946 }
947 }
948 env, err := cel.NewEnv(envOpts...)
949 if err != nil {
950 t.Fatalf("NewEnv() failed: %v", err)
951 }
952 ast, iss := env.Compile(expr)
953 if iss.Err() != nil {
954 t.Fatalf("Compile(%q) failed: %v", expr, iss.Err())
955 }
956 rootID := ast.NativeRep().Expr().ID()
957 for _, deferred := range deferredPrgOpts {
958 prgOpts = append(prgOpts, deferred(rootID))
959 }
960 prg, err := env.Program(ast, prgOpts...)
961 if err != nil {
962 t.Fatalf("Program() failed: %v", err)
963 }
964 return prg
965}
966
967type countingObserver struct {
968 started atomic.Int32

Calls 7

CompileMethod · 0.95
ProgramMethod · 0.95
NewEnvFunction · 0.92
ErrMethod · 0.80
NativeRepMethod · 0.80
IDMethod · 0.65
ExprMethod · 0.65

Tested by

no test coverage detected