display_expr.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. #include <sstream>
  8. #include <boost/proto/proto.hpp>
  9. #include <boost/test/unit_test.hpp>
  10. namespace mpl = boost::mpl;
  11. namespace proto = boost::proto;
  12. using proto::_;
  13. struct A {};
  14. struct B : A {};
  15. std::ostream& operator<<( std::ostream& out, const A& ) { return out << "this is A!"; }
  16. struct C {};
  17. void test_display_expr()
  18. {
  19. // https://svn.boost.org/trac/boost/ticket/4910
  20. proto::terminal<int>::type i = {0};
  21. {
  22. std::stringstream sout;
  23. proto::display_expr(i + A(), sout);
  24. BOOST_CHECK_EQUAL(sout.str(), std::string(
  25. "plus(\n"
  26. " terminal(0)\n"
  27. " , terminal(this is A!)\n"
  28. ")\n"));
  29. }
  30. {
  31. std::stringstream sout;
  32. proto::display_expr(i + B(), sout);
  33. BOOST_CHECK_EQUAL(sout.str(), std::string(
  34. "plus(\n"
  35. " terminal(0)\n"
  36. " , terminal(this is A!)\n"
  37. ")\n"));
  38. }
  39. {
  40. std::stringstream sout;
  41. char const * Cname = BOOST_CORE_TYPEID(C).name();
  42. proto::display_expr(i + C(), sout);
  43. BOOST_CHECK_EQUAL(sout.str(), std::string(
  44. "plus(\n"
  45. " terminal(0)\n"
  46. " , terminal(") + Cname + std::string(")\n"
  47. ")\n"));
  48. }
  49. }
  50. using namespace boost::unit_test;
  51. ///////////////////////////////////////////////////////////////////////////////
  52. // init_unit_test_suite
  53. //
  54. test_suite* init_unit_test_suite( int argc, char* argv[] )
  55. {
  56. test_suite *test = BOOST_TEST_SUITE("test display_expr() function");
  57. test->add(BOOST_TEST_CASE(&test_display_expr));
  58. return test;
  59. }