• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright Abel Sinkovics (abel@sinkovics.hu) 2015.
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/optional.hpp>
7 #include <boost/metaparse/string.hpp>
8 #include <boost/metaparse/lit_c.hpp>
9 #include <boost/metaparse/get_result.hpp>
10 #include <boost/metaparse/start.hpp>
11 
12 #include <boost/mpl/assert.hpp>
13 #include <boost/mpl/equal_to.hpp>
14 #include <boost/mpl/char.hpp>
15 
16 #include <boost/type_traits/is_same.hpp>
17 
18 #include "test_case.hpp"
19 
BOOST_METAPARSE_TEST_CASE(optional)20 BOOST_METAPARSE_TEST_CASE(optional)
21 {
22   using boost::metaparse::optional;
23   using boost::metaparse::lit_c;
24   using boost::metaparse::string;
25   using boost::metaparse::get_result;
26   using boost::metaparse::start;
27 
28   using boost::mpl::equal_to;
29 
30   using boost::is_same;
31 
32   typedef optional<lit_c<'x'>, double> optional_x;
33 
34   // test_optional_parser_succeeds
35   BOOST_MPL_ASSERT((
36     equal_to<
37       boost::mpl::char_<'x'>,
38       get_result<optional_x::apply<string<'x'>, start> >::type
39     >
40   ));
41 
42   // test_optional_parser_fails
43   BOOST_MPL_ASSERT((
44     is_same<double, get_result<optional_x::apply<string<'y'>, start> >::type>
45   ));
46 
47   // test_optional_parser_default_value
48   BOOST_MPL_ASSERT((
49     is_same<
50       void,
51       get_result<optional<lit_c<'x'> >::apply<string<'y'>, start> >::type
52     >
53   ));
54 }
55 
56