assign_test.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*=============================================================================
  2. Copyright (c) 2003 Jonathan de Halleux (dehalleux@pelikhan.com)
  3. http://spirit.sourceforge.net/
  4. Use, modification and distribution is subject to the Boost Software
  5. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. =============================================================================*/
  8. ///////////////////////////////////////////////////////////////////////////////
  9. // Test suite for assign_actor
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #include "action_tests.hpp"
  12. #include <boost/spirit/include/classic_core.hpp>
  13. #include <boost/spirit/include/classic_assign_actor.hpp>
  14. void assign_test()
  15. {
  16. using namespace BOOST_SPIRIT_CLASSIC_NS;
  17. const char* cp = "63";
  18. const char* cp_first = cp;
  19. const char* cp_last = cp + test_impl::string_length(cp);
  20. int h=127;
  21. int hm=h;
  22. scanner<char const*> scan( cp_first, cp_last );
  23. match<> hit;
  24. hit = int_p[ assign_a(hm)].parse(scan);
  25. BOOST_CHECK(hit);
  26. BOOST_CHECK_EQUAL(scan.first, scan.last);
  27. h=63;
  28. BOOST_CHECK_EQUAL( hm,h);
  29. }
  30. void assign_test_ref()
  31. {
  32. using namespace BOOST_SPIRIT_CLASSIC_NS;
  33. const char* cp = "63";
  34. const char* cp_first = cp;
  35. const char* cp_last = cp + test_impl::string_length(cp);
  36. int h=127;
  37. int hm=63;
  38. scanner<char const*> scan( cp_first, cp_last );
  39. match<> hit;
  40. hit = int_p[ assign_a(h,hm)].parse(scan);
  41. BOOST_CHECK(hit);
  42. BOOST_CHECK_EQUAL(scan.first, scan.last);
  43. BOOST_CHECK_EQUAL( hm,h);
  44. }
  45. void assign_action_test()
  46. {
  47. assign_test();
  48. assign_test_ref();
  49. }