1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // test_skip.hpp |
3 | // |
4 | // Copyright 2008 Eric Niebler. Distributed under the Boost |
5 | // Software License, Version 1.0. (See accompanying file |
6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
7 | |
8 | #include <map> |
9 | #include <iostream> |
10 | #include <boost/xpressive/xpressive.hpp> |
11 | #include <boost/xpressive/regex_actions.hpp> |
12 | #include <boost/test/unit_test.hpp> |
13 | |
14 | using namespace boost::unit_test; |
15 | using namespace boost::xpressive; |
16 | |
17 | void test1() |
18 | { |
19 | std::string s = "a a b b c c" ; |
20 | |
21 | sregex rx = |
22 | "a a" >> |
23 | skip(skip: _s) |
24 | ( |
25 | (s1= as_xpr('b')) >> |
26 | as_xpr('b') >> |
27 | *as_xpr('c') // causes backtracking |
28 | ) >> |
29 | "c c" ; |
30 | |
31 | smatch what; |
32 | BOOST_CHECK( regex_match(s, what, rx) ); |
33 | |
34 | s = "123,456,789" ; |
35 | sregex rx2 = skip(skip: ',')(+_d); |
36 | BOOST_CHECK( regex_match(s, what, rx2) ); |
37 | |
38 | s = "foo" ; |
39 | sregex rx3 = skip(skip: _s)(after(expr: "fo" ) >> 'o'); |
40 | BOOST_CHECK( regex_search(s, what, rx3) ); |
41 | } |
42 | |
43 | template<typename Expr> |
44 | void test_skip_aux(Expr const &expr) |
45 | { |
46 | sregex rx = skip(skip: _s)(expr); |
47 | } |
48 | |
49 | void test_skip() |
50 | { |
51 | int i=0; |
52 | std::map<std::string, int> syms; |
53 | std::locale loc; |
54 | |
55 | test_skip_aux( expr: 'a' ); |
56 | test_skip_aux( expr: _ ); |
57 | test_skip_aux( expr: +_ ); |
58 | test_skip_aux( expr: -+_ ); |
59 | test_skip_aux( expr: !_ ); |
60 | test_skip_aux( expr: -!_ ); |
61 | test_skip_aux( expr: repeat<0,42>(expr: _) ); |
62 | test_skip_aux( expr: -repeat<0,42>(expr: _) ); |
63 | test_skip_aux( expr: _ >> 'a' ); |
64 | test_skip_aux( expr: _ >> 'a' | _ ); |
65 | test_skip_aux( expr: _ >> 'a' | _ >> 'b' ); |
66 | test_skip_aux( expr: s1= _ >> 'a' | _ >> 'b' ); |
67 | test_skip_aux( expr: icase(_ >> 'a' | _ >> 'b') ); |
68 | test_skip_aux( expr: imbue(loc)(_ >> 'a' | _ >> 'b') ); |
69 | test_skip_aux( expr: (set='a') ); |
70 | test_skip_aux( expr: (set='a','b') ); |
71 | test_skip_aux( expr: ~(set='a') ); |
72 | test_skip_aux( expr: ~(set='a','b') ); |
73 | test_skip_aux( expr: range(ch_min: 'a',ch_max: 'b') ); |
74 | test_skip_aux( expr: ~range(ch_min: 'a',ch_max: 'b') ); |
75 | test_skip_aux( expr: set['a' | alpha] ); |
76 | test_skip_aux( expr: ~set['a' | alpha] ); |
77 | test_skip_aux( expr: before(expr: _) ); |
78 | test_skip_aux( expr: ~before(expr: _) ); |
79 | test_skip_aux( expr: after(expr: _) ); |
80 | test_skip_aux( expr: ~after(expr: _) ); |
81 | test_skip_aux( expr: keep(expr: *_) ); |
82 | test_skip_aux( expr: (*_)[ref(t&: i) = as<int>(a: _) + 1] ); |
83 | test_skip_aux( expr: (a1= syms)[ref(t&: i) = a1 + 1] ); |
84 | } |
85 | |
86 | /////////////////////////////////////////////////////////////////////////////// |
87 | // init_unit_test_suite |
88 | // |
89 | test_suite* init_unit_test_suite( int argc, char* argv[] ) |
90 | { |
91 | test_suite *test = BOOST_TEST_SUITE("test skip()" ); |
92 | |
93 | test->add(BOOST_TEST_CASE(&test1)); |
94 | |
95 | return test; |
96 | } |
97 | |