1313// limitations under the License.
1414
1515#include < cstddef>
16+ #include < optional>
1617#include < utility>
1718#include < vector>
1819
2223#include " absl/status/statusor.h"
2324#include " absl/strings/string_view.h"
2425#include " absl/time/time.h"
25- #include " absl/types/optional.h"
2626#include " common/memory.h"
2727#include " common/type.h"
2828#include " common/value.h"
2929#include " common/value_kind.h"
3030#include " common/value_testing.h"
31+ #include " internal/parse_text_proto.h"
3132#include " internal/testing.h"
3233#include " cel/expr/conformance/proto3/test_all_types.pb.h"
34+ #include " google/protobuf/arena.h"
3335#include " google/protobuf/io/zero_copy_stream_impl_lite.h"
3436
3537namespace cel {
@@ -45,6 +47,7 @@ using ::cel::test::DurationValueIs;
4547using ::cel::test::ErrorValueIs;
4648using ::cel::test::IntValueIs;
4749using ::cel::test::IsNullValue;
50+ using ::cel::test::StringValueIs;
4851using ::cel::test::UintValueIs;
4952using ::testing::_;
5053using ::testing::ElementsAre;
@@ -446,5 +449,74 @@ TEST_F(ParsedRepeatedFieldValueTest, Contains) {
446449 IsOkAndHolds (BoolValueIs (false )));
447450}
448451
452+ TEST_F (ParsedRepeatedFieldValueTest, CloneDefault) {
453+ ParsedRepeatedFieldValue value;
454+ EXPECT_FALSE (value.Clone (arena ()));
455+ }
456+
457+ TEST_F (ParsedRepeatedFieldValueTest, CloneSameArena) {
458+ ParsedRepeatedFieldValue value (
459+ DynamicParseTextProto<TestAllTypesProto3>(R"pb( repeated_int64: 1
460+ repeated_int64: 2)pb" ),
461+ DynamicGetField<TestAllTypesProto3>(" repeated_int64" ), arena ());
462+ auto cloned = value.Clone (arena ());
463+ EXPECT_THAT (
464+ cloned.Equal (value, descriptor_pool (), message_factory (), arena ()),
465+ IsOkAndHolds (BoolValueIs (true )));
466+ }
467+
468+ TEST_F (ParsedRepeatedFieldValueTest, CloneDifferentArenaInt64) {
469+ google::protobuf::Arena other_arena;
470+ ParsedRepeatedFieldValue value (
471+ ::cel::internal::DynamicParseTextProto<TestAllTypesProto3>(
472+ &other_arena, R"pb( repeated_int64: 1 repeated_int64: 2)pb" ,
473+ descriptor_pool (), message_factory ()),
474+ DynamicGetField<TestAllTypesProto3>(" repeated_int64" ), &other_arena);
475+ auto cloned = value.Clone (arena ());
476+ EXPECT_THAT (
477+ cloned.Equal (value, descriptor_pool (), message_factory (), arena ()),
478+ IsOkAndHolds (BoolValueIs (true )));
479+ EXPECT_EQ (cloned.Size (), 2 );
480+ EXPECT_THAT (cloned.Get (0 , descriptor_pool (), message_factory (), arena ()),
481+ IsOkAndHolds (IntValueIs (1 )));
482+ EXPECT_THAT (cloned.Get (1 , descriptor_pool (), message_factory (), arena ()),
483+ IsOkAndHolds (IntValueIs (2 )));
484+ }
485+
486+ TEST_F (ParsedRepeatedFieldValueTest, CloneDifferentArenaString) {
487+ google::protobuf::Arena other_arena;
488+ ParsedRepeatedFieldValue value (
489+ ::cel::internal::DynamicParseTextProto<TestAllTypesProto3>(
490+ &other_arena, R"pb( repeated_string: "foo" repeated_string: "bar")pb" ,
491+ descriptor_pool (), message_factory ()),
492+ DynamicGetField<TestAllTypesProto3>(" repeated_string" ), &other_arena);
493+ auto cloned = value.Clone (arena ());
494+ EXPECT_THAT (
495+ cloned.Equal (value, descriptor_pool (), message_factory (), arena ()),
496+ IsOkAndHolds (BoolValueIs (true )));
497+ EXPECT_EQ (cloned.Size (), 2 );
498+ EXPECT_THAT (cloned.Get (0 , descriptor_pool (), message_factory (), arena ()),
499+ IsOkAndHolds (StringValueIs (" foo" )));
500+ EXPECT_THAT (cloned.Get (1 , descriptor_pool (), message_factory (), arena ()),
501+ IsOkAndHolds (StringValueIs (" bar" )));
502+ }
503+
504+ TEST_F (ParsedRepeatedFieldValueTest, CloneDifferentArenaMessage) {
505+ google::protobuf::Arena other_arena;
506+ ParsedRepeatedFieldValue value (
507+ ::cel::internal::DynamicParseTextProto<TestAllTypesProto3>(
508+ &other_arena,
509+ R"pb( repeated_nested_message: { bb: 1 }
510+ repeated_nested_message: { bb: 2 })pb" ,
511+ descriptor_pool (), message_factory ()),
512+ DynamicGetField<TestAllTypesProto3>(" repeated_nested_message" ),
513+ &other_arena);
514+ auto cloned = value.Clone (arena ());
515+ EXPECT_THAT (
516+ cloned.Equal (value, descriptor_pool (), message_factory (), arena ()),
517+ IsOkAndHolds (BoolValueIs (true )));
518+ EXPECT_EQ (cloned.Size (), 2 );
519+ }
520+
449521} // namespace
450522} // namespace cel
0 commit comments