(t *testing.T)
| 1063 | } |
| 1064 | |
| 1065 | func TestNativeNestedStruct(t *testing.T) { |
| 1066 | var nativeTests = []struct { |
| 1067 | expr string |
| 1068 | in any |
| 1069 | }{ |
| 1070 | { |
| 1071 | expr: `test.ListVal.exists(x, x.custom_name == "name")`, |
| 1072 | in: map[string]any{ |
| 1073 | "test": &TestNestedStruct{ListVal: []*TestNestedType{{NestedCustomName: "name"}}}, |
| 1074 | }, |
| 1075 | }, |
| 1076 | } |
| 1077 | |
| 1078 | envOpts := []cel.EnvOption{ |
| 1079 | NativeTypes( |
| 1080 | reflect.ValueOf(&TestNestedStruct{}), |
| 1081 | ParseStructTag("json"), |
| 1082 | ), |
| 1083 | cel.Variable("test", cel.ObjectType("ext.TestNestedStruct")), |
| 1084 | } |
| 1085 | |
| 1086 | env, err := cel.NewEnv(envOpts...) |
| 1087 | if err != nil { |
| 1088 | t.Fatalf("cel.NewEnv(NativeTypes()) failed: %v", err) |
| 1089 | } |
| 1090 | |
| 1091 | for i, tst := range nativeTests { |
| 1092 | tc := tst |
| 1093 | t.Run(fmt.Sprintf("[%d]", i), func(t *testing.T) { |
| 1094 | var asts []*cel.Ast |
| 1095 | pAst, iss := env.Parse(tc.expr) |
| 1096 | if iss.Err() != nil { |
| 1097 | t.Fatalf("env.Parse(%v) failed: %v", tc.expr, iss.Err()) |
| 1098 | } |
| 1099 | asts = append(asts, pAst) |
| 1100 | cAst, iss := env.Check(pAst) |
| 1101 | if iss.Err() != nil { |
| 1102 | t.Fatalf("env.Check(%v) failed: %v", tc.expr, iss.Err()) |
| 1103 | } |
| 1104 | asts = append(asts, cAst) |
| 1105 | for _, ast := range asts { |
| 1106 | prg, err := env.Program(ast) |
| 1107 | if err != nil { |
| 1108 | t.Fatal(err) |
| 1109 | } |
| 1110 | out, _, err := prg.Eval(tc.in) |
| 1111 | if err != nil { |
| 1112 | t.Fatal(err) |
| 1113 | } |
| 1114 | if !reflect.DeepEqual(out.Value(), true) { |
| 1115 | t.Errorf("got %v, wanted true for expr: %s", out.Value(), tc.expr) |
| 1116 | } |
| 1117 | } |
| 1118 | }) |
| 1119 | } |
| 1120 | } |
| 1121 | |
| 1122 | func TestNativeTypesVersion(t *testing.T) { |
nothing calls this directly
no test coverage detected