• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/token.hpp>
7 #include <boost/metaparse/keyword.hpp>
8 #include <boost/metaparse/is_error.hpp>
9 #include <boost/metaparse/start.hpp>
10 #include <boost/metaparse/get_result.hpp>
11 #include <boost/metaparse/get_remaining.hpp>
12 
13 #include "common.hpp"
14 
15 #include <boost/mpl/equal_to.hpp>
16 #include <boost/mpl/apply.hpp>
17 #include <boost/mpl/equal.hpp>
18 #include <boost/mpl/assert.hpp>
19 
20 #include "test_case.hpp"
21 
22 namespace
23 {
24   using boost::metaparse::keyword;
25   using boost::metaparse::token;
26 
27   using boost::mpl::list_c;
28 
29   typedef list_c<char, 'h', 'e', 'l', 'l', 'o', ' ', '\t'> str_hello_t;
30 
31   typedef keyword<str_hello, int13> test_parser;
32   typedef token<test_parser> a_test_token;
33 }
34 
BOOST_METAPARSE_TEST_CASE(token)35 BOOST_METAPARSE_TEST_CASE(token)
36 {
37   using boost::metaparse::get_result;
38   using boost::metaparse::start;
39   using boost::metaparse::get_remaining;
40   using boost::metaparse::is_error;
41 
42   using boost::mpl::equal_to;
43   using boost::mpl::apply_wrap2;
44   using boost::mpl::equal;
45 
46   // test_no_space
47   BOOST_MPL_ASSERT((
48     equal_to<
49       get_result<apply_wrap2<a_test_token, str_hello, start> >::type,
50       get_result<apply_wrap2<test_parser, str_hello, start> >::type
51     >
52   ));
53 
54   // test_spaces
55   BOOST_MPL_ASSERT((
56     equal_to<
57       get_result<apply_wrap2<a_test_token, str_hello_t, start> >::type,
58       get_result<apply_wrap2<test_parser, str_hello, start> >::type
59     >
60   ));
61 
62   // test_spaces_consumed
63   BOOST_MPL_ASSERT((
64     equal<
65       get_remaining<apply_wrap2<a_test_token, str_hello_t, start> >::type,
66       str_
67     >
68   ));
69 
70   // test_fail
71   BOOST_MPL_ASSERT((is_error<apply_wrap2<a_test_token, str_, start> >));
72 }
73 
74 
75