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

Function testCompile

cel/decls_test.go:992–1017  ·  view source on GitHub ↗
(t testing.TB, env *Env, expr string, want any)

Source from the content-addressed store, hash-verified

990}
991
992func testCompile(t testing.TB, env *Env, expr string, want any) {
993 t.Helper()
994 ast, iss := env.Compile(expr)
995 if iss.Err() != nil {
996 t.Fatalf("env.Compile(%s) failed: %v", expr, iss.Err())
997 }
998 prg, err := env.Program(ast)
999 if err != nil {
1000 t.Fatalf("env.Program() failed: %v", err)
1001 }
1002 out, _, err := prg.Eval(map[string]any{"err": types.NewErr("error argument"), "unk": types.NewUnknown(42, nil)})
1003 switch want := want.(type) {
1004 case *types.Unknown:
1005 if !want.Contains(out.(*types.Unknown)) {
1006 t.Errorf("prg.Eval() got %v, wanted %v", out, want)
1007 }
1008 case ref.Val:
1009 if want.Equal(out) != types.True {
1010 t.Errorf("prg.Eval() got %v, wanted %v", out, want)
1011 }
1012 case error:
1013 if err == nil || want.Error() != err.Error() {
1014 t.Errorf("prg.Eval() got error '%v', wanted '%v'", err, want)
1015 }
1016 }
1017}

Callers 2

TestFunctionBindingFunction · 0.85

Calls 9

NewErrFunction · 0.92
NewUnknownFunction · 0.92
ErrMethod · 0.80
ProgramMethod · 0.80
CompileMethod · 0.65
EvalMethod · 0.65
ContainsMethod · 0.65
EqualMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected