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

Function TEST

common/ast_test.cc:30–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28using ::testing::Truly;
29
30TEST(AstImpl, RawExprCtor) {
31 // arrange
32 // make ast for 2 + 1 == 3
33 Expr expr;
34 auto& call = expr.mutable_call_expr();
35 expr.set_id(5);
36 call.set_function("_==_");
37 auto& eq_lhs = call.mutable_args().emplace_back();
38 eq_lhs.mutable_call_expr().set_function("_+_");
39 eq_lhs.set_id(3);
40 auto& sum_lhs = eq_lhs.mutable_call_expr().mutable_args().emplace_back();
41 sum_lhs.mutable_const_expr().set_int_value(2);
42 sum_lhs.set_id(1);
43 auto& sum_rhs = eq_lhs.mutable_call_expr().mutable_args().emplace_back();
44 sum_rhs.mutable_const_expr().set_int_value(1);
45 sum_rhs.set_id(2);
46 auto& eq_rhs = call.mutable_args().emplace_back();
47 eq_rhs.mutable_const_expr().set_int_value(3);
48 eq_rhs.set_id(4);
49
50 SourceInfo source_info;
51 source_info.mutable_positions()[5] = 6;
52
53 // act
54 Ast ast(std::move(expr), std::move(source_info));
55
56 // assert
57 ASSERT_FALSE(ast.is_checked());
58 EXPECT_EQ(ast.GetTypeOrDyn(1), TypeSpec(DynTypeSpec()));
59 EXPECT_EQ(ast.GetReturnType(), TypeSpec(DynTypeSpec()));
60 EXPECT_EQ(ast.GetReference(1), nullptr);
61 EXPECT_TRUE(ast.root_expr().has_call_expr());
62 EXPECT_EQ(ast.root_expr().call_expr().function(), "_==_");
63 EXPECT_EQ(ast.root_expr().id(), 5); // Parser IDs leaf to root.
64 EXPECT_EQ(ast.source_info().positions().at(5), 6); // start pos of ==
65}
66
67TEST(AstImpl, CheckedExprCtor) {
68 Expr expr;

Callers

nothing calls this directly

Calls 15

TypeSpecClass · 0.85
DynTypeSpecClass · 0.85
set_functionMethod · 0.80
is_checkedMethod · 0.80
GetReferenceMethod · 0.80
has_call_exprMethod · 0.80
atMethod · 0.80
source_infoMethod · 0.80
set_syntax_versionMethod · 0.80
has_ident_exprMethod · 0.80
expr_versionMethod · 0.80
IsCheckedMethod · 0.80

Tested by

no test coverage detected