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
13 #include <boost/test/test_tools.hpp>
14 #include <boost/test/unit_test.hpp>
15
16 #include <boost/range/algorithm_ext/push_back.hpp>
17
18 #include <algorithm>
19 #include <string>
20 #include <vector>
21
22 namespace boost
23 {
24 namespace
25 {
26 template< class Iterator, class Container >
tokenized_test_impl(Container & c,std::size_t expected_result)27 void tokenized_test_impl( Container& c, std::size_t expected_result )
28 {
29 using namespace boost::adaptors;
30
31 std::vector< boost::sub_match< Iterator > > test_result1;
32 boost::push_back(test_result1, c | tokenized(boost::regex("\\b")));
33
34 BOOST_CHECK_EQUAL( test_result1.size(), expected_result );
35
36 // std::vector< boost::sub_match< Iterator > > test_result2;
37 // boost::push_back(test_result2, adaptors::tokenize(c, boost::regex("\\b")));
38
39 // BOOST_CHECK_EQUAL( test_result2.size(), expected_result );
40 }
41
42 template< class Container1, class Container2 >
tokenized_test_impl()43 void tokenized_test_impl()
44 {
45 Container1 c;
46 Container2& r = c;
47
48 typedef typename boost::range_iterator<Container2>::type It;
49
50 // Test empty
51 tokenized_test_impl<It, Container2>(r, 0u);
52
53 // Test one element
54 c = "a";
55 tokenized_test_impl<It, Container2>(r, 2u);
56
57 // Test many elements
58 c = "a b c d e f g hijlmnopqrstuvwxyz";
59 tokenized_test_impl<It, Container2>(r, 16u);
60 }
61
tokenized_test()62 void tokenized_test()
63 {
64 // tokenized_test_impl<std::string, const std::string>();
65 tokenized_test_impl<std::string, std::string>();
66 }
67 }
68 }
69
70 boost::unit_test::test_suite*
init_unit_test_suite(int argc,char * argv[])71 init_unit_test_suite(int argc, char* argv[])
72 {
73 boost::unit_test::test_suite* test
74 = BOOST_TEST_SUITE( "RangeTestSuite.adaptor.tokenized" );
75
76 test->add( BOOST_TEST_CASE( &boost::tokenized_test ) );
77
78 return test;
79 }
80