(t *testing.T)
| 2247 | } |
| 2248 | |
| 2249 | func TestResidualAstModified(t *testing.T) { |
| 2250 | env := testEnv(t, |
| 2251 | Variable("x", MapType(StringType, IntType)), |
| 2252 | Variable("y", IntType), |
| 2253 | ) |
| 2254 | ast, iss := env.Parse("x == y") |
| 2255 | if iss.Err() != nil { |
| 2256 | t.Fatalf("env.Parse() failed: %v", iss.Err()) |
| 2257 | } |
| 2258 | prg, err := env.Program(ast, |
| 2259 | EvalOptions(OptTrackState, OptPartialEval), |
| 2260 | ) |
| 2261 | if err != nil { |
| 2262 | t.Fatalf("env.Program() failed: %v", err) |
| 2263 | } |
| 2264 | for _, x := range []int{123, 456} { |
| 2265 | vars, _ := PartialVars(map[string]any{ |
| 2266 | "x": x, |
| 2267 | }, AttributePattern("y")) |
| 2268 | out, det, err := prg.Eval(vars) |
| 2269 | if !types.IsUnknown(out) { |
| 2270 | t.Fatalf("got %v, expected unknown", out) |
| 2271 | } |
| 2272 | if err != nil { |
| 2273 | t.Fatal(err) |
| 2274 | } |
| 2275 | residual, err := env.ResidualAst(ast, det) |
| 2276 | if err != nil { |
| 2277 | t.Fatal(err) |
| 2278 | } |
| 2279 | orig, err := AstToString(ast) |
| 2280 | if err != nil { |
| 2281 | t.Fatal(err) |
| 2282 | } |
| 2283 | if orig != "x == y" { |
| 2284 | t.Errorf("parsed ast: got expr: %s, wanted x == y", orig) |
| 2285 | } |
| 2286 | expr, err := AstToString(residual) |
| 2287 | if err != nil { |
| 2288 | t.Fatal(err) |
| 2289 | } |
| 2290 | want := fmt.Sprintf("%d == y", x) |
| 2291 | if expr != want { |
| 2292 | t.Errorf("residual ast: got expr: %s, wanted %s", expr, want) |
| 2293 | } |
| 2294 | } |
| 2295 | } |
| 2296 | |
| 2297 | func TestContextProto(t *testing.T) { |
| 2298 | descriptor := new(proto3pb.TestAllTypes).ProtoReflect().Descriptor() |
nothing calls this directly
no test coverage detected