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

Function TEST

eval/tests/end_to_end_test.cc:57–99  ·  view source on GitHub ↗

Simple end-to-end test, which also serves as usage example.

Source from the content-addressed store, hash-verified

55
56// Simple end-to-end test, which also serves as usage example.
57TEST(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.
102TEST(EndToEndTest, EmptyStringCompare) {

Callers

nothing calls this directly

Calls 13

RegisterBuiltinFunctionsFunction · 0.85
GetRegistryMethod · 0.80
InsertValueMethod · 0.80
IsInt64Method · 0.80
Int64OrDieMethod · 0.80
BoolOrDieMethod · 0.80
IsBoolMethod · 0.45
set_containerMethod · 0.45
IsNullMethod · 0.45
RegisterMethod · 0.45
GetValueMethod · 0.45

Tested by

no test coverage detected