]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/classic/test/epsilon_tests.cpp
1 /*=============================================================================
2 Copyright (c) 2002-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 =============================================================================*/
12 // This test program only includes the epsilon.hpp header from Spirit
13 #include <boost/spirit/include/classic_epsilon.hpp>
14 #include "impl/var.hpp"
15 #include "impl/string_length.hpp"
17 #include <boost/core/lightweight_test.hpp>
20 static BOOST_SPIRIT_CLASSIC_NS::parse_info
<char const *> pi
;
22 ////////////////////////////////////////////////
23 // These macros are used with BOOST_TEST
24 #define matches (pi.hit)
25 #define full_match (pi.hit && pi.full)
26 #define partial_match (pi.hit && !pi.full)
27 #define no_match (!pi.hit && !pi.full)
28 #define zero_length_match (pi.length == 0)
29 #define stop_equals_start (pi.stop == s)
31 template<typename ParserT
>
33 parse(char const *s
, ParserT
const &p
, bool match
)
36 pi
= BOOST_SPIRIT_CLASSIC_NS::parse(s
, s
+ test_impl::string_length(s
), p
);
40 BOOST_TEST(zero_length_match
);
41 BOOST_TEST(stop_equals_start
);
49 static char const empty
[] = "";
50 static char const not_empty
[] = "asdfgh";
52 ////////////////////////////////////////////////
53 // Test wether epsilon_p/eps_p work as
56 epsilon_as_primitive()
58 // This test case also is a compile time check wether
59 // both eps_p and epsilon_p are present.
61 parse(empty
, BOOST_SPIRIT_CLASSIC_NS::epsilon_p
, true);
62 BOOST_TEST(full_match
);
63 parse(not_empty
, BOOST_SPIRIT_CLASSIC_NS::epsilon_p
, true);
64 BOOST_TEST(partial_match
);
66 parse(empty
, BOOST_SPIRIT_CLASSIC_NS::eps_p
, true);
67 BOOST_TEST(full_match
);
68 parse(not_empty
, BOOST_SPIRIT_CLASSIC_NS::eps_p
, true);
69 BOOST_TEST(partial_match
);
72 ////////////////////////////////////////////////
73 // Test wether epsilon_p/eps_p work correctly as
74 // a parser generator for creating parsers from
77 epsilon_as_parser_generator_for_functors()
80 parse(empty
, BOOST_SPIRIT_CLASSIC_NS::epsilon_p(var(flag
)), flag
);
84 parse(empty
, BOOST_SPIRIT_CLASSIC_NS::epsilon_p(var(flag
)), flag
);
85 BOOST_TEST(full_match
);
88 ////////////////////////////////////////////////
89 // Test wether epsilon_p/eps_p work correctly as
90 // a parser generator for creating parsers from
93 epsilon_as_parser_generator_for_parsers()
95 // This test case uses a parser created by epsilon_p
96 // as body-parser for another invokation of epsilon_p
99 parse(empty
, BOOST_SPIRIT_CLASSIC_NS::epsilon_p(
100 BOOST_SPIRIT_CLASSIC_NS::epsilon_p(var(flag
))), flag
);
101 BOOST_TEST(no_match
);
104 parse(empty
, BOOST_SPIRIT_CLASSIC_NS::epsilon_p(
105 BOOST_SPIRIT_CLASSIC_NS::epsilon_p(var(flag
))), flag
);
106 BOOST_TEST(full_match
);
109 ////////////////////////////////////////////////
110 // Test wether epsilon_p/eps_p support negation
112 negation_operator_for_epsilon()
115 parse(empty
, ~BOOST_SPIRIT_CLASSIC_NS::epsilon_p(var(flag
)), !flag
);
116 BOOST_TEST(full_match
);
117 parse(empty
, ~~BOOST_SPIRIT_CLASSIC_NS::epsilon_p(var(flag
)), flag
);
118 BOOST_TEST(no_match
);
121 parse(empty
, ~BOOST_SPIRIT_CLASSIC_NS::epsilon_p(var(flag
)), !flag
);
122 BOOST_TEST(no_match
);
123 parse(empty
, ~~BOOST_SPIRIT_CLASSIC_NS::epsilon_p(var(flag
)), flag
);
124 BOOST_TEST(full_match
);
130 epsilon_as_primitive();
131 epsilon_as_parser_generator_for_functors();
132 epsilon_as_parser_generator_for_parsers();
133 negation_operator_for_epsilon();
135 return boost::report_errors();