(t *testing.T)
| 992 | } |
| 993 | |
| 994 | func TestNativeNestedStruct(t *testing.T) { |
| 995 | var nativeTests = []struct { |
| 996 | expr string |
| 997 | in any |
| 998 | }{ |
| 999 | { |
| 1000 | expr: `test.ListVal.exists(x, x.custom_name == "name")`, |
| 1001 | in: map[string]any{ |
| 1002 | "test": &TestNestedStruct{ListVal: []*TestNestedType{{NestedCustomName: "name"}}}, |
| 1003 | }, |
| 1004 | }, |
| 1005 | } |
| 1006 | |
| 1007 | envOpts := []cel.EnvOption{ |
| 1008 | NativeTypes( |
| 1009 | reflect.ValueOf(&TestNestedStruct{}), |
| 1010 | ParseStructTag("json"), |
| 1011 | ), |
| 1012 | cel.Variable("test", cel.ObjectType("ext.TestNestedStruct")), |
| 1013 | } |
| 1014 | |
| 1015 | env, err := cel.NewEnv(envOpts...) |
| 1016 | if err != nil { |
| 1017 | t.Fatalf("cel.NewEnv(NativeTypes()) failed: %v", err) |
| 1018 | } |
| 1019 | |
| 1020 | for i, tst := range nativeTests { |
| 1021 | tc := tst |
| 1022 | t.Run(fmt.Sprintf("[%d]", i), func(t *testing.T) { |
| 1023 | var asts []*cel.Ast |
| 1024 | pAst, iss := env.Parse(tc.expr) |
| 1025 | if iss.Err() != nil { |
| 1026 | t.Fatalf("env.Parse(%v) failed: %v", tc.expr, iss.Err()) |
| 1027 | } |
| 1028 | asts = append(asts, pAst) |
| 1029 | cAst, iss := env.Check(pAst) |
| 1030 | if iss.Err() != nil { |
| 1031 | t.Fatalf("env.Check(%v) failed: %v", tc.expr, iss.Err()) |
| 1032 | } |
| 1033 | asts = append(asts, cAst) |
| 1034 | for _, ast := range asts { |
| 1035 | prg, err := env.Program(ast) |
| 1036 | if err != nil { |
| 1037 | t.Fatal(err) |
| 1038 | } |
| 1039 | out, _, err := prg.Eval(tc.in) |
| 1040 | if err != nil { |
| 1041 | t.Fatal(err) |
| 1042 | } |
| 1043 | if !reflect.DeepEqual(out.Value(), true) { |
| 1044 | t.Errorf("got %v, wanted true for expr: %s", out.Value(), tc.expr) |
| 1045 | } |
| 1046 | } |
| 1047 | }) |
| 1048 | } |
| 1049 | } |
| 1050 | |
| 1051 | func TestNativeTypesVersion(t *testing.T) { |
nothing calls this directly
no test coverage detected