|
16 | 16 |
|
17 | 17 | #include <memory> |
18 | 18 | #include <string> |
| 19 | +#include <utility> |
19 | 20 |
|
20 | 21 | #include "cel/expr/syntax.pb.h" |
21 | 22 | #include "absl/status/status_matchers.h" |
22 | 23 | #include "checker/standard_library.h" |
23 | 24 | #include "checker/validation_result.h" |
24 | 25 | #include "common/ast_proto.h" |
25 | 26 | #include "common/minimal_descriptor_pool.h" |
| 27 | +#include "common/value.h" |
| 28 | +#include "compiler/compiler.h" |
26 | 29 | #include "compiler/compiler_factory.h" |
27 | 30 | #include "eval/public/activation.h" |
28 | 31 | #include "eval/public/builtin_func_registrar.h" |
|
32 | 35 | #include "eval/public/cel_options.h" |
33 | 36 | #include "eval/public/cel_value.h" |
34 | 37 | #include "internal/testing.h" |
| 38 | +#include "runtime/activation.h" |
| 39 | +#include "runtime/runtime.h" |
| 40 | +#include "runtime/runtime_builder.h" |
35 | 41 | #include "runtime/runtime_options.h" |
| 42 | +#include "runtime/standard_runtime_builder_factory.h" |
36 | 43 | #include "google/protobuf/arena.h" |
37 | 44 |
|
38 | 45 | namespace cel::extensions { |
@@ -93,6 +100,44 @@ TEST_P(CelSetsFunctionsTest, EndToEnd) { |
93 | 100 | EXPECT_TRUE(out.BoolOrDie()) << test_info.expr << " -> " << out.DebugString(); |
94 | 101 | } |
95 | 102 |
|
| 103 | +TEST_P(CelSetsFunctionsTest, RuntimeEndToEnd) { |
| 104 | + const TestInfo& test_info = GetParam(); |
| 105 | + ASSERT_OK_AND_ASSIGN(std::unique_ptr<CompilerBuilder> compiler_builder, |
| 106 | + NewCompilerBuilder(cel::GetMinimalDescriptorPool())); |
| 107 | + |
| 108 | + ASSERT_THAT(compiler_builder->AddLibrary(StandardCheckerLibrary()), IsOk()); |
| 109 | + ASSERT_THAT(compiler_builder->AddLibrary(SetsCompilerLibrary()), IsOk()); |
| 110 | + ASSERT_OK_AND_ASSIGN(std::unique_ptr<const Compiler> compiler, |
| 111 | + compiler_builder->Build()); |
| 112 | + |
| 113 | + ASSERT_OK_AND_ASSIGN(ValidationResult compiled, |
| 114 | + compiler->Compile(test_info.expr)); |
| 115 | + |
| 116 | + ASSERT_TRUE(compiled.IsValid()) << compiled.FormatError(); |
| 117 | + |
| 118 | + RuntimeOptions options; |
| 119 | + options.enable_heterogeneous_equality = true; |
| 120 | + options.enable_empty_wrapper_null_unboxing = true; |
| 121 | + options.enable_qualified_type_identifiers = true; |
| 122 | + ASSERT_OK_AND_ASSIGN( |
| 123 | + RuntimeBuilder runtime_builder, |
| 124 | + CreateStandardRuntimeBuilder(cel::GetMinimalDescriptorPool(), options)); |
| 125 | + ASSERT_THAT( |
| 126 | + RegisterSetsFunctions(runtime_builder.function_registry(), options), |
| 127 | + IsOk()); |
| 128 | + ASSERT_OK_AND_ASSIGN(std::unique_ptr<const Runtime> runtime, |
| 129 | + std::move(runtime_builder).Build()); |
| 130 | + |
| 131 | + ASSERT_OK_AND_ASSIGN(std::unique_ptr<Program> program, |
| 132 | + runtime->CreateProgram(*compiled.ReleaseAst())); |
| 133 | + Arena arena; |
| 134 | + cel::Activation activation; |
| 135 | + ASSERT_OK_AND_ASSIGN(Value out, program->Evaluate(&arena, activation)); |
| 136 | + ASSERT_TRUE(out.IsBool()) << test_info.expr << " -> " << out.DebugString(); |
| 137 | + EXPECT_TRUE(out.GetBool().NativeValue()) |
| 138 | + << test_info.expr << " -> " << out.DebugString(); |
| 139 | +} |
| 140 | + |
96 | 141 | INSTANTIATE_TEST_SUITE_P( |
97 | 142 | CelSetsFunctionsTest, CelSetsFunctionsTest, |
98 | 143 | testing::ValuesIn<TestInfo>({ |
|
0 commit comments