| 1806 | } |
| 1807 | |
| 1808 | absl::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 | |
| 1839 | TEST(FlatExprBuilderTest, Ternary) { |
| 1840 | Expr expr; |
no test coverage detected