swap_test.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 and_assign_actor
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #include "action_tests.hpp"
  12. #include <boost/spirit/include/classic_core.hpp>
  13. #include <boost/spirit/include/classic_swap_actor.hpp>
  14. void swap_action_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. std::vector<int> v1,v2;
  21. v1.push_back(0);
  22. v1.push_back(1);
  23. v2.push_back(2);
  24. v2.push_back(3);
  25. scanner<char const*> scan( cp_first, cp_last );
  26. match<> hit;
  27. hit = int_p[ swap_a(v1,v2)].parse(scan);
  28. BOOST_CHECK(hit);
  29. BOOST_CHECK_EQUAL(scan.first, scan.last);
  30. BOOST_CHECK(v1.size()==2);
  31. BOOST_CHECK(v2.size()==2);
  32. BOOST_CHECK_EQUAL(v2[0],0);
  33. BOOST_CHECK_EQUAL(v2[1],1);
  34. BOOST_CHECK_EQUAL(v1[0],2);
  35. BOOST_CHECK_EQUAL(v1[1],3);
  36. }