Simple end-to-end test, which also serves as usage example.
| 55 | |
| 56 | // Simple end-to-end test, which also serves as usage example. |
| 57 | TEST(EndToEndTest, SimpleOnePlusOne) { |
| 58 | // AST CEL equivalent of "1+var" |
| 59 | constexpr char kExpr0[] = R"( |
| 60 | call_expr: < |
| 61 | function: "_+_" |
| 62 | args: < |
| 63 | ident_expr: < |
| 64 | name: "var" |
| 65 | > |
| 66 | > |
| 67 | args: < |
| 68 | const_expr: < |
| 69 | int64_value: 1 |
| 70 | > |
| 71 | > |
| 72 | > |
| 73 | )"; |
| 74 | |
| 75 | Expr expr; |
| 76 | SourceInfo source_info; |
| 77 | TextFormat::ParseFromString(kExpr0, &expr); |
| 78 | |
| 79 | // Obtain CEL Expression builder. |
| 80 | std::unique_ptr<CelExpressionBuilder> builder = CreateCelExpressionBuilder(); |
| 81 | |
| 82 | // Builtin registration. |
| 83 | ASSERT_OK(RegisterBuiltinFunctions(builder->GetRegistry())); |
| 84 | |
| 85 | // Create CelExpression from AST (Expr object). |
| 86 | ASSERT_OK_AND_ASSIGN(auto cel_expr, |
| 87 | builder->CreateExpression(&expr, &source_info)); |
| 88 | Activation activation; |
| 89 | |
| 90 | // Bind value to "var" parameter. |
| 91 | activation.InsertValue("var", CelValue::CreateInt64(1)); |
| 92 | |
| 93 | Arena arena; |
| 94 | |
| 95 | // Run evaluation. |
| 96 | ASSERT_OK_AND_ASSIGN(CelValue result, cel_expr->Evaluate(activation, &arena)); |
| 97 | ASSERT_TRUE(result.IsInt64()); |
| 98 | EXPECT_EQ(result.Int64OrDie(), 2); |
| 99 | } |
| 100 | |
| 101 | // Simple end-to-end test, which also serves as usage example. |
| 102 | TEST(EndToEndTest, EmptyStringCompare) { |
nothing calls this directly
no test coverage detected