]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/x3/seek.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / spirit / test / x3 / seek.cpp
1 /*//////////////////////////////////////////////////////////////////////////////
2 Copyright (c) 2011 Jamboree
3 Copyright (c) 2014 Lee Clagett
4
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 //////////////////////////////////////////////////////////////////////////////*/
8 #include <vector>
9
10 #include <boost/spirit/home/x3/auxiliary/eoi.hpp>
11 #include <boost/spirit/home/x3/core.hpp>
12 #include <boost/spirit/home/x3/char.hpp>
13 #include <boost/spirit/home/x3/string.hpp>
14 #include <boost/spirit/home/x3/numeric.hpp>
15 #include <boost/spirit/home/x3/operator/plus.hpp>
16 #include <boost/spirit/home/x3/operator/sequence.hpp>
17
18 #include <boost/spirit/home/x3/directive/seek.hpp>
19
20 #include "test.hpp"
21
22
23 ///////////////////////////////////////////////////////////////////////////////
24 int main()
25 {
26 using namespace spirit_test;
27 namespace x3 = boost::spirit::x3;
28
29 BOOST_SPIRIT_ASSERT_CONSTEXPR_CTORS(x3::seek['x']);
30
31 // test eoi
32 {
33 BOOST_TEST(test("", x3::seek[x3::eoi]));
34 BOOST_TEST(test(" ", x3::seek[x3::eoi], x3::space));
35 BOOST_TEST(test("a", x3::seek[x3::eoi]));
36 BOOST_TEST(test(" a", x3::seek[x3::eoi], x3::space));
37 }
38
39 // test literal finding
40 {
41 int i = 0;
42
43 BOOST_TEST(
44 test_attr("!@#$%^&*KEY:123", x3::seek["KEY:"] >> x3::int_, i)
45 && i == 123
46 );
47 }
48 // test sequence finding
49 {
50 int i = 0;
51
52 BOOST_TEST(
53 test_attr("!@#$%^&* KEY : 123", x3::seek[x3::lit("KEY") >> ':'] >> x3::int_, i, x3::space)
54 && i == 123
55 );
56 }
57
58 // test attr finding
59 {
60 std::vector<int> v;
61
62 BOOST_TEST( // expect partial match
63 test_attr("a06b78c3d", +x3::seek[x3::int_], v, false)
64 && v.size() == 3 && v[0] == 6 && v[1] == 78 && v[2] == 3
65 );
66 }
67
68 // test action
69 {
70
71 bool b = false;
72 auto const action = [&b]() { b = true; };
73
74 BOOST_TEST( // expect partial match
75 test("abcdefg", x3::seek["def"][action], false)
76 && b
77 );
78 }
79
80 // test container
81 {
82 std::vector<int> v;
83
84 BOOST_TEST(
85 test_attr("abcInt:100Int:95Int:44", x3::seek[+("Int:" >> x3::int_)], v)
86 && v.size() == 3 && v[0] == 100 && v[1] == 95 && v[2] == 44
87 );
88 }
89
90 // test failure rollback
91 {
92 BOOST_TEST(test_failure("abcdefg", x3::seek[x3::int_]));
93 }
94
95 // past the end regression GH#658
96 BOOST_TEST(!test(" ", x3::seek['x'], x3::space));
97
98 return boost::report_errors();
99 }