• 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/transform.hpp>
7 #include <boost/metaparse/is_error.hpp>
8 #include <boost/metaparse/start.hpp>
9 #include <boost/metaparse/get_result.hpp>
10 #include <boost/metaparse/repeated.hpp>
11 #include <boost/metaparse/one_char.hpp>
12 
13 #include "common.hpp"
14 
15 #include <boost/mpl/equal_to.hpp>
16 #include <boost/mpl/always.hpp>
17 #include <boost/mpl/apply_wrap.hpp>
18 #include <boost/mpl/front.hpp>
19 #include <boost/mpl/assert.hpp>
20 
21 #include "test_case.hpp"
22 
23 namespace
24 {
25   using boost::metaparse::repeated;
26   using boost::metaparse::one_char;
27 
28   using boost::mpl::always;
29 
30   typedef always<char_x> f;
31   typedef repeated<one_char> repeated_one_char;
32 
33   struct get_front
34   {
35     typedef get_front type;
36 
37     template <class C>
38     struct apply : boost::mpl::front<C> {};
39   };
40 }
41 
BOOST_METAPARSE_TEST_CASE(transform)42 BOOST_METAPARSE_TEST_CASE(transform)
43 {
44   using boost::metaparse::get_result;
45   using boost::metaparse::transform;
46   using boost::metaparse::start;
47   using boost::metaparse::is_error;
48 
49   using boost::mpl::equal_to;
50   using boost::mpl::apply_wrap2;
51 
52   // test_normal_case
53   BOOST_MPL_ASSERT((
54     equal_to<
55       get_result<apply_wrap2<transform<lit_h, f>, str_hello, start> >::type,
56       char_x
57     >
58   ));
59 
60   // test_parser_fails
61   BOOST_MPL_ASSERT((
62     is_error<apply_wrap2<transform<lit_x, f>, str_hello, start> >
63   ));
64 
65   // test_empty_input
66   BOOST_MPL_ASSERT((is_error<apply_wrap2<transform<lit_h, f>, str_, start> >));
67 
68   // test_tranformation_functions_arg
69   BOOST_MPL_ASSERT((
70     equal_to<
71       get_result<
72         apply_wrap2<transform<repeated_one_char, get_front>, str_hello, start>
73       >::type,
74       char_h
75     >
76   ));
77 }
78 
79 
80