| 54 | using TestParamType = std::tuple<bool, bool, bool>; |
| 55 | |
| 56 | CelValue EvaluateAttributeHelper( |
| 57 | const absl_nonnull std::shared_ptr<const RuntimeEnv>& env, |
| 58 | google::protobuf::Arena* arena, CelValue container, CelValue key, |
| 59 | bool use_recursive_impl, bool receiver_style, bool enable_unknown, |
| 60 | const std::vector<CelAttributePattern>& patterns) { |
| 61 | ExecutionPath path; |
| 62 | |
| 63 | Expr expr; |
| 64 | SourceInfo source_info; |
| 65 | auto& call = expr.mutable_call_expr(); |
| 66 | |
| 67 | call.set_function(cel::builtin::kIndex); |
| 68 | |
| 69 | call.mutable_args().reserve(2); |
| 70 | Expr& container_expr = (receiver_style) ? call.mutable_target() |
| 71 | : call.mutable_args().emplace_back(); |
| 72 | Expr& key_expr = call.mutable_args().emplace_back(); |
| 73 | |
| 74 | container_expr.mutable_ident_expr().set_name("container"); |
| 75 | key_expr.mutable_ident_expr().set_name("key"); |
| 76 | |
| 77 | if (use_recursive_impl) { |
| 78 | path.push_back(std::make_unique<WrappedDirectStep>( |
| 79 | CreateDirectContainerAccessStep(CreateDirectIdentStep("container", 1), |
| 80 | CreateDirectIdentStep("key", 2), |
| 81 | /*enable_optional_types=*/false, 3), |
| 82 | 3)); |
| 83 | } else { |
| 84 | path.push_back(std::move(CreateIdentStep("container", 1).value())); |
| 85 | path.push_back(std::move(CreateIdentStep("key", 2).value())); |
| 86 | path.push_back(std::move(CreateContainerAccessStep(call, 3).value())); |
| 87 | } |
| 88 | |
| 89 | cel::RuntimeOptions options; |
| 90 | options.unknown_processing = cel::UnknownProcessingOptions::kAttributeOnly; |
| 91 | options.enable_heterogeneous_equality = false; |
| 92 | CelExpressionFlatImpl cel_expr( |
| 93 | env, |
| 94 | FlatExpression(std::move(path), /*comprehension_slot_count=*/0, |
| 95 | env->type_registry.GetComposedTypeProvider(), options)); |
| 96 | Activation activation; |
| 97 | |
| 98 | activation.InsertValue("container", container); |
| 99 | activation.InsertValue("key", key); |
| 100 | |
| 101 | activation.set_unknown_attribute_patterns(patterns); |
| 102 | auto result = cel_expr.Evaluate(activation, arena); |
| 103 | return *result; |
| 104 | } |
| 105 | |
| 106 | class ContainerAccessStepTest : public ::testing::Test { |
| 107 | protected: |
no test coverage detected