| 79 | } |
| 80 | |
| 81 | TEST_F(InstrumentationTest, Basic) { |
| 82 | FlatExprBuilder builder(env_, options_); |
| 83 | |
| 84 | std::vector<int64_t> expr_ids; |
| 85 | Instrumentation expr_id_recorder = |
| 86 | [&expr_ids](int64_t expr_id, const cel::Value&) -> absl::Status { |
| 87 | expr_ids.push_back(expr_id); |
| 88 | return absl::OkStatus(); |
| 89 | }; |
| 90 | |
| 91 | builder.AddProgramOptimizer(CreateInstrumentationExtension( |
| 92 | [=](const cel::Ast&) -> Instrumentation { return expr_id_recorder; })); |
| 93 | |
| 94 | ASSERT_OK_AND_ASSIGN(ParsedExpr expr, Parse("1 + 2 + 3")); |
| 95 | ASSERT_OK_AND_ASSIGN(auto ast, |
| 96 | cel::extensions::CreateAstFromParsedExpr(expr)); |
| 97 | ASSERT_OK_AND_ASSIGN(auto plan, |
| 98 | builder.CreateExpressionImpl(std::move(ast), |
| 99 | /*issues=*/nullptr)); |
| 100 | |
| 101 | auto state = plan.MakeEvaluatorState(env_->descriptor_pool.get(), |
| 102 | env_->MutableMessageFactory(), &arena_); |
| 103 | cel::Activation activation; |
| 104 | |
| 105 | ASSERT_OK_AND_ASSIGN(auto value, plan.EvaluateWithCallback( |
| 106 | activation, /*embedder_context=*/nullptr, |
| 107 | EvaluationListener(), state)); |
| 108 | |
| 109 | // AST for the test expression: |
| 110 | // + <4> |
| 111 | // / \ |
| 112 | // +<2> 3<5> |
| 113 | // / \ |
| 114 | // 1<1> 2<3> |
| 115 | EXPECT_THAT(expr_ids, ElementsAre(1, 3, 2, 5, 4)); |
| 116 | } |
| 117 | |
| 118 | TEST_F(InstrumentationTest, BasicWithConstFolding) { |
| 119 | FlatExprBuilder builder(env_, options_); |
nothing calls this directly
no test coverage detected