4444import dev .cel .common .values .CelByteString ;
4545import dev .cel .common .values .NullValue ;
4646import dev .cel .compiler .CelCompiler ;
47+ import dev .cel .expr .conformance .proto3 .NestedTestAllTypes ;
4748import dev .cel .expr .conformance .proto3 .TestAllTypes ;
4849import dev .cel .expr .conformance .proto3 .TestAllTypes .NestedMessage ;
4950import dev .cel .parser .CelMacro ;
@@ -603,6 +604,16 @@ public void optionalFieldSelection_onMap_returnsOptionalValue() throws Exception
603604 assertThat (result ).hasValue (2L );
604605 }
605606
607+ @ Test
608+ public void optionalFieldSelection_onMap_chained_returnsSinglyWrappedOptional () throws Exception {
609+ Cel cel = newCelBuilder ().setResultType (OptionalType .create (SimpleType .STRING )).build ();
610+ CelAbstractSyntaxTree ast = compile (cel , "{'foo': {'bar': 'baz'}}.?foo.?bar" );
611+
612+ Optional <String > result = (Optional <String >) cel .createProgram (ast ).eval ();
613+
614+ assertThat (result ).hasValue ("baz" );
615+ }
616+
606617 @ Test
607618 public void optionalFieldSelection_onProtoMessage_returnsOptionalEmpty () throws Exception {
608619 Cel cel =
@@ -619,6 +630,30 @@ public void optionalFieldSelection_onProtoMessage_returnsOptionalEmpty() throws
619630 assertThat (result ).isEmpty ();
620631 }
621632
633+ @ Test
634+ public void optionalFieldSelection_onProtoMessage_chained_returnsSinglyWrappedOptional ()
635+ throws Exception {
636+ Cel cel =
637+ newCelBuilder ()
638+ .setResultType (OptionalType .create (SimpleType .INT ))
639+ .addVar (
640+ "msg" , StructTypeReference .create (NestedTestAllTypes .getDescriptor ().getFullName ()))
641+ .build ();
642+ CelAbstractSyntaxTree ast = compile (cel , "msg.?payload.?single_int32" );
643+
644+ Optional <Long > result =
645+ (Optional <Long >)
646+ cel .createProgram (ast )
647+ .eval (
648+ ImmutableMap .of (
649+ "msg" ,
650+ NestedTestAllTypes .newBuilder ()
651+ .setPayload (TestAllTypes .newBuilder ().setSingleInt32 (5 ).build ())
652+ .build ()));
653+
654+ assertThat (result ).hasValue (5L );
655+ }
656+
622657 @ Test
623658 public void optionalFieldSelection_onProtoMessage_returnsOptionalValue () throws Exception {
624659 Cel cel =
0 commit comments