]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/qi/symbols1.cpp
1 /*=============================================================================
2 Copyright (c) 2001-2010 Joel de Guzman
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 =============================================================================*/
7 #include <boost/detail/lightweight_test.hpp>
8 #include <boost/spirit/include/qi_string.hpp>
9 #include <boost/spirit/include/qi_char.hpp>
10 #include <boost/spirit/include/qi_action.hpp>
11 #include <boost/spirit/include/qi_auxiliary.hpp>
12 #include <boost/spirit/include/qi_directive.hpp>
13 #include <boost/spirit/include/qi_operator.hpp>
14 #include <boost/spirit/include/qi_nonterminal.hpp>
15 #include <boost/spirit/include/support_argument.hpp>
16 #include <boost/spirit/include/phoenix_core.hpp>
17 #include <boost/spirit/include/phoenix_operator.hpp>
22 // Custom string type with a C-style string conversion.
23 struct custom_string_c
25 custom_string_c(char c
) { str
[0] = c
; str
[1] = '\0'; }
27 operator char*() { return str
; }
28 operator char const*() const { return str
; }
37 using spirit_test::test
;
38 using spirit_test::test_attr
;
39 using boost::spirit::qi::symbols
;
40 using boost::spirit::qi::rule
;
41 using boost::spirit::qi::lazy
;
42 using boost::spirit::qi::_r1
;
45 symbols
<char, int> sym
;
57 boost::mpl::true_ f
= boost::mpl::bool_
<boost::spirit::traits::is_parser
<symbols
<char, int> >::value
>();
59 // silence stupid compiler warnings
60 // i.e. MSVC warning C4189: 'f' : local variable is initialized but not referenced
61 BOOST_TEST((f
.value
));
63 BOOST_TEST((test("Joel", sym
)));
64 BOOST_TEST((test("Ruby", sym
)));
65 BOOST_TEST((test("Tenji", sym
)));
66 BOOST_TEST((test("Tutit", sym
)));
67 BOOST_TEST((test("Kim", sym
)));
68 BOOST_TEST((test("Joey", sym
)));
69 BOOST_TEST((test("Joeyboy", sym
)));
70 BOOST_TEST((!test("XXX", sym
)));
73 symbols
<char, int> sym2
;
75 BOOST_TEST((test("Joel", sym2
)));
76 BOOST_TEST((test("Ruby", sym2
)));
77 BOOST_TEST((test("Tenji", sym2
)));
78 BOOST_TEST((test("Tutit", sym2
)));
79 BOOST_TEST((test("Kim", sym2
)));
80 BOOST_TEST((test("Joey", sym2
)));
81 BOOST_TEST((!test("XXX", sym2
)));
83 // make sure it plays well with other parsers
84 BOOST_TEST((test("Joelyo", sym
>> "yo")));
91 BOOST_TEST((!test("Joel", sym
)));
92 BOOST_TEST((!test("Ruby", sym
)));
96 symbols
<char, int> sym
;
97 sym
+= "Joel", "Ruby", "Tenji", "Tutit", "Kim", "Joey";
99 BOOST_TEST((test("Joel", sym
)));
100 BOOST_TEST((test("Ruby", sym
)));
101 BOOST_TEST((test("Tenji", sym
)));
102 BOOST_TEST((test("Tutit", sym
)));
103 BOOST_TEST((test("Kim", sym
)));
104 BOOST_TEST((test("Joey", sym
)));
105 BOOST_TEST((!test("XXX", sym
)));
107 sym
-= "Joel", "Ruby";
109 BOOST_TEST((!test("Joel", sym
)));
110 BOOST_TEST((!test("Ruby", sym
)));
113 { // no-case handling
114 using namespace boost::spirit::ascii
;
116 symbols
<char, int> sym
;
117 // NOTE: make sure all entries are in lower-case!!!
118 sym
= "joel", "ruby", "tenji", "tutit", "kim", "joey";
120 BOOST_TEST((test("joel", no_case
[sym
])));
121 BOOST_TEST((test("ruby", no_case
[sym
])));
122 BOOST_TEST((test("tenji", no_case
[sym
])));
123 BOOST_TEST((test("tutit", no_case
[sym
])));
124 BOOST_TEST((test("kim", no_case
[sym
])));
125 BOOST_TEST((test("joey", no_case
[sym
])));
127 BOOST_TEST((test("JOEL", no_case
[sym
])));
128 BOOST_TEST((test("RUBY", no_case
[sym
])));
129 BOOST_TEST((test("TENJI", no_case
[sym
])));
130 BOOST_TEST((test("TUTIT", no_case
[sym
])));
131 BOOST_TEST((test("KIM", no_case
[sym
])));
132 BOOST_TEST((test("JOEY", no_case
[sym
])));
134 // make sure it plays well with other parsers
135 BOOST_TEST((test("Joelyo", no_case
[sym
] >> "yo")));
139 symbols
<char, int> sym
;
152 BOOST_TEST((test_attr("Joel", sym
, i
)));
154 BOOST_TEST((test_attr("Ruby", sym
, i
)));
156 BOOST_TEST((test_attr("Tenji", sym
, i
)));
158 BOOST_TEST((test_attr("Tutit", sym
, i
)));
160 BOOST_TEST((test_attr("Kim", sym
, i
)));
162 BOOST_TEST((test_attr("Joey", sym
, i
)));
164 BOOST_TEST((test_attr("Joeyboy", sym
, i
)));
166 BOOST_TEST((!test_attr("XXX", sym
, i
)));
170 sym
.add("Joel", 265);
171 BOOST_TEST((test_attr("Joel", sym
, i
)));
176 namespace phx
= boost::phoenix
;
177 using boost::spirit::_1
;
179 symbols
<char, int> sym
;
190 BOOST_TEST((test("Joel", sym
[phx::ref(i
) = _1
])));
192 BOOST_TEST((test("Ruby", sym
[phx::ref(i
) = _1
])));
194 BOOST_TEST((test("Tenji", sym
[phx::ref(i
) = _1
])));
196 BOOST_TEST((test("Tutit", sym
[phx::ref(i
) = _1
])));
198 BOOST_TEST((test("Kim", sym
[phx::ref(i
) = _1
])));
200 BOOST_TEST((test("Joey", sym
[phx::ref(i
) = _1
])));
202 BOOST_TEST((!test("XXX", sym
[phx::ref(i
) = _1
])));
205 return boost::report_errors();