tokenized.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Boost.Range library
  2. //
  3. // Copyright Neil Groves 2009. Use, modification and
  4. // distribution is subject to the Boost Software License, Version
  5. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. //
  9. // For more information, see http://www.boost.org/libs/range/
  10. //
  11. #include <boost/range/adaptor/tokenized.hpp>
  12. #include <boost/test/test_tools.hpp>
  13. #include <boost/test/unit_test.hpp>
  14. #include <boost/range/algorithm_ext/push_back.hpp>
  15. #include <algorithm>
  16. #include <string>
  17. #include <vector>
  18. namespace boost
  19. {
  20. namespace
  21. {
  22. template< class Iterator, class Container >
  23. void tokenized_test_impl( Container& c, std::size_t expected_result )
  24. {
  25. using namespace boost::adaptors;
  26. std::vector< boost::sub_match< Iterator > > test_result1;
  27. boost::push_back(test_result1, c | tokenized(boost::regex("\\b")));
  28. BOOST_CHECK_EQUAL( test_result1.size(), expected_result );
  29. // std::vector< boost::sub_match< Iterator > > test_result2;
  30. // boost::push_back(test_result2, adaptors::tokenize(c, boost::regex("\\b")));
  31. // BOOST_CHECK_EQUAL( test_result2.size(), expected_result );
  32. }
  33. template< class Container1, class Container2 >
  34. void tokenized_test_impl()
  35. {
  36. Container1 c;
  37. Container2& r = c;
  38. typedef typename boost::range_iterator<Container2>::type It;
  39. // Test empty
  40. tokenized_test_impl<It, Container2>(r, 0u);
  41. // Test one element
  42. c = "a";
  43. tokenized_test_impl<It, Container2>(r, 2u);
  44. // Test many elements
  45. c = "a b c d e f g hijlmnopqrstuvwxyz";
  46. tokenized_test_impl<It, Container2>(r, 16u);
  47. }
  48. void tokenized_test()
  49. {
  50. // tokenized_test_impl<std::string, const std::string>();
  51. tokenized_test_impl<std::string, std::string>();
  52. }
  53. }
  54. }
  55. boost::unit_test::test_suite*
  56. init_unit_test_suite(int argc, char* argv[])
  57. {
  58. boost::unit_test::test_suite* test
  59. = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.tokenized" );
  60. test->add( BOOST_TEST_CASE( &boost::tokenized_test ) );
  61. return test;
  62. }