• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2011 Jamboree
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 
9 #include <vector>
10 
11 #include <boost/config/warning_disable.hpp>
12 #include <boost/detail/lightweight_test.hpp>
13 
14 #include <boost/spirit/include/qi_parse.hpp>
15 #include <boost/spirit/include/qi_char.hpp>
16 #include <boost/spirit/include/qi_string.hpp>
17 #include <boost/spirit/include/qi_int.hpp>
18 #include <boost/spirit/include/qi_sequence.hpp>
19 #include <boost/spirit/include/qi_plus.hpp>
20 #include <boost/spirit/include/qi_eoi.hpp>
21 #include <boost/spirit/include/qi_action.hpp>
22 
23 #include <boost/spirit/include/phoenix_core.hpp>
24 #include <boost/spirit/include/phoenix_operator.hpp>
25 
26 #include <boost/spirit/repository/include/qi_seek.hpp>
27 
28 #include "test.hpp"
29 
30 
31 ///////////////////////////////////////////////////////////////////////////////
main()32 int main()
33 {
34     using namespace spirit_test;
35     namespace qi = boost::spirit::qi;
36     namespace phx = boost::phoenix;
37     using boost::spirit::repository::qi::seek;
38     using boost::spirit::standard::space;
39 
40     // test eoi
41     {
42         using qi::eoi;
43 
44         BOOST_TEST(test("", seek[eoi]));
45         BOOST_TEST(test(" ", seek[eoi], space));
46         BOOST_TEST(test("a", seek[eoi]));
47         BOOST_TEST(test(" a", seek[eoi], space));
48     }
49 
50     // test literal finding
51     {
52         using qi::int_;
53         using qi::char_;
54 
55         int i = 0;
56 
57         BOOST_TEST(
58             test_attr("!@#$%^&*KEY:123", seek["KEY:"] >> int_, i)
59             && i == 123
60         );
61     }
62 
63     // test sequence finding
64     {
65         using qi::int_;
66         using qi::lit;
67 
68         int i = 0;
69 
70         BOOST_TEST(
71             test_attr("!@#$%^&* KEY : 123", seek[lit("KEY") >> ':'] >> int_, i, space)
72             && i == 123
73         );
74     }
75 
76     // test attr finding
77     {
78         using qi::int_;
79 
80         std::vector<int> v;
81 
82         BOOST_TEST( // expect partial match
83             test_attr("a06b78c3d", +seek[int_], v, false)
84             && v[0] == 6 && v[1] == 78 && v[2] == 3
85         );
86     }
87 
88     // test action
89     {
90         using phx::ref;
91 
92         bool b = false;
93 
94         BOOST_TEST( // expect partial match
95             test("abcdefg", seek["def"][ref(b) = true], false)
96             && b
97         );
98     }
99 
100     return boost::report_errors();
101 }
102