]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/spirit/test/x3/raw.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / spirit / test / x3 / raw.cpp
CommitLineData
7c673cae
FG
1/*=============================================================================
2 Copyright (c) 2001-2014 Joel de Guzman
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 <boost/detail/lightweight_test.hpp>
8#include <boost/spirit/home/x3.hpp>
92f5a8d4 9#include <boost/fusion/include/std_pair.hpp>
7c673cae
FG
10
11#include <iostream>
12#include <string>
13#include "test.hpp"
14
15int main()
16{
17 using spirit_test::test;
18 using spirit_test::test_attr;
19 using namespace boost::spirit::x3::ascii;
20 using boost::spirit::x3::raw;
21 using boost::spirit::x3::eps;
11fdf7f2 22 using boost::spirit::x3::lit;
7c673cae 23 using boost::spirit::x3::_attr;
92f5a8d4
TL
24 using boost::spirit::x3::parse;
25 using boost::spirit::x3::int_;
26 using boost::spirit::x3::char_;
7c673cae
FG
27
28 {
29 boost::iterator_range<char const*> range;
30 std::string str;
31 BOOST_TEST((test_attr("spirit_test_123", raw[alpha >> *(alnum | '_')], range)));
32 BOOST_TEST((std::string(range.begin(), range.end()) == "spirit_test_123"));
33 BOOST_TEST((test_attr(" spirit", raw[*alpha], range, space)));
34 BOOST_TEST((range.size() == 6));
35 }
36
37 {
38 std::string str;
39 BOOST_TEST((test_attr("spirit_test_123", raw[alpha >> *(alnum | '_')], str)));
40 BOOST_TEST((str == "spirit_test_123"));
41 }
42
43 {
44 boost::iterator_range<char const*> range;
45 BOOST_TEST((test("x", raw[alpha])));
46 BOOST_TEST((test_attr("x", raw[alpha], range)));
47 }
48
49 {
50 boost::iterator_range<char const*> range;
51 BOOST_TEST((test("x", raw[alpha][ ([&](auto& ctx){ range = _attr(ctx); }) ])));
52 BOOST_TEST(range.size() == 1 && *range.begin() == 'x');
53 }
54
11fdf7f2
TL
55 {
56 boost::iterator_range<char const*> range;
57 BOOST_TEST((test("x123x", lit('x') >> raw[+digit] >> lit('x'))));
58 BOOST_TEST((test_attr("x123x", lit('x') >> raw[+digit] >> lit('x'), range)));
59 BOOST_TEST((std::string(range.begin(), range.end()) == "123"));
60 }
61
92f5a8d4
TL
62 {
63 using range = boost::iterator_range<std::string::iterator>;
64 boost::variant<int, range> attr;
65
66 std::string str("test");
67 parse(str.begin(), str.end(), (int_ | raw[*char_]), attr);
68
69 auto rng = boost::get<range>(attr);
70 BOOST_TEST(std::string(rng.begin(), rng.end()) == "test");
71 }
72
73 {
74 std::vector<boost::iterator_range<std::string::iterator>> attr;
75 std::string str("123abcd");
76 parse(str.begin(), str.end()
77 , (raw[int_] >> raw[*char_])
78 , attr
79 );
80 BOOST_TEST(attr.size() == 2);
81 BOOST_TEST(std::string(attr[0].begin(), attr[0].end()) == "123");
82 BOOST_TEST(std::string(attr[1].begin(), attr[1].end()) == "abcd");
83 }
84
85 {
86 std::pair<int, boost::iterator_range<std::string::iterator>> attr;
87 std::string str("123abcd");
88 parse(str.begin(), str.end()
89 , (int_ >> raw[*char_])
90 , attr
91 );
92 BOOST_TEST(attr.first == 123);
93 BOOST_TEST(std::string(attr.second.begin(), attr.second.end()) == "abcd");
94 }
95
7c673cae
FG
96 return boost::report_errors();
97}