]>
Commit | Line | Data |
---|---|---|
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 | ||
8 | // this file deliberately contains non-ascii characters | |
9 | // boostinspect:noascii | |
10 | ||
11 | #include <boost/detail/lightweight_test.hpp> | |
12 | #include <boost/spirit/home/x3.hpp> | |
13 | ||
14 | #include <string> | |
15 | #include <cstring> | |
16 | #include <iostream> | |
17 | #include "test.hpp" | |
18 | ||
19 | int | |
20 | main() | |
21 | { | |
22 | using spirit_test::test_attr; | |
23 | using spirit_test::test; | |
24 | ||
25 | using namespace boost::spirit::x3::ascii; | |
26 | using boost::spirit::x3::rule; | |
27 | using boost::spirit::x3::int_; | |
28 | using boost::spirit::x3::lit; | |
29 | using boost::spirit::x3::unused_type; | |
30 | using boost::spirit::x3::phrase_parse; | |
31 | using boost::spirit::x3::skip_flag; | |
32 | ||
33 | { // basic tests | |
34 | ||
35 | auto a = lit('a'); | |
36 | auto b = lit('b'); | |
37 | auto c = lit('c'); | |
38 | rule<class r> r; | |
39 | ||
40 | { | |
41 | auto start = | |
42 | r = *(a | b | c); | |
43 | ||
44 | BOOST_TEST(test("abcabcacb", start)); | |
45 | } | |
46 | ||
47 | { | |
48 | auto start = | |
49 | r = (a | b) >> (r | b); | |
50 | ||
51 | BOOST_TEST(test("aaaabababaaabbb", start)); | |
52 | BOOST_TEST(test("aaaabababaaabba", start, false)); | |
53 | ||
54 | // ignore the skipper! | |
55 | BOOST_TEST(test("aaaabababaaabba", start, space, false)); | |
56 | } | |
57 | } | |
58 | ||
59 | { // basic tests w/ skipper | |
60 | ||
61 | auto a = lit('a'); | |
62 | auto b = lit('b'); | |
63 | auto c = lit('c'); | |
64 | rule<class r> r; | |
65 | ||
66 | { | |
67 | auto start = | |
68 | r = *(a | b | c); | |
69 | ||
70 | BOOST_TEST(test(" a b c a b c a c b ", start, space)); | |
71 | } | |
72 | ||
73 | { | |
74 | auto start = | |
75 | r = (a | b) >> (r | b); | |
76 | ||
77 | BOOST_TEST(test(" a a a a b a b a b a a a b b b ", start, space)); | |
78 | BOOST_TEST(test(" a a a a b a b a b a a a b b a ", start, space, false)); | |
79 | } | |
80 | } | |
81 | ||
82 | { // basic tests w/ skipper but no final post-skip | |
83 | ||
84 | auto a = rule<class a>() | |
85 | = lit('a'); | |
86 | ||
87 | auto b = rule<class b>() | |
88 | = lit('b'); | |
89 | ||
90 | auto c = rule<class c>() | |
91 | = lit('c'); | |
92 | ||
93 | { | |
94 | auto start = rule<class start>() = *(a | b) >> c; | |
95 | ||
96 | char const *s1 = " a b a a b b a c ... " | |
97 | , *const e1 = s1 + std::strlen(s1); | |
98 | BOOST_TEST(phrase_parse(s1, e1, start, space, skip_flag::dont_post_skip) | |
99 | && s1 == e1 - 5); | |
100 | ||
101 | } | |
102 | ||
103 | { | |
104 | rule<class start> start; | |
105 | ||
106 | auto p = | |
107 | start = (a | b) >> (start | c); | |
108 | { | |
109 | char const *s1 = " a a a a b a b a b a a a b b b c " | |
110 | , *const e1 = s1 + std::strlen(s1); | |
111 | BOOST_TEST(phrase_parse(s1, e1, p, space, skip_flag::post_skip) | |
112 | && s1 == e1); | |
113 | } | |
114 | { | |
115 | char const *s1 = " a a a a b a b a b a a a b b b c " | |
116 | , *const e1 = s1 + std::strlen(s1); | |
117 | BOOST_TEST(phrase_parse(s1, e1, p, space, skip_flag::dont_post_skip) | |
118 | && s1 == e1 - 1); | |
119 | } | |
120 | } | |
121 | } | |
122 | ||
123 | return boost::report_errors(); | |
124 | } |