(t *testing.T)
| 1047 | } |
| 1048 | |
| 1049 | func TestNativeStructEmbeddedPointer(t *testing.T) { |
| 1050 | nativeTests := []struct { |
| 1051 | expr string |
| 1052 | in map[string]any |
| 1053 | out any |
| 1054 | }{ |
| 1055 | { |
| 1056 | expr: `!has(test.custom_name) && test.custom_name == ""`, |
| 1057 | in: map[string]any{ |
| 1058 | "test": &TestEmbeddedPointerTypes{ |
| 1059 | TestNestedType: nil, |
| 1060 | }, |
| 1061 | }, |
| 1062 | out: true, |
| 1063 | }, |
| 1064 | { |
| 1065 | expr: `has(test.custom_name) && test.custom_name == "name"`, |
| 1066 | in: map[string]any{ |
| 1067 | "test": &TestEmbeddedPointerTypes{ |
| 1068 | TestNestedType: &TestNestedType{NestedCustomName: "name"}, |
| 1069 | }, |
| 1070 | }, |
| 1071 | out: true, |
| 1072 | }, |
| 1073 | { |
| 1074 | expr: `ext.TestEmbeddedPointerTypes{custom_name: "name"}.custom_name == "name"`, |
| 1075 | in: nil, |
| 1076 | out: true, |
| 1077 | }, |
| 1078 | } |
| 1079 | |
| 1080 | envOpts := []cel.EnvOption{ |
| 1081 | NativeTypes( |
| 1082 | reflect.TypeFor[*TestEmbeddedPointerTypes](), |
| 1083 | reflect.TypeFor[*TestNestedType](), |
| 1084 | ParseStructTag("json"), |
| 1085 | ), |
| 1086 | cel.Variable("test", cel.ObjectType("ext.TestEmbeddedPointerTypes")), |
| 1087 | } |
| 1088 | |
| 1089 | env, err := cel.NewEnv(envOpts...) |
| 1090 | if err != nil { |
| 1091 | t.Fatalf("cel.NewEnv(NativeTypes()) failed: %v", err) |
| 1092 | } |
| 1093 | |
| 1094 | for i, tst := range nativeTests { |
| 1095 | tc := tst |
| 1096 | t.Run(fmt.Sprintf("[%d]", i), func(t *testing.T) { |
| 1097 | pAst, iss := env.Parse(tc.expr) |
| 1098 | if iss.Err() != nil { |
| 1099 | t.Fatalf("env.Parse(%v) failed: %v", tc.expr, iss.Err()) |
| 1100 | } |
| 1101 | cAst, iss := env.Check(pAst) |
| 1102 | if iss.Err() != nil { |
| 1103 | t.Fatalf("env.Check(%v) failed: %v", tc.expr, iss.Err()) |
| 1104 | } |
| 1105 | for _, ast := range []*cel.Ast{pAst, cAst} { |
| 1106 | prg, err := env.Program(ast) |
nothing calls this directly
no test coverage detected