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

Function TestResidualAstModified

cel/cel_test.go:2353–2399  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2351}
2352
2353func TestResidualAstModified(t *testing.T) {
2354 env := testEnv(t,
2355 Variable("x", MapType(StringType, IntType)),
2356 Variable("y", IntType),
2357 )
2358 ast, iss := env.Parse("x == y")
2359 if iss.Err() != nil {
2360 t.Fatalf("env.Parse() failed: %v", iss.Err())
2361 }
2362 prg, err := env.Program(ast,
2363 EvalOptions(OptTrackState, OptPartialEval),
2364 )
2365 if err != nil {
2366 t.Fatalf("env.Program() failed: %v", err)
2367 }
2368 for _, x := range []int{123, 456} {
2369 vars, _ := PartialVars(map[string]any{
2370 "x": x,
2371 }, AttributePattern("y"))
2372 out, det, err := prg.Eval(vars)
2373 if !types.IsUnknown(out) {
2374 t.Fatalf("got %v, expected unknown", out)
2375 }
2376 if err != nil {
2377 t.Fatal(err)
2378 }
2379 residual, err := env.ResidualAst(ast, det)
2380 if err != nil {
2381 t.Fatal(err)
2382 }
2383 orig, err := AstToString(ast)
2384 if err != nil {
2385 t.Fatal(err)
2386 }
2387 if orig != "x == y" {
2388 t.Errorf("parsed ast: got expr: %s, wanted x == y", orig)
2389 }
2390 expr, err := AstToString(residual)
2391 if err != nil {
2392 t.Fatal(err)
2393 }
2394 want := fmt.Sprintf("%d == y", x)
2395 if expr != want {
2396 t.Errorf("residual ast: got expr: %s, wanted %s", expr, want)
2397 }
2398 }
2399}
2400
2401func TestContextProto(t *testing.T) {
2402 descriptor := new(proto3pb.TestAllTypes).ProtoReflect().Descriptor()

Callers

nothing calls this directly

Calls 12

IsUnknownFunction · 0.92
EvalOptionsFunction · 0.85
PartialVarsFunction · 0.85
AstToStringFunction · 0.85
ErrMethod · 0.80
ProgramMethod · 0.80
ResidualAstMethod · 0.80
testEnvFunction · 0.70
VariableFunction · 0.70
AttributePatternFunction · 0.70
ParseMethod · 0.65
EvalMethod · 0.65

Tested by

no test coverage detected