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

Function ASSERT_OK_AND_ASSIGN

common/navigable_ast_test.cc:241–369  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

239
240TEST(NavigableAst, ParentRelationCreateList) {
241 ASSERT_OK_AND_ASSIGN(auto parsed_expr, Parse("[123]"));
242
243 NavigableAst ast = NavigableAst::Build(parsed_expr->root_expr());
244 const NavigableAstNode& root = ast.Root();
245
246 EXPECT_EQ(root.node_kind(), NodeKind::kList);
247 ASSERT_THAT(root.children(), SizeIs(1));
248 const auto* child = root.children()[0];
249
250 EXPECT_EQ(child->parent_relation(), ChildKind::kListElem);
251 EXPECT_EQ(child->node_kind(), NodeKind::kConstant);
252}
253
254TEST(NavigableAst, ParentRelationComprehension) {
255 ASSERT_OK_AND_ASSIGN(auto parsed_expr, Parse("[1].all(x, x < 2)"));
256
257 NavigableAst ast = NavigableAst::Build(parsed_expr->root_expr());
258 const NavigableAstNode& root = ast.Root();
259
260 EXPECT_EQ(root.node_kind(), NodeKind::kComprehension);
261 ASSERT_THAT(root.children(), SizeIs(5));
262 const auto* range = root.children()[0];
263 const auto* init = root.children()[1];
264 const auto* condition = root.children()[2];
265 const auto* step = root.children()[3];
266 const auto* finish = root.children()[4];
267
268 EXPECT_EQ(range->parent_relation(), ChildKind::kComprehensionRange);
269 EXPECT_EQ(init->parent_relation(), ChildKind::kComprehensionInit);
270 EXPECT_EQ(condition->parent_relation(), ChildKind::kComprehensionCondition);
271 EXPECT_EQ(step->parent_relation(), ChildKind::kComprehensionLoopStep);
272 EXPECT_EQ(finish->parent_relation(), ChildKind::kComprensionResult);
273}
274
275TEST(NavigableAst, DescendantsPostorder) {
276 ASSERT_OK_AND_ASSIGN(auto parsed_expr, Parse("1 + (x * 3)"));
277
278 NavigableAst ast = NavigableAst::Build(parsed_expr->root_expr());
279 const NavigableAstNode& root = ast.Root();
280
281 EXPECT_EQ(root.node_kind(), NodeKind::kCall);
282
283 std::vector<int> constants;
284 std::vector<NodeKind> node_kinds;
285
286 for (const NavigableAstNode& node : root.DescendantsPostorder()) {
287 if (node.node_kind() == NodeKind::kConstant) {
288 constants.push_back(node.expr()->const_expr().int64_value());
289 }
290 node_kinds.push_back(node.node_kind());
291 }
292
293 EXPECT_THAT(node_kinds, ElementsAre(NodeKind::kConstant, NodeKind::kIdent,
294 NodeKind::kConstant, NodeKind::kCall,
295 NodeKind::kCall));
296 EXPECT_THAT(constants, ElementsAre(1, 3));
297}
298

Callers 7

source_test.ccFile · 0.70
TESTFunction · 0.70
TEST_PFunction · 0.70
TESTFunction · 0.70
TEST_PFunction · 0.50
TESTFunction · 0.50
TESTFunction · 0.50

Calls 10

node_kindMethod · 0.80
childrenMethod · 0.80
parent_relationMethod · 0.80
DescendantsPostorderMethod · 0.80
DescendantsPreorderMethod · 0.80
tree_sizeMethod · 0.80
TESTFunction · 0.70
ParseFunction · 0.70
exprMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected