1818#include < functional>
1919#include < limits>
2020#include < memory>
21- #include < optional>
2221#include < string>
2322#include < utility>
2423#include < vector>
3635#include " absl/time/time.h"
3736#include " absl/types/span.h"
3837#include " base/builtins.h"
39- #include " checker/validation_result.h"
40- #include " common/ast.h"
41- #include " common/decl.h"
42- #include " common/expr.h"
4338#include " common/function_descriptor.h"
4439#include " common/kind.h"
45- #include " common/type.h"
4640#include " common/value.h"
47- #include " compiler/compiler.h"
48- #include " compiler/compiler_factory.h"
49- #include " compiler/standard_library.h"
5041#include " eval/compiler/cel_expression_builder_flat_impl.h"
5142#include " eval/compiler/constant_folding.h"
52- #include " eval/compiler/flat_expr_builder_extensions.h"
5343#include " eval/compiler/qualified_reference_resolver.h"
54- #include " eval/eval/evaluator_core.h"
5544#include " eval/eval/expression_step_logic.h"
5645#include " eval/public/activation.h"
5746#include " eval/public/ast_rewrite.h"
@@ -3417,22 +3406,33 @@ TEST(FlatExprBuilderTest, ListAppendComprehensionWithTargetFailsPlanning) {
34173406}
34183407
34193408TEST (FlatExprBuilderTest, ProgramOptimizerResolvesTypesWhenRequested) {
3420- std::shared_ptr<cel::runtime_internal::RuntimeEnv> env =
3421- NewTestingRuntimeEnv ();
3422- ASSERT_OK_AND_ASSIGN (std::unique_ptr<cel::CompilerBuilder> compiler_builder,
3423- cel::NewCompilerBuilder (env->descriptor_pool ));
3424- ASSERT_THAT (compiler_builder->AddLibrary (cel::StandardCompilerLibrary ()),
3425- IsOk ());
3426- ASSERT_THAT (compiler_builder->GetCheckerBuilder ().AddVariable (
3427- cel::MakeVariableDecl (" x" , cel::IntType ())),
3428- IsOk ());
3429- ASSERT_OK_AND_ASSIGN (std::unique_ptr<cel::Compiler> compiler,
3430- compiler_builder->Build ());
3431- ASSERT_OK_AND_ASSIGN (cel::ValidationResult validation_result,
3432- compiler->Compile (" x == 1" ));
3433- ASSERT_TRUE (validation_result.IsValid ());
3434- ASSERT_OK_AND_ASSIGN (std::unique_ptr<cel::Ast> ast,
3435- validation_result.ReleaseAst ());
3409+ CheckedExpr expr;
3410+ ASSERT_TRUE (google::protobuf::TextFormat::ParseFromString (
3411+ R"pb(
3412+ type_map {
3413+ key: 1
3414+ value { primitive: BOOL }
3415+ }
3416+ type_map {
3417+ key: 2
3418+ value { primitive: INT64 }
3419+ }
3420+ expr {
3421+ id: 1
3422+ call_expr {
3423+ function: "_==_"
3424+ args {
3425+ id: 2
3426+ ident_expr { name: "x" }
3427+ }
3428+ args {
3429+ id: 3
3430+ const_expr { int64_value: 1 }
3431+ }
3432+ }
3433+ }
3434+ )pb" ,
3435+ &expr));
34363436
34373437 class TypeRecordingOptimizer : public ProgramOptimizer {
34383438 public:
@@ -3467,7 +3467,7 @@ TEST(FlatExprBuilderTest, ProgramOptimizerResolvesTypesWhenRequested) {
34673467
34683468 cel::RuntimeOptions options;
34693469 options.enable_typed_field_access = false ;
3470- CelExpressionBuilderFlatImpl builder (env , options);
3470+ CelExpressionBuilderFlatImpl builder (NewTestingRuntimeEnv () , options);
34713471 ASSERT_THAT (RegisterBuiltinFunctions (builder.GetRegistry ()), IsOk ());
34723472
34733473 absl::flat_hash_map<int64_t , cel::Type> pre_visit_types;
@@ -3480,17 +3480,14 @@ TEST(FlatExprBuilderTest, ProgramOptimizerResolvesTypesWhenRequested) {
34803480 post_visit_types);
34813481 });
34823482
3483- ASSERT_OK_AND_ASSIGN (FlatExpression flat_expr,
3484- builder.flat_expr_builder ().CreateExpressionImpl (
3485- std::move (ast), /* issues=*/ nullptr ));
3483+ ASSERT_OK_AND_ASSIGN (std::unique_ptr<CelExpression> cel_expr,
3484+ builder.CreateExpression (&expr));
34863485 EXPECT_THAT (pre_visit_types,
3487- testing::UnorderedElementsAre (testing::Pair (1 , cel::IntType ()),
3488- testing::Pair (2 , cel::BoolType ()),
3489- testing::Pair (3 , cel::IntType ())));
3486+ testing::UnorderedElementsAre (testing::Pair (1 , cel::BoolType ()),
3487+ testing::Pair (2 , cel::IntType ())));
34903488 EXPECT_THAT (post_visit_types,
3491- testing::UnorderedElementsAre (testing::Pair (1 , cel::IntType ()),
3492- testing::Pair (2 , cel::BoolType ()),
3493- testing::Pair (3 , cel::IntType ())));
3489+ testing::UnorderedElementsAre (testing::Pair (1 , cel::BoolType ()),
3490+ testing::Pair (2 , cel::IntType ())));
34943491}
34953492
34963493} // namespace
0 commit comments