erase_at_test.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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, pop_front_actor
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #include "action_tests.hpp"
  12. #include <boost/spirit/include/classic_core.hpp>
  13. #include <boost/spirit/include/classic_erase_actor.hpp>
  14. #include <map>
  15. void erase_action_test()
  16. {
  17. using namespace BOOST_SPIRIT_CLASSIC_NS;
  18. const char* cp = "one,two,three";
  19. const char* cp_first = cp;
  20. const char* cp_last = cp + test_impl::string_length(cp);
  21. const char* cp_i[] = {"one","two","three"};
  22. typedef std::map<std::string, int> map_string_type;
  23. map_string_type c;
  24. map_string_type::const_iterator it_find;
  25. scanner<char const*> scan(cp_first, cp_last);
  26. match<> hit;
  27. c["one"]=1;
  28. c["two"]=2;
  29. c["three"]=3;
  30. c["four"]=4;
  31. hit = (*((+alpha_p)[ erase_a(c) ] >> !ch_p(','))).parse(scan);
  32. BOOST_CHECK(hit);
  33. BOOST_CHECK_EQUAL(scan.first, scan.last);
  34. BOOST_CHECK_EQUAL( c.size(), static_cast<map_string_type::size_type>(1));
  35. for (int i=0;i<3;++i)
  36. {
  37. it_find = c.find(cp_i[i]);
  38. BOOST_CHECK( it_find == c.end() );
  39. }
  40. scan.first = cp;
  41. }