1 // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010.
2 // Distributed under the Boost Software License, Version 1.0.
3 //    (See accompanying file LICENSE_1_0.txt or copy at
4 //          http://www.boost.org/LICENSE_1_0.txt)
5 
6 #include <boost/metaparse/spaces.hpp>
7 #include <boost/metaparse/is_error.hpp>
8 #include <boost/metaparse/start.hpp>
9 #include <boost/metaparse/get_remaining.hpp>
10 
11 #include "common.hpp"
12 
13 #include <boost/mpl/equal_to.hpp>
14 #include <boost/mpl/apply_wrap.hpp>
15 #include <boost/mpl/not.hpp>
16 #include <boost/mpl/equal.hpp>
17 #include <boost/mpl/assert.hpp>
18 
19 #include "test_case.hpp"
20 
21 namespace
22 {
23   using boost::mpl::list_c;
24 
25   typedef list_c<char, 'e', 'l', 'l', 'o'> str_ello;
26   typedef
27     list_c<char, ' ', '\t', '\n', '\r', 'e', 'l', 'l', 'o'>
28     str_____ello;
29 
30 }
31 
BOOST_METAPARSE_TEST_CASE(spaces)32 BOOST_METAPARSE_TEST_CASE(spaces)
33 {
34   using boost::metaparse::is_error;
35   using boost::metaparse::spaces;
36   using boost::metaparse::start;
37   using boost::metaparse::get_remaining;
38 
39   using boost::mpl::apply_wrap2;
40   using boost::mpl::not_;
41   using boost::mpl::equal;
42 
43   // test_reject_no_space
44   BOOST_MPL_ASSERT((
45     is_error<apply_wrap2<spaces, str_hello, start> >
46   ));
47 
48   // test_accept_one_space
49   BOOST_MPL_ASSERT((
50     not_<is_error<apply_wrap2<spaces, str__ello, start> > >
51   ));
52 
53   // test_accept_only_space
54   BOOST_MPL_ASSERT((
55     equal<get_remaining<apply_wrap2<spaces, str__ello, start> >::type, str_ello>
56   ));
57 
58   // test_accept_all_spaces
59   BOOST_MPL_ASSERT((not_<is_error<apply_wrap2<spaces, str_____ello,start> > >));
60 
61   // test_consume_all_spaces
62   BOOST_MPL_ASSERT((
63     equal<
64       get_remaining<apply_wrap2<spaces, str_____ello, start> >::type,
65       str_ello
66     >
67   ));
68 }
69 
70 
71