(t *testing.T)
| 2351 | } |
| 2352 | |
| 2353 | func 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 | |
| 2401 | func TestContextProto(t *testing.T) { |
| 2402 | descriptor := new(proto3pb.TestAllTypes).ProtoReflect().Descriptor() |
nothing calls this directly
no test coverage detected