@@ -941,6 +941,67 @@ func TestNativeStructEmbedded(t *testing.T) {
941941 }
942942}
943943
944+ type TestNestedStruct struct {
945+ ListVal []* TestNestedType
946+ }
947+
948+ func TestNativeNestedStruct (t * testing.T ) {
949+ var nativeTests = []struct {
950+ expr string
951+ in any
952+ }{
953+ {
954+ expr : `test.ListVal.exists(x, x.custom_name == "name")` ,
955+ in : map [string ]any {
956+ "test" : & TestNestedStruct {ListVal : []* TestNestedType {{NestedCustomName : "name" }}},
957+ },
958+ },
959+ }
960+
961+ envOpts := []cel.EnvOption {
962+ NativeTypes (
963+ reflect .ValueOf (& TestNestedStruct {}),
964+ ParseStructTag ("json" ),
965+ ),
966+ cel .Variable ("test" , cel .ObjectType ("ext.TestNestedStruct" )),
967+ }
968+
969+ env , err := cel .NewEnv (envOpts ... )
970+ if err != nil {
971+ t .Fatalf ("cel.NewEnv(NativeTypes()) failed: %v" , err )
972+ }
973+
974+ for i , tst := range nativeTests {
975+ tc := tst
976+ t .Run (fmt .Sprintf ("[%d]" , i ), func (t * testing.T ) {
977+ var asts []* cel.Ast
978+ pAst , iss := env .Parse (tc .expr )
979+ if iss .Err () != nil {
980+ t .Fatalf ("env.Parse(%v) failed: %v" , tc .expr , iss .Err ())
981+ }
982+ asts = append (asts , pAst )
983+ cAst , iss := env .Check (pAst )
984+ if iss .Err () != nil {
985+ t .Fatalf ("env.Check(%v) failed: %v" , tc .expr , iss .Err ())
986+ }
987+ asts = append (asts , cAst )
988+ for _ , ast := range asts {
989+ prg , err := env .Program (ast )
990+ if err != nil {
991+ t .Fatal (err )
992+ }
993+ out , _ , err := prg .Eval (tc .in )
994+ if err != nil {
995+ t .Fatal (err )
996+ }
997+ if ! reflect .DeepEqual (out .Value (), true ) {
998+ t .Errorf ("got %v, wanted true for expr: %s" , out .Value (), tc .expr )
999+ }
1000+ }
1001+ })
1002+ }
1003+ }
1004+
9441005func TestNativeTypesVersion (t * testing.T ) {
9451006 _ , err := cel .NewEnv (NativeTypes (NativeTypesVersion (0 )))
9461007 if err != nil {
0 commit comments