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

Function RunTernaryExpression

eval/compiler/flat_expr_builder_test.cc:1808–1837  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1806}
1807
1808absl::Status RunTernaryExpression(CelValue selector, CelValue value1,
1809 CelValue value2, google::protobuf::Arena* arena,
1810 CelValue* result) {
1811 Expr expr;
1812 SourceInfo source_info;
1813 auto call_expr = expr.mutable_call_expr();
1814 call_expr->set_function(builtin::kTernary);
1815
1816 auto arg0 = call_expr->add_args();
1817 arg0->mutable_ident_expr()->set_name("selector");
1818 auto arg1 = call_expr->add_args();
1819 arg1->mutable_ident_expr()->set_name("value1");
1820 auto arg2 = call_expr->add_args();
1821 arg2->mutable_ident_expr()->set_name("value2");
1822
1823 CelExpressionBuilderFlatImpl builder(NewTestingRuntimeEnv());
1824 CEL_ASSIGN_OR_RETURN(auto cel_expr,
1825 builder.CreateExpression(&expr, &source_info));
1826
1827 std::string variable = "test";
1828
1829 Activation activation;
1830 activation.InsertValue("selector", selector);
1831 activation.InsertValue("value1", value1);
1832 activation.InsertValue("value2", value2);
1833
1834 CEL_ASSIGN_OR_RETURN(auto eval, cel_expr->Evaluate(activation, arena));
1835 *result = eval;
1836 return absl::OkStatus();
1837}
1838
1839TEST(FlatExprBuilderTest, Ternary) {
1840 Expr expr;

Callers 1

TESTFunction · 0.85

Calls 3

set_functionMethod · 0.80
InsertValueMethod · 0.80
set_nameMethod · 0.45

Tested by

no test coverage detected