]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/classic/test/operators_tests.cpp
1 /*=============================================================================
2 Copyright (c) 1998-2003 Joel de Guzman
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 #include <boost/detail/lightweight_test.hpp>
14 #include <boost/spirit/include/classic_core.hpp>
15 using namespace BOOST_SPIRIT_CLASSIC_NS
;
17 ///////////////////////////////////////////////////////////////////////////////
21 ///////////////////////////////////////////////////////////////////////////////
25 parse_info
<char const*> pi
;
27 pi
= parse("Hello World", str_p("Hello ") >> "World");
30 BOOST_TEST(pi
.length
== 11);
31 BOOST_TEST(*pi
.stop
== 0);
33 pi
= parse("Banana", str_p("Banana") | "Pineapple");
36 BOOST_TEST(pi
.length
== 6);
37 BOOST_TEST(*pi
.stop
== 0);
39 pi
= parse("Pineapple", str_p("Banana") | "Pineapple");
42 BOOST_TEST(pi
.length
== 9);
43 BOOST_TEST(*pi
.stop
== 0);
45 pi
= parse("a.2 ", alpha_p
|| ('.' >> digit_p
));
47 BOOST_TEST(pi
.length
== 3);
49 pi
= parse("a ", alpha_p
|| ('.' >> digit_p
));
51 BOOST_TEST(pi
.length
== 1);
53 pi
= parse(".1 ", alpha_p
|| ('.' >> digit_p
));
55 BOOST_TEST(pi
.length
== 2);
57 pi
= parse("1.a ", alpha_p
|| ('.' >> digit_p
));
60 pi
= parse("abcdefghij", +xdigit_p
& +alpha_p
);
62 BOOST_TEST(pi
.length
== 6);
64 pi
= parse("abcdefghij", +alpha_p
& +xdigit_p
);
67 pi
= parse("abcdefghij", +digit_p
& +alpha_p
);
70 pi
= parse("abcdefghij", +alpha_p
& +digit_p
);
73 // Test for bug reported by Yusaku Sugai here:
74 // http://article.gmane.org/gmane.comp.parsers.spirit.general/8544
75 pi
= parse( "foo", (anychar_p
& anychar_p
), ch_p(' ') );
78 pi
= parse("F", xdigit_p
- range_p('5','8'));
80 BOOST_TEST(pi
.length
== 1);
82 pi
= parse("0", xdigit_p
- range_p('5','8'));
84 BOOST_TEST(pi
.length
== 1);
86 pi
= parse("4", xdigit_p
- range_p('5','8'));
88 BOOST_TEST(pi
.length
== 1);
90 pi
= parse("9", xdigit_p
- range_p('5','8'));
92 BOOST_TEST(pi
.length
== 1);
94 pi
= parse("5", xdigit_p
- range_p('5','8'));
97 pi
= parse("7", xdigit_p
- range_p('5','8'));
100 pi
= parse("x*/", anychar_p
- "*/");
102 BOOST_TEST(pi
.length
== 1);
104 pi
= parse("*/", anychar_p
- "*/");
107 pi
= parse("switcher ", str_p("switcher") - "switch");
109 BOOST_TEST(pi
.length
== 8);
111 pi
= parse("Z", alpha_p
^ xdigit_p
);
113 BOOST_TEST(pi
.length
== 1);
115 pi
= parse("1", alpha_p
^ xdigit_p
);
117 BOOST_TEST(pi
.length
== 1);
119 pi
= parse("B", alpha_p
^ xdigit_p
);
122 pi
= parse("B", !alpha_p
);
124 BOOST_TEST(pi
.length
== 1);
126 pi
= parse("1", !alpha_p
);
128 BOOST_TEST(pi
.length
== 0);
129 BOOST_TEST(*pi
.stop
== '1');
131 pi
= parse("1234 5678 1234 5678", *(+digit_p
>> *space_p
));
134 BOOST_TEST(pi
.length
== 19);
135 BOOST_TEST(*pi
.stop
== 0);
137 pi
= parse("abcdefghijklmnopqrstuvwxyz123", *alpha_p
);
139 BOOST_TEST(pi
.length
== 26);
141 pi
= parse("1234+5678*1234/5678", +digit_p
% (ch_p('+') | '*' | '/'));
144 BOOST_TEST(pi
.length
== 19);
145 BOOST_TEST(*pi
.stop
== 0);
147 pi
= parse("1234+", +digit_p
% '+');
149 BOOST_TEST(!pi
.full
);
150 BOOST_TEST(pi
.length
== 4);
153 ///////////////////////////////////////////////////////////////////////////////
157 ///////////////////////////////////////////////////////////////////////////////
162 return boost::report_errors();