push_back_test.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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_back_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 <algorithm>
  19. #include <boost/bind.hpp>
  20. #include <boost/spirit/include/classic_push_back_actor.hpp>
  21. #include <boost/spirit/include/classic_lists.hpp>
  22. template<typename ContainerT>
  23. void push_back_test()
  24. {
  25. using namespace BOOST_SPIRIT_CLASSIC_NS;
  26. const char* cp = "one,two,three";
  27. const char* cp_first = cp;
  28. const char* cp_last = cp + test_impl::string_length(cp);
  29. const char* cp_i[] = {"one","two","three"};
  30. int i;
  31. ContainerT c;
  32. typename ContainerT::const_iterator it;
  33. scanner<char const*> scan( cp_first, cp_last );
  34. match<> hit;
  35. hit = list_p( (*alpha_p)[ push_back_a(c)] , ch_p(',') ).parse(scan);
  36. BOOST_CHECK(hit);
  37. BOOST_CHECK_EQUAL(scan.first, scan.last);
  38. BOOST_CHECK_EQUAL( c.size(), static_cast<typename ContainerT::size_type>(3));
  39. for (i=0, it = c.begin();i<3 && it != c.end();++i, ++it)
  40. BOOST_CHECK_EQUAL( cp_i[i], *it);
  41. scan.first = cp;
  42. }
  43. void push_back_action_test()
  44. {
  45. push_back_test< std::deque<std::string> >();
  46. push_back_test< std::vector<std::string> >();
  47. }