]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/test/x3/seek.cpp
1 /*//////////////////////////////////////////////////////////////////////////////
2 Copyright (c) 2011 Jamboree
3 Copyright (c) 2014 Lee Clagett
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 //////////////////////////////////////////////////////////////////////////////*/
10 #include <boost/detail/lightweight_test.hpp>
11 #include <boost/spirit/home/x3/auxiliary/eoi.hpp>
12 #include <boost/spirit/home/x3/core.hpp>
13 #include <boost/spirit/home/x3/char.hpp>
14 #include <boost/spirit/home/x3/string.hpp>
15 #include <boost/spirit/home/x3/numeric.hpp>
16 #include <boost/spirit/home/x3/operator/plus.hpp>
17 #include <boost/spirit/home/x3/operator/sequence.hpp>
19 #include <boost/spirit/home/x3/directive/seek.hpp>
24 ///////////////////////////////////////////////////////////////////////////////
27 using namespace spirit_test
;
28 namespace x3
= boost::spirit::x3
;
32 BOOST_TEST(test("", x3::seek
[x3::eoi
]));
33 BOOST_TEST(test(" ", x3::seek
[x3::eoi
], x3::space
));
34 BOOST_TEST(test("a", x3::seek
[x3::eoi
]));
35 BOOST_TEST(test(" a", x3::seek
[x3::eoi
], x3::space
));
38 // test literal finding
43 test_attr("!@#$%^&*KEY:123", x3::seek
["KEY:"] >> x3::int_
, i
)
47 // test sequence finding
52 test_attr("!@#$%^&* KEY : 123", x3::seek
[x3::lit("KEY") >> ':'] >> x3::int_
, i
, x3::space
)
61 BOOST_TEST( // expect partial match
62 test_attr("a06b78c3d", +x3::seek
[x3::int_
], v
, false)
63 && v
.size() == 3 && v
[0] == 6 && v
[1] == 78 && v
[2] == 3
71 auto const action
= [&b
]() { b
= true; };
73 BOOST_TEST( // expect partial match
74 test("abcdefg", x3::seek
["def"][action
], false)
84 test_attr("abcInt:100Int:95Int:44", x3::seek
[+("Int:" >> x3::int_
)], v
)
85 && v
.size() == 3 && v
[0] == 100 && v
[1] == 95 && v
[2] == 44
89 // test failure rollback
91 BOOST_TEST(test_failure("abcdefg", x3::seek
[x3::int_
]));
94 return boost::report_errors();