Blame view

3rdparty/boost_1_81_0/libs/metaparse/test/sequence.cpp 2.77 KB
73ef4ff3   Hu Chunming   提交三方库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
  // Copyright Abel Sinkovics (abel@sinkovics.hu) 2010.
  // Distributed under the Boost Software License, Version 1.0.
  //    (See accompanying file LICENSE_1_0.txt or copy at
  //          http://www.boost.org/LICENSE_1_0.txt)
  
  #include <boost/metaparse/sequence.hpp>
  #include <boost/metaparse/is_error.hpp>
  #include <boost/metaparse/start.hpp>
  #include <boost/metaparse/get_result.hpp>
  #include <boost/metaparse/always.hpp>
  #include <boost/metaparse/one_char.hpp>
  
  #include "common.hpp"
  
  #include <boost/mpl/equal_to.hpp>
  #include <boost/mpl/apply_wrap.hpp>
  #include <boost/mpl/list.hpp>
  #include <boost/mpl/at.hpp>
  #include <boost/mpl/equal.hpp>
  #include <boost/mpl/vector_c.hpp>
  #include <boost/mpl/vector.hpp>
  #include <boost/mpl/assert.hpp>
  
  #include "test_case.hpp"
  
  BOOST_METAPARSE_TEST_CASE(sequence)
  {
    using boost::metaparse::get_result;
    using boost::metaparse::sequence;
    using boost::metaparse::start;
    using boost::metaparse::is_error;
    using boost::metaparse::always;
    using boost::metaparse::one_char;
    
    using boost::mpl::equal;
    using boost::mpl::apply_wrap2;
    using boost::mpl::list;
    using boost::mpl::equal_to;
    using boost::mpl::at_c;
    using boost::mpl::vector_c;
    using boost::mpl::vector;
  
    typedef always<one_char, int> always_int;
  
    // test_no_parser
    BOOST_MPL_ASSERT((
      equal<get_result<apply_wrap2<sequence<>, str_hello, start> >::type, list<> >
    ));
  
    // test_one_parser
    BOOST_MPL_ASSERT((
      equal<
        get_result<apply_wrap2<sequence<lit_h>, str_hello, start> >::type,
        vector_c<char, 'h'>
      >
    ));
  
    // test_one_failing_parser
    BOOST_MPL_ASSERT((is_error<apply_wrap2<sequence<lit_e>, str_hello, start> >));
    
    // test_two_chars
    BOOST_MPL_ASSERT((
      equal<
        get_result<apply_wrap2<sequence<lit_h, lit_e>, str_hello, start> >::type,
        vector_c<char, 'h', 'e'>
      >
    ));
  
    // test_first_fails
    BOOST_MPL_ASSERT((
      is_error<apply_wrap2<sequence<lit_x, lit_e>, str_hello, start> >
    ));
  
    // test_second_fails
    BOOST_MPL_ASSERT((
      is_error<apply_wrap2<sequence<lit_h, lit_x>, str_hello, start> >
    ));
  
    // test_empty_input
    BOOST_MPL_ASSERT((is_error<apply_wrap2<sequence<lit_h,lit_e>, str_,start> >));
  
    // test_three_chars
    BOOST_MPL_ASSERT((
      equal<
        get_result<
          apply_wrap2<sequence<lit_h, lit_e, lit_l>, str_hello, start>
        >::type,
        vector_c<char, 'h', 'e', 'l'>
      >
    ));
  
    // test_indexing_in_result
    BOOST_MPL_ASSERT((
      equal_to<
        at_c<
          get_result<
            apply_wrap2<sequence<lit_h, lit_e, lit_l>, str_hello, start>
          >::type,
          1
        >::type,
        char_e
      >
    ));
  
    // test_no_extra_evaluation
    BOOST_MPL_ASSERT((
      equal<
        get_result<
          apply_wrap2<sequence<always_int, always_int>, str_ca, start>
        >::type,
        vector<int, int>
      >
    ));
  }