| 28 | using ::testing::Truly; |
| 29 | |
| 30 | TEST(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 | |
| 67 | TEST(AstImpl, CheckedExprCtor) { |
| 68 | Expr expr; |
nothing calls this directly
no test coverage detected