• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2001-2011 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/include/qi_char.hpp>
9 #include <boost/spirit/include/qi_directive.hpp>
10 #include <boost/spirit/include/qi_operator.hpp>
11 #include <boost/spirit/include/phoenix_core.hpp>
12 
13 #include <iostream>
14 #include "test.hpp"
15 
16 int
main()17 main()
18 {
19     using spirit_test::test;
20     using spirit_test::test_attr;
21     using boost::spirit::qi::skip;
22     using boost::spirit::qi::lexeme;
23     using boost::spirit::qi::lit;
24     using boost::spirit::ascii::char_;
25     using boost::spirit::ascii::space;
26     using boost::spirit::ascii::alpha;
27 
28     {
29         BOOST_TEST((test("a b c d", skip(space)[*char_])));
30     }
31 
32     { // test attribute
33         std::string s;
34         BOOST_TEST((test_attr("a b c d", skip(space)[*char_], s)));
35         BOOST_TEST(s == "abcd");
36     }
37 
38     { // reskip
39         BOOST_TEST((test("ab c d", lexeme[lit('a') >> 'b' >> skip[lit('c') >> 'd']], space)));
40         BOOST_TEST((test("abcd", lexeme[lit('a') >> 'b' >> skip[lit('c') >> 'd']], space)));
41         BOOST_TEST(!(test("a bcd", lexeme[lit('a') >> 'b' >> skip[lit('c') >> 'd']], space)));
42 
43         BOOST_TEST((test("ab c d", lexeme[lexeme[lit('a') >> 'b' >> skip[lit('c') >> 'd']]], space)));
44         BOOST_TEST((test("abcd", lexeme[lexeme[lit('a') >> 'b' >> skip[lit('c') >> 'd']]], space)));
45         BOOST_TEST(!(test("a bcd", lexeme[lexeme[lit('a') >> 'b' >> skip[lit('c') >> 'd']]], space)));
46     }
47 
48     { // lazy skip
49         using boost::phoenix::val;
50 
51         BOOST_TEST((test("a b c d", skip(val(space))[*char_])));
52     }
53 
54     return boost::report_errors();
55 }
56