]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/classic/test/for_tests.cpp
1 /*=============================================================================
2 Copyright (c) 2003 Martin Wille
3 http://spirit.sourceforge.net/
5 Use, modification and distribution is subject to the Boost Software
6 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 http://www.boost.org/LICENSE_1_0.txt)
8 =============================================================================*/
10 // Tests for spirit::for_p
12 ////////////////////////////////////////////////////////////////////////////////
16 #include <boost/spirit/include/classic_core.hpp>
17 #include <boost/spirit/include/classic_assign_actor.hpp>
18 #include <boost/spirit/include/classic_for.hpp>
19 #include <boost/ref.hpp>
20 #include "impl/string_length.hpp"
26 : public ::boost::reference_wrapper
<T
>
28 typedef ::boost::reference_wrapper
<T
> parent
;
30 explicit inline var_wrapper(T
& t
) : parent(t
) {}
32 inline T
& operator()() const { return parent::get(); }
39 return var_wrapper
<T
>(t
);
49 explicit add_actor(T
&ref_
) : ref(ref_
) {}
51 template <typename T2
>
52 void operator()(T2
const &val
) const
60 inline add_actor
<T
> const
63 return add_actor
<T
>(ref
);
67 typedef ::BOOST_SPIRIT_CLASSIC_NS::rule
<> rule_t
;
69 unsigned int test_count
= 0;
70 unsigned int error_count
= 0;
72 unsigned int iterations_performed
;
73 unsigned int iterations_desired
;
74 std::string input_matched
;
76 //static const unsigned int kError = 999;
77 static const bool good
= true;
78 static const bool bad
= false;
89 unsigned int iterations_expected
96 iterations_performed
= 0;
98 ::BOOST_SPIRIT_CLASSIC_NS::parse_info
<> m
= ::BOOST_SPIRIT_CLASSIC_NS::parse(s
, s
+ test_impl::string_length(s
), r
);
100 bool result
= (succeed
==m
.full
)?good
:bad
;
102 if (m
.full
&& (m
.length
!= test_impl::string_length(s
)))
105 result
&= iterations_expected
== iterations_performed
;
115 cout
<< ": \"" << s
<< "\" ==> ";
119 cout
<< '"' << input_matched
<< '"';
121 cout
<< " " << iterations_performed
<< " of "
122 << iterations_desired
<< " iterations\n";
127 void zero() { iterations_performed
= 0; }
131 inline void operator()() const { ++iterations_performed
; }
135 inline bool operator()() const
137 return iterations_performed
<iterations_desired
;
147 using BOOST_SPIRIT_CLASSIC_NS::uint_p
;
148 using BOOST_SPIRIT_CLASSIC_NS::for_p
;
149 using BOOST_SPIRIT_CLASSIC_NS::assign_a
;
152 SPIRIT_DEBUG_RULE(for_rule
);
153 SPIRIT_DEBUG_RULE(for_rule2
);
157 = uint_p
[assign_a(iterations_desired
)] >> ':'
158 >> for_p(&zero
, cmp(), inc())["xy"]
159 [assign_a(input_matched
)]
163 = for_p(&zero
, '.', inc())["xy"]
164 [assign_a(input_matched
)]
167 cout
<< "/////////////////////////////////////////////////////////\n";
169 cout
<< " for_p test\n";
171 cout
<< "/////////////////////////////////////////////////////////\n";
174 test_for("3:xyxyxy", true, for_rule
, 3);
175 test_for("3:", false, for_rule
, 0);
176 test_for("3:xyxy", false, for_rule
, 2);
177 test_for("3:xyxyxyxy", false, for_rule
, 3);
179 test_for(".xy.xy.xy", true, for_rule2
, 3);
180 test_for(".xy.xy.xy.", false, for_rule2
, 3);
184 cout
<< "All " << test_count
<< " for_p-tests passed.\n"
185 << "Test concluded successfully\n";
187 cout
<< error_count
<< " of " << test_count
<< " for_p-tests failed\n"
190 return error_count
!=0;