MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / EvaluateAttributeHelper

Function EvaluateAttributeHelper

eval/eval/container_access_step_test.cc:56–104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

54using TestParamType = std::tuple<bool, bool, bool>;
55
56CelValue 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
106class ContainerAccessStepTest : public ::testing::Test {
107 protected:

Callers 2

EvaluateAttributeMethod · 0.85
EvaluateAttributeMethod · 0.85

Calls 11

CreateDirectIdentStepFunction · 0.85
CreateIdentStepFunction · 0.85
FlatExpressionClass · 0.85
set_functionMethod · 0.80
InsertValueMethod · 0.80
set_nameMethod · 0.45
valueMethod · 0.45
EvaluateMethod · 0.45

Tested by

no test coverage detected