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

Function TEST_P

extensions/lists_functions_test.cc:71–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69class ListsFunctionsTest : public testing::TestWithParam<TestInfo> {};
70
71TEST_P(ListsFunctionsTest, EndToEnd) {
72 const TestInfo& test_info = GetParam();
73 RecordProperty("cel_expression", test_info.expr);
74 if (!test_info.err.empty()) {
75 RecordProperty("cel_expected_error", test_info.err);
76 }
77
78 ASSERT_OK_AND_ASSIGN(auto source, cel::NewSource(test_info.expr, "<input>"));
79
80 MacroRegistry macro_registry;
81 ParserOptions parser_options{.add_macro_calls = true};
82 ASSERT_THAT(RegisterStandardMacros(macro_registry, parser_options), IsOk());
83 ASSERT_THAT(RegisterListsMacros(macro_registry, parser_options), IsOk());
84 ASSERT_OK_AND_ASSIGN(ParsedExpr parsed_expr,
85 google::api::expr::parser::Parse(*source, macro_registry,
86 parser_options));
87 Expr expr = parsed_expr.expr();
88 SourceInfo source_info = parsed_expr.source_info();
89
90 google::protobuf::Arena arena;
91 const auto options = RuntimeOptions{};
92 ASSERT_OK_AND_ASSIGN(auto builder,
93 CreateStandardRuntimeBuilder(
94 internal::GetTestingDescriptorPool(), options));
95
96 // Needed to resolve namespaced functions when evaluating a ParsedExpr.
97 ASSERT_THAT(cel::EnableReferenceResolver(
98 builder, cel::ReferenceResolverEnabled::kAlways),
99 IsOk());
100 EXPECT_THAT(RegisterListsFunctions(builder.function_registry(), options),
101 IsOk());
102 ASSERT_OK_AND_ASSIGN(auto runtime, std::move(builder).Build());
103
104 ASSERT_OK_AND_ASSIGN(std::unique_ptr<Program> program,
105 ProtobufRuntimeAdapter::CreateProgram(*runtime, expr));
106
107 Activation activation;
108 ASSERT_OK_AND_ASSIGN(Value result, program->Evaluate(&arena, activation));
109 if (!test_info.err.empty()) {
110 EXPECT_THAT(result,
111 ErrorValueIs(StatusIs(testing::_, HasSubstr(test_info.err))));
112 return;
113 }
114 ASSERT_TRUE(result.IsBool())
115 << test_info.expr << " -> " << result.DebugString();
116 EXPECT_TRUE(result.GetBool().NativeValue())
117 << test_info.expr << " -> " << result.DebugString();
118}
119
120INSTANTIATE_TEST_SUITE_P(
121 ListsFunctionsTest, ListsFunctionsTest,

Callers

nothing calls this directly

Calls 15

RegisterStandardMacrosFunction · 0.85
RegisterListsMacrosFunction · 0.85
EnableReferenceResolverFunction · 0.85
RegisterListsFunctionsFunction · 0.85
CreateProgramFunction · 0.85
ErrorValueIsFunction · 0.85
ListsCompilerLibraryFunction · 0.85
CompilerOptionsClass · 0.85
StandardCompilerLibraryFunction · 0.85
source_infoMethod · 0.80
IsValidMethod · 0.80
FormatErrorMethod · 0.80

Tested by

no test coverage detected