]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/spirit/test/qi/regression_repeat.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / spirit / test / qi / regression_repeat.cpp
CommitLineData
7c673cae
FG
1// Copyright (c) 2001-2010 Hartmut Kaiser
2// Copyright (c) 2010 Head Geek
3//
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 <iostream>
8#include <boost/detail/lightweight_test.hpp>
9#include <boost/spirit/include/qi.hpp>
10
11namespace qi = boost::spirit::qi;
12using qi::omit;
13using qi::repeat;
14using std::cout;
15using std::endl;
16
17typedef qi::rule<std::string::const_iterator, std::string()> strrule_type;
18
19void test(const std::string input, strrule_type rule, std::string result)
20{
21 std::string target;
22 std::string::const_iterator i = input.begin(), ie = input.end();
23
24 BOOST_TEST(qi::parse(i, ie, rule, target) && target == result);
25}
26
27int main()
28{
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];
34
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");
41
42 return boost::report_errors();
43}
44