]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/spirit/test/x3/rule1.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / spirit / test / x3 / rule1.cpp
CommitLineData
7c673cae
FG
1/*=============================================================================
2 Copyright (c) 2001-2015 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
7c673cae
FG
8#include <boost/detail/lightweight_test.hpp>
9#include <boost/spirit/home/x3.hpp>
10
11#include <string>
12#include <cstring>
13#include <iostream>
14#include "test.hpp"
15
16int
17main()
18{
19 using spirit_test::test_attr;
20 using spirit_test::test;
21
22 using namespace boost::spirit::x3::ascii;
23 using boost::spirit::x3::rule;
7c673cae 24 using boost::spirit::x3::lit;
92f5a8d4 25 using boost::spirit::x3::int_;
7c673cae
FG
26 using boost::spirit::x3::unused_type;
27 using boost::spirit::x3::phrase_parse;
28 using boost::spirit::x3::skip_flag;
92f5a8d4
TL
29 using boost::spirit::x3::traits::has_attribute;
30
31 // check attribute advertising
32 static_assert( has_attribute<rule<class r, int>, /*Context=*/unused_type>::value, "");
33 static_assert(!has_attribute<rule<class r >, /*Context=*/unused_type>::value, "");
34 static_assert( has_attribute<decltype(rule<class r, int>{} = int_), /*Context=*/unused_type>::value, "");
35 static_assert(!has_attribute<decltype(rule<class r >{} = int_), /*Context=*/unused_type>::value, "");
36
7c673cae
FG
37
38 { // basic tests
39
40 auto a = lit('a');
41 auto b = lit('b');
42 auto c = lit('c');
43 rule<class r> r;
44
45 {
46 auto start =
47 r = *(a | b | c);
48
49 BOOST_TEST(test("abcabcacb", start));
50 }
51
52 {
53 auto start =
54 r = (a | b) >> (r | b);
55
56 BOOST_TEST(test("aaaabababaaabbb", start));
57 BOOST_TEST(test("aaaabababaaabba", start, false));
58
59 // ignore the skipper!
60 BOOST_TEST(test("aaaabababaaabba", start, space, false));
61 }
62 }
63
64 { // basic tests w/ skipper
65
66 auto a = lit('a');
67 auto b = lit('b');
68 auto c = lit('c');
69 rule<class r> r;
70
71 {
72 auto start =
73 r = *(a | b | c);
74
75 BOOST_TEST(test(" a b c a b c a c b ", start, space));
76 }
77
78 {
79 auto start =
80 r = (a | b) >> (r | b);
81
82 BOOST_TEST(test(" a a a a b a b a b a a a b b b ", start, space));
83 BOOST_TEST(test(" a a a a b a b a b a a a b b a ", start, space, false));
84 }
85 }
86
87 { // basic tests w/ skipper but no final post-skip
88
89 auto a = rule<class a>()
90 = lit('a');
91
92 auto b = rule<class b>()
93 = lit('b');
94
95 auto c = rule<class c>()
96 = lit('c');
97
98 {
99 auto start = rule<class start>() = *(a | b) >> c;
100
101 char const *s1 = " a b a a b b a c ... "
102 , *const e1 = s1 + std::strlen(s1);
103 BOOST_TEST(phrase_parse(s1, e1, start, space, skip_flag::dont_post_skip)
104 && s1 == e1 - 5);
105
106 }
107
108 {
109 rule<class start> start;
110
111 auto p =
112 start = (a | b) >> (start | c);
113 {
114 char const *s1 = " a a a a b a b a b a a a b b b c "
115 , *const e1 = s1 + std::strlen(s1);
116 BOOST_TEST(phrase_parse(s1, e1, p, space, skip_flag::post_skip)
117 && s1 == e1);
118 }
119 {
120 char const *s1 = " a a a a b a b a b a a a b b b c "
121 , *const e1 = s1 + std::strlen(s1);
122 BOOST_TEST(phrase_parse(s1, e1, p, space, skip_flag::dont_post_skip)
123 && s1 == e1 - 1);
124 }
125 }
126 }
127
128 return boost::report_errors();
129}