]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/spirit/classic/test/if_p_int_as_condition_test.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / spirit / classic / test / if_p_int_as_condition_test.cpp
CommitLineData
7c673cae
FG
1/*=============================================================================
2 Copyright (c) 2004 Martin Wille
3 http://spirit.sourceforge.net/
4
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>
1e59de90
TL
12
13#include <boost/core/lightweight_test.hpp>
7c673cae 14#include <iostream>
7c673cae
FG
15
16using namespace BOOST_SPIRIT_CLASSIC_NS;
17int the_var_to_be_tested = 0;
18
19namespace local
20{
21 template <typename T>
22 struct var_wrapper : public ::boost::reference_wrapper<T>
23 {
24 typedef ::boost::reference_wrapper<T> parent;
25
26 explicit inline var_wrapper(T& t) : parent(t) {}
27
28 inline T& operator()() const { return parent::get(); }
29 };
30
31 template <typename T>
32 inline var_wrapper<T>
33 var(T& t)
34 {
35 return var_wrapper<T>(t);
36 }
37}
38
39struct test_grammar : public grammar <test_grammar>
40{
41 template <typename ScannerT>
42
43 struct definition
44 {
45 rule <ScannerT, parser_tag <0> > test;
46
11fdf7f2 47 definition(const test_grammar& /*self*/)
7c673cae
FG
48 {
49 test
50 = if_p(local::var(the_var_to_be_tested))
51 [
52 real_p
53 ];
54
55 }
56 const rule <ScannerT, parser_tag<0> >& start() const {return test;}
57 };
58};
59
60int main()
61{
62 test_grammar gram;
63 tree_parse_info <const char*> result;
64
65 //predictably fails
66 the_var_to_be_tested = 0;
67 result = ast_parse("1.50", gram, space_p);
68 std::cout << "Testing if_p against: " << the_var_to_be_tested << std::endl;
69 std::cout << "success: " << result.full << std::endl;
70 BOOST_TEST(!result.full);
71
72 //predicatably succeeds
73 the_var_to_be_tested = 1;
74 result = ast_parse("1.50", gram, space_p);
75 std::cout << "Testing if_p against: " << the_var_to_be_tested << std::endl;
76 std::cout << "success: " << result.full << std::endl;
77 BOOST_TEST(result.full);
78
79 //should succeed
80 the_var_to_be_tested = 2;
81 result = ast_parse("1.50", gram, space_p);
82 std::cout << "Testing if_p against: " << the_var_to_be_tested << std::endl;
83 std::cout << "success: " << result.full << std::endl;
84 BOOST_TEST(result.full);
85
86 return boost::report_errors();
87}
88