1 /////////////////////////////////////////////////////////////////////////////// 2 // display_expr.cpp 3 // 4 // Copyright 2010 Eric Niebler. Distributed under the Boost 5 // Software License, Version 1.0. (See accompanying file 6 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 8 #include <sstream> 9 #include <boost/proto/proto.hpp> 10 #include <boost/test/unit_test.hpp> 11 12 namespace mpl = boost::mpl; 13 namespace proto = boost::proto; 14 using proto::_; 15 16 struct A {}; 17 struct B : A {}; operator <<(std::ostream & out,const A &)18 std::ostream& operator<<( std::ostream& out, const A& ) { return out << "this is A!"; } 19 20 struct C {}; 21 test_display_expr()22 void test_display_expr() 23 { 24 // https://svn.boost.org/trac/boost/ticket/4910 25 proto::terminal<int>::type i = {0}; 26 27 { 28 std::stringstream sout; 29 proto::display_expr(i + A(), sout); 30 BOOST_CHECK_EQUAL(sout.str(), std::string( 31 "plus(\n" 32 " terminal(0)\n" 33 " , terminal(this is A!)\n" 34 ")\n")); 35 } 36 37 { 38 std::stringstream sout; 39 proto::display_expr(i + B(), sout); 40 BOOST_CHECK_EQUAL(sout.str(), std::string( 41 "plus(\n" 42 " terminal(0)\n" 43 " , terminal(this is A!)\n" 44 ")\n")); 45 } 46 47 { 48 std::stringstream sout; 49 char const * Cname = BOOST_CORE_TYPEID(C).name(); 50 proto::display_expr(i + C(), sout); 51 BOOST_CHECK_EQUAL(sout.str(), std::string( 52 "plus(\n" 53 " terminal(0)\n" 54 " , terminal(") + Cname + std::string(")\n" 55 ")\n")); 56 } 57 } 58 59 using namespace boost::unit_test; 60 /////////////////////////////////////////////////////////////////////////////// 61 // init_unit_test_suite 62 // init_unit_test_suite(int argc,char * argv[])63 test_suite* init_unit_test_suite( int argc, char* argv[] ) 64 { 65 test_suite *test = BOOST_TEST_SUITE("test display_expr() function"); 66 test->add(BOOST_TEST_CASE(&test_display_expr)); 67 return test; 68 } 69