]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/classic/test/if_p_int_as_condition_test.cpp
1 /*=============================================================================
2 Copyright (c) 2004 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 =============================================================================*/
9 #include <boost/spirit/include/classic_core.hpp>
10 #include <boost/spirit/include/classic_dynamic.hpp>
11 #include <boost/spirit/include/classic_ast.hpp>
13 #include <boost/detail/lightweight_test.hpp>
15 using namespace BOOST_SPIRIT_CLASSIC_NS
;
16 int the_var_to_be_tested
= 0;
21 struct var_wrapper
: public ::boost::reference_wrapper
<T
>
23 typedef ::boost::reference_wrapper
<T
> parent
;
25 explicit inline var_wrapper(T
& t
) : parent(t
) {}
27 inline T
& operator()() const { return parent::get(); }
34 return var_wrapper
<T
>(t
);
38 struct test_grammar
: public grammar
<test_grammar
>
40 template <typename ScannerT
>
44 rule
<ScannerT
, parser_tag
<0> > test
;
46 definition(const test_grammar
& self
)
49 = if_p(local::var(the_var_to_be_tested
))
55 const rule
<ScannerT
, parser_tag
<0> >& start() const {return test
;}
62 tree_parse_info
<const char*> result
;
65 the_var_to_be_tested
= 0;
66 result
= ast_parse("1.50", gram
, space_p
);
67 std::cout
<< "Testing if_p against: " << the_var_to_be_tested
<< std::endl
;
68 std::cout
<< "success: " << result
.full
<< std::endl
;
69 BOOST_TEST(!result
.full
);
71 //predicatably succeeds
72 the_var_to_be_tested
= 1;
73 result
= ast_parse("1.50", gram
, space_p
);
74 std::cout
<< "Testing if_p against: " << the_var_to_be_tested
<< std::endl
;
75 std::cout
<< "success: " << result
.full
<< std::endl
;
76 BOOST_TEST(result
.full
);
79 the_var_to_be_tested
= 2;
80 result
= ast_parse("1.50", gram
, space_p
);
81 std::cout
<< "Testing if_p against: " << the_var_to_be_tested
<< std::endl
;
82 std::cout
<< "success: " << result
.full
<< std::endl
;
83 BOOST_TEST(result
.full
);
85 return boost::report_errors();