/Src/Dependencies/Boost/libs/spirit/phoenix/test/core/primitives_tests.cpp

http://hadesmem.googlecode.com/ · C++ · 69 lines · 39 code · 12 blank · 18 comment · 13 complexity · 4716e28852975f9bd1c6004e99fd64ea MD5 · raw file

  1. /*=============================================================================
  2. Copyright (c) 2001-2007 Joel de Guzman
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #include <iostream>
  7. #include <string>
  8. #include <boost/spirit/include/phoenix_core.hpp>
  9. #include <boost/detail/lightweight_test.hpp>
  10. using namespace boost::phoenix;
  11. using namespace boost::phoenix::arg_names;
  12. using namespace std;
  13. int
  14. main()
  15. {
  16. char c1 = '1';
  17. int i1 = 1, i2 = 2, i = 4;
  18. const char* s2 = "2";
  19. ///////////////////////////////////////////////////////////////////////////
  20. //
  21. // Values, references and arguments
  22. //
  23. ///////////////////////////////////////////////////////////////////////////
  24. // argument
  25. BOOST_TEST(arg1(c1) == c1);
  26. BOOST_TEST(arg1(i1, i2) == i1);
  27. BOOST_TEST(arg2(i1, s2) == s2);
  28. BOOST_TEST(&(arg1(c1)) == &c1); // must be an lvalue
  29. // value
  30. cout << val("Hello,")() << val(' ')() << val("World")() << endl;
  31. BOOST_TEST(val(3)() == 3);
  32. BOOST_TEST(val("Hello, world")() == std::string("Hello, world"));
  33. BOOST_TEST(val(_1)(i1) == i1);
  34. // should not compile:
  35. #ifdef PHOENIX_SHOULD_NOT_COMPILE_TEST
  36. &val(_1)(i1); // should return an rvalue
  37. #endif
  38. // reference
  39. BOOST_TEST(cref(i)() == ref(i)());
  40. BOOST_TEST(cref(i)() == 4);
  41. BOOST_TEST(i == 4);
  42. BOOST_TEST(ref(++i)() == 5);
  43. BOOST_TEST(i == 5);
  44. // should not compile:
  45. #ifdef PHOENIX_SHOULD_NOT_COMPILE_TEST
  46. ref(arg1);
  47. #endif
  48. // testing consts
  49. int const ic = 123;
  50. BOOST_TEST(arg1(ic) == 123);
  51. // should not compile:
  52. #ifdef PHOENIX_SHOULD_NOT_COMPILE_TEST
  53. arg1();
  54. #endif
  55. return boost::report_errors();
  56. }