1 // Copyright (c) 2001-2010 Hartmut Kaiser
2 // Copyright (c) 2010 Head Geek
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)
8 #include <boost/detail/lightweight_test.hpp>
9 #include <boost/spirit/include/qi.hpp>
11 namespace qi
= boost::spirit::qi
;
17 typedef qi::rule
<std::string::const_iterator
, std::string()> strrule_type
;
19 void test(const std::string input
, strrule_type rule
, std::string result
)
22 std::string::const_iterator i
= input
.begin(), ie
= input
.end();
24 BOOST_TEST(qi::parse(i
, ie
, rule
, target
) && target
== result
);
29 strrule_type obsolete_year
=
30 omit
[-qi::char_(" \t")] >>
31 repeat(2)[qi::digit
] >>
32 omit
[-qi::char_(" \t")];
33 strrule_type correct_year
= repeat(4)[qi::digit
];
35 test("1776", qi::hold
[correct_year
] | repeat(2)[qi::digit
], "1776");
36 test("76", obsolete_year
, "76");
37 test("76", qi::hold
[obsolete_year
] | correct_year
, "76");
38 test(" 76", qi::hold
[correct_year
] | obsolete_year
, "76");
39 test("76", qi::hold
[correct_year
] | obsolete_year
, "76");
40 test("76", qi::hold
[correct_year
] | repeat(2)[qi::digit
], "76");
42 return boost::report_errors();