push_front_test.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 push_front_actor
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #include "action_tests.hpp"
  12. #include <string>
  13. #include <vector>
  14. #include <deque>
  15. #include <cstring>
  16. #include <iostream>
  17. #include <boost/spirit/include/classic_core.hpp>
  18. #include <boost/spirit/include/classic_push_front_actor.hpp>
  19. #include <boost/spirit/include/classic_lists.hpp>
  20. template<typename ContainerT>
  21. void push_front_test()
  22. {
  23. using namespace BOOST_SPIRIT_CLASSIC_NS;
  24. const char* cp = "one,two,three";
  25. const char* cp_first = cp;
  26. const char* cp_last = cp + test_impl::string_length(cp);
  27. const char* cp_i[] = {"one","two","three"};;
  28. int i;
  29. ContainerT c;
  30. typename ContainerT::const_iterator it;
  31. scanner<char const*> scan( cp_first, cp_last );
  32. match<> hit;
  33. hit = list_p( (*alpha_p)[ push_front_a(c)] , ch_p(',') ).parse(scan);
  34. BOOST_CHECK(hit);
  35. BOOST_CHECK_EQUAL(scan.first, scan.last);
  36. BOOST_CHECK_EQUAL( c.size(), static_cast<typename ContainerT::size_type>(3));
  37. for (i=2, it = c.begin();i>=0 && it != c.end();--i, ++it)
  38. BOOST_CHECK_EQUAL( cp_i[i], *it);
  39. scan.first = cp;
  40. }
  41. void push_front_action_test()
  42. {
  43. push_front_test< std::deque<std::string> >();
  44. }