(t *testing.T)
| 1167 | } |
| 1168 | |
| 1169 | func TestNativeNestedStruct(t *testing.T) { |
| 1170 | var nativeTests = []struct { |
| 1171 | expr string |
| 1172 | in any |
| 1173 | }{ |
| 1174 | { |
| 1175 | expr: `test.ListVal.exists(x, x.custom_name == "name")`, |
| 1176 | in: map[string]any{ |
| 1177 | "test": &TestNestedStruct{ListVal: []*TestNestedType{{NestedCustomName: "name"}}}, |
| 1178 | }, |
| 1179 | }, |
| 1180 | } |
| 1181 | |
| 1182 | envOpts := []cel.EnvOption{ |
| 1183 | NativeTypes( |
| 1184 | reflect.ValueOf(&TestNestedStruct{}), |
| 1185 | ParseStructTag("json"), |
| 1186 | ), |
| 1187 | cel.Variable("test", cel.ObjectType("ext.TestNestedStruct")), |
| 1188 | } |
| 1189 | |
| 1190 | env, err := cel.NewEnv(envOpts...) |
| 1191 | if err != nil { |
| 1192 | t.Fatalf("cel.NewEnv(NativeTypes()) failed: %v", err) |
| 1193 | } |
| 1194 | |
| 1195 | for i, tst := range nativeTests { |
| 1196 | tc := tst |
| 1197 | t.Run(fmt.Sprintf("[%d]", i), func(t *testing.T) { |
| 1198 | var asts []*cel.Ast |
| 1199 | pAst, iss := env.Parse(tc.expr) |
| 1200 | if iss.Err() != nil { |
| 1201 | t.Fatalf("env.Parse(%v) failed: %v", tc.expr, iss.Err()) |
| 1202 | } |
| 1203 | asts = append(asts, pAst) |
| 1204 | cAst, iss := env.Check(pAst) |
| 1205 | if iss.Err() != nil { |
| 1206 | t.Fatalf("env.Check(%v) failed: %v", tc.expr, iss.Err()) |
| 1207 | } |
| 1208 | asts = append(asts, cAst) |
| 1209 | for _, ast := range asts { |
| 1210 | prg, err := env.Program(ast) |
| 1211 | if err != nil { |
| 1212 | t.Fatal(err) |
| 1213 | } |
| 1214 | out, _, err := prg.Eval(tc.in) |
| 1215 | if err != nil { |
| 1216 | t.Fatal(err) |
| 1217 | } |
| 1218 | if !reflect.DeepEqual(out.Value(), true) { |
| 1219 | t.Errorf("got %v, wanted true for expr: %s", out.Value(), tc.expr) |
| 1220 | } |
| 1221 | } |
| 1222 | }) |
| 1223 | } |
| 1224 | } |
| 1225 | |
| 1226 | func TestNativeTypesVersion(t *testing.T) { |
nothing calls this directly
no test coverage detected