#include "expression.hpp" #include "print.hpp" #include #include template using term = boost::proto17::terminal; namespace bp17 = boost::proto17; namespace bh = boost::hana; template struct user_expr { using this_type = user_expr; static boost::proto17::expr_kind const kind = Kind; Tuple elements; BOOST_PROTO17_USER_BINARY_OPERATOR_MEMBER(plus, this_type, ::user_expr) }; template using user_term = boost::proto17::terminal; template using user_ref = boost::proto17::expression_ref; struct thing {}; TEST(expression, test_print) { term unity{1.0}; int i_ = 42; term i{std::move(i_)}; bp17::expression< bp17::expr_kind::plus, bh::tuple< bp17::expression_ref &>, term > > expr = unity + std::move(i); bp17::expression< bp17::expr_kind::plus, bh::tuple< bp17::expression_ref &>, bp17::expression< bp17::expr_kind::plus, bh::tuple< bp17::expression_ref &>, term > > > > unevaluated_expr = unity + std::move(expr); { std::ostringstream oss; bp17::print(oss, unity); EXPECT_EQ(oss.str(), R"(term[=1] )"); } { std::ostringstream oss; bp17::print(oss, expr); EXPECT_EQ(oss.str(), R"(expr<+> term[=1] & term[=42] )"); } { std::ostringstream oss; bp17::print(oss, unevaluated_expr); EXPECT_EQ(oss.str(), R"(expr<+> term[=1] & expr<+> term[=1] & term[=42] )"); } term a_thing(thing{}); { std::ostringstream oss; bp17::print(oss, a_thing); EXPECT_EQ(oss.str(), R"(term[=<>] )"); } term const const_unity{1.0}; bp17::expression< bp17::expr_kind::plus, bh::tuple< bp17::expression_ref &>, bp17::expression_ref const &> > > nonconst_plus_const = unity + const_unity; { std::ostringstream oss; bp17::print(oss, nonconst_plus_const); EXPECT_EQ(oss.str(), R"(expr<+> term[=1] & term[=1] const & )"); } } TEST(user_expr, test_print) { user_term unity{1.0}; int i_ = 42; user_term i{std::move(i_)}; user_expr< bp17::expr_kind::plus, bh::tuple< user_ref &>, user_term > > expr = unity + std::move(i); user_expr< bp17::expr_kind::plus, bh::tuple< user_ref &>, user_expr< bp17::expr_kind::plus, bh::tuple< user_ref &>, user_term > > > > unevaluated_expr = unity + std::move(expr); { std::ostringstream oss; bp17::print(oss, unity); EXPECT_EQ(oss.str(), R"(term[=1] )"); } { std::ostringstream oss; bp17::print(oss, expr); EXPECT_EQ(oss.str(), R"(expr<+> term[=1] & term[=42] )"); } { std::ostringstream oss; bp17::print(oss, unevaluated_expr); EXPECT_EQ(oss.str(), R"(expr<+> term[=1] & expr<+> term[=1] & term[=42] )"); } user_term a_thing{bh::make_tuple(thing{})}; { std::ostringstream oss; bp17::print(oss, a_thing); EXPECT_EQ(oss.str(), R"(term[=<>] )"); } user_term const const_unity{1.0}; user_expr< bp17::expr_kind::plus, bh::tuple< user_ref &>, user_ref const &> > > nonconst_plus_const = unity + const_unity; { std::ostringstream oss; bp17::print(oss, nonconst_plus_const); EXPECT_EQ(oss.str(), R"(expr<+> term[=1] & term[=1] const & )"); } }