summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/metaparse/test/one_of.cpp
blob: b7890f00da56a331924a16eb778f07af5da667be (plain)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// 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/one_of.hpp>
#include <boost/metaparse/one_char.hpp>
#include <boost/metaparse/fail.hpp>
#include <boost/metaparse/is_error.hpp>
#include <boost/metaparse/start.hpp>
#include <boost/metaparse/get_result.hpp>
#include <boost/metaparse/sequence.hpp>
#include <boost/metaparse/get_position.hpp>
#include <boost/metaparse/next_char.hpp>

#include "common.hpp"

#include <boost/mpl/equal_to.hpp>
#include <boost/mpl/apply_wrap.hpp>
#include <boost/mpl/assert.hpp>

#include "test_case.hpp"

BOOST_METAPARSE_TEST_CASE(one_of)
{
  using boost::metaparse::is_error;
  using boost::metaparse::one_of;
  using boost::metaparse::start;
  using boost::metaparse::get_result;
  using boost::metaparse::one_char;
  using boost::metaparse::fail;
  using boost::metaparse::sequence;
  using boost::metaparse::get_position;
  using boost::metaparse::next_char;
  
  using boost::mpl::apply_wrap2;
  using boost::mpl::equal_to;
  
  typedef fail<test_failure> test_fail;
  typedef sequence<one_char, test_fail> test_fail_later;

  // test_1_with_good
  BOOST_MPL_ASSERT((
    equal_to<
      get_result<apply_wrap2<one_of<one_char>, str_hello, start> >::type,
      char_h
    >
  ));

  // test_1_with_bad
  BOOST_MPL_ASSERT((
    is_error<apply_wrap2<one_of<test_fail>, str_hello, start> >
  ));

  // test_2_with_two_good
  BOOST_MPL_ASSERT((
    equal_to<
      get_result<
        apply_wrap2<one_of<one_char, one_char>, str_hello, start>
      >::type,
      char_h
    >
  ));

  // test_2_with_first_good
  BOOST_MPL_ASSERT((
    equal_to<
      get_result<
        apply_wrap2<one_of<one_char, test_fail>, str_hello, start>
      >::type,
      char_h
    >
  ));

  // test_2_with_second_good
  BOOST_MPL_ASSERT((
    equal_to<
      get_result<
        apply_wrap2<one_of<test_fail, one_char>, str_hello, start>
      >::type,
      char_h
    >
  ));

  // test_2_with_two_bad
  BOOST_MPL_ASSERT((
    is_error<apply_wrap2<one_of<test_fail, test_fail>, str_hello, start> >
  ));





  // test
  BOOST_MPL_ASSERT((is_error<apply_wrap2<one_of< >, str_hello, start> >));
  
  // test_with_good
  BOOST_MPL_ASSERT((
    equal_to<
      get_result<apply_wrap2<one_of<one_char>, str_hello, start> >::type,
      char_h
    >
  ));
  
  // test_with_bad
  BOOST_MPL_ASSERT((is_error<apply_wrap2<one_of<test_fail>,str_hello,start> >));

  // test_with_two_good
  BOOST_MPL_ASSERT((
    equal_to<
      get_result<
        apply_wrap2<one_of<one_char, one_char>, str_hello, start>
      >::type,
      char_h
    >
  ));
    
  // test_with_first_good
  BOOST_MPL_ASSERT((
    equal_to<
      get_result<
        apply_wrap2<one_of<one_char, test_fail>, str_hello, start>
      >::type,
      char_h
    >
  ));

  // test_with_second_good
  BOOST_MPL_ASSERT((
    equal_to<
      get_result<
        apply_wrap2<one_of<test_fail, one_char>, str_hello, start>
      >::type,
      char_h
    >
  ));

  // test_with_two_bad
  BOOST_MPL_ASSERT((
    is_error<apply_wrap2<one_of<test_fail, test_fail>, str_hello, start> >
  ));

  // test_error_is_the_last_error
  BOOST_MPL_ASSERT((
    equal_to<
      next_char<start, char_h>::type,
      get_position<
        apply_wrap2<
          one_of<test_fail, test_fail_later>,
          str_hello,
          start
        >
      >::type
    >
  ));
}