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

Function conformanceTest

conformance/conformance_test.go:191–287  ·  view source on GitHub ↗
(t *testing.T, name string, pb *testpb.SimpleTest)

Source from the content-addressed store, hash-verified

189}
190
191func conformanceTest(t *testing.T, name string, pb *testpb.SimpleTest) {
192 if shouldSkipTest(name) {
193 t.SkipNow()
194 return
195 }
196 var env *cel.Env
197 if pb.GetDisableMacros() {
198 env = envNoMacros
199 } else {
200 env = envWithMacros
201 }
202 src := common.NewStringSource(pb.GetExpr(), pb.GetName())
203 ast, iss := env.ParseSource(src)
204 if err := iss.Err(); err != nil {
205 t.Fatal(err)
206 }
207 var opts []cel.EnvOption
208 if pb.GetContainer() != "" {
209 opts = append(opts, cel.Container(pb.GetContainer()))
210 }
211 for _, d := range pb.GetTypeEnv() {
212 opt, err := cel.ProtoAsDeclaration(d)
213 if err != nil {
214 t.Fatal(err)
215 }
216 opts = append(opts, opt)
217 }
218 var err error
219 env, err = env.Extend(opts...)
220 if err != nil {
221 t.Fatal(err)
222 }
223 if !pb.GetDisableCheck() {
224 ast, iss = env.Check(ast)
225 if err := iss.Err(); err != nil {
226 t.Fatal(err)
227 }
228 }
229 if pb.GetCheckOnly() {
230 m, ok := pb.GetResultMatcher().(*testpb.SimpleTest_TypedResult)
231 if !ok {
232 t.Fatalf("unexpected matcher kind for check only test: %T", pb.GetResultMatcher())
233 }
234 if diff, err := diffType(m.TypedResult.DeducedType, ast.OutputType()); err != nil || diff != "" {
235 t.Errorf("env.Check() output type err: %v (-want +got):\n%s", err, diff)
236 }
237 return
238 }
239 program, err := env.Program(ast)
240 if err != nil {
241 t.Fatal(err)
242 }
243 act := make(map[string]any, len(pb.GetBindings()))
244 for k, v := range pb.GetBindings() {
245 act[k], err = exprValueToRefValue(env.CELTypeAdapter(), v)
246 if err != nil {
247 t.Fatal(err)
248 }

Callers 1

TestConformanceFunction · 0.85

Calls 15

ParseSourceMethod · 0.95
ExtendMethod · 0.95
CheckMethod · 0.95
ProgramMethod · 0.95
CELTypeAdapterMethod · 0.95
NewStringSourceFunction · 0.92
ContainerFunction · 0.92
ProtoAsDeclarationFunction · 0.92
IsErrorFunction · 0.92
diffTypeFunction · 0.85
exprValueToRefValueFunction · 0.85
diffValueFunction · 0.85

Tested by

no test coverage detected